Skip to content

Commit

Permalink
Preferences: Implement a font scaling option
Browse files Browse the repository at this point in the history
This is currently incomplete - it only works for GUI2 text.
  • Loading branch information
CelticMinstrel committed Feb 15, 2016
1 parent 342532e commit 0a65dcd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
15 changes: 15 additions & 0 deletions data/gui/default/window/preferences/02_display.cfg
Expand Up @@ -208,6 +208,21 @@
[/grid]
[/column]
[/row]

[row]
[column]
horizontal_grow = true
{_GUI_PREFERENCES_CHECKBOX_ALIGN_BORDER}
{_GUI_PREFERENCES_MAIN_COMPOSITE_SLIDER
scaling_value ( _ "Percentage Font Scaling:")
scaling_slider (
minimum_value,maximum_value=100,200
step_size=5
tooltip= _ "Set the scaling factor of fonts"
)
}
[/column]
[/row]
#enddef

#define _GUI_PREFERENCES_DISPLAY_GRID_2
Expand Down
6 changes: 6 additions & 0 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -554,6 +554,12 @@ void tpreferences::initialize_members(twindow& window)
idle_anim(), idle_anim_rate(),
set_idle_anim, set_idle_anim_rate, window);

/** FONT SCALING **/
tslider& scale_slider = find_widget<tslider>(&window, "scaling_slider", false);
scale_slider.set_value(font_scaling()); // This shouldn't be necessary, but it won't work without it...
register_integer("scaling_slider", false, font_scaling, set_font_scaling);
bind_status_label(scale_slider, "scaling_value", window);

/** SELECT THEME **/
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "choose_theme", false),
Expand Down
16 changes: 16 additions & 0 deletions src/preferences.cpp
Expand Up @@ -411,6 +411,22 @@ void save_turbo_speed(const double speed)
{
prefs["turbo_speed"] = speed;
}

int font_scaling()
{
// Clip at 50 because if it's too low it'll cause crashes
return std::max<int>(50, prefs["font_scale"].to_int(100));
}

void set_font_scaling(int scale)
{
prefs["font_scale"] = scale;
}

int font_scaled(int size)
{
return (size * font_scaling()) / 100;
}

bool idle_anim()
{
Expand Down
4 changes: 4 additions & 0 deletions src/preferences.hpp
Expand Up @@ -81,6 +81,10 @@ namespace preferences {

double turbo_speed();
void save_turbo_speed(const double speed);

int font_scaling();
void set_font_scaling(int scale);
int font_scaled(int size);

bool idle_anim();
void _set_idle_anim(const bool ison);
Expand Down
6 changes: 4 additions & 2 deletions src/text.cpp
Expand Up @@ -24,6 +24,7 @@
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#include "tstring.hpp"
#include "preferences.hpp"

#include <boost/foreach.hpp>

Expand Down Expand Up @@ -404,8 +405,9 @@ ttext& ttext::set_family_class(font::family_class fclass)

ttext& ttext::set_font_size(const unsigned font_size)
{
if(font_size != font_size_) {
font_size_ = font_size;
unsigned int actual_size = preferences::font_scaled(font_size);
if(actual_size != font_size_) {
font_size_ = actual_size;
calculation_dirty_ = true;
surface_dirty_ = true;
}
Expand Down

0 comments on commit 0a65dcd

Please sign in to comment.