This repository has been archived on 2024-01-18. You can view files and clone it, but cannot push or open issues or pull requests.
DamesEtCo/src/Ecran.cpp

53 lines
1.2 KiB
C++
Raw Normal View History

2023-11-24 20:13:20 +01:00
#include "../includes/Ecran.hpp"
2023-12-01 16:36:50 +01:00
sf::RenderWindow Ecran::window;
std::string Ecran::message = "";
Ecran::Ecran(const uint w, const uint h, const std::string n) {
2023-11-24 20:13:20 +01:00
// Création de la fenêtre SFML
window.create(sf::VideoMode(w, h + bottomTxtPadding), n);
2023-11-24 20:13:20 +01:00
}
Ecran::~Ecran() {}
void Ecran::afficher(
const std::function<void()> dessin,
2023-12-28 00:30:44 +01:00
const std::function<void(const int, const int)> onLeftClick) const {
2023-12-28 17:09:00 +01:00
sf::Font font;
font.loadFromFile("assets/open-sans-latin-400-normal.ttf");
sf::Text text;
text.setFont(font);
text.setCharacterSize(24);
text.setPosition(0, hauteur());
text.setFillColor(sf::Color::White);
2023-11-24 20:13:20 +01:00
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
2023-12-28 00:30:44 +01:00
// Fermeture de la fenêtre
2023-11-24 20:13:20 +01:00
if (event.type == sf::Event::Closed) {
window.close();
}
2023-12-28 00:30:44 +01:00
// Récupération des coordonnées du clic de souris
if (event.type == sf::Event::MouseButtonPressed &&
event.mouseButton.button == sf::Mouse::Left) {
2023-12-28 00:30:44 +01:00
onLeftClick(event.mouseButton.x, event.mouseButton.y);
}
}
2023-12-28 00:28:34 +01:00
window.clear();
2023-12-28 00:27:29 +01:00
// Appel d'une fonction dessin
dessin();
2023-12-28 17:09:00 +01:00
// Ecriture du message
text.setString(message);
window.draw(text);
2023-11-24 20:13:20 +01:00
window.display();
}
}