From b8f1ca5634fcd0c16479259d97c820965fe3266c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Thu, 28 Apr 2016 21:11:51 +0200 Subject: [PATCH] Ajout des boutons de modification du timer --- include/gui/action_toolbar.hpp | 17 ++++++++ res/gui.theme | 17 ++++++-- res/textures/toolbar/icon_arrow_down.tga | Bin 0 -> 186 bytes res/textures/toolbar/icon_arrow_up.tga | Bin 0 -> 186 bytes res/textures/toolbar/icon_restart.png | Bin 655 -> 0 bytes src/gui/action_toolbar.cpp | 50 ++++++++++++++++++----- src/states/editor.cpp | 8 +++- 7 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 res/textures/toolbar/icon_arrow_down.tga create mode 100644 res/textures/toolbar/icon_arrow_up.tga delete mode 100644 res/textures/toolbar/icon_restart.png diff --git a/include/gui/action_toolbar.hpp b/include/gui/action_toolbar.hpp index 4f755b0..63d6694 100644 --- a/include/gui/action_toolbar.hpp +++ b/include/gui/action_toolbar.hpp @@ -14,11 +14,20 @@ private: // widgets de la barre sfg::Window::Ptr toolbar_window; sfg::Box::Ptr toolbar_box; + sfg::Label::Ptr timer_label; + sfg::Box::Ptr timer_buttons_box; + sfg::Button::Ptr timer_button_up; + sfg::Button::Ptr timer_button_down; int left_buttons_count; int time; + /** + * Crée un bouton icône avec l'icône donnée + */ + sfg::Button::Ptr createButton(std::string name); + public: ActionToolbar(); @@ -50,6 +59,14 @@ public: * Modifie le temps restant */ void setTime(int set_time); + + /** + * Configure les boutons de modification du temps + */ + void setTimeEditable( + std::function up_callback = std::function(), + std::function down_callback = std::function() + ); }; #endif diff --git a/res/gui.theme b/res/gui.theme index 3abae8d..6bc6a1c 100644 --- a/res/gui.theme +++ b/res/gui.theme @@ -42,6 +42,11 @@ Button, ComboBox, Entry { Spacing: 10; } +Button.icon { + FontSize: 0; + BackgroundColor: #00000000; +} + Entry { BackgroundColor: #D2D2D2ff; } @@ -51,10 +56,6 @@ ComboBox { HighlightedColor: #B4B4B4ff; } -Button.notext { - BackgroundColor: #00000000; -} - ObjectButton { BorderColor: #B4B4B4ff; BackgroundColor: #D2D2D2ff; @@ -69,11 +70,19 @@ Button:PRELIGHT, ComboBox:PRELIGHT, ComboBox:ACTIVE { BackgroundColor: #D2D2D2ff; } +Button.icon:PRELIGHT { + BackgroundColor: #E6E6E6ff; +} + Button:ACTIVE, Entry:ACTIVE { Color: #000000ff; BackgroundColor: #B4B4B4ff; } +Button.icon:ACTIVE { + BackgroundColor: #D2D2D2ff; +} + Separator { Color: #D2D2D2ff; } diff --git a/res/textures/toolbar/icon_arrow_down.tga b/res/textures/toolbar/icon_arrow_down.tga new file mode 100644 index 0000000000000000000000000000000000000000..82c460d99d185c43f6c80254512be49483e6b8da GIT binary patch literal 186 zcmZQz;9`IQ4h9Ye1&($Qw+Tcv0x=_)1tu6pL`2eoI1MhzzzpO{0r7hv{wO3QBm>d{ z*2lmA6k6X1B>sa~Tfh>GAXy+Uq8TL4C@Lx%4iW(i1341S;^N{;AYloRFxVj=1_*=% Vg}R1$27CJZ=|;GD`nc*b003yB7cKw* literal 0 HcmV?d00001 diff --git a/res/textures/toolbar/icon_arrow_up.tga b/res/textures/toolbar/icon_arrow_up.tga new file mode 100644 index 0000000000000000000000000000000000000000..b25d69c4d5ba243d8dd83ff099f3ac8d447587a5 GIT binary patch literal 186 zcmZQz;9`IQ4h9Ye1&($Qmk~sWii%1!i;IgZF@jidVG$9L$Yvn%pAkqzfP@=C1Ot$_ zp%EkwVr>PBfeB_HR|<&V1Mx>8At70?XcI^a$b<|aP6zYA1W1w*%mO#h8G~IGt_uXtZ`%$DNi#C%a88Gt{z-0jE{*FaabUTjYO=b=O z^Z;Bm#=LDb8k?02+U@q~TCMg<2yvB}pO^E~hAa5(%`rcwDlXf~TV pNs=`H!m_MyAdd(toolbar_box); - // ajout du timer et des espaceurs + // ajout du timer, des boutons et des espaceurs sfg::Alignment::Ptr left_spacer = sfg::Alignment::Create(); sfg::Alignment::Ptr right_spacer = sfg::Alignment::Create(); + + timer_buttons_box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL); + timer_button_up = createButton("arrow_up"); + timer_button_down = createButton("arrow_down"); timer_label = sfg::Label::Create("00:00"); + timer_label->SetClass("timer"); left_spacer->SetRequisition(sf::Vector2f(5.f, 1.f)); - timer_label->SetClass("timer"); right_spacer->SetRequisition(sf::Vector2f(5.f, 1.f)); + timer_buttons_box->PackEnd(timer_button_up, false, false); + timer_buttons_box->PackEnd(timer_button_down, false, false); + toolbar_box->PackEnd(left_spacer, true, false); - toolbar_box->PackEnd(timer_label); + toolbar_box->PackEnd(timer_label, false, false); + toolbar_box->PackEnd(timer_buttons_box, false, false); + timer_buttons_box->Show(false); toolbar_box->PackEnd(right_spacer, true, false); // pour les styles toolbar_window->SetId("action_toolbar"); } +sfg::Button::Ptr ActionToolbar::createButton(std::string name) { + // création d'un bouton avec pour image l'image passée + sfg::Button::Ptr button = sfg::Button::Create(""); + button->SetClass("icon"); + button->SetImage(sfg::Image::Create( + *ResourceManager::get().getImage("toolbar/icon_" + name + ".tga") + )); + + return button; +} + sfg::Button::Ptr ActionToolbar::addButton( std::string name, Utility::Direction direction, int position, std::function callback ) { - // création d'un bouton avec pour image l'image passée - sfg::Button::Ptr button = sfg::Button::Create(""); - button->SetClass("notext"); - button->SetImage(sfg::Image::Create( - *ResourceManager::get().getImage("toolbar/icon_" + name + ".tga") - )); + sfg::Button::Ptr button = createButton(name); // liaison du bouton avec la callback, s'il y en a une if (callback) { @@ -44,7 +59,7 @@ sfg::Button::Ptr ActionToolbar::addButton( // ajout du bouton à la barre selon la position donnée if (direction == Utility::Direction::WEST) { - position += left_buttons_count + 3; + position += left_buttons_count + 4; } else { left_buttons_count++; } @@ -85,3 +100,18 @@ void ActionToolbar::setTime(int set_time) { timer_label->SetText(minutes + ":" + seconds); } + +void ActionToolbar::setTimeEditable( + std::function up_callback, + std::function down_callback +) { + // si on passe des callbacks vides, on désactive l'édition du temps + if (!up_callback || !down_callback) { + timer_buttons_box->Show(false); + return; + } + + timer_buttons_box->Show(true); + timer_button_up->GetSignal(sfg::Widget::OnLeftClick).Connect(up_callback); + timer_button_down->GetSignal(sfg::Widget::OnLeftClick).Connect(down_callback); +} diff --git a/src/states/editor.cpp b/src/states/editor.cpp index d56be78..ce11d0e 100644 --- a/src/states/editor.cpp +++ b/src/states/editor.cpp @@ -47,6 +47,12 @@ Editor::Editor(Manager& manager) : Level(manager), std::bind(&Editor::test, this) ); + // affichage de l'interface d'édition du temps + action_toolbar.setTimeEditable( + [this]() { setTotalTime(getTotalTime() + 5); }, + [this]() { setTotalTime(getTotalTime() - 5); } + ); + // ajout de la barre d'objets à l'écran getManager().addWidget(object_toolbar.getWindow()); } @@ -269,7 +275,7 @@ void Editor::frame() { draw(); // màj du temps du timer - action_toolbar.setTime(total_time); + action_toolbar.setTime(getTotalTime()); // scroll de la caméra lorsque la souris se situe sur les bords if (window.hasFocus()) {