Changeset - r28454:29a6b80a530c
[Not reviewed]
master
0 6 0
Michael Lutz - 12 months ago 2023-12-16 17:28:49
michi@icosahedron.de
Add: GUI options to select sprite font and AA mode for all fonts.
6 files changed with 66 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -93,13 +93,13 @@ int GetCharacterHeight(FontSize size)
 
/* Check if a glyph should be rendered with anti-aliasing. */
 
bool GetFontAAState(FontSize size, bool check_blitter)
 
{
 
	/* AA is only supported for 32 bpp */
 
	if (check_blitter && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
 

	
 
	return GetFontCacheSubSetting(size)->aa;
 
	return _fcsettings.global_aa || GetFontCacheSubSetting(size)->aa;
 
}
 

	
 
void SetFont(FontSize fontsize, const std::string &font, uint size, bool aa)
 
{
 
	FontCacheSubSetting *setting = GetFontCacheSubSetting(fontsize);
 
	bool changed = false;
 
@@ -201,13 +201,13 @@ void InitFontCache(bool monospace)
 
	for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
 
		if (monospace != (fs == FS_MONO)) continue;
 

	
 
		FontCache *fc = FontCache::Get(fs);
 
		if (fc->HasParent()) delete fc;
 

	
 
		if (GetFontCacheSubSetting(fs)->font.empty()) {
 
		if (!_fcsettings.prefer_sprite && GetFontCacheSubSetting(fs)->font.empty()) {
 
			TryLoadDefaultTrueTypeFont(fs);
 
		} else {
 
#ifdef WITH_FREETYPE
 
			LoadFreeTypeFont(fs);
 
#elif defined(_WIN32)
 
			LoadWin32Font(fs);
src/fontcache.h
Show inline comments
 
@@ -215,12 +215,14 @@ struct FontCacheSubSetting {
 
/** Settings for the four different fonts. */
 
struct FontCacheSettings {
 
	FontCacheSubSetting small;  ///< The smallest font; mostly used for zoomed out view.
 
	FontCacheSubSetting medium; ///< The normal font size.
 
	FontCacheSubSetting large;  ///< The largest font; mostly used for newspapers.
 
	FontCacheSubSetting mono;   ///< The mono space font used for license/readme viewers.
 
	bool prefer_sprite;         ///< Whether to prefer the built-in sprite font over resizable fonts.
 
	bool global_aa;             ///< Whether to anti alias all font sizes.
 
};
 

	
 
extern FontCacheSettings _fcsettings;
 

	
 
/**
 
 * Get the settings of a given font size.
src/lang/english.txt
Show inline comments
 
@@ -1041,12 +1041,17 @@ STR_GAME_OPTIONS_GUI_SCALE_TOOLTIP      
 
STR_GAME_OPTIONS_GUI_SCALE_AUTO                                 :{BLACK}Auto-detect size
 
STR_GAME_OPTIONS_GUI_SCALE_AUTO_TOOLTIP                         :{BLACK}Check this box to detect interface size automatically
 

	
 
STR_GAME_OPTIONS_GUI_SCALE_BEVELS                               :{BLACK}Scale bevels
 
STR_GAME_OPTIONS_GUI_SCALE_BEVELS_TOOLTIP                       :{BLACK}Check this box to scale bevels by interface size
 

	
 
STR_GAME_OPTIONS_GUI_FONT_SPRITE                                :{BLACK}Use traditional sprite font
 
STR_GAME_OPTIONS_GUI_FONT_SPRITE_TOOLTIP                        :{BLACK}Check this box if you prefer to use the tradition fixed-size sprite font.
 
STR_GAME_OPTIONS_GUI_FONT_AA                                    :{BLACK}Anti-alias fonts
 
STR_GAME_OPTIONS_GUI_FONT_AA_TOOLTIP                            :{BLACK}Check this box to anti-alias resizable fonts.
 

	
 
STR_GAME_OPTIONS_GUI_SCALE_1X                                   :1x
 
STR_GAME_OPTIONS_GUI_SCALE_2X                                   :2x
 
STR_GAME_OPTIONS_GUI_SCALE_3X                                   :3x
 
STR_GAME_OPTIONS_GUI_SCALE_4X                                   :4x
 
STR_GAME_OPTIONS_GUI_SCALE_5X                                   :5x
 

	
src/settings_gui.cpp
Show inline comments
 
@@ -47,12 +47,16 @@
 
#include "network/network_survey.h"
 
#include "video/video_driver.hpp"
 

	
 
#include "safeguards.h"
 

	
 

	
 
#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
 
#	define HAS_TRUETYPE_FONT
 
#endif
 

	
 
static const StringID _autosave_dropdown[] = {
 
	STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
 
	STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_10_MINUTES,
 
	STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_30_MINUTES,
 
	STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_60_MINUTES,
 
	STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_120_MINUTES,
 
@@ -556,12 +560,36 @@ struct GameOptionsWindow : Window {
 

	
 
				SetupWidgetDimensions();
 
				ReInitAllWindows(true);
 
				break;
 
			}
 

	
 
#ifdef HAS_TRUETYPE_FONT
 
			case WID_GO_GUI_FONT_SPRITE:
 
				_fcsettings.prefer_sprite = !_fcsettings.prefer_sprite;
 

	
 
				this->SetWidgetLoweredState(WID_GO_GUI_FONT_SPRITE, _fcsettings.prefer_sprite);
 
				this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
 
				this->SetDirty();
 

	
 
				InitFontCache(false);
 
				InitFontCache(true);
 
				SetupWidgetDimensions();
 
				ReInitAllWindows(true);
 
				break;
 

	
 
			case WID_GO_GUI_FONT_AA:
 
				_fcsettings.global_aa = !_fcsettings.global_aa;
 

	
 
				this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
 
				this->SetDirty();
 

	
 
				ClearFontCache();
 
				break;
 
#endif /* HAS_TRUETYPE_FONT */
 

	
 
			case WID_GO_GUI_SCALE:
 
				if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, this->gui_scale)) {
 
					if (!_ctrl_pressed) this->gui_scale = ((this->gui_scale + 12) / 25) * 25;
 
					this->SetWidgetDirty(widget);
 
				}
 

	
 
@@ -747,12 +775,17 @@ struct GameOptionsWindow : Window {
 
		this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_vsync);
 
		this->SetWidgetDisabledState(WID_GO_VIDEO_VSYNC_BUTTON, !_video_hw_accel);
 
#endif
 

	
 
		this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, _gui_scale_cfg == -1);
 
		this->SetWidgetLoweredState(WID_GO_GUI_SCALE_BEVEL_BUTTON, _settings_client.gui.scale_bevels);
 
#ifdef HAS_TRUETYPE_FONT
 
		this->SetWidgetLoweredState(WID_GO_GUI_FONT_SPRITE, _fcsettings.prefer_sprite);
 
		this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
 
		this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
 
#endif /* HAS_TRUETYPE_FONT */
 

	
 
		this->SetWidgetDisabledState(WID_GO_BASE_GRF_DROPDOWN, _game_mode != GM_MENU);
 
		this->SetWidgetDisabledState(WID_GO_BASE_SFX_DROPDOWN, _game_mode != GM_MENU);
 

	
 
		this->SetWidgetDisabledState(WID_GO_BASE_GRF_PARAMETERS, BaseGraphics::GetUsedSet() == nullptr || !BaseGraphics::GetUsedSet()->IsConfigurable());
 

	
 
@@ -820,12 +853,22 @@ static const NWidgetPart _nested_game_op
 
							NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_SCALE_AUTO), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_SCALE_AUTO_TOOLTIP),
 
						EndContainer(),
 
						NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
 
							NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_SCALE_BEVELS, STR_NULL),
 
							NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_SCALE_BEVEL_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_SCALE_BEVELS_TOOLTIP),
 
						EndContainer(),
 
#ifdef HAS_TRUETYPE_FONT
 
						NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
 
							NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_FONT_SPRITE, STR_NULL),
 
							NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_FONT_SPRITE), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_FONT_SPRITE_TOOLTIP),
 
						EndContainer(),
 
						NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
 
							NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_FONT_AA, STR_NULL),
 
							NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_FONT_AA), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_FONT_AA_TOOLTIP),
 
						EndContainer(),
 
#endif /* HAS_TRUETYPE_FONT */
 
					EndContainer(),
 
				EndContainer(),
 

	
 
				NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GRAPHICS, STR_NULL),
 
					NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
 
						NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
src/table/settings/misc_settings.ini
Show inline comments
 
@@ -255,12 +255,24 @@ def      = false
 
[SDTG_BOOL]
 
ifdef    = HAS_TRUETYPE_FONT
 
name     = ""mono_aa""
 
var      = _fcsettings.mono.aa
 
def      = false
 

	
 
[SDTG_BOOL]
 
ifdef    = HAS_TRUETYPE_FONT
 
name     = ""global_aa""
 
var      = _fcsettings.global_aa
 
def      = true
 

	
 
[SDTG_BOOL]
 
ifdef    = HAS_TRUETYPE_FONT
 
name     = ""prefer_sprite_font""
 
var      = _fcsettings.prefer_sprite
 
def      = false
 

	
 
[SDTG_VAR]
 
name     = ""sprite_cache_size_px""
 
type     = SLE_UINT
 
var      = _sprite_cache_size
 
def      = 128
 
min      = 1
src/widgets/settings_widget.h
Show inline comments
 
@@ -22,12 +22,14 @@ enum GameOptionsWidgets : WidgetID {
 
	WID_GO_LANG_DROPDOWN,          ///< Language dropdown.
 
	WID_GO_RESOLUTION_DROPDOWN,    ///< Dropdown for the resolution.
 
	WID_GO_FULLSCREEN_BUTTON,      ///< Toggle fullscreen.
 
	WID_GO_GUI_SCALE,              ///< GUI Scale slider.
 
	WID_GO_GUI_SCALE_AUTO,         ///< Autodetect GUI scale button.
 
	WID_GO_GUI_SCALE_BEVEL_BUTTON, ///< Toggle for chunky bevels.
 
	WID_GO_GUI_FONT_SPRITE,        ///< Toggle whether to prefer the sprite font over TTF fonts.
 
	WID_GO_GUI_FONT_AA,            ///< Toggle whether to anti-alias fonts.
 
	WID_GO_BASE_GRF_DROPDOWN,      ///< Use to select a base GRF.
 
	WID_GO_BASE_GRF_PARAMETERS,    ///< Base GRF parameters.
 
	WID_GO_BASE_GRF_OPEN_URL,      ///< Open base GRF URL.
 
	WID_GO_BASE_GRF_TEXTFILE,      ///< Open base GRF readme, changelog (+1) or license (+2).
 
	WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END,     ///< Description of selected base GRF.
 
	WID_GO_BASE_SFX_DROPDOWN,      ///< Use to select a base SFX.
0 comments (0 inline, 0 general)