En relisant... je suis stupide.....
This commit is contained in:
parent
c46a976044
commit
71ece11ddf
2 changed files with 5 additions and 21 deletions
|
@ -17,6 +17,6 @@ struct Ecran {
|
|||
|
||||
/* Prend 2 arguments: position X, position Y
|
||||
* -> appellé à chaque fois que l'utilisateur fait clic gauche */
|
||||
const std::function<void(const int, const int)> doOnClick = {
|
||||
const std::function<void(const int, const int)> doOnLeftClick = {
|
||||
[](const int, const int) {}}) const;
|
||||
};
|
||||
|
|
|
@ -11,41 +11,25 @@ Ecran::~Ecran() {}
|
|||
|
||||
void Ecran::afficher(
|
||||
const std::function<void()> dessin,
|
||||
const std::function<void(const int, const int)> onClick) const {
|
||||
const std::function<void(const int, const int)> onLeftClick) const {
|
||||
// Flag qui track si le clic gauche est pressé
|
||||
bool mouseButtonPressed = false;
|
||||
|
||||
while (window.isOpen()) {
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
// Fermeture de la fenêtre
|
||||
if (event.type == sf::Event::Closed) {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
/****************
|
||||
* Evenements *
|
||||
***************/
|
||||
|
||||
// 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;
|
||||
onLeftClick(event.mouseButton.x, event.mouseButton.y);
|
||||
}
|
||||
}
|
||||
|
||||
// Réinitialisation du flag lorsque le bouton est relâché
|
||||
if (event.type == sf::Event::MouseButtonReleased &&
|
||||
event.mouseButton.button == sf::Mouse::Left) {
|
||||
mouseButtonPressed = false;
|
||||
}
|
||||
|
||||
/****************
|
||||
* Dessin *
|
||||
***************/
|
||||
|
||||
window.clear();
|
||||
|
||||
// Appel d'une fonction dessin
|
||||
|
|
Reference in a new issue