From 7b28078da29c51a871969785c8b5101daeff8556 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 26 Apr 2018 23:03:02 +0100 Subject: [PATCH] Remove use of gUseTrueTypeFont --- src/openrct2-ui/interface/InGameConsole.cpp | 3 ++- src/openrct2-ui/windows/About.cpp | 3 ++- .../windows/TitleScenarioSelect.cpp | 3 ++- src/openrct2/drawing/Font.cpp | 5 ++-- src/openrct2/drawing/ScrollingText.cpp | 3 ++- src/openrct2/drawing/String.cpp | 7 +++--- src/openrct2/drawing/TTF.cpp | 3 ++- src/openrct2/interface/Fonts.cpp | 25 +++++++++++-------- src/openrct2/interface/Fonts.h | 7 +++++- src/openrct2/localisation/Language.h | 1 - .../localisation/LocalisationService.cpp | 2 +- .../localisation/LocalisationService.h | 3 ++- src/openrct2/paint/Paint.cpp | 3 ++- 13 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index d4eb7bf1a6..f1415ba5ab 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "InGameConsole.h" @@ -256,7 +257,7 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi) const } // TTF looks far better without the outlines - if (!gUseTrueTypeFont) + if (!LocalisationService_UseTrueTypeFont()) { textColour |= COLOUR_FLAG_OUTLINE; } diff --git a/src/openrct2-ui/windows/About.cpp b/src/openrct2-ui/windows/About.cpp index f8af10b775..8f70adf07c 100644 --- a/src/openrct2-ui/windows/About.cpp +++ b/src/openrct2-ui/windows/About.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #define WW 400 @@ -249,7 +250,7 @@ static void window_about_openrct2_paint(rct_window *w, rct_drawpixelinfo *dpi) // Copyright disclaimer; hidden when using truetype fonts to prevent // the text from overlapping the changelog button. - if (!gUseTrueTypeFont) + if (!LocalisationService_UseTrueTypeFont()) { gfx_draw_string_centred_wrapped(dpi, nullptr, x, y, width, STR_ABOUT_OPENRCT2_DESCRIPTION_3, w->colours[2]); } diff --git a/src/openrct2-ui/windows/TitleScenarioSelect.cpp b/src/openrct2-ui/windows/TitleScenarioSelect.cpp index d03991f4fc..5e5e9eb95a 100644 --- a/src/openrct2-ui/windows/TitleScenarioSelect.cpp +++ b/src/openrct2-ui/windows/TitleScenarioSelect.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -282,7 +283,7 @@ static void window_scenarioselect_mousedown(rct_window *w, rct_widgetindex widge static sint32 get_scenario_list_item_size() { - if (!gUseTrueTypeFont) + if (!LocalisationService_UseTrueTypeFont()) return 24; // Scenario title diff --git a/src/openrct2/drawing/Font.cpp b/src/openrct2/drawing/Font.cpp index 1c47307140..d745b7985a 100644 --- a/src/openrct2/drawing/Font.cpp +++ b/src/openrct2/drawing/Font.cpp @@ -17,6 +17,7 @@ #include "../core/Util.hpp" #include "../localisation/FormatCodes.h" #include "../localisation/Language.h" +#include "../localisation/LocalisationService.h" #include "../sprites.h" #include "Drawing.h" #include "Font.h" @@ -158,7 +159,7 @@ sint32 font_get_line_height(sint32 fontSpriteBase) { sint32 fontSize = font_get_size_from_sprite_base(fontSpriteBase); #ifndef NO_TTF - if (gUseTrueTypeFont) { + if (LocalisationService_UseTrueTypeFont()) { return gCurrentTTFFontSet->size[fontSize].line_height; } else { #endif // NO_TTF @@ -265,7 +266,7 @@ bool font_supports_string_ttf(const utf8 *text, sint32 fontSize) bool font_supports_string(const utf8 *text, sint32 fontSize) { - if (gUseTrueTypeFont) { + if (LocalisationService_UseTrueTypeFont()) { return font_supports_string_ttf(text, fontSize); } else { return font_supports_string_sprite(text); diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index d8c1ceb417..72851990fb 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -18,6 +18,7 @@ #include "../config/Config.h" #include "../interface/Colour.h" #include "../localisation/Localisation.h" +#include "../localisation/LocalisationService.h" #include "../paint/Paint.h" #include "../sprites.h" #include "Drawing.h" @@ -1459,7 +1460,7 @@ sint32 scrolling_text_setup(paint_session * session, rct_string_id stringId, uin const sint16* scrollingModePositions = _scrollPositions[scrollingMode]; memset(scrollText->bitmap, 0, 320 * 8); - if (gUseTrueTypeFont) { + if (LocalisationService_UseTrueTypeFont()) { scrolling_text_set_bitmap_for_ttf(scrollString, scroll, scrollText->bitmap, scrollingModePositions); } else { scrolling_text_set_bitmap_for_sprite(scrollString, scroll, scrollText->bitmap, scrollingModePositions); diff --git a/src/openrct2/drawing/String.cpp b/src/openrct2/drawing/String.cpp index 164635f7bd..9659c1b1c0 100644 --- a/src/openrct2/drawing/String.cpp +++ b/src/openrct2/drawing/String.cpp @@ -20,6 +20,7 @@ #include "../drawing/Drawing.h" #include "../interface/Viewport.h" #include "../localisation/Localisation.h" +#include "../localisation/LocalisationService.h" #include "../platform/platform.h" #include "../sprites.h" #include "../util/Util.h" @@ -822,7 +823,7 @@ void ttf_draw_string(rct_drawpixelinfo *dpi, const_utf8string text, sint32 colou info.x = x; info.y = y; - if (gUseTrueTypeFont) { + if (LocalisationService_UseTrueTypeFont()) { info.flags |= TEXT_DRAW_FLAG_TTF; } @@ -851,7 +852,7 @@ static sint32 ttf_get_string_width(const utf8 *text) info.maxY = 0; info.flags |= TEXT_DRAW_FLAG_NO_DRAW; - if (gUseTrueTypeFont) { + if (LocalisationService_UseTrueTypeFont()) { info.flags |= TEXT_DRAW_FLAG_TTF; } @@ -877,7 +878,7 @@ void gfx_draw_string_with_y_offsets(rct_drawpixelinfo *dpi, const utf8 *text, si info.flags |= TEXT_DRAW_FLAG_Y_OFFSET_EFFECT; - if (!forceSpriteFont && gUseTrueTypeFont) { + if (!forceSpriteFont && LocalisationService_UseTrueTypeFont()) { info.flags |= TEXT_DRAW_FLAG_TTF; } diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 043cebd5bc..1b6d54c86e 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -21,6 +21,7 @@ #include "../config/Config.h" #include "../localisation/Localisation.h" +#include "../localisation/LocalisationService.h" #include "../OpenRCT2.h" #include "../platform/platform.h" #include "TTF.h" @@ -157,7 +158,7 @@ static void ttf_surface_cache_dispose_all() void ttf_toggle_hinting() { - if (!gUseTrueTypeFont) + if (!LocalisationService_UseTrueTypeFont()) { return; } diff --git a/src/openrct2/interface/Fonts.cpp b/src/openrct2/interface/Fonts.cpp index c2c48e7a84..f63832a736 100644 --- a/src/openrct2/interface/Fonts.cpp +++ b/src/openrct2/interface/Fonts.cpp @@ -21,6 +21,9 @@ #include "../drawing/TTF.h" #include "../localisation/Language.h" +#include "../localisation/LocalisationService.h" + +using namespace OpenRCT2::Localisation; #ifndef NO_TTF uint8 const HINTING_DISABLED = 0; @@ -100,19 +103,19 @@ TTFFontSetDescriptor TTFFontArialUnicode = { { // clang-format on #endif // NO_TTF -static void LoadSpriteFont() +static void LoadSpriteFont(LocalisationService& localisationService) { ttf_dispose(); - gUseTrueTypeFont = false; + localisationService.UseTrueTypeFont(false); #ifndef NO_TTF gCurrentTTFFontSet = nullptr; #endif // NO_TTF } #ifndef NO_TTF -static bool LoadFont(TTFFontSetDescriptor * font) +static bool LoadFont(LocalisationService& localisationService, TTFFontSetDescriptor * font) { - gUseTrueTypeFont = true; + localisationService.UseTrueTypeFont(true); gCurrentTTFFontSet = font; ttf_dispose(); @@ -120,7 +123,7 @@ static bool LoadFont(TTFFontSetDescriptor * font) return fontInitialised; } -static bool LoadCustomConfigFont() +static bool LoadCustomConfigFont(LocalisationService& localisationService) { static TTFFontSetDescriptor TTFFontCustom = { { { gConfigFonts.file_name, gConfigFonts.font_name, gConfigFonts.size_tiny, gConfigFonts.x_offset, gConfigFonts.y_offset, @@ -134,7 +137,7 @@ static bool LoadCustomConfigFont() } }; ttf_dispose(); - gUseTrueTypeFont = true; + localisationService.UseTrueTypeFont(true); gCurrentTTFFontSet = &TTFFontCustom; bool fontInitialised = ttf_initialise(); @@ -142,7 +145,7 @@ static bool LoadCustomConfigFont() } #endif // NO_TTF -void TryLoadFonts() +void TryLoadFonts(LocalisationService& localisationService) { #ifndef NO_TTF TTFontFamily const * fontFamily = LanguagesDescriptors[gCurrentLanguage].font_family; @@ -151,7 +154,7 @@ void TryLoadFonts() { if (!String::IsNullOrEmpty(gConfigFonts.file_name)) { - if (LoadCustomConfigFont()) + if (LoadCustomConfigFont(localisationService)) { return; } @@ -160,7 +163,7 @@ void TryLoadFonts() for (auto &font : *fontFamily) { - if (LoadFont(font)) + if (LoadFont(localisationService, font)) { return; } @@ -175,7 +178,7 @@ void TryLoadFonts() for (auto &font : TTFFamilySansSerif) { - if (LoadFont(font)) + if (LoadFont(localisationService, font)) { return; } @@ -188,5 +191,5 @@ void TryLoadFonts() } } #endif // NO_TTF - LoadSpriteFont(); + LoadSpriteFont(localisationService); } diff --git a/src/openrct2/interface/Fonts.h b/src/openrct2/interface/Fonts.h index a1a30c6184..44be1a51f9 100644 --- a/src/openrct2/interface/Fonts.h +++ b/src/openrct2/interface/Fonts.h @@ -17,6 +17,11 @@ #ifndef OPENRCT2_FONTS_H #define OPENRCT2_FONTS_H +namespace OpenRCT2::Localisation +{ + class LocalisationService; +} + #include "../drawing/Font.h" #ifndef NO_TTF @@ -35,6 +40,6 @@ extern TTFFontSetDescriptor TTFFontArialUnicode; #define FONT(x) FONT_OPENRCT2_SPRITE #endif // NO_TTF -void TryLoadFonts(); +void TryLoadFonts(OpenRCT2::Localisation::LocalisationService& localisationService); #endif // OPENRCT2_FONTS_H diff --git a/src/openrct2/localisation/Language.h b/src/openrct2/localisation/Language.h index 7ad4a2493e..1e20175715 100644 --- a/src/openrct2/localisation/Language.h +++ b/src/openrct2/localisation/Language.h @@ -87,7 +87,6 @@ struct language_descriptor { extern const language_descriptor LanguagesDescriptors[LANGUAGE_COUNT]; extern sint32 gCurrentLanguage; -extern bool gUseTrueTypeFont; extern const utf8 BlackUpArrowString[]; extern const utf8 BlackDownArrowString[]; diff --git a/src/openrct2/localisation/LocalisationService.cpp b/src/openrct2/localisation/LocalisationService.cpp index 56adc5ac11..ee08e1b75d 100644 --- a/src/openrct2/localisation/LocalisationService.cpp +++ b/src/openrct2/localisation/LocalisationService.cpp @@ -93,7 +93,7 @@ void LocalisationService::OpenLanguage(sint32 id, IObjectManager& objectManager) if (_languageCurrent != nullptr) { _currentLanguage = id; - TryLoadFonts(); + TryLoadFonts(*this); // Objects and their localised strings need to be refreshed objectManager.ResetObjects(); diff --git a/src/openrct2/localisation/LocalisationService.h b/src/openrct2/localisation/LocalisationService.h index 23beeb6a02..11b04c51c8 100644 --- a/src/openrct2/localisation/LocalisationService.h +++ b/src/openrct2/localisation/LocalisationService.h @@ -42,7 +42,8 @@ namespace OpenRCT2::Localisation public: sint32 GetCurrentLanguage() const { return _currentLanguage; } - sint32 UseTrueTypeFont() const { return _useTrueTypeFont; } + bool UseTrueTypeFont() const { return _useTrueTypeFont; } + void UseTrueTypeFont(bool value) { _useTrueTypeFont = value; } LocalisationService(const std::shared_ptr& env); diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 3315053eff..fbbe4a63bc 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -20,6 +20,7 @@ #include "../drawing/Drawing.h" #include "../interface/Viewport.h" #include "../localisation/Localisation.h" +#include "../localisation/LocalisationService.h" #include "Paint.h" #include "sprite/Sprite.h" #include "tile_element/TileElement.h" @@ -1201,7 +1202,7 @@ void paint_draw_money_structs(rct_drawpixelinfo * dpi, paint_string_struct * ps) // Use sprite font unless the currency contains characters unsupported by the sprite font bool forceSpriteFont = false; const currency_descriptor& currencyDesc = CurrencyDescriptors[gConfigGeneral.currency_format]; - if (gUseTrueTypeFont && font_supports_string_sprite(currencyDesc.symbol_unicode)) + if (LocalisationService_UseTrueTypeFont() && font_supports_string_sprite(currencyDesc.symbol_unicode)) { forceSpriteFont = true; }