Working with the mouse

OK, I have basically no clue on mouse events using SDL.

Actually, I want to create a situation where you click on a button in a 2D scene.

What I assumed is that I need to know the top-left, top-right, bottom-left, and bottom-right coordinates of the button image. Apparently, I know all this. The thing is how do I get to find out if the left/right mouse button was clicked within these coordinates of the button image? I’ll need an example to be able to understand this.

Thanks.

Winner of the 2003 Internet Service Providers’ Association awards for Best Unmetered ISP and Best Consumer Application.

Sorry not an example.

Basicly you check in your event loop for mouse button events and then
check if that event occured inside one of your buttons.

for( i = 0; i < numOfButtons; i++ ) {
button = buttons[i];
if( mouseEvent.x >= button.x &&
mouseEvent.x < button.x + button.width &&
mouseEvent.y >= button.y &&
mouseEvent.y < button.y + button.height )
print(“Button: %s\n State: %d\n”,
button.name,
( button.state = !button.state ) );
}

Another alternative is to use button masks and check if the event
cordinates match with the button mask. This way one can make non
rectangle buttons and expect correct working.

One can even use whole screen mask and simply take the corresponding
cordinate value to know, which button was pressed. This will take only
width*height bytes of memory if under 256 buttons are required and thus
is not a big deal. Or if the buttons are in lower part of the screen
one can simply first check if the cordinate is on the gui part and then
take the relative position and check that against the gui part mask.On Saturday 05 July 2003 16:20, gpa at fsmail.net wrote:

OK, I have basically no clue on mouse events using SDL.

Actually, I want to create a situation where you click on a button in
a 2D scene.

What I assumed is that I need to know the top-left, top-right,
bottom-left, and bottom-right coordinates of the button image.
Apparently, I know all this. The thing is how do I get to find out if
the left/right mouse button was clicked within these coordinates of
the button image? I’ll need an example to be able to understand this.

Sadly, enough, the only SDL mouse function I know is SDL_GetMouseState9params)

Someone, please help. A tutorial will do.

NB: Cone3D’s GFX with SDL tutorial 5 - Clickomania, didn’t help

Winner of the 2003 Internet Service Providers’ Association awards for Best Unmetered ISP and Best Consumer Application.

maybe this will help
http://sdldoc.csn.ul.ie/sdlmousemotionevent.phpOn Sunday 06 July 2003 8:58 am, gpa at fsmail.net wrote:

Sadly, enough, the only SDL mouse function I know is
SDL_GetMouseState9params)

Someone, please help. A tutorial will do.

NB: Cone3D’s GFX with SDL tutorial 5 - Clickomania, didn’t help

  • Akin

Join Freeserve http://www.freeserve.com/time/

Winner of the 2003 Internet Service Providers’ Association awards for Best
Unmetered ISP and Best Consumer Application.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety. "
–Benjamin Franklin