Check for clicks within an object

Writing this code that handles clicks with the left mouse button. But I want to be able to check for clicks within a 200x200 pixel area. Here's what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void EGame::OnLButtonDown(int mX, int mY) {
    int ID = mX / 200;
    ID = ID + ((mY / 200) * 3);

    if(grid[ID] != GRID_TYPE_NONE) {
        return;
    }

    if(currentplayer == 0) {
        SetCell(ID, GRID_TYPE_X);
        currentplayer = 1;
        Logger::Log("X player has moved.");
    }else{
        SetCell(ID, GRID_TYPE_O);
        currentplayer = 0;
        Logger::Log("O player has moved.");
    }
// Code that checks for clicks.

}


Using the width and height of the object, e.g; pX->w is width and pX->h is height
How would I check within the 200x200 area with mX and mY?
Last edited on
I'm not sure I understand correctly what is your question. Do you need the position inside your 200x200 cell? then I would replace lines 2 and 3 with
1
2
int idX=mX/200, idY=mY/200;
int ID=idX+3*idY;


and then after line 18,
1
2
3
int posX,posY;
posX=mX-idX*200;
posY=mY-idY*200;

@ats15

Sorry for not being clear, as the top code is fine. It's the comment line. mX and mY are the coords where the mouse clicks.
Topic archived. No new replies allowed.