SFML community forums

General => Feature requests => Topic started by: hamzse on November 10, 2016, 04:18:07 pm

Title: Adding sf::Window::getTitle()
Post by: hamzse on November 10, 2016, 04:18:07 pm
Hello!

To say it in a short way, this is how i start my game:


int main(){
    MainProgram game(new sf::RenderWindow(sf::VideoMode(1280, 720), "Title"));

    game.insertNewState<StateMainMenu>();
    game.programLoop();
}
 

And it looks cool (to me) until i want to go fullscreen. The only way i can go fullscreen is by closing the  current window, then making a new one. The problem is i cannot get the title from the window, to pass it to the new one.


Originally i was about posting this here: http://en.sfml-dev.org/forums/index.php?topic=2276.0 , then the site warned me to make a new post instead of writing into a really old one.
Title: Re: Adding sf::Window::getTitle()
Post by: korczurekk on November 10, 2016, 05:12:55 pm
int main() {
    std::string title = "SomeTitle?";
    MainProgram game(new sf::RenderWindow(sf::VideoMode(1280, 720), title.c_str()));

    game.insertNewState<StateMainMenu>();
    game.programLoop();
}
 
Or add „title” member to your MainProgram.

But IMHO getTitle() function would be nice feature.
Title: Re: Adding sf::Window::getTitle()
Post by: Mario on November 10, 2016, 07:12:05 pm
Just FYI: You don't have to actively close your window, just call sf::Window::create() once again.

Don't think a sf::Window::getTitle() would hurt, but at the same time just storing your title shouldn't be such a huge issue.
Title: Re: Adding sf::Window::getTitle()
Post by: Hapax on November 11, 2016, 12:15:58 am
Storing the title in a string first has always been my work-around for this "problem". It can then be re-applied whenever the window is re-created (as when you change to fullscreen).

The added advantage to storing a string is that you can then add additional text that is more contextual. For example, the string would be the application name and then you could add information about the window after the title. Personally, I have used it to show feedback in the titlebar and still keeping the name ;)

One thing to note is that you don't actually have to convert it to a c string to pass it to the window as korczurekk's code did.