Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Expose events, grabbing input and window captions  (Read 3682 times)

0 Members and 1 Guest are viewing this topic.

sparklehorse

  • Newbie
  • *
  • Posts: 5
    • View Profile
Expose events, grabbing input and window captions
« on: February 10, 2010, 08:23:59 pm »
Hi (again:-)),

I'm a "converting SDL user", and currently migrating my project to SFML (1.5). Moving my code to SFML has been fairly painless for me because SFML and SDL are very similar in many parts (at least in the way that I use them). Still, there are some features that I used in SDL which I cannot find a counterpart for in SFML... these are not necessarily "must have" features, but I just don't know if I overlooked them, hence the following questions:

In SDL, there is an event specificly for video expose (for example, when a part of the window that was previously obscured becomes visible). I cannot find an expose event in the documentation or source of SFML, so I'm assuming this does not exist. Is there some other way for to determine an expose event through SFML (i.e. a portable approach)?

Grabbing input is another thing that SDL provides that I found no SFML counterpart for. Essentially, SDL handles the "grabbed input" state in such a way that the mouse cursor is restricted to the application window. When it hits the window boundary, the mouse move events that are generated still return the relative mouse motion, but the absolute x/y position of the cursor (and the cursor itself) remains within the window. I can probably "hack" around this by simply resetting the mouse position (in fact, I read somewhere in the forum that this was a suggested workaround), but I was curious if this is really the best approach.

Finally, one other thing that I was curious about is changing the window caption. In SDL, it is possible to change the window caption of a stand alone application at any time (SDL_WM_SetCaption). I didn't see any similar means in the SFML documentation, and I read on the forum that it is required to recreate the window if you want to change the caption. Is this correct?

I would really like to get the window expose events, though I could live with (or hack around) the other 2. Any help is greatly appreciated.

Best regards,

  Matthias

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Expose events, grabbing input and window captions
« Reply #1 on: February 10, 2010, 08:34:13 pm »
Quote
In SDL, there is an event specificly for video expose (for example, when a part of the window that was previously obscured becomes visible). I cannot find an expose event in the documentation or source of SFML, so I'm assuming this does not exist. Is there some other way for to determine an expose event through SFML (i.e. a portable approach)?

SFML is made for real-time applications that are refreshed contiuously, I can't find how this kind of event would be used in this context. But I'm sure you have a good example to tell me :)

Quote
Grabbing input is another thing that SDL provides that I found no SFML counterpart for. Essentially, SDL handles the "grabbed input" state in such a way that the mouse cursor is restricted to the application window. When it hits the window boundary, the mouse move events that are generated still return the relative mouse motion, but the absolute x/y position of the cursor (and the cursor itself) remains within the window. I can probably "hack" around this by simply resetting the mouse position (in fact, I read somewhere in the forum that this was a suggested workaround), but I was curious if this is really the best approach.

The MouseMoved event in SFML doesn't return the relative motion, so this kind of feature would be useless (what do you do when the cursor is stuck on a border?).
Resetting the mouse position every frame is a good solution, it's not a hack or workaround.

Quote
Finally, one other thing that I was curious about is changing the window caption. In SDL, it is possible to change the window caption of a stand alone application at any time (SDL_WM_SetCaption). I didn't see any similar means in the SFML documentation, and I read on the forum that it is required to recreate the window if you want to change the caption. Is this correct?

Correct. I should implement it, but honestly I can't find any reason for the title to change after the window is created so I'm a little lazy to do it :)
Laurent Gomila - SFML developer

sparklehorse

  • Newbie
  • *
  • Posts: 5
    • View Profile
Expose events, grabbing input and window captions
« Reply #2 on: February 10, 2010, 09:36:05 pm »
Hi Laurant,

Quote from: Laurent
Quote
SFML is made for real-time applications that are refreshed contiuously, I can't find how this kind of event would be used in this context. But I'm sure you have a good example to tell me :)


I agree that it does not make sense for applications that refresh continuously. I concede that I kind of "abused" that event in SDL anyway: I mainly used it to handle initialization on window realization (which would trigger an expose event in SDL). I can live without it:-) (and I guess now I have a motivation clean up the code there).

Quote

Resetting the mouse position every frame is a good solution, it's not a hack or workaround.


'Kay, thanks. I'll handle that in my code then.

Quote
I should implement it, but honestly I can't find any reason for the title to change after the window is created so I'm a little lazy to do it :)


Hmm.. I guess one such reason could be that you want an application to display the filename of the data you are currently viewing - you know, like the webbrowser shows the title of the page? That is the best example I can come up with.

Anyway, I can live without the things, so it's no big deal. I was just curious if I was missing something - you know, migrating from SDL and all.

Thanks for the quick reply!

Matthias

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Expose events, grabbing input and window captions
« Reply #3 on: February 10, 2010, 11:10:42 pm »
Quote
Hmm.. I guess one such reason could be that you want an application to display the filename of the data you are currently viewing - you know, like the webbrowser shows the title of the page? That is the best example I can come up with.

That's a very good example. Maybe I'll be slightly less lazy to implement it now :mrgreen:

Quote
Anyway, I can live without the things, so it's no big deal. I was just curious if I was missing something - you know, migrating from SDL and all.

And I was curious if I was missing something, too ;)

Thanks for your feedback.
Laurent Gomila - SFML developer

mattlic

  • Newbie
  • *
  • Posts: 7
    • View Profile
Expose events, grabbing input and window captions
« Reply #4 on: August 08, 2010, 03:11:25 pm »
Quote from: "Laurent"

SFML is made for real-time applications that are refreshed contiuously, I can't find how this kind of event would be used in this context. But I'm sure you have a good example to tell me :)


I choose SFML2 to build a library because it is nice to use in C++, but I didn't know that is was not made for application that do not refresh continuously.
Sometimes in my library, I need to freeze the display, so I start a thread that listen to resize and focus events and redraw the content of the frozen window when necessary.
At this time, my quick and dirty fix was  to catch Expose events and push them in the SFML queue as GainedFocus in WindowImplX11::ProcessEvent:

Code: [Select]

        // Expose
        case Expose :
        {
            Event event;
            event.Type = Event::GainedFocus;
            PushEvent(event);
            break;
        }


I also added ExposureMask to the eventMask variable to receive exposure events from X11.

It works fine in my case, but I know this is a dirty fix...