aboutsummaryrefslogtreecommitdiff
path: root/cObjectHandler.cpp
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2019-01-08 14:27:18 +0100
committerGravatar jonas <himself@jonasgunz.de> 2019-01-08 14:27:18 +0100
commit75baef0cb96f65c500ac87cf71ebe5e05c0dae0d (patch)
treee0acfd121adc56578cbaf24d9cd7afeba2fc5150 /cObjectHandler.cpp
parent75a09cb6229b8c14ad180f05edf1b5402eed5299 (diff)
downloadtermgl-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.cpp11
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;