From 75baef0cb96f65c500ac87cf71ebe5e05c0dae0d Mon Sep 17 00:00:00 2001 From: jonas Date: Tue, 8 Jan 2019 14:27:18 +0100 Subject: cInputHandler now supplies cObject:onClick with click position relative to the objects origin --- cObjectHandler.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'cObjectHandler.cpp') 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; -- cgit v1.2.3