GUI2/Dispatcher: added a connect_signal convenience wrapper for draw 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.
This commit is contained in:
Charles Dang 2018-05-30 11:14:43 +11:00
parent 31c4d09528
commit 569d86277a
7 changed files with 15 additions and 9 deletions

View file

@ -181,6 +181,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

View file

@ -1013,6 +1013,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

View file

@ -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);

View file

@ -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));

View file

@ -131,8 +131,7 @@ void loading_screen::pre_show(window& window)
animation_label_ = find_widget<label>(&window, "test_animation", false, true);
// Add a draw callback to handle the animation, et al.
window.connect_signal<event::DRAW>(
std::bind(&loading_screen::draw_callback, this), event::dispatcher::front_child);
connect_signal_on_draw(window, std::bind(&loading_screen::draw_callback, this));
set_next_animation_time();
}

View file

@ -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();
}

View file

@ -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);
}