From e5d3212a087ff380c4c2bc21e9824455d1f24a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Wed, 6 Apr 2016 00:31:46 +0200 Subject: [PATCH] =?UTF-8?q?Utilisation=20du=20widget=20timer=20dans=20l'?= =?UTF-8?q?=C3=A9diteur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/editor.hpp | 2 ++ levels/level1.dat | Bin 342 -> 342 bytes res/selection.png | Bin 301 -> 0 bytes src/editor.cpp | 22 +++++++++++++++++----- 4 files changed, 19 insertions(+), 5 deletions(-) delete mode 100644 res/selection.png diff --git a/include/editor.hpp b/include/editor.hpp index a79dc14..7df48e8 100644 --- a/include/editor.hpp +++ b/include/editor.hpp @@ -3,6 +3,7 @@ #include #include "level.hpp" +#include "util/widget_timer.hpp" /** * La classe Editor permet l'édition de @@ -11,6 +12,7 @@ class Editor : public Level { private: std::unordered_map selection; + WidgetTimer widget_timer; /** * Ajoute un objet du type actuel à la position donnée diff --git a/levels/level1.dat b/levels/level1.dat index 1b52150de29916e630cfc5db9d3a82a44f9b2729..faa343dd8ac567f3e0bc2f39109bf5d928b822c2 100644 GIT binary patch delta 26 gcmcb{bd5>S$uWo_B(=CiAy3bc0SIh13c4}^0A!;EXaE2J delta 26 gcmcb{bd5>S$uWo_B(=CiAy3bc0SNwY6m(?-0BCXtD*ylh diff --git a/res/selection.png b/res/selection.png deleted file mode 100644 index 344428ef6f1147ea08424efe9965ff59ae047393..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^Iv~u!1|;QLq8Nb`TavfC3&Vd9T(EcfWS|IVfk$L9 z0|Va?5N4dJ%_j{MWH0gbb!C6R!XhfmeCOAl4xrF3PZ!6Kh{JDh8gjK5h_pOBnY7h> zqiA&hL)C8%afgy~c2~&Uj?fgEq`>{E`%mypCz&`q9iiv5qg0?bj=yFBm*s{an^LB{Ts5qs)2L diff --git a/src/editor.cpp b/src/editor.cpp index b85a81a..6ffd07c 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1,9 +1,11 @@ #include +#include #include "editor.hpp" #include "block.hpp" #include "constants.hpp" -Editor::Editor(Manager& manager) : Level(manager) { +Editor::Editor(Manager& manager) : Level(manager), + widget_timer(manager, std::bind(&Editor::setTotalTime, this, std::placeholders::_1)) { // activation de la synchronisation verticale // car, dans l'éditeur, nous n'avons besoin que de dessiner // (pas de mise à jour physique) @@ -20,9 +22,15 @@ void Editor::load(std::ifstream& file) { void Editor::frame() { const std::vector& events = manager.getEvents(); + // traitement des événements for (unsigned int i = 0; i < events.size(); i++) { const sf::Event& event = events[i]; + // traitement des événements du widget timer + if (widget_timer.processEvent(event)) { + continue; + } + // lorsque l'on clique dans l'éditeur if (event.type == sf::Event::MouseButtonPressed) { sf::Vector2f position(event.mouseButton.x, event.mouseButton.y); @@ -33,25 +41,25 @@ void Editor::frame() { if (!updateSelection(position)) { addObject(position); } - } - - if (event.mouseButton.button == sf::Mouse::Right) { + } else if (event.mouseButton.button == sf::Mouse::Right) { // clic droit : on supprime l'objet pointé removeObject(position); } } } + // dessin de la frame draw(); } void Editor::draw() { Level::draw(); + sf::RenderWindow& window = manager.getWindow(); sf::View window_view = manager.getWindowView(); sf::Color selection_color(255, 50, 41); - // on dessine des carrés de sélection autour des objets sélectionnés + // dessin de la sélection autour des objets sélectionnés for (auto iter = selection.begin(); iter != selection.end(); iter++) { sf::VertexArray selection(sf::LinesStrip, 5); std::unique_ptr aabb = iter->first->getAABB(); @@ -70,6 +78,10 @@ void Editor::draw() { window.draw(selection); } + // dessin du widget timer + widget_timer.setTimeLeft(getTotalTime()); + widget_timer.draw(sf::Vector2f(window_view.getSize().x / 2 - 50, 0)); + // menu sf::RectangleShape menu(sf::Vector2f(window_view.getSize().x, 64)); menu.setPosition(sf::Vector2f(0, window_view.getSize().y - 64));