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 0000000..82c460d Binary files /dev/null and b/res/textures/toolbar/icon_arrow_down.tga differ diff --git a/res/textures/toolbar/icon_arrow_up.tga b/res/textures/toolbar/icon_arrow_up.tga new file mode 100644 index 0000000..b25d69c Binary files /dev/null and b/res/textures/toolbar/icon_arrow_up.tga differ diff --git a/res/textures/toolbar/icon_restart.png b/res/textures/toolbar/icon_restart.png deleted file mode 100644 index 4e44ba7..0000000 Binary files a/res/textures/toolbar/icon_restart.png and /dev/null differ diff --git a/src/gui/action_toolbar.cpp b/src/gui/action_toolbar.cpp index 9408b46..f1432ce 100644 --- a/src/gui/action_toolbar.cpp +++ b/src/gui/action_toolbar.cpp @@ -9,33 +9,48 @@ ActionToolbar::ActionToolbar() : left_buttons_count(0) { toolbar_window = sfg::Window::Create(sfg::Window::Style::BACKGROUND); toolbar_window->Add(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()) {