From 8684953938527e8571e0b352cd527451ce5587e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Fri, 29 Apr 2016 02:45:32 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20probl=C3=A8me=20bouton=20d'objets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...bject_button.hpp => icon_radio_button.hpp} | 12 +++++----- include/gui/object_toolbar.hpp | 4 ++-- res/gui.theme | 10 +++------ ...bject_button.cpp => icon_radio_button.cpp} | 22 +++++++++++-------- src/gui/object_toolbar.cpp | 7 +++--- 5 files changed, 28 insertions(+), 27 deletions(-) rename include/gui/{object_button.hpp => icon_radio_button.hpp} (85%) rename src/gui/{object_button.cpp => icon_radio_button.cpp} (81%) diff --git a/include/gui/object_button.hpp b/include/gui/icon_radio_button.hpp similarity index 85% rename from include/gui/object_button.hpp rename to include/gui/icon_radio_button.hpp index e0d5335..b2b6fa7 100644 --- a/include/gui/object_button.hpp +++ b/include/gui/icon_radio_button.hpp @@ -1,5 +1,5 @@ -#ifndef __SKIZZLE_OBJECT_BUTTON_HPP__ -#define __SKIZZLE_OBJECT_BUTTON_HPP__ +#ifndef __SKIZZLE_ICON_RADIO_BUTTON_HPP__ +#define __SKIZZLE_ICON_RADIO_BUTTON_HPP__ #include #include @@ -16,10 +16,10 @@ * (note: cette classe suit les conventions de nommage de SFGUI, pas * celles de Skizzle, pour plus de cohérence) */ -class ObjectButton : public sfg::RadioButton { +class IconRadioButton : public sfg::RadioButton { public: - typedef std::shared_ptr Ptr; - typedef std::shared_ptr PtrConst; + typedef std::shared_ptr Ptr; + typedef std::shared_ptr PtrConst; /** * Crée un nouveau bouton d'objet. La convention pour les widgets @@ -42,7 +42,7 @@ protected: * On utilise le constructeur par défaut, mais on est obligés de le * déclarer explicitement pour qu'il soit protégé */ - ObjectButton() = default; + IconRadioButton() = default; /** * Recalcule la géométrie du widget diff --git a/include/gui/object_toolbar.hpp b/include/gui/object_toolbar.hpp index 9a86908..9890256 100644 --- a/include/gui/object_toolbar.hpp +++ b/include/gui/object_toolbar.hpp @@ -7,7 +7,7 @@ #include #include "../objects/object.hpp" #include "../utility.hpp" -#include "object_button.hpp" +#include "icon_radio_button.hpp" /** * Barre d'outils qui affiche une liste d'objets à choisir @@ -21,7 +21,7 @@ private: // types d'objets de la barre d'outils sfg::RadioButtonGroup::Ptr creators_group; sfg::Table::Ptr creators_table; - std::map> creators; + std::map> creators; int creators_table_pos_x, creators_table_pos_y; diff --git a/res/gui.theme b/res/gui.theme index e84599d..935057f 100644 --- a/res/gui.theme +++ b/res/gui.theme @@ -60,7 +60,8 @@ Button.icon { BackgroundColor: #00000000; } -Entry { +Entry, IconRadioButton { + BorderWidth: 0; BackgroundColor: #D2D2D2ff; } @@ -69,12 +70,7 @@ ComboBox { HighlightedColor: #B4B4B4ff; } -ObjectButton { - BorderColor: #B4B4B4ff; - BackgroundColor: #D2D2D2ff; -} - -ObjectButton:PRELIGHT { +IconRadioButton:PRELIGHT { BackgroundColor: #E6E6E6ff; } diff --git a/src/gui/object_button.cpp b/src/gui/icon_radio_button.cpp similarity index 81% rename from src/gui/object_button.cpp rename to src/gui/icon_radio_button.cpp index cdc7014..56211e4 100644 --- a/src/gui/object_button.cpp +++ b/src/gui/icon_radio_button.cpp @@ -3,13 +3,13 @@ #include #include #include -#include "gui/object_button.hpp" +#include "gui/icon_radio_button.hpp" -ObjectButton::Ptr ObjectButton::Create( +IconRadioButton::Ptr IconRadioButton::Create( sfg::Image::Ptr image, std::shared_ptr group ) { - auto ptr = Ptr(new ObjectButton); + auto ptr = Ptr(new IconRadioButton); ptr->SetImage(image); ptr->SetLabel(L""); @@ -24,12 +24,12 @@ ObjectButton::Ptr ObjectButton::Create( return ptr; } -const std::string& ObjectButton::GetName() const { - static const std::string name = "ObjectButton"; +const std::string& IconRadioButton::GetName() const { + static const std::string name = "IconRadioButton"; return name; } -sf::Vector2f ObjectButton::CalculateRequisition() { +sf::Vector2f IconRadioButton::CalculateRequisition() { float padding = sfg::Context::Get().GetEngine().GetProperty( "Padding", shared_from_this() ); @@ -44,9 +44,13 @@ sf::Vector2f ObjectButton::CalculateRequisition() { return child_req; } -std::unique_ptr ObjectButton::InvalidateImpl() const { +std::unique_ptr IconRadioButton::InvalidateImpl() const { auto queue = std::unique_ptr(new sfg::RenderQueue); + auto border_width = sfg::Context::Get().GetEngine().GetProperty( + "BorderWidth", shared_from_this() + ); + auto border_color = sfg::Context::Get().GetEngine().GetProperty( "BorderColor", shared_from_this() ); @@ -76,7 +80,7 @@ std::unique_ptr ObjectButton::InvalidateImpl() const { } queue->Add(sfg::Renderer::Get().CreatePane( - position, size, 1.f, + position, size, border_width, background_color, border_color, 0 )); } @@ -98,6 +102,6 @@ std::unique_ptr ObjectButton::InvalidateImpl() const { return queue; } -void ObjectButton::HandleStateChange(sfg::Widget::State old_state) { +void IconRadioButton::HandleStateChange(sfg::Widget::State old_state) { Invalidate(); } diff --git a/src/gui/object_toolbar.cpp b/src/gui/object_toolbar.cpp index d4ab503..abfb9a5 100644 --- a/src/gui/object_toolbar.cpp +++ b/src/gui/object_toolbar.cpp @@ -68,9 +68,10 @@ ObjectToolbar::ObjectToolbar() { void ObjectToolbar::addCreator(std::string path, std::function creator) { // on crée un bouton d'objet correspondant au créateur donné - ObjectButton::Ptr button = ObjectButton::Create(sfg::Image::Create( - *ResourceManager::get().getImage(path + ".tga") - )); + IconRadioButton::Ptr button = IconRadioButton::Create( + sfg::Image::Create(*ResourceManager::get().getImage(path + ".tga")), + creators_group + ); creators[button] = creator;