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

Author Topic: How to prevent window.close() and do some other activity instead?  (Read 5221 times)

0 Members and 1 Guest are viewing this topic.

ImNewToSFML

  • Newbie
  • *
  • Posts: 2
    • View Profile
How to prevent window.close() and do some other activity instead?
« on: September 27, 2021, 03:03:37 pm »
I'm new to SFML, using C++.

How to prevent window.close() and do some other activity instead in case of the
Event::EventType::Closed:
event?

For example, if I want the user to either save or discard a file made, how would I do that?

This is the part of code from the SFML tutorial, a bit modified.
sf::Event e;
        while (sfmlWin.pollEvent(e)) {

            switch (e.type) {
            case sf::Event::EventType::Closed:

                using namespace sf;

                Text t;

                t.setString("Something.");
               
                sfmlWin.draw(t);


            }
        }

Thanks in advance!


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10226
    • View Profile
    • development blog
    • Email
Re: How to prevent window.close() and do some other activity instead?
« Reply #1 on: September 27, 2021, 04:28:40 pm »
You simply don't call window.close() in that regards.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

ImNewToSFML

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to prevent window.close() and do some other activity instead?
« Reply #2 on: September 27, 2021, 04:34:50 pm »
Yes, I didn't call it. Still when I click the close button of the SFML window, it closes.
Very sorry, I had another piece of code that was blocking it.
Also, is there any pre-built button class or do we have to make it on our own using Text(s)? Thanks!
« Last Edit: September 27, 2021, 04:46:28 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10226
    • View Profile
    • development blog
    • Email
Re: How to prevent window.close() and do some other activity instead?
« Reply #3 on: September 27, 2021, 04:51:40 pm »
Please use the edit button when you have multiple updates in such a short amount of time, this isn't Twitter :D

No, SFML doesn't provide a button class.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/