SFML community forums

Help => Window => Topic started by: malkierian on October 17, 2013, 03:53:30 am

Title: Clicking in Window Doesn't Give Focus
Post by: malkierian on October 17, 2013, 03:53:30 am
So I just started developing games using SFML, and I've got a major problem.  I have my main loop set up thusly:

while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
                        if (event.type == sf::Event::LostFocus)
                                paused = true;
                        if (event.type == sf::Event::GainedFocus)
                                paused = false;
        }
                if(paused)
                        continue;
                ship.resetDirections();
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        ship.direction[3] = true;
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        ship.direction[1] = true;
                }

                ship.updatePosition();

        window.clear();
        window.draw(ship);
        window.display();
    }
Now, you'll notice, in the polling loop, I have a pausing thing going on.  Losing focus pauses the game, gaining focus resumes the game.  Pretty basic pausing system for now (I'll make a pause menu eventually).  But, when I click inside the window frame (anywhere but the title bar, or the outline around the black that the background currently is), the window isn't actually getting focus.  It doesn't, unless I actually go and click the window frame, or click the program's icon on my start bar (Windows 7).  I'm using VS2012, and have it going through the System package to maintain compatibility.
Title: Re: Clicking in Window Doesn't Give Focus
Post by: eXpl0it3r on October 17, 2013, 04:42:04 am
It's a bug in SFML 2.1, but it got already fixed in the current Git version. ;)
Title: Re: Clicking in Window Doesn't Give Focus
Post by: malkierian on October 17, 2013, 05:12:54 am
Ah, I see.  And there just happens to be a link to some dev builds in your sig!  How convenient :D
Title: Re: Clicking in Window Doesn't Give Focus
Post by: TheRabbit on November 02, 2013, 10:56:21 pm
Is there a way that I can fix this using an sf::Event? Or is the only way around it to use a dev build?
Title: Re: Clicking in Window Doesn't Give Focus
Post by: zsbzsb on November 02, 2013, 10:59:17 pm
Is there a way that I can fix this using an sf::Event? Or is the only way around it to use a dev build?

Just build SFML yourself, after all it would be very beneficial to you if you learned how to do it.  ;)