Skip to content

Commit

Permalink
GUI2/Dispatcher: added a connect_signal convenience wrapper for draw …
Browse files Browse the repository at this point in the history
…callbacks

Didn't use this in the window widget since that doesn't specify front_child as
the queue position. I need to evaluate whether draw callbacks need to be in that
position anyway. AFAIR I only started adding them there since I noticed the one
in the debug clock dialog used that.

(cherry-picked from commit 569d862)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent 1520676 commit adaa115
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/gui/core/event/dispatcher.cpp
Expand Up @@ -235,6 +235,12 @@ void connect_signal_notify_modified(dispatcher& dispatcher, const signal_notific
dispatcher.connect_signal<NOTIFY_MODIFIED>(signal);
}

void connect_signal_on_draw(dispatcher& dispatcher, const signal_function& signal)
{
// TODO: evaluate whether draw events need go in this queue position.
dispatcher.connect_signal<DRAW>(signal, dispatcher::front_child);
}

} // namespace event

} // namespace gui2
Expand Down
3 changes: 3 additions & 0 deletions src/gui/core/event/dispatcher.hpp
Expand Up @@ -880,6 +880,9 @@ void connect_signal_mouse_left_double_click(dispatcher& dispatcher, const signal
/** Connects a signal handler for getting a notification upon modification. */
void connect_signal_notify_modified(dispatcher& dispatcher, const signal_notification_function& signal);

/** Connects a signal handler for a callback when the widget is drawn. */
void connect_signal_on_draw(dispatcher& dispatcher, const signal_function& signal);

} // namespace event

} // namespace gui2
3 changes: 1 addition & 2 deletions src/gui/dialogs/debug_clock.cpp
Expand Up @@ -104,8 +104,7 @@ void debug_clock::pre_show(window& window)
clock_ = find_widget<styled_widget>(&window, "clock", false, false);

signal_ = std::bind(&debug_clock::update_time, this, false);
window.connect_signal<event::DRAW>(signal_,
event::dispatcher::front_child);
connect_signal_on_draw(window, signal_);

time_.set_current_time();
update_time(true);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/end_credits.cpp
Expand Up @@ -55,7 +55,7 @@ void end_credits::pre_show(window& window)
last_scroll_ = SDL_GetTicks() + 3000;
});

window.connect_signal<event::DRAW>(std::bind(&end_credits::timer_callback, this), event::dispatcher::front_child);
connect_signal_on_draw(window, std::bind(&end_credits::timer_callback, this));

connect_signal_pre_key_press(window, std::bind(&end_credits::key_press_callback, this, _5));

Expand Down
3 changes: 1 addition & 2 deletions src/gui/dialogs/outro.cpp
Expand Up @@ -52,8 +52,7 @@ void outro::pre_show(window& window)
window.set_enter_disabled(true);
window.get_canvas(0).set_variable("outro_text", wfl::variant(text_));

window.connect_signal<event::DRAW>(
std::bind(&outro::draw_callback, this, std::ref(window)), event::dispatcher::front_child);
connect_signal_on_draw(window, std::bind(&outro::draw_callback, this, std::ref(window)));

set_next_draw();
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dialogs/story_viewer.cpp
Expand Up @@ -88,8 +88,8 @@ void story_viewer::pre_show(window& window)
connect_signal_mouse_left_click(find_widget<button>(&window, "back", false),
std::bind(&story_viewer::nav_button_callback, this, std::ref(window), DIR_BACKWARDS));

window.connect_signal<event::DRAW>(
std::bind(&story_viewer::draw_callback, this, std::ref(window)), event::dispatcher::front_child);
connect_signal_on_draw(window,
std::bind(&story_viewer::draw_callback, this, std::ref(window)));

display_part(window);
}
Expand Down

0 comments on commit adaa115

Please sign in to comment.