Last active
October 24, 2016 16:17
-
-
Save kim366/71346d9cea42b8272eb838b466700035 to your computer and use it in GitHub Desktop.
Dry SFML Event/Keyboard Poll code
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
sf::Event event; | |
while (window.pollEvent(event)) | |
{ | |
using k = sf::Keyboard; | |
using e = sf::Event; | |
auto kc = event.key.code; | |
auto et = event.type; | |
auto kp = e::KeyPressed; | |
//DIREKTER VERGLEICH///////////////////////////////////////////////// | |
if (et == e::Closed || (et == kp && kc == k::Escape)) | |
window.close(); | |
if (et == kp && (kc == k::C || kc == k::X)) | |
grid.fill(kc == k::X); | |
//DIREKTER VERGLEICH ENDE//////////////////////////////////////////// | |
} | |
{ | |
using m = sf::Mouse; | |
auto bp = &m::isButtonPressed; | |
auto gp = std::bind(static_cast<sf::Vector2i(*)(const sf::Window&)>(m::getPosition), std::cref(window)); | |
//DIREKTER VERGLEICH///////////////////////////////////////////////// | |
if (previous_mouse_position != gp() && (bp(m::Left) || bp(m::Right))) | |
{ | |
grid.on_click(gp(), bp(m::Left)); | |
previous_mouse_position = gp(); | |
} | |
//DIREKTER VERGLEICH ENDE//////////////////////////////////////////// | |
} |
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
sf::Event event; | |
while (window.pollEvent(event)) | |
{ | |
//DIREKTER VERGLEICH///////////////////////////////////////////////// | |
if (event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)) | |
window.close(); | |
if (event.type == sf::Event::KeyPressed && (event.key.code == sf::Keyboard::C || event.key.code == sf::Keyboard::X)) | |
grid.fill(event.key.code == sf::Keyboard::X); | |
//DIREKTER VERGLEICH ENDE//////////////////////////////////////////// | |
} | |
//DIREKTER VERGLEICH///////////////////////////////////////////////// | |
if (previous_mouse_position != sf::Mouse::getPosition(window) && (sf::Mouse::isButtonPressed(sf::Mouse::Left) || sf::Mouse::isButtonPressed(sf::Mouse::Right))) | |
{ | |
grid.on_click(sf::Mouse::getPosition(window), sf::Mouse::isButtonPressed(sf::Mouse::Left)); | |
previous_mouse_position = sf::Mouse::getPosition(window); | |
} | |
//DIREKTER VERGLEICH ENDE//////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment