Skip to content

Commit

Permalink
GUI2/End Credits: use DRAW event hook to scroll text instead of a timer
Browse files Browse the repository at this point in the history
There's no visual difference between these methods since any of the scroll position changes wouldn't
take effect until the next draw anyway
  • Loading branch information
Vultraz committed Aug 25, 2017
1 parent cf8060c commit c980ffc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
17 changes: 2 additions & 15 deletions src/gui/dialogs/end_credits.cpp
Expand Up @@ -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"
Expand All @@ -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")) {
Expand All @@ -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<event::DRAW>(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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/gui/dialogs/end_credits.hpp
Expand Up @@ -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);
Expand All @@ -55,8 +53,6 @@ class end_credits : public modal_dialog

std::vector<std::string> backgrounds_;

size_t timer_id_;

scroll_label* text_widget_;

// The speed of auto-scrolling, specified as px/s
Expand Down

0 comments on commit c980ffc

Please sign in to comment.