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
 
@@ -96,7 +96,7 @@ bool GetFontAAState(FontSize size, bool 
 
	/* 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)
 
@@ -204,7 +204,7 @@ void InitFontCache(bool monospace)
 
		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
src/fontcache.h
Show inline comments
 
@@ -218,6 +218,8 @@ struct FontCacheSettings {
 
	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;
src/lang/english.txt
Show inline comments
 
@@ -1044,6 +1044,11 @@ STR_GAME_OPTIONS_GUI_SCALE_AUTO_TOOLTIP 
 
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
src/settings_gui.cpp
Show inline comments
 
@@ -50,6 +50,10 @@
 
#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,
 
@@ -559,6 +563,30 @@ struct GameOptionsWindow : Window {
 
				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;
 
@@ -750,6 +778,11 @@ struct GameOptionsWindow : Window {
 

	
 
		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);
 
@@ -823,6 +856,16 @@ static const NWidgetPart _nested_game_op
 
							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(),
 

	
src/table/settings/misc_settings.ini
Show inline comments
 
@@ -258,6 +258,18 @@ 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
src/widgets/settings_widget.h
Show inline comments
 
@@ -25,6 +25,8 @@ enum GameOptionsWidgets : WidgetID {
 
	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.
0 comments (0 inline, 0 general)