Advertisement

SDL mouse

Started by October 19, 2004 09:25 PM
6 comments, last by sand_man 19 years, 10 months ago
Can someone please give me an example of how to poll the mouse in SDL? I thought it would work the same as the keyboard but it isn't working for me.
I have a tutorial on my website. If you haven't tried that out yet, do that first.

If you have, try to be a little more specific.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Advertisement
There's a very good example in the SDL Docs, you know. That's how I learned how to do it. I'll post an example if you geniunely can't figure it out from PnP's [great] site and the docs...but try those, first.

It's all about try, fail, try, fail, get drunk, give up, and try.
Things change.
I did look in the SDL docs but obviously i didnt look hard enough
I'm reading PnP's tutorials now.
thanks guys

[edit]
Thanks to PnP Bios's tutorial I know how to use the mouse buttons. I've just spent another hour reading the SDL docs trying to understand how to find out where the mouse is when clicked.

i read this
typedef struct{  Uint8 type;  Uint8 button;  Uint8 state;  Uint16 x, y;} SDL_MouseButtonEvent;

"x, y The X/Y coordinates of the mouse at press/release time "

But all the nested structs and unions have confused me and I dont know how to access these variables.

[/edit]

[Edited by - sand_man on October 20, 2004 2:50:36 AM]
The SDL_Event structure contains a member of this type (SDL_MouseButtonEvent) called button.
So, to get the mouse coordinates you would use:
event.button.x or event.button.y
thanks AP
Advertisement
One more thing, if you're in windowed mode and you want to grab mouse coordinates JUST from the window, you can use
SDL_WM_GrabInput(SDL_GRAB_ON)
and the border of the window will be the limit of where you can move the mouse. If you do use this, make sure that it scales mouse x and y coordinates to the window size (I know it does this with xrel/yrel values).
Things change.
Thanks it's all working now.

This topic is closed to new replies.

Advertisement