use screen for sfml
This commit is contained in:
parent
c52e644c7a
commit
9239c100d5
2 changed files with 45 additions and 0 deletions
19
includes/Ecran.hpp
Normal file
19
includes/Ecran.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef PROJECT_ECRAN_HPP
|
||||
#define PROJECT_ECRAN_HPP 1
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <functional>
|
||||
|
||||
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<void()> f = {[]() {}});
|
||||
};
|
||||
|
||||
#endif
|
26
src/Ecran.cpp
Normal file
26
src/Ecran.cpp
Normal file
|
@ -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<void()> 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();
|
||||
}
|
||||
}
|
Reference in a new issue