Skip to content

Commit

Permalink
tpreferences: fixup ad84686
Browse files Browse the repository at this point in the history
The previous iteration caused a crash on exit if you weren't in the display tab,
since the scale slider couldn't be found. This keeps the value of the slider in
a class member variable so its always accessible.
  • Loading branch information
Vultraz committed Feb 21, 2016
1 parent 8952ca0 commit 07169f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -90,6 +90,7 @@ tpreferences::tpreferences(CVideo& video, const config& game_cfg)
, friend_names_()
, last_selected_item_(0)
, accl_speeds_()
, font_scaling_(font_scaling())
{
BOOST_FOREACH(const config& adv, game_cfg.child_range("advanced_preference")) {
adv_preferences_cfg_.push_back(adv);
Expand Down Expand Up @@ -556,9 +557,14 @@ void tpreferences::initialize_members(twindow& window)
set_idle_anim, set_idle_anim_rate, window);

/** FONT SCALING **/
// The setter is handled in post_show to avoid dynamically changing text
tslider& scale_slider = find_widget<tslider>(&window, "scaling_slider", false);

scale_slider.set_value(font_scaling());

connect_signal_notify_modified(scale_slider, boost::bind(
&tpreferences::font_scaling_slider_callback,
this, boost::ref(scale_slider)));

bind_status_label(scale_slider, "scaling_value", window, "%");

/** SELECT THEME **/
Expand Down Expand Up @@ -1006,6 +1012,11 @@ void tpreferences::max_autosaves_slider_callback(tslider& slider, tcontrol& stat
status_label.set_label(get_max_autosaves_status_label(slider));
}

void tpreferences::font_scaling_slider_callback(tslider& slider)
{
font_scaling_ = slider.get_value();
}

void tpreferences::toggle_radio_callback(
const std::vector<std::pair<ttoggle_button*, int> >& vec,
int& value,
Expand Down Expand Up @@ -1044,7 +1055,7 @@ void tpreferences::on_tab_select(twindow& window, const std::string& widget_id)
void tpreferences::post_show(twindow& window)
{
// Handle the font scaling setter only once prefs is closed
set_font_scaling(find_widget<tslider>(&window, "scaling_slider", false).get_value());
set_font_scaling(font_scaling_);
}

} // end namespace gui2
5 changes: 5 additions & 0 deletions src/gui/dialogs/preferences_dialog.hpp
Expand Up @@ -84,6 +84,7 @@ class tpreferences : public tdialog
void fullscreen_toggle_callback(twindow& window);
void accl_speed_slider_callback(tslider& slider);
void max_autosaves_slider_callback(tslider& slider, tcontrol& status_label);
void font_scaling_slider_callback(tslider& slider);

/**
* Sets the initial state and callback for a simple bool-state toggle button
Expand Down Expand Up @@ -199,6 +200,10 @@ class tpreferences : public tdialog
int last_selected_item_;

std::vector<t_string> accl_speeds_;

// Special variable to keep the value of the scaling slider,
// to be used in post_show
int font_scaling_;
};

} // namespace gui2
Expand Down

0 comments on commit 07169f5

Please sign in to comment.