diff options
author | jonas <himself@jonasgunz.de> | 2019-01-08 14:27:18 +0100 |
---|---|---|
committer | jonas <himself@jonasgunz.de> | 2019-01-08 14:27:18 +0100 |
commit | 75baef0cb96f65c500ac87cf71ebe5e05c0dae0d (patch) | |
tree | e0acfd121adc56578cbaf24d9cd7afeba2fc5150 /cObjectHandler.cpp | |
parent | 75a09cb6229b8c14ad180f05edf1b5402eed5299 (diff) | |
download | termgl-75baef0cb96f65c500ac87cf71ebe5e05c0dae0d.tar.gz |
cInputHandler now supplies cObject:onClick with click position relative to the objects origin
Diffstat (limited to 'cObjectHandler.cpp')
-rw-r--r-- | cObjectHandler.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/cObjectHandler.cpp b/cObjectHandler.cpp index 3b56e82..140aadd 100644 --- a/cObjectHandler.cpp +++ b/cObjectHandler.cpp @@ -81,8 +81,13 @@ int cObjectHandler::clickEvent(sPos _pos, unsigned int _button) if(objects[ iHitMap[_pos.x][_pos.y] ]) { + sPos rel_pos; + sPos obj_pos = objects[ iHitMap[_pos.x][_pos.y] ]->getPosition(); + rel_pos.x = _pos.x - obj_pos.x; + rel_pos.y = _pos.y - obj_pos.y; + iActiveObject = iHitMap[_pos.x][_pos.y]; //Set active object - objects[ iHitMap[_pos.x][_pos.y] ]->onClick(_pos, _button); + objects[ iHitMap[_pos.x][_pos.y] ]->onClick(rel_pos, _button); } else return 1; @@ -141,9 +146,9 @@ void cObjectHandler::buildHitmap() sPos oPos = objects[i]->getPosition(); sPos oSize = objects[i]->getSize(); - for(int x = oPos.x; x <= oPos.x + oSize.x; x++) + for(int x = oPos.x; x < oPos.x + oSize.x; x++) { - for(int y = oPos.y; y <= oPos.y + oSize.y; y++) + for(int y = oPos.y; y < oPos.y + oSize.y; y++) { if((x < size.x && y < size.y) && (x >= 0 && y >= 0)) //Objects can be outside the screen. iHitMap[x][y] = i; |