Jump to content
  • Advertisement
Sign in to follow this  
Feidias

How to reset SDL events?

This topic is 4009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've probably asked this before (don't remember) but I'm using Windows file dialog in SDL program. It works, but when you return to SDL it's acting like left mouse button being pressed down. When you press it again it returns to normal. I was wondering how to reset SDL events after returning from the dialog and why it's acting like that in the first place?

Share this post


Link to post
Share on other sites
Advertisement
Nothing I've heard of before, but it could be like this:

You monitor only when the mousebutton changes state and not when it is actually pushed? That way, when you click in the dialog box it doesnt get registered. When you return to SDL you have it pushed down, and then it registers when you let the button up again.

Crappy solution: manually create a mouse-buttonpress-event and send it with SDL_PushEvent.
Better solution: Don't read when the mouse changes state, instead read if it is actually pressed.

That's all I can offer before I know more about the problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by NQ
You monitor only when the mousebutton changes state and not when it is actually pushed?


I'm checking the button with SDL_MOUSEBUTTONDOWN. I don't know what you mean by "actually" pushed.

Share this post


Link to post
Share on other sites
Do you actually get a mouse-down event after you dismiss the dialog? If so, is it possible to ignore the first mouse-down event after such a situation?

Share this post


Link to post
Share on other sites
SDL_Delay doesn't do anything. Maybe it didn't become clear in my first post, but the mouse button seems to be pressed (after returning from windows file dialog) even when I'm not actually pressing any of mouse buttons. That's a bit of mystery. The event loop is still happily getting mouse button down event inside the mouse motion event.
To make it more complicated the bug appears only when I load new set of tiles (in my tile editor where the bug is). When I edit tiles and then load new tiles (it's asking y/n confirmation) the bug doesn't appear.

Here's the source from that part I'm handling the mouse:


if (event.type==SDL_MOUSEBUTTONDOWN)
{
mb=event.button;
b=mb.button;

if (b>0)
{
if (b>2) b=2; //if it's bigger than second button, turn it to second one

id=Mouse_Command(mb.x,mb.y,b);
if (id==2) done=1; //2=quit returned
}
}

if (event.type==SDL_MOUSEMOTION)
{
mo=event.motion;
omx=mo.x;
omy=mo.y;

if (g_edit->Hit(omx,omy)==1) //inside edit area
{
mx=g_edit->EditX(omx);
my=g_edit->EditY(omy);

if (tool->Get_Precise_Brush_Update()==1)
{
dm=tool->Get_Mode(); //current drawing tool
//show selector or precise brush
if (dm==dmSELECTOR_BRUSH) g_edit->Draw_Selector_Brush(mx,my);
else if (ds_options->Get(optPRECISE_BRUSH)>0)
{
g_edit->Draw_Precise_Brush(dm,omx,omy);
}
}
}
else
{
//change brush to mouse cursor when outside editor window
g_edit->Check_Update();
}

if (mo.state>0) Mouse_Command(mo.x,mo.y,mo.state);
else //show tooltips
{
id=g_tool1->Icon_ID(mo.x,mo.y);

if (id==-1) id=g_tool2->Icon_ID(mo.x,mo.y);
if (id!=-1) Show_Command_Help(id);
}
}




[Edited by - Feidias on September 27, 2007 4:53:30 AM]

Share this post


Link to post
Share on other sites
Yeah, forget about that for now, as I thought you were doing something else.

How do you know that the button 'seems' to be pressed? Do you get an extra mouse button down event after the dialog is dismissed? I don't know what you mean by "happily getting mouse button down event inside the mouse motion event" because that doesn't really make sense - events are lumps of data in this case, and you get them one at a time.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
How do you know that the button 'seems' to be pressed?


It's a tile editor. When I load tiles and move the mouse over the edit window it's magically drawing pixels even the mouse button is not pressed. When I press it again it stops and returns to normal.

Edit: Just noticed that I don't need to call Mouse_Command in SDL_MOUSEMOTION, but the bug is still there. I changed that part to show the tooltips when mo.state==0, but when I load tiles the dialog somehow changes mo.state without the mouse button being pressed. It will again return to normal when you press mouse button and the only problem now is that tooltips don't show after loading tiles. It's less dangerous than drawing over tiles. Still would be nice to know what causes this bug.


[Edited by - Feidias on September 29, 2007 9:37:59 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!