diff options
-rw-r--r-- | cInput.cpp | 9 | ||||
-rw-r--r-- | cObject.h | 1 | ||||
-rw-r--r-- | cObjectHandler.cpp | 11 | ||||
-rw-r--r-- | testobject.h | 2 |
4 files changed, 13 insertions, 10 deletions
@@ -10,10 +10,6 @@ cInput::cInput() cfmakeraw (&raw); tcsetattr (STDIN_FILENO, TCSANOW, &raw); - // Switch to the alternate buffer screen - //write (STDOUT_FILENO, "\e[?47h", 6); - ///MOVED TO cRender - // Enable mouse tracking write (STDOUT_FILENO, "\e[?1000h", 8); } @@ -22,7 +18,6 @@ cInput::~cInput() { //revert changes to console write (STDOUT_FILENO, "\e[?1000l", 8); - //write (STDOUT_FILENO, "\e[?47l", 6); tcsetattr (STDIN_FILENO, TCSANOW, &original); } @@ -58,8 +53,8 @@ sInputEvent cInput::poll() if(buff[1] == 'M') //Mouse Event { ret.b = buff[2] - 32; - ret.x = buff[3] - 32; - ret.y = buff[4] - 32; + ret.x = buff[3] - 32 - 1; //Console sees origin at 1,1 + ret.y = buff[4] - 32 - 1; //Program at 0,0 ret.type = _EVENT_MOUSE; } else //e.g. Arrow Keys @@ -44,6 +44,7 @@ public: */ virtual void onClick(sPos _pos, unsigned int _button){} /** Called by cObjecthandler if cObject is active on keyboard input + * _pos decribes the relative position of mousepointer to origin of object */ virtual void onChar(unsigned char _c){} 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; diff --git a/testobject.h b/testobject.h index 1da8987..80882b7 100644 --- a/testobject.h +++ b/testobject.h @@ -24,6 +24,8 @@ public: { cc++; drawText(std::to_string(cc), {2,2}, _COL_RED); + + drawPoint('Q', _pos, true, _COL_YELLOW); } virtual void onChar(unsigned char _c) |