Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 7c28b73

Browse files
committed
Add option to get 32bpp versions of GUI fonts in FrameMan font getters
1 parent 64ea6fb commit 7c28b73

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

Managers/FrameMan.cpp

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ namespace RTE {
6262
m_BlackColor = 245;
6363
m_AlmostBlackColor = 245;
6464
m_ColorTablePruneTimer.Reset();
65-
m_GUIScreen = nullptr;
66-
m_LargeFont = nullptr;
67-
m_SmallFont = nullptr;
65+
m_GUIScreens.fill(nullptr);
66+
m_LargeFonts.fill(nullptr);
67+
m_SmallFonts.fill(nullptr);
6868
m_TextBlinkTimer.Reset();
6969

7070
for (int screenCount = 0; screenCount < c_MaxScreenCount; ++screenCount) {
@@ -187,10 +187,15 @@ namespace RTE {
187187
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
188188

189189
void FrameMan::Destroy() {
190-
delete m_GUIScreen;
191-
delete m_LargeFont;
192-
delete m_SmallFont;
193-
190+
for (const GUIScreen *guiScreen : m_GUIScreens) {
191+
delete guiScreen;
192+
}
193+
for (const GUIFont *guiFont : m_LargeFonts) {
194+
delete guiFont;
195+
}
196+
for (const GUIFont *guiFont : m_SmallFonts) {
197+
delete guiFont;
198+
}
194199
Clear();
195200
}
196201

@@ -326,7 +331,7 @@ namespace RTE {
326331
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
327332

328333
std::string FrameMan::SplitStringToFitWidth(const std::string &stringToSplit, int widthLimit, bool useSmallFont) {
329-
GUIFont *fontToUse = GetFont(useSmallFont);
334+
GUIFont *fontToUse = GetFont(useSmallFont, false);
330335
auto SplitSingleLineAsNeeded = [this, &widthLimit, &fontToUse](std::string &lineToSplitAsNeeded) {
331336
int numberOfScreenWidthsForText = static_cast<int>(std::ceil(static_cast<float>(fontToUse->CalculateWidth(lineToSplitAsNeeded)) / static_cast<float>(widthLimit)));
332337
if (numberOfScreenWidthsForText > 1) {
@@ -714,21 +719,39 @@ namespace RTE {
714719

715720
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
716721

717-
GUIFont * FrameMan::GetFont(bool isSmall) {
718-
if (!m_GUIScreen) { m_GUIScreen = new AllegroScreen(m_BackBuffer8.get()); }
722+
GUIFont * FrameMan::GetFont(bool isSmall, bool trueColor) {
723+
size_t colorIndex = trueColor ? 1 : 0;
724+
725+
if (!m_GUIScreens[colorIndex]) {
726+
m_GUIScreens[colorIndex] = new AllegroScreen(trueColor ? m_BackBuffer32.get() : m_BackBuffer8.get());
727+
}
719728

720729
if (isSmall) {
721-
if (!m_SmallFont) {
722-
m_SmallFont = new GUIFont("SmallFont");
723-
m_SmallFont->Load(m_GUIScreen, "Base.rte/GUIs/Skins/FontSmall.png");
730+
if (!m_SmallFonts[colorIndex]) {
731+
std::string fontName = "SmallFont";
732+
std::string fontPath = "Base.rte/GUIs/Skins/FontSmall.png";
733+
734+
if (trueColor) {
735+
fontName = "SmallFont32";
736+
fontPath = "Base.rte/GUIs/Skins/Menus/FontSmall.png";
737+
}
738+
m_SmallFonts[colorIndex] = new GUIFont(fontName);
739+
m_SmallFonts[colorIndex]->Load(m_GUIScreens[colorIndex], fontPath);
724740
}
725-
return m_SmallFont;
741+
return m_SmallFonts[colorIndex];
726742
}
727-
if (!m_LargeFont) {
728-
m_LargeFont = new GUIFont("FatFont");
729-
m_LargeFont->Load(m_GUIScreen, "Base.rte/GUIs/Skins/FontLarge.png");
743+
if (!m_LargeFonts[colorIndex]) {
744+
std::string fontName = "FatFont";
745+
std::string fontPath = "Base.rte/GUIs/Skins/FontLarge.png";
746+
747+
if (trueColor) {
748+
fontName = "FatFont32";
749+
fontPath = "Base.rte/GUIs/Skins/Menus/FontLarge.png";
750+
}
751+
m_LargeFonts[colorIndex] = new GUIFont(fontName);
752+
m_LargeFonts[colorIndex]->Load(m_GUIScreens[colorIndex], fontPath);
730753
}
731-
return m_LargeFont;
754+
return m_LargeFonts[colorIndex];
732755
}
733756

734757
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Managers/FrameMan.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,16 @@ namespace RTE {
176176
/// <summary>
177177
/// Gets the small font from the GUI engine's current skin. Ownership is NOT transferred!
178178
/// </summary>
179+
/// <param name="trueColor">Whether to get the 32bpp color version of the font.</param>
179180
/// <returns>A pointer to the requested font, or 0 if no small font was found.</returns>
180-
GUIFont * GetSmallFont() { return GetFont(true); }
181+
GUIFont * GetSmallFont(bool trueColor = false) { return GetFont(true, trueColor); }
181182

182183
/// <summary>
183184
/// Gets the large font from the GUI engine's current skin. Ownership is NOT transferred!
184185
/// </summary>
186+
/// <param name="trueColor">Whether to get the 32bpp color version of the font.</param>
185187
/// <returns>A pointer to the requested font, or 0 if no large font was found.</returns>
186-
GUIFont * GetLargeFont() { return GetFont(false); }
188+
GUIFont * GetLargeFont(bool trueColor = false) { return GetFont(false, trueColor); }
187189

188190
/// <summary>
189191
/// Calculates the width of a text string using the given font size.
@@ -493,9 +495,9 @@ namespace RTE {
493495
int m_PlayerScreenWidth; //!< Width of the screen of each player. Will be smaller than resolution only if the screen is split.
494496
int m_PlayerScreenHeight; //!< Height of the screen of each player. Will be smaller than resolution only if the screen is split.
495497

496-
AllegroScreen *m_GUIScreen; //!< GUI screen object kept and owned just for the fonts.
497-
GUIFont *m_SmallFont; //!< Pointer to the standard small font for quick access.
498-
GUIFont *m_LargeFont; //!< Pointer to the standard large font for quick access.
498+
std::array<AllegroScreen *, 2> m_GUIScreens; //!< GUI screen objects kept and owned just for the fonts.
499+
std::array<GUIFont *, 2> m_SmallFonts; //!< Pointers to the standard small font for quick access.
500+
std::array<GUIFont *, 2> m_LargeFonts; //!< Pointers to the standard large font for quick access.
499501

500502
std::string m_ScreenText[c_MaxScreenCount]; //!< The text to be displayed on each player's screen.
501503
bool m_TextCentered[c_MaxScreenCount]; //!< Whether screen text is centered vertically.
@@ -626,8 +628,9 @@ namespace RTE {
626628
/// Gets the requested font from the GUI engine's current skin. Ownership is NOT transferred!
627629
/// </summary>
628630
/// <param name="isSmall">Size of font to get. True for small font, false for large font.</param>
631+
/// <param name="trueColor">Whether to get the 32bpp color version of the font.</param>
629632
/// <returns>A pointer to the requested font, or 0 if no font was found.</returns>
630-
GUIFont * GetFont(bool isSmall);
633+
GUIFont * GetFont(bool isSmall, bool trueColor);
631634

632635
/// <summary>
633636
/// Clears all the member variables of this FrameMan, effectively resetting the members of this abstraction level only.

0 commit comments

Comments
 (0)