Ajout des boutons de modification du timer
This commit is contained in:
parent
231aee482e
commit
b8f1ca5634
|
@ -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<void()> up_callback = std::function<void()>(),
|
||||
std::function<void()> down_callback = std::function<void()>()
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 655 B |
|
@ -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<void()> 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<void()> up_callback,
|
||||
std::function<void()> 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);
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue