Skip to content

Commit 790b6e1

Browse files
committed
Move font icons to engine/font_icons.h, actually use namespace
This significantly reduces the number of source files that need to be recompiled when adding/removing font icons, as previously all files depending on `textrender.h` had to be recompiled. Sort the constants in lexicographical order to make it easier to add more, as the grouping and ordering was previously unclear. Use qualified names for all font icons and rename the namespace to `FontIcon`, instead of duplicating the `FONT_ICON_` part in the constant name and mostly using `using namespace FontIcons` in other files.
1 parent 5bda840 commit 790b6e1

23 files changed

+280
-290
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,7 @@ set_src(ENGINE_INTERFACE GLOB src/engine
20552055
editor.h
20562056
engine.h
20572057
favorites.h
2058+
font_icons.h
20582059
friends.h
20592060
ghost.h
20602061
graphics.cpp

src/engine/font_icons.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#ifndef ENGINE_FONT_ICONS_H
2+
#define ENGINE_FONT_ICONS_H
3+
4+
namespace FontIcon
5+
{
6+
// Each font icon is named according to its official name in Font Awesome.
7+
// The constants are sorted in lexicographical order.
8+
9+
inline const char *const ARROW_ROTATE_LEFT = "\xEF\x83\xA2";
10+
inline const char *const ARROW_ROTATE_RIGHT = "\xEF\x80\x9E";
11+
inline const char *const ARROW_UP_RIGHT_FROM_SQUARE = "\xEF\x82\x8E";
12+
inline const char *const ARROWS_LEFT_RIGHT = "\xEF\x8C\xB7";
13+
inline const char *const ARROWS_ROTATE = "\xEF\x80\xA1";
14+
inline const char *const ARROWS_UP_DOWN = "\xEF\x81\xBD";
15+
inline const char *const BACKWARD = "\xEF\x81\x8A";
16+
inline const char *const BACKWARD_FAST = "\xEF\x81\x89";
17+
inline const char *const BACKWARD_STEP = "\xEF\x81\x88";
18+
inline const char *const BAN = "\xEF\x81\x9E";
19+
inline const char *const BOOKMARK = "\xEF\x80\xAE";
20+
inline const char *const BORDER_ALL = "\xEF\xA1\x8C";
21+
inline const char *const CAMERA = "\xEF\x80\xB0";
22+
inline const char *const CHEVRON_DOWN = "\xEF\x81\xB8";
23+
inline const char *const CHEVRON_LEFT = "\xEF\x81\x93";
24+
inline const char *const CHEVRON_RIGHT = "\xEF\x81\x94";
25+
inline const char *const CHEVRON_UP = "\xEF\x81\xB7";
26+
inline const char *const CIRCLE = "\xEF\x84\x91";
27+
inline const char *const CIRCLE_CHEVRON_DOWN = "\xEF\x84\xBA";
28+
inline const char *const CIRCLE_PLAY = "\xEF\x85\x84";
29+
inline const char *const CLAPPERBOARD = "\xEE\x84\xB1";
30+
inline const char *const COMMENT = "\xEF\x81\xB5";
31+
inline const char *const COMMENT_SLASH = "\xEF\x92\xB3";
32+
inline const char *const DICE_FIVE = "\xEF\x94\xA3";
33+
inline const char *const DICE_FOUR = "\xEF\x94\xA4";
34+
inline const char *const DICE_ONE = "\xEF\x94\xA5";
35+
inline const char *const DICE_SIX = "\xEF\x94\xA6";
36+
inline const char *const DICE_THREE = "\xEF\x94\xA7";
37+
inline const char *const DICE_TWO = "\xEF\x94\xA8";
38+
inline const char *const EARTH_AMERICAS = "\xEF\x95\xBD";
39+
inline const char *const ELLIPSIS = "\xEF\x85\x81";
40+
inline const char *const EYE = "\xEF\x81\xAE";
41+
inline const char *const EYE_DROPPER = "\xEF\x87\xBB";
42+
inline const char *const EYE_SLASH = "\xEF\x81\xB0";
43+
inline const char *const FILE = "\xEF\x85\x9B";
44+
inline const char *const FILM = "\xEF\x80\x88";
45+
inline const char *const FLAG_CHECKERED = "\xEF\x84\x9E";
46+
inline const char *const FOLDER = "\xEF\x81\xBB";
47+
inline const char *const FOLDER_OPEN = "\xEF\x81\xBC";
48+
inline const char *const FOLDER_TREE = "\xEF\xA0\x82";
49+
inline const char *const FORWARD = "\xEF\x81\x8E";
50+
inline const char *const FORWARD_FAST = "\xEF\x81\x90";
51+
inline const char *const FORWARD_STEP = "\xEF\x81\x91";
52+
inline const char *const GEAR = "\xEF\x80\x93";
53+
inline const char *const HEART = "\xEF\x80\x84";
54+
inline const char *const HEART_CRACK = "\xEF\x9E\xA9";
55+
inline const char *const HOUSE = "\xEF\x80\x95";
56+
inline const char *const IMAGE = "\xEF\x80\xBE";
57+
inline const char *const INFO = "\xEF\x84\xA9";
58+
inline const char *const KEY = "\xEF\x82\x84";
59+
inline const char *const KEYBOARD = "\xE2\x8C\xA8";
60+
inline const char *const LAYER_GROUP = "\xEF\x97\xBD";
61+
inline const char *const LIST_UL = "\xEF\x83\x8A";
62+
inline const char *const LOCK = "\xEF\x80\xA3";
63+
inline const char *const MAGNIFYING_GLASS = "\xEF\x80\x82";
64+
inline const char *const MAP = "\xEF\x89\xB9";
65+
inline const char *const MINUS = "-";
66+
inline const char *const MUSIC = "\xEF\x80\x81";
67+
inline const char *const NETWORK_WIRED = "\xEF\x9B\xBF";
68+
inline const char *const NEWSPAPER = "\xEF\x87\xAA";
69+
inline const char *const PAUSE = "\xEF\x81\x8C";
70+
inline const char *const PEN_TO_SQUARE = "\xEF\x81\x84";
71+
inline const char *const PENCIL = "\xEF\x8C\x83";
72+
inline const char *const PLAY = "\xEF\x81\x8B";
73+
inline const char *const PLUS = "+";
74+
inline const char *const POWER_OFF = "\xEF\x80\x91";
75+
inline const char *const QUESTION = "?";
76+
inline const char *const REDO = "\xEF\x8B\xB9";
77+
inline const char *const RIGHT_FROM_BRACKET = "\xEF\x8B\xB5";
78+
inline const char *const RIGHT_TO_BRACKET = "\xEF\x8B\xB6";
79+
inline const char *const SLASH = "\xEF\x9C\x95";
80+
inline const char *const SORT_DOWN = "\xEF\x83\x9D";
81+
inline const char *const SORT_UP = "\xEF\x83\x9E";
82+
inline const char *const SQUARE_MINUS = "\xEF\x85\x86";
83+
inline const char *const SQUARE_PLUS = "\xEF\x83\xBE";
84+
inline const char *const STAR = "\xEF\x80\x85";
85+
inline const char *const STOP = "\xEF\x81\x8D";
86+
inline const char *const TERMINAL = "\xEF\x84\xA0";
87+
inline const char *const TRASH = "\xEF\x87\xB8";
88+
inline const char *const TRIANGLE_EXCLAMATION = "\xEF\x81\xB1";
89+
inline const char *const UNDO = "\xEF\x8B\xAA";
90+
inline const char *const USER = "\xEF\x80\x87";
91+
inline const char *const VIDEO = "\xEF\x80\xBD";
92+
inline const char *const XMARK = "\xEF\x80\x8D";
93+
}
94+
95+
#endif

src/engine/textrender.h

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -63,104 +63,6 @@ enum class EFontPreset
6363
ICON_FONT,
6464
};
6565

66-
namespace FontIcons
67-
{
68-
// Each font icon is named according to its official name in Font Awesome
69-
[[maybe_unused]] static const char *FONT_ICON_PLUS = "+";
70-
[[maybe_unused]] static const char *FONT_ICON_MINUS = "-";
71-
[[maybe_unused]] static const char *FONT_ICON_LOCK = "\xEF\x80\xA3";
72-
[[maybe_unused]] static const char *FONT_ICON_MAGNIFYING_GLASS = "\xEF\x80\x82";
73-
[[maybe_unused]] static const char *FONT_ICON_HEART = "\xEF\x80\x84";
74-
[[maybe_unused]] static const char *FONT_ICON_HEART_CRACK = "\xEF\x9E\xA9";
75-
[[maybe_unused]] static const char *FONT_ICON_STAR = "\xEF\x80\x85";
76-
[[maybe_unused]] static const char *FONT_ICON_XMARK = "\xEF\x80\x8D";
77-
[[maybe_unused]] static const char *FONT_ICON_CIRCLE = "\xEF\x84\x91";
78-
[[maybe_unused]] static const char *FONT_ICON_ARROW_ROTATE_LEFT = "\xEF\x83\xA2";
79-
[[maybe_unused]] static const char *FONT_ICON_ARROW_ROTATE_RIGHT = "\xEF\x80\x9E";
80-
[[maybe_unused]] static const char *FONT_ICON_FLAG_CHECKERED = "\xEF\x84\x9E";
81-
[[maybe_unused]] static const char *FONT_ICON_BAN = "\xEF\x81\x9E";
82-
[[maybe_unused]] static const char *FONT_ICON_CIRCLE_CHEVRON_DOWN = "\xEF\x84\xBA";
83-
[[maybe_unused]] static const char *FONT_ICON_KEY = "\xEF\x82\x84";
84-
[[maybe_unused]] static const char *FONT_ICON_SQUARE_MINUS = "\xEF\x85\x86";
85-
[[maybe_unused]] static const char *FONT_ICON_SQUARE_PLUS = "\xEF\x83\xBE";
86-
[[maybe_unused]] static const char *FONT_ICON_SORT_UP = "\xEF\x83\x9E";
87-
[[maybe_unused]] static const char *FONT_ICON_SORT_DOWN = "\xEF\x83\x9D";
88-
[[maybe_unused]] static const char *FONT_ICON_TRIANGLE_EXCLAMATION = "\xEF\x81\xB1";
89-
90-
[[maybe_unused]] static const char *FONT_ICON_HOUSE = "\xEF\x80\x95";
91-
[[maybe_unused]] static const char *FONT_ICON_BOOKMARK = "\xEF\x80\xAE";
92-
[[maybe_unused]] static const char *FONT_ICON_NEWSPAPER = "\xEF\x87\xAA";
93-
[[maybe_unused]] static const char *FONT_ICON_POWER_OFF = "\xEF\x80\x91";
94-
[[maybe_unused]] static const char *FONT_ICON_GEAR = "\xEF\x80\x93";
95-
[[maybe_unused]] static const char *FONT_ICON_PEN_TO_SQUARE = "\xEF\x81\x84";
96-
[[maybe_unused]] static const char *FONT_ICON_CLAPPERBOARD = "\xEE\x84\xB1";
97-
[[maybe_unused]] static const char *FONT_ICON_EARTH_AMERICAS = "\xEF\x95\xBD";
98-
[[maybe_unused]] static const char *FONT_ICON_NETWORK_WIRED = "\xEF\x9B\xBF";
99-
[[maybe_unused]] static const char *FONT_ICON_LIST_UL = "\xEF\x83\x8A";
100-
[[maybe_unused]] static const char *FONT_ICON_INFO = "\xEF\x84\xA9";
101-
[[maybe_unused]] static const char *FONT_ICON_TERMINAL = "\xEF\x84\xA0";
102-
[[maybe_unused]] static const char *FONT_ICON_USER = "\xEF\x80\x87";
103-
104-
[[maybe_unused]] static const char *FONT_ICON_SLASH = "\xEF\x9C\x95";
105-
[[maybe_unused]] static const char *FONT_ICON_PLAY = "\xEF\x81\x8B";
106-
[[maybe_unused]] static const char *FONT_ICON_PAUSE = "\xEF\x81\x8C";
107-
[[maybe_unused]] static const char *FONT_ICON_STOP = "\xEF\x81\x8D";
108-
[[maybe_unused]] static const char *FONT_ICON_CHEVRON_LEFT = "\xEF\x81\x93";
109-
[[maybe_unused]] static const char *FONT_ICON_CHEVRON_RIGHT = "\xEF\x81\x94";
110-
[[maybe_unused]] static const char *FONT_ICON_CHEVRON_UP = "\xEF\x81\xB7";
111-
[[maybe_unused]] static const char *FONT_ICON_CHEVRON_DOWN = "\xEF\x81\xB8";
112-
[[maybe_unused]] static const char *FONT_ICON_BACKWARD = "\xEF\x81\x8A";
113-
[[maybe_unused]] static const char *FONT_ICON_FORWARD = "\xEF\x81\x8E";
114-
[[maybe_unused]] static const char *FONT_ICON_RIGHT_FROM_BRACKET = "\xEF\x8B\xB5";
115-
[[maybe_unused]] static const char *FONT_ICON_RIGHT_TO_BRACKET = "\xEF\x8B\xB6";
116-
[[maybe_unused]] static const char *FONT_ICON_ARROW_UP_RIGHT_FROM_SQUARE = "\xEF\x82\x8E";
117-
[[maybe_unused]] static const char *FONT_ICON_BACKWARD_STEP = "\xEF\x81\x88";
118-
[[maybe_unused]] static const char *FONT_ICON_FORWARD_STEP = "\xEF\x81\x91";
119-
[[maybe_unused]] static const char *FONT_ICON_BACKWARD_FAST = "\xEF\x81\x89";
120-
[[maybe_unused]] static const char *FONT_ICON_FORWARD_FAST = "\xEF\x81\x90";
121-
[[maybe_unused]] static const char *FONT_ICON_KEYBOARD = "\xE2\x8C\xA8";
122-
[[maybe_unused]] static const char *FONT_ICON_ELLIPSIS = "\xEF\x85\x81";
123-
124-
[[maybe_unused]] static const char *FONT_ICON_FOLDER = "\xEF\x81\xBB";
125-
[[maybe_unused]] static const char *FONT_ICON_FOLDER_OPEN = "\xEF\x81\xBC";
126-
[[maybe_unused]] static const char *FONT_ICON_FOLDER_TREE = "\xEF\xA0\x82";
127-
[[maybe_unused]] static const char *FONT_ICON_FILM = "\xEF\x80\x88";
128-
[[maybe_unused]] static const char *FONT_ICON_VIDEO = "\xEF\x80\xBD";
129-
[[maybe_unused]] static const char *FONT_ICON_MAP = "\xEF\x89\xB9";
130-
[[maybe_unused]] static const char *FONT_ICON_IMAGE = "\xEF\x80\xBE";
131-
[[maybe_unused]] static const char *FONT_ICON_MUSIC = "\xEF\x80\x81";
132-
[[maybe_unused]] static const char *FONT_ICON_FILE = "\xEF\x85\x9B";
133-
134-
[[maybe_unused]] static const char *FONT_ICON_PENCIL = "\xEF\x8C\x83";
135-
[[maybe_unused]] static const char *FONT_ICON_TRASH = "\xEF\x87\xB8";
136-
137-
[[maybe_unused]] static const char *FONT_ICON_ARROWS_LEFT_RIGHT = "\xEF\x8C\xB7";
138-
[[maybe_unused]] static const char *FONT_ICON_ARROWS_UP_DOWN = "\xEF\x81\xBD";
139-
[[maybe_unused]] static const char *FONT_ICON_CIRCLE_PLAY = "\xEF\x85\x84";
140-
[[maybe_unused]] static const char *FONT_ICON_BORDER_ALL = "\xEF\xA1\x8C";
141-
[[maybe_unused]] static const char *FONT_ICON_EYE = "\xEF\x81\xAE";
142-
[[maybe_unused]] static const char *FONT_ICON_EYE_SLASH = "\xEF\x81\xB0";
143-
[[maybe_unused]] static const char *FONT_ICON_EYE_DROPPER = "\xEF\x87\xBB";
144-
[[maybe_unused]] static const char *FONT_ICON_COMMENT = "\xEF\x81\xB5";
145-
[[maybe_unused]] static const char *FONT_ICON_COMMENT_SLASH = "\xEF\x92\xB3";
146-
147-
[[maybe_unused]] static const char *FONT_ICON_DICE_ONE = "\xEF\x94\xA5";
148-
[[maybe_unused]] static const char *FONT_ICON_DICE_TWO = "\xEF\x94\xA8";
149-
[[maybe_unused]] static const char *FONT_ICON_DICE_THREE = "\xEF\x94\xA7";
150-
[[maybe_unused]] static const char *FONT_ICON_DICE_FOUR = "\xEF\x94\xA4";
151-
[[maybe_unused]] static const char *FONT_ICON_DICE_FIVE = "\xEF\x94\xA3";
152-
[[maybe_unused]] static const char *FONT_ICON_DICE_SIX = "\xEF\x94\xA6";
153-
154-
[[maybe_unused]] static const char *FONT_ICON_LAYER_GROUP = "\xEF\x97\xBD";
155-
[[maybe_unused]] static const char *FONT_ICON_UNDO = "\xEF\x8B\xAA";
156-
[[maybe_unused]] static const char *FONT_ICON_REDO = "\xEF\x8B\xB9";
157-
158-
[[maybe_unused]] static const char *FONT_ICON_ARROWS_ROTATE = "\xEF\x80\xA1";
159-
[[maybe_unused]] static const char *FONT_ICON_QUESTION = "?";
160-
161-
[[maybe_unused]] static const char *FONT_ICON_CAMERA = "\xEF\x80\xB0";
162-
}
163-
16466
enum ETextCursorSelectionMode
16567
{
16668
// ignore any kind of selection

src/game/client/components/hud.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <base/color.h>
1111

12+
#include <engine/font_icons.h>
1213
#include <engine/graphics.h>
1314
#include <engine/shared/config.h>
1415
#include <engine/textrender.h>
@@ -1323,7 +1324,7 @@ void CHud::RenderSpectatorCount()
13231324
float x = StartX + 2;
13241325

13251326
TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
1326-
TextRender()->Text(x, y, Fontsize, FontIcons::FONT_ICON_EYE, -1.0f);
1327+
TextRender()->Text(x, y, Fontsize, FontIcon::EYE, -1.0f);
13271328
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
13281329
TextRender()->Text(x + Fontsize + 3.f, y, Fontsize, aBuf, -1.0f);
13291330
}
@@ -1601,7 +1602,7 @@ void CHud::RenderSpectatorHud()
16011602
Graphics()->DrawRect(TagX, m_Height - 12.0f, TagWidth, 10.0f, ColorRGBA(1.0f, 1.0f, 1.0f, AutoSpecCameraEnabled ? 0.50f : 0.10f), IGraphics::CORNER_ALL, 2.5f);
16021603
TextRender()->TextColor(1, 1, 1, AutoSpecCameraEnabled ? 1.0f : 0.65f);
16031604
TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
1604-
TextRender()->Text(TagX + Padding, m_Height - 10.0f, 6.0f, FontIcons::FONT_ICON_CAMERA, -1.0f);
1605+
TextRender()->Text(TagX + Padding, m_Height - 10.0f, 6.0f, FontIcon::CAMERA, -1.0f);
16051606
TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
16061607
TextRender()->Text(TagX + Padding + IconWidth + Padding, m_Height - 10.0f, 6.0f, pLabelText, -1.0f);
16071608
TextRender()->TextColor(1, 1, 1, 1);

src/game/client/components/key_binder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
#include <base/color.h>
66

7+
#include <engine/font_icons.h>
8+
79
#include <game/client/components/binds.h>
810
#include <game/client/gameclient.h>
911
#include <game/client/ui.h>
1012
#include <game/localization.h>
1113

12-
using namespace FontIcons;
13-
1414
bool CKeyBinder::OnInput(const IInput::CEvent &Event)
1515
{
1616
if(!m_TakeKey)
@@ -39,7 +39,7 @@ CKeyBinder::CKeyReaderResult CKeyBinder::DoKeyReader(CButtonContainer *pReaderBu
3939
pRect->VSplitRight(pRect->h, &KeyReaderButton, &ClearButton);
4040

4141
const int ClearButtonResult = Ui()->DoButton_FontIcon(
42-
pClearButton, FONT_ICON_TRASH,
42+
pClearButton, FontIcon::TRASH,
4343
Result.m_Bind == CBindSlot(KEY_UNKNOWN, KeyModifier::NONE) ? 1 : 0,
4444
&ClearButton, BUTTONFLAG_LEFT, IGraphics::CORNER_R);
4545

0 commit comments

Comments
 (0)