PDA

View Full Version : SDL.pas missing windowing events?!?



paul_nicholls
31-12-2011, 10:17 PM
Hi all,
I am trying to detect when the mouse enters/leaves my SDL window in my game "The Probe (http://www.pascalgamedevelopment.com/showthread.php?5877-The-Probe)" so I can show/hide my self-rendered mouse pointer.

I did some googling and found this site:
http://wiki.libsdl.org/moin.cgi/SDL_WindowEvent

Unfortunately, I don't have any of those window events defined in my copy of SDL.pas!

Any ideas?

cheers,
Paul

SilverWarior
31-12-2011, 10:53 PM
As far as I see SDL_WindowEvent is only present in SDL 1.3 but not in SDL 1.2 wich ships with FPC Lazarus.

Stoney
31-12-2011, 11:51 PM
I ran across the same issue recently. You might want to read this C++ tutorial from LazyFoo: http://lazyfoo.net/SDL_tutorials/lesson26/index.php
The interesting part about this is detecting SDL_APPMOUSEMOCUS through event.active.state where event is TSDL_Event in your event loop.
There is a small bug with that though, if your mouse cursor is over the application when the application starts, the event is not recognized, but if you move the mouse away from the window and then back into the window, it works again.

paul_nicholls
01-01-2012, 01:08 AM
@SilverWarior (http://www.pascalgamedevelopment.com/member.php?75542-SilverWarior): Thanks for the info, I am not going to use SDL 1.3 at this time so I will think of an other way :)
@Stoney (http://www.pascalgamedevelopment.com/member.php?75542-SilverWarior): Ok, I will take a look at that site...thanks for the info :)

EDIT: hmm...I think I might have just thought of a way around my issue, but I need to test it first :)
I am going to test the mouse position each frame and if it is within a small border around the screen, then I will not render the cursor.
If that doesn't work, I will try the SDL_APPMOUSEMOCUS way and see how that goes..

cheers,
Paul

paul_nicholls
01-01-2012, 02:12 AM
hmm...I think I might have just thought of a way around my issue, but I need to test it first :)
I am going to test the mouse position each frame and if it is within a small border around the screen, then I will not render the cursor.
If that doesn't work, I will try the SDL_APPMOUSEMOCUS way and see how that goes..

Ok, that works, but not if I move the mouse too fast...and it looks strange with the mouse appearing/disappearing with the border test :(

I will try the SDL_APPMOUSEMOCUS​ now then :)

SilverWarior
01-01-2012, 04:43 AM
hmm...I think I might have just thought of a way around my issue, but I need to test it first :)
I am going to test the mouse position each frame and if it is within a small border around the screen, then I will not render the cursor

If you are testing the mouse position every frame you could simply check whether it's position is over your window instead just for smal border.

Another idea: When creating your SDL window do you have an option to set default cursor type for it. In windows each window can have it's default cursor type set. This causes mouse cursor to automaticly change as soon as the mouse cursor moves over that window. If you can then you can just set your SDL window's default curspor type to crNone and then programaticly check what is the current cursor type each frame. So when mouse cursor type is set to crNone you know that the mouse cursor is over your window and you need to render your ingame cursor, if mouse cursor is set to anything else then it probably isn't over your window so no ingame cursor renderning is requred.