Skip to content

Commit

Permalink
Feature: Add option to adjust font size separately from GUI size. (Op…
Browse files Browse the repository at this point in the history
…enTTD#7003)

Adds an option in the "Game Options" next to "Interface Size" called "Font Size". Available options are normal, double, and quad.
  • Loading branch information
gregcarlin authored and PeterN committed Feb 23, 2019
1 parent 56a6d7a commit 00d28a5
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/fontcache.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/gfx.cpp
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/lang/english.txt
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions src/script/api/game/game_window.hpp.sq
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/script/api/script_window.hpp
Expand Up @@ -2184,6 +2184,7 @@ class ScriptWindow : public ScriptObject {
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. */
Expand Down
30 changes: 30 additions & 0 deletions src/settings_gui.cpp
Expand Up @@ -36,6 +36,7 @@
#include "textfile_gui.h"
#include "stringfilter_type.h"
#include "querystring_gui.h"
#include "fontcache.h"

#include <vector>

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),

Expand Down
14 changes: 7 additions & 7 deletions src/spritecache.cpp
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/table/misc_settings.ini
Expand Up @@ -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]

1 change: 1 addition & 0 deletions src/widgets/settings_widget.h
Expand Up @@ -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. */
Expand Down
2 changes: 2 additions & 0 deletions src/zoom_type.h
Expand Up @@ -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 */

0 comments on commit 00d28a5

Please sign in to comment.