From b7ebc8e91d807295efc51097daa2991f1115bb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Wed, 27 Apr 2016 19:58:22 +0200 Subject: [PATCH] =?UTF-8?q?M=C3=A0J=20du=20bouton=20de=20mute=20en=20fonct?= =?UTF-8?q?ion=20de=20l'=C3=A9tat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/gui/action_toolbar.hpp | 6 ++-- include/states/editor.hpp | 1 + src/gui/action_toolbar.cpp | 10 ++++-- src/states/editor.cpp | 57 +++++++++++++++++++++------------- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/include/gui/action_toolbar.hpp b/include/gui/action_toolbar.hpp index f5b544b..a4f20e4 100644 --- a/include/gui/action_toolbar.hpp +++ b/include/gui/action_toolbar.hpp @@ -21,7 +21,7 @@ public: /** * Ajoute un nouveau bouton d'action à la barre d'outils */ - void addButton( + sfg::Button::Ptr addButton( sf::Image image, std::function callback = std::function() ); @@ -29,7 +29,9 @@ public: /** * Ajoute un nouvel espaceur */ - void addSpacer(float width, bool expand, bool fill); + sfg::Alignment::Ptr addSpacer( + float width, bool expand, bool fill + ); /** * Récupère la fenêtre de la barre d'outils diff --git a/include/states/editor.hpp b/include/states/editor.hpp index 29cd7bd..e96be06 100644 --- a/include/states/editor.hpp +++ b/include/states/editor.hpp @@ -25,6 +25,7 @@ private: ActionToolbar action_toolbar; ObjectToolbar object_toolbar; + sfg::Button::Ptr mute_button; /** * Renvoie l'objet pointé à la position donnée diff --git a/src/gui/action_toolbar.cpp b/src/gui/action_toolbar.cpp index a0bbe05..c03b28a 100644 --- a/src/gui/action_toolbar.cpp +++ b/src/gui/action_toolbar.cpp @@ -12,7 +12,9 @@ ActionToolbar::ActionToolbar() { toolbar_window->SetId("action_toolbar"); } -void ActionToolbar::addButton(sf::Image image, std::function callback) { +sfg::Button::Ptr ActionToolbar::addButton( + sf::Image image, std::function callback +) { // création d'un bouton avec pour image l'image passée sfg::Button::Ptr button = sfg::Button::Create(""); button->SetImage(sfg::Image::Create(image)); @@ -25,14 +27,18 @@ void ActionToolbar::addButton(sf::Image image, std::function callback) { // ajout du bouton à la barre toolbar_box->PackEnd(button, false, false); + return button; } -void ActionToolbar::addSpacer(float width, bool expand, bool fill) { +sfg::Alignment::Ptr ActionToolbar::addSpacer( + float width, bool expand, bool fill +) { sfg::Alignment::Ptr spacer = sfg::Alignment::Create(); spacer->SetRequisition(sf::Vector2f(width, 1.f)); // ajout de l'espaceur à la barre toolbar_box->PackEnd(spacer, expand, fill); + return spacer; } sfg::Window::Ptr ActionToolbar::getWindow() { diff --git a/src/states/editor.cpp b/src/states/editor.cpp index d5d0958..21dd2fe 100644 --- a/src/states/editor.cpp +++ b/src/states/editor.cpp @@ -41,7 +41,7 @@ Editor::Editor(Manager& manager) : Level(manager), std::bind(&Manager::popState, &getManager()) ); - action_toolbar.addButton( + mute_button = action_toolbar.addButton( *ResourceManager::get().getImage("toolbar/icon_music.tga"), []() { // on inverse le drapeau de muet @@ -290,17 +290,12 @@ void Editor::processEvent(const sf::Event& event) { } void Editor::frame() { - // dessin de la frame - draw(); - - // màj du titre de la fenêtre - getManager().setTitle(sf::String(L"Édition de ") + getName()); -} - -void Editor::draw() { sf::RenderWindow& window = getManager().getWindow(); sf::Vector2i window_size = (sf::Vector2i) window.getSize(); + // dessin de la frame + draw(); + // scroll de la caméra lorsque la souris se situe sur les bords if (window.hasFocus()) { sf::View camera = getCamera(); @@ -320,6 +315,37 @@ void Editor::draw() { setCamera(camera); } + // mise à jour de l'icône du mute + sf::Image image; + + if (ResourceManager::get().isMuted()) { + image = *ResourceManager::get().getImage("toolbar/icon_no_music.tga"); + } else { + image = *ResourceManager::get().getImage("toolbar/icon_music.tga"); + } + + mute_button->SetImage(sfg::Image::Create(image)); + + // màj du titre de la fenêtre + getManager().setTitle(sf::String(L"Édition de ") + getName()); + + // positionnement des barres d'outils au bon endroit + action_toolbar.getWindow()->SetAllocation(sf::FloatRect( + 0, 0, window_size.x, + action_toolbar.getHeight() + )); + + object_toolbar.getWindow()->SetAllocation(sf::FloatRect( + window_size.x - object_toolbar.getWidth(), + action_toolbar.getHeight(), + object_toolbar.getWidth(), + window_size.y - action_toolbar.getHeight() + )); +} + +void Editor::draw() { + sf::RenderWindow& window = getManager().getWindow(); + // dessin des objets du niveau Level::draw(); @@ -360,19 +386,6 @@ void Editor::draw() { window.draw(selection_rect); } - - // on positionne les barres d'outils au bon endroit - action_toolbar.getWindow()->SetAllocation(sf::FloatRect( - 0, 0, window_size.x, - action_toolbar.getHeight() - )); - - object_toolbar.getWindow()->SetAllocation(sf::FloatRect( - window_size.x - object_toolbar.getWidth(), - action_toolbar.getHeight(), - object_toolbar.getWidth(), - window_size.y - action_toolbar.getHeight() - )); } Object::Ptr Editor::getObject(sf::Vector2f position) {