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

Author Topic: [MOVED] Problem: returning control to command line after closing window  (Read 1017 times)

0 Members and 1 Guest are viewing this topic.

2767210869

  • Newbie
  • *
  • Posts: 3
    • View Profile
EDIT: Moved to General after realising that I have used the Graphics package not the Window package and also that the solution is more likely to be of a general type as opposed to something specific to the Graphics library.

I'm trying to write a program for manually recording some data. Some of the entry is in the command line with a basic menu system, but I'm using SFML for pop-up windows to record location data.
The problem is that when the window closes, the cursor doesn't return to the command line automatically. I have to manually move the mouse and click on the terminal before being able to enter keyboard input for the menu system on the command line. Is there a way so that this happens automatically?

I haven't been able to find any results on this topic by searching Google or this forum.
Any help or guidance would be greatly appreciated.

This is a simplified version that demonstrates the essence of the menu system and pop-up window.
#include <SFML/Graphics.hpp>
#include <iostream>

int locationCoordinates[2] = {0};

void locationWindow()
    {
    sf::RenderWindow window(sf::VideoMode(800, 600), "");
    window.setFramerateLimit(60);
    window.requestFocus();
   
    while (window.isOpen())
        {
        sf::Event event;
       
        while(window.pollEvent(event))
            {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == event.MouseButtonPressed)
                {
                sf::Vector2i location = sf::Mouse::getPosition(window);
                locationCoordinates[0] = location.x;
                locationCoordinates[1] = location.y;
                window.close();
                }
            }
        window.clear(sf::Color::White);
        window.display();
        }
    }

int main()
    {
    bool done = false;
    int input = 0;
       
    while (done == false)
        {
        std::cout << "1. Locate" << std::endl;
        std::cout << "2. Exit" << std::endl;
        std::cin >> input;
        if (input == 1)
            {
            locationWindow();
            std::cout << locationCoordinates[0] << ", " << locationCoordinates[0] << std::endl;
            }
        else if (input == 2)
            done = true;
        }
       
    return 0;
    }
 

Details: SFML 2.4.2, Mac OS Sierra 10.12.6, Xcode 8.3.3
« Last Edit: August 26, 2017, 06:11:41 pm by 2767210869 »