From c980ffc74febfd9f5e98a8120d756d78b3c121c3 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 25 Aug 2017 16:06:55 +1100 Subject: [PATCH] GUI2/End Credits: use DRAW event hook to scroll text instead of a timer There's no visual difference between these methods since any of the scroll position changes wouldn't take effect until the next draw anyway --- src/gui/dialogs/end_credits.cpp | 17 ++--------------- src/gui/dialogs/end_credits.hpp | 4 ---- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/gui/dialogs/end_credits.cpp b/src/gui/dialogs/end_credits.cpp index 39079f29b5ea1..446f8f87e0476 100644 --- a/src/gui/dialogs/end_credits.cpp +++ b/src/gui/dialogs/end_credits.cpp @@ -19,7 +19,6 @@ #include "config.hpp" #include "game_config.hpp" #include "gui/auxiliary/find_widget.hpp" -#include "gui/core/timer.hpp" #include "gui/widgets/grid.hpp" #include "gui/widgets/repeating_button.hpp" #include "gui/widgets/scrollbar.hpp" @@ -42,20 +41,11 @@ REGISTER_DIALOG(end_credits) end_credits::end_credits(const std::string& campaign) : focus_on_(campaign) , backgrounds_() - , timer_id_() , text_widget_(nullptr) , scroll_speed_(100) { } -end_credits::~end_credits() -{ - if(timer_id_ != 0) { - remove_timer(timer_id_); - timer_id_ = 0; - } -} - static void parse_about_tag(const config& cfg, std::stringstream& ss) { if(!cfg.has_child("entry")) { @@ -73,11 +63,12 @@ void end_credits::pre_show(window& window) { window.set_callback_next_draw([this]() { - timer_id_ = add_timer(10, std::bind(&end_credits::timer_callback, this), true); // Delay a little before beginning the scrolling last_scroll_ = SDL_GetTicks() + 3000; }); + window.connect_signal(std::bind(&end_credits::timer_callback, this), event::dispatcher::front_child); + connect_signal_pre_key_press(window, std::bind(&end_credits::key_press_callback, this, _5)); std::stringstream ss; @@ -160,10 +151,6 @@ void end_credits::timer_callback() text_widget_->set_vertical_scrollbar_item_position(cur_pos + needed_dist); last_scroll_ = now; - - if(text_widget_->vertical_scrollbar_at_end()) { - remove_timer(timer_id_); - } } void end_credits::key_press_callback(const SDL_Keycode key) diff --git a/src/gui/dialogs/end_credits.hpp b/src/gui/dialogs/end_credits.hpp index 089b7633a828e..33c3919aa938c 100644 --- a/src/gui/dialogs/end_credits.hpp +++ b/src/gui/dialogs/end_credits.hpp @@ -34,8 +34,6 @@ class end_credits : public modal_dialog public: explicit end_credits(const std::string& campaign); - ~end_credits(); - static void display(CVideo& video, const std::string& campaign = "") { end_credits(campaign).show(video); @@ -55,8 +53,6 @@ class end_credits : public modal_dialog std::vector backgrounds_; - size_t timer_id_; - scroll_label* text_widget_; // The speed of auto-scrolling, specified as px/s