#include "../includes/Ecran.hpp" sf::RenderWindow Ecran::window; Ecran::Ecran(const uint w, const uint h, const std::string n) { // Création de la fenêtre SFML window.create(sf::VideoMode(w, h), n); } Ecran::~Ecran() {} void Ecran::afficher( const std::function dessin, const std::function onclick) const { // Boolean flag to track whether the mouse button is pressed bool mouseButtonPressed = false; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } window.clear(); // Appel d'une fonction dessin dessin(); // Récupération des coordonnées du clic de souris if (!mouseButtonPressed) { if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) { onclick(event.mouseButton.x, event.mouseButton.y); mouseButtonPressed = true; } } // Réinitialisation du flag lorsque le bouton est relâché if (event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left) { mouseButtonPressed = false; } window.display(); } }