From 9239c100d59e6dfddde99e1a0b764ca894126b9f Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 24 Nov 2023 20:13:20 +0100 Subject: [PATCH] use screen for sfml --- includes/Ecran.hpp | 19 +++++++++++++++++++ src/Ecran.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 includes/Ecran.hpp create mode 100644 src/Ecran.cpp diff --git a/includes/Ecran.hpp b/includes/Ecran.hpp new file mode 100644 index 0000000..ad2b3da --- /dev/null +++ b/includes/Ecran.hpp @@ -0,0 +1,19 @@ +#ifndef PROJECT_ECRAN_HPP +#define PROJECT_ECRAN_HPP 1 + +#include +#include + +class Ecran { + // Fenêtre + sf::RenderWindow window; + +public: + Ecran(const uint width = 800, const uint height = 800, + const std::string name = "Projet"); // constructor + ~Ecran(); // destructor + + void afficher(std::function f = {[]() {}}); +}; + +#endif diff --git a/src/Ecran.cpp b/src/Ecran.cpp new file mode 100644 index 0000000..67806b9 --- /dev/null +++ b/src/Ecran.cpp @@ -0,0 +1,26 @@ +#include "../includes/Ecran.hpp" + +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(std::function dessin) { + 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(); + + window.display(); + } +}