How to use buttons

Hello,

I was trying to use an example for buttons on LazyFoo Production’s homepage,
but it was not explained very good.

Got anyone an example or a good tutorial for me?

Thanks,

P. Lorenz

Hello !

I was trying to use an example for buttons on LazyFoo Production’s
homepage,
but it was not explained very good.

Got anyone an example or a good tutorial for me?

Where is your problem ? Is it blitting the gfx for the
buttons or checking if the user pressed one ?

CU

Hi
Buttons are simple, Make a Global dest SDL_Rect for the button and blit
to the screen with that rect, on your mouse motion event check the mouse pos
is within the Rect, that will give you the mouse over. then on the mouse
down event again check if the mouse is within the Rect and then do what ever
action you require. my personal choice is to do the action on the mouse up
rather than the down.

its a simple collision check
if(MouseX>ButtonRect.x && MouseX<ButtonRect.x+ButtonRect.w && MouseY>
ButtonRect.y && MouseY<ButtonRect.y+ButtonRect.h)
{
//Do somthing
}

Trish x

my personal choice is to do the action on the mouse up
rather than the down.

And, of course, most common UIs only respond to mouse-up if you’re
still within the widget you mouse-downed in.

its a simple collision check
if(MouseX>ButtonRect.x && MouseX<ButtonRect.x+ButtonRect.w && MouseY>
ButtonRect.y && MouseY<ButtonRect.y+ButtonRect.h)
{
//Do somthing
}

MouseX >= ButtonRect.x … MouseY >= ButtonRect.y … would be better. :wink:

-bill!On Thu, Apr 05, 2007 at 11:16:33AM +0700, Patricia Curtis wrote:

my personal choice is to do the action on the mouse up
rather than the down.

And, of course, most common UIs only respond to mouse-up if you’re
still within the widget you mouse-downed in.

If you want complete UI example, I suggest you look at blender source
(this is full OpenGL).

RegardsOn Apr 5, 2007, at 5:49 PM, Bill Kendrick wrote:

On Thu, Apr 05, 2007 at 11:16:33AM +0700, Patricia Curtis wrote:


Kuon from japan.

“Your computer requests another OS, deny or allow?”

Blog:
http://arkhi.goyman.com/blojsom/blog/default/