diff options
author | Greg Carlin <gregcarlin@users.noreply.github.com> | 2019-02-23 03:27:46 -0500 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2019-02-23 08:27:46 +0000 |
commit | 00d28a500d9b2c32877871e0d2b917c8b28a82a6 (patch) | |
tree | 4833e57b77c01a0dfa327e546831319336c4cd13 /src | |
parent | 56a6d7aec88b170eaf0dd57e14f5fffc24d3b1af (diff) | |
download | openttd-00d28a500d9b2c32877871e0d2b917c8b28a82a6.tar.xz |
Feature: Add option to adjust font size separately from GUI size. (#7003)
Adds an option in the "Game Options" next to "Interface Size" called "Font Size". Available options are normal, double, and quad.
Diffstat (limited to 'src')
-rw-r--r-- | src/fontcache.cpp | 8 | ||||
-rw-r--r-- | src/gfx.cpp | 1 | ||||
-rw-r--r-- | src/lang/english.txt | 7 | ||||
-rw-r--r-- | src/script/api/game/game_window.hpp.sq | 1 | ||||
-rw-r--r-- | src/script/api/script_window.hpp | 1 | ||||
-rw-r--r-- | src/settings_gui.cpp | 30 | ||||
-rw-r--r-- | src/spritecache.cpp | 14 | ||||
-rw-r--r-- | src/table/misc_settings.ini | 9 | ||||
-rw-r--r-- | src/widgets/settings_widget.h | 1 | ||||
-rw-r--r-- | src/zoom_type.h | 2 |
10 files changed, 65 insertions, 9 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 98e8bdf41..9b732ce1e 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -189,7 +189,7 @@ uint SpriteFontCache::GetGlyphWidth(GlyphID key) int SpriteFontCache::GetHeight() const { - return ScaleGUITrad(this->height); + return this->height * (1 << (ZOOM_LVL_OUT_4X - _font_zoom)); } bool SpriteFontCache::GetDrawGlyphShadow() @@ -293,6 +293,10 @@ void FreeTypeFontCache::SetFontSize(FontSize fs, FT_Face face, int pixels) pixels = Clamp(min(head->Lowest_Rec_PPEM, 20) + diff, scaled_height, MAX_FONT_SIZE); } } + + /* Apply user-specified font zoom. */ + pixels *= (1 << (ZOOM_LVL_OUT_4X - _font_zoom)); + this->used_size = pixels; FT_Error err = FT_Set_Pixel_Sizes(this->face, 0, pixels); @@ -438,7 +442,7 @@ void FreeTypeFontCache::ClearFontCache() Layouter::ResetFontCache(this->fs); /* GUI scaling might have changed, determine font size anew if it was automatically selected. */ - if (this->face != NULL && this->req_size == 0) this->SetFontSize(this->fs, this->face, this->req_size); + if (this->face != NULL) this->SetFontSize(this->fs, this->face, this->req_size); } FreeTypeFontCache::GlyphEntry *FreeTypeFontCache::GetGlyphPtr(GlyphID key) diff --git a/src/gfx.cpp b/src/gfx.cpp index 85cd3bfb5..0f050971c 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -58,6 +58,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, static ReusableBuffer<uint8> _cursor_backup; ZoomLevelByte _gui_zoom; ///< GUI Zoom level +ZoomLevelByte _font_zoom; ///< Font Zoom level /** * The rect for repaint. diff --git a/src/lang/english.txt b/src/lang/english.txt index ceb42a5c6..3c5c7dcdf 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -995,6 +995,13 @@ STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL :Normal STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM :Double size STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM :Quad size +STR_GAME_OPTIONS_FONT_ZOOM :{BLACK}Font size +STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP :{BLACK}Select the interface font size to use + +STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL :Normal +STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM :Double size +STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM :Quad size + STR_GAME_OPTIONS_BASE_GRF :{BLACK}Base graphics set STR_GAME_OPTIONS_BASE_GRF_TOOLTIP :{BLACK}Select the base graphics set to use STR_GAME_OPTIONS_BASE_GRF_STATUS :{RED}{NUM} missing/corrupted file{P "" s} diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index fc818a443..1fdcdbf52 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -1029,6 +1029,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_RESOLUTION_DROPDOWN, "WID_GO_RESOLUTION_DROPDOWN"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_FULLSCREEN_BUTTON, "WID_GO_FULLSCREEN_BUTTON"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_GUI_ZOOM_DROPDOWN, "WID_GO_GUI_ZOOM_DROPDOWN"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_FONT_ZOOM_DROPDOWN, "WID_GO_FONT_ZOOM_DROPDOWN"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_BASE_GRF_DROPDOWN, "WID_GO_BASE_GRF_DROPDOWN"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_BASE_GRF_STATUS, "WID_GO_BASE_GRF_STATUS"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_BASE_GRF_TEXTFILE, "WID_GO_BASE_GRF_TEXTFILE"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 8dfeafc4c..1ed4fcf57 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -2184,6 +2184,7 @@ public: WID_GO_BASE_MUSIC_STATUS = ::WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc. WID_GO_BASE_MUSIC_TEXTFILE = ::WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2). WID_GO_BASE_MUSIC_DESCRIPTION = ::WID_GO_BASE_MUSIC_DESCRIPTION, ///< Description of selected base music set. + WID_GO_FONT_ZOOM_DROPDOWN = ::WID_GO_FONT_ZOOM_DROPDOWN, ///< Dropdown for the font zoom level. }; /** Widgets of the #GameSettingsWindow class. */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 2faf2b150..a15f2ff58 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -36,6 +36,7 @@ #include "textfile_gui.h" #include "stringfilter_type.h" #include "querystring_gui.h" +#include "fontcache.h" #include <vector> @@ -64,6 +65,13 @@ static const StringID _gui_zoom_dropdown[] = { INVALID_STRING_ID, }; +static const StringID _font_zoom_dropdown[] = { + STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL, + STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM, + STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM, + INVALID_STRING_ID, +}; + int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of original town names. static StringID *_grf_names = NULL; ///< Pointer to town names defined by NewGRFs. static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs. @@ -302,6 +310,16 @@ struct GameOptionsWindow : Window { break; } + case WID_GO_FONT_ZOOM_DROPDOWN: { + list = new DropDownList(); + *selected_index = ZOOM_LVL_OUT_4X - _font_zoom; + const StringID *items = _font_zoom_dropdown; + for (int i = 0; *items != INVALID_STRING_ID; items++, i++) { + *list->Append() = new DropDownListStringItem(*items, i, false); + } + break; + } + case WID_GO_BASE_GRF_DROPDOWN: list = BuildSetDropDownList<BaseGraphics>(selected_index, (_game_mode == GM_MENU)); break; @@ -331,6 +349,7 @@ struct GameOptionsWindow : Window { case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break; case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break; case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[ZOOM_LVL_OUT_4X - _gui_zoom]); break; + case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[ZOOM_LVL_OUT_4X - _font_zoom]); break; case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break; case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break; case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break; @@ -541,6 +560,14 @@ struct GameOptionsWindow : Window { UpdateAllVirtCoords(); break; + case WID_GO_FONT_ZOOM_DROPDOWN: + GfxClearSpriteCache(); + _font_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index); + ClearFontCache(); + UpdateAllVirtCoords(); + ReInitAllWindows(); + break; + case WID_GO_BASE_GRF_DROPDOWN: this->SetMediaSet<BaseGraphics>(index); break; @@ -616,6 +643,9 @@ static const NWidgetPart _nested_game_options_widgets[] = { NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0), EndContainer(), NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1), + NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_FONT_ZOOM, STR_NULL), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_FONT_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0), + EndContainer(), EndContainer(), EndContainer(), diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 579791d0d..8a5a25ac0 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -462,13 +462,13 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator); } - if (sprite->type == ST_FONT && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) { - /* Make ZOOM_LVL_GUI be ZOOM_LVL_NORMAL */ - sprite[ZOOM_LVL_NORMAL].width = sprite[ZOOM_LVL_GUI].width; - sprite[ZOOM_LVL_NORMAL].height = sprite[ZOOM_LVL_GUI].height; - sprite[ZOOM_LVL_NORMAL].x_offs = sprite[ZOOM_LVL_GUI].x_offs; - sprite[ZOOM_LVL_NORMAL].y_offs = sprite[ZOOM_LVL_GUI].y_offs; - sprite[ZOOM_LVL_NORMAL].data = sprite[ZOOM_LVL_GUI].data; + if (sprite->type == ST_FONT && ZOOM_LVL_FONT != ZOOM_LVL_NORMAL) { + /* Make ZOOM_LVL_NORMAL be ZOOM_LVL_FONT */ + sprite[ZOOM_LVL_NORMAL].width = sprite[ZOOM_LVL_FONT].width; + sprite[ZOOM_LVL_NORMAL].height = sprite[ZOOM_LVL_FONT].height; + sprite[ZOOM_LVL_NORMAL].x_offs = sprite[ZOOM_LVL_FONT].x_offs; + sprite[ZOOM_LVL_NORMAL].y_offs = sprite[ZOOM_LVL_FONT].y_offs; + sprite[ZOOM_LVL_NORMAL].data = sprite[ZOOM_LVL_FONT].data; } return BlitterFactory::GetCurrentBlitter()->Encode(sprite, allocator); diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index b710478fb..787a82dd8 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -308,5 +308,14 @@ min = ZOOM_LVL_MIN max = ZOOM_LVL_OUT_4X cat = SC_BASIC +[SDTG_VAR] +name = ""font_zoom"" +type = SLE_UINT8 +var = _font_zoom +def = ZOOM_LVL_OUT_4X +min = ZOOM_LVL_MIN +max = ZOOM_LVL_OUT_4X +cat = SC_BASIC + [SDTG_END] diff --git a/src/widgets/settings_widget.h b/src/widgets/settings_widget.h index 661f788cd..ac64ac80a 100644 --- a/src/widgets/settings_widget.h +++ b/src/widgets/settings_widget.h @@ -35,6 +35,7 @@ enum GameOptionsWidgets { WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc. WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2). WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_END, ///< Description of selected base music set. + WID_GO_FONT_ZOOM_DROPDOWN, ///< Dropdown for the font zoom level. }; /** Widgets of the #GameSettingsWindow class. */ diff --git a/src/zoom_type.h b/src/zoom_type.h index c29f136cf..ea8302761 100644 --- a/src/zoom_type.h +++ b/src/zoom_type.h @@ -53,6 +53,8 @@ DECLARE_POSTFIX_INCREMENT(ZoomLevel) typedef SimpleTinyEnumT<ZoomLevel, byte> ZoomLevelByte; extern ZoomLevelByte _gui_zoom; +extern ZoomLevelByte _font_zoom; #define ZOOM_LVL_GUI (_gui_zoom) +#define ZOOM_LVL_FONT (_font_zoom) #endif /* ZOOM_TYPE_H */ |