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

Author Topic: Making sf::Event hold a reference to the window that caused the Event?  (Read 2870 times)

0 Members and 1 Guest are viewing this topic.

Nyrox

  • Newbie
  • *
  • Posts: 9
    • View Profile
So today I was working on GUI code and I was wondering why not let sf::Event hold a reference to the window that it was caused in? I think this is a small change that can make a great improvement, as having to pass a window around everytime you wanna map mouse coordinates is quite the bother.

What do you think? :)

Props
Mark

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Making sf::Event hold a reference to the window that caused the Event?
« Reply #1 on: November 19, 2015, 12:06:21 pm »
That would be causing unnecessary overhead for everyone not using that "feature" I think.

Besides that, to actually retrieve the event the window has to be known to your code, so why don't you pass it in a second parameter or as part of a bigger structure, something like this:

struct EventData {
    sf::Event event;
    sf::Window *window;
};

On the other hand, this might also be some general design issue in your program. Are you really sure you need that? You could also translate mouse coordinates before passing them to your own code, i.e. never pass the original event.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Making sf::Event hold a reference to the window that caused the Event?
« Reply #2 on: November 19, 2015, 02:29:38 pm »
Adding a reference would make the event non-assignable, which is an unnecessary limitation. But even adding a pointer is a bad idea, since sf::Event is currently a self-contained POD type. There's no need to make it depend on other SFML components, especially not for the sake of "having to pass a window is quite the bother" :P

If passing around objects is a serious concern in your application, you should rethink your design and your priorities ;)
Mario already showed you a simple way to combine events with windows.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: