#include <SFML\Graphics.hpp>
int main() {
sf::RenderWindow renderWindow(sf::VideoMode(400, 350), " Testing Stuff 1", sf::Style::Close);
renderWindow.setFramerateLimit(60);
sf::RenderWindow renderWindow2(sf::VideoMode(200, 400), " Testing stuff 2", sf::Style::Close);
renderWindow2.setFramerateLimit(60);
renderWindow2.setVisible(false);
sf::Font font;
font.loadFromFile("COUR.ttf");
sf::Text texto("Options", font, 25);
texto.setPosition(150,150);
sf::FloatRect rect(150.f, 150.f, texto.getGlobalBounds().width, texto.getGlobalBounds().height);
sf::Event evt;
sf::Event evt2;
bool isMousePressed = false;
bool wasMousePressed = false;
bool isJoyPressed = false;
bool wasJoyPressed = false;
bool isMousePressed_2 = false;
bool wasMousePressed_2 = false;
bool isJoyPressed_2 = false;
bool wasJoyPressed_2 = false;
bool r1 = true; // true = renderwindow | false = renderWindow2
while (renderWindow.isOpen()) {
if (r1) {
while (renderWindow.pollEvent(evt)) {
switch (evt.type) {
case sf::Event::Closed:
renderWindow.close();
break;
case sf::Event::MouseButtonPressed:
wasMousePressed = isMousePressed;
isMousePressed = true;
break;
case sf::Event::MouseButtonReleased:
wasMousePressed = isMousePressed;
isMousePressed = false;
break;
case sf::Event::JoystickButtonPressed:
wasJoyPressed = isJoyPressed;
isJoyPressed = true;
break;
case sf::Event::JoystickButtonReleased:
wasJoyPressed = isJoyPressed;
isJoyPressed = false;
break;
case sf::Event::KeyPressed:
switch (evt.key.code) {
case sf::Keyboard::Return:
r1 = false;
renderWindow2.setVisible(true);
isMousePressed_2 = false; //to reset it
wasMousePressed_2 = false;// ^
isJoyPressed_2 = false;
wasJoyPressed_2 = false;
break;
} //switch key code
} // switch evt type
} //while poll evt
if (isMousePressed && !wasMousePressed) {
if (rect.contains(sf::Mouse::getPosition(renderWindow).x, sf::Mouse::getPosition(renderWindow).y)) {
r1 = false;
renderWindow2.setVisible(true);
isMousePressed_2 = false; //to reset it
wasMousePressed_2 = false;// ^
isJoyPressed_2 = false;
wasJoyPressed_2 = false;
}
}
if (isJoyPressed && !wasJoyPressed) {
r1 = false;
renderWindow2.setVisible(true);
isMousePressed_2 = false; //to reset it
wasMousePressed_2 = false;// ^
isJoyPressed_2 = false;
wasJoyPressed_2 = false;
}
renderWindow.clear(sf::Color(15, 15, 15));
renderWindow.draw(texto);
renderWindow.display();
}
else {
while (renderWindow2.pollEvent(evt2)) {
switch (evt2.type) {
case sf::Event::Closed:
r1 = true;
renderWindow2.setVisible(false);
isMousePressed = false; //to reset it
wasMousePressed = false;// ^
isJoyPressed = false;
wasJoyPressed = false;
break;
case sf::Event::MouseButtonPressed:
wasMousePressed_2 = isMousePressed_2;
isMousePressed_2 = true;
break;
case sf::Event::MouseButtonReleased:
wasMousePressed_2 = isMousePressed_2;
isMousePressed_2 = false;
break;
case sf::Event::JoystickButtonPressed:
wasJoyPressed_2 = isJoyPressed_2;
isJoyPressed_2 = true;
break;
case sf::Event::JoystickButtonReleased:
wasJoyPressed_2 = isJoyPressed_2;
isJoyPressed_2 = false;
break;
case sf::Event::KeyPressed:
switch (evt2.key.code) {
case sf::Keyboard::Return:
r1 = true;
renderWindow2.setVisible(false);
isMousePressed = false; //to reset it
wasMousePressed = false;// ^
isJoyPressed = false;
wasJoyPressed = false;
break;
} //switch key code
} //witch evt2 type
} //poll event
if (isMousePressed_2 && !wasMousePressed_2) {
r1 = true;
renderWindow2.setVisible(false);
isMousePressed = false; //to reset it
wasMousePressed = false;// ^
isJoyPressed = false;
wasJoyPressed = false;
}
if (isJoyPressed_2 && !wasJoyPressed_2) {
r1 = true;
renderWindow2.setVisible(false);
isMousePressed = false; //to reset it
wasMousePressed = false;// ^
isJoyPressed = false;
wasJoyPressed = false;
}
renderWindow2.clear(sf::Color(50,50,50));
renderWindow2.display();
}//else
} //while open
}