Last active
August 20, 2017 13:43
-
-
Save llongi/e02ea9d824572a0854a032c10b35d136 to your computer and use it in GitHub Desktop.
SFML position set/get test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Window.hpp> | |
#include <iostream> | |
void printPosition(sf::Window &window); | |
void printSize(sf::Window &window); | |
void printPosition(sf::Window &window) { | |
const sf::Vector2i currPos = window.getPosition(); | |
std::cout << "Pos x: " << currPos.x << " - y: " << currPos.y << std::endl; | |
} | |
void printSize(sf::Window &window) { | |
const sf::Vector2u currSize = window.getSize(); | |
std::cout << "Size x: " << currSize.x << " - y: " << currSize.y << std::endl; | |
} | |
int main() { | |
sf::Window window(sf::VideoMode(100, 100), "My window", sf::Style::Titlebar | sf::Style::Close); | |
window.setPosition(sf::Vector2i(100, 100)); | |
while (window.isOpen()) { | |
sf::Event event; | |
while (window.pollEvent(event)) { | |
if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Key::A) { | |
window.setSize(sf::Vector2u(250, 250)); | |
window.setPosition(sf::Vector2i(250, 250)); | |
} | |
else if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Key::S) { | |
window.setSize(sf::Vector2u(100, 100)); | |
window.setPosition(sf::Vector2i(100, 100)); | |
} | |
else if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Key::D) { | |
printPosition(window); | |
printSize(window); | |
} | |
else if (event.type == sf::Event::Closed) { | |
window.close(); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment