Skip to content

Instantly share code, notes, and snippets.

@llongi
Last active August 20, 2017 13:43
Show Gist options
  • Save llongi/e02ea9d824572a0854a032c10b35d136 to your computer and use it in GitHub Desktop.
Save llongi/e02ea9d824572a0854a032c10b35d136 to your computer and use it in GitHub Desktop.
SFML position set/get test
#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