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

Author Topic: Is there a way to send a "Close" event to Window?  (Read 4716 times)

0 Members and 1 Guest are viewing this topic.

gasim

  • Newbie
  • *
  • Posts: 4
    • View Profile
Is there a way to send a "Close" event to Window?
« on: November 29, 2013, 08:15:34 pm »
I want to send a "close" event to sf::Window from an external source. Is that possible?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Is there a way to send a "Close" event to Window?
« Reply #1 on: November 29, 2013, 08:38:06 pm »
No. But it's not necessary either. Just call the function that normally reacts to your Closed event.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Is there a way to send a "Close" event to Window?
« Reply #2 on: November 29, 2013, 09:05:55 pm »
Why do you want to do that?
Laurent Gomila - SFML developer

gasim

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Is there a way to send a "Close" event to Window?
« Reply #3 on: November 29, 2013, 09:31:12 pm »
I want to keep Input separate from Window. If I press Escape an event I assigned gets send (for example "closeWindow"), then the GraphicsSystem gets the event and changes the status of the Event Object. I guess I am going to call the quit function straight up.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
AW: Is there a way to send a "Close" event to Window?
« Reply #4 on: November 30, 2013, 11:21:59 am »
Implement your own message bus, SFML's event system is not built for that.
See Tank's GDD article on Message Bus for some details. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Is there a way to send a "Close" event to Window?
« Reply #5 on: November 30, 2013, 11:52:51 am »
Why would you need a Closed event for that?

Usually, your input system has a custom event type with high-level descriptions of the events, e.g. "quit". Now, when a Closed event or a KeyPressed event (with the key being Escape) is polled by SFML, you trigger the custom "quit" event and dispatch it to the other modules. These can then react individually.

In the case of quitting, it will often be enough to stop the game loop.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gasim

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Is there a way to send a "Close" event to Window?
« Reply #6 on: November 30, 2013, 01:05:25 pm »
This whole thing started with me trying to figure out how to keep input and window separately. Is there a way to receive the current event from mWindow to process and dispatch the needed events to the window system to close?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: Is there a way to send a "Close" event to Window?
« Reply #7 on: November 30, 2013, 01:31:21 pm »
Input randomInputObject;
sf::RenderWindow window({600, 800}, "Hello World");

while(window.isOpen())
{
    sf::Event event;
    while(window.pollEvent(event))
    {
        randomInputObject.processEvent(event);
    }
    window.clear();
    window.display();
}

Hard to tell what you really want to do, but you can pass around event objects. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/