nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
theme.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_THEME_H_
2#define NANOMMO_CLIENT_THEME_H_
3
4#include <imgui.h>
5
6#include <string>
7
8namespace nanommo {
9
10/// nanoMMO's own colours, as its videos and its website have them: the near
11/// black of a dying fire, its reds, its embers, gold for what's prized, and
12/// the cream of old paper for words.
13namespace colors {
14inline constexpr ImU32 kNight = IM_COL32(11, 5, 7, 255);
15inline constexpr ImU32 kCoal = IM_COL32(30, 14, 17, 255);
16inline constexpr ImU32 kWine = IM_COL32(76, 11, 20, 255);
17inline constexpr ImU32 kCrimson = IM_COL32(148, 18, 31, 255);
18inline constexpr ImU32 kRed = IM_COL32(196, 29, 41, 255);
19inline constexpr ImU32 kEmber = IM_COL32(255, 90, 60, 255);
20inline constexpr ImU32 kFlame = IM_COL32(255, 160, 74, 255);
21inline constexpr ImU32 kGold = IM_COL32(255, 211, 77, 255);
22inline constexpr ImU32 kGoldLight = IM_COL32(255, 243, 196, 255);
23inline constexpr ImU32 kGoldDark = IM_COL32(201, 138, 18, 255);
24/// The trim round every panel: gold gone dark with age.
25inline constexpr ImU32 kBrass = IM_COL32(138, 98, 38, 255);
26inline constexpr ImU32 kPaper = IM_COL32(243, 233, 220, 255);
27inline constexpr ImU32 kMuted = IM_COL32(181, 162, 151, 255);
28inline constexpr ImU32 kFaint = IM_COL32(143, 123, 112, 255);
29inline constexpr ImU32 kShadow = IM_COL32(0, 0, 0, 200);
30inline constexpr ImU32 kHealth = IM_COL32(214, 52, 46, 255);
31inline constexpr ImU32 kHealthDark = IM_COL32(110, 16, 22, 255);
32inline constexpr ImU32 kGood = IM_COL32(126, 214, 112, 255);
33} // namespace colors
34
35/// The same colour, with its alpha times the share.
36ImU32 Faded(ImU32 color, float share);
37
38/// The faces the interface is set in: a book face for what's read, its bold,
39/// and a carved capital face for titles. Before they're loaded, as in tests,
40/// each is ImGui's own.
41struct Fonts {
42 ImFont* text = nullptr;
43 ImFont* bold = nullptr;
44 ImFont* title = nullptr;
45};
46const Fonts& GetFonts();
47
48/// Loads the faces from the folder, in ImGui's font loading, with Font
49/// Awesome's icons merged into the text face after them.
50void LoadFonts(const std::string& folder);
51
52/// Where the client's fonts are, next to it.
53std::string FontFolder();
54
55/// In points, at a scale of one.
56inline constexpr float kTextSize = 18.0f;
57
58/// How much bigger than on a screen 1080 points high the interface is drawn,
59/// for a screen this high, times the player's own scale: twice as big on a
60/// 4K screen, so that it's the same share of the screen on each, but never
61/// so small that it can't be read.
62float InterfaceScale(float height, float player);
63
64/// The scale the theme was last applied at, which points in the interface's
65/// layouts are multiplied by.
66float UiScale();
67inline float Ui(float points) { return points * UiScale(); }
68inline ImVec2 Ui(ImVec2 points) { return {Ui(points.x), Ui(points.y)}; }
69
70/// ImGui's style in our colours, with its sizes and its text at the scale.
71void ApplyTheme(float scale);
72
73/// A panel's shape: a rectangle with its corners cut off.
74void PathPanel(ImDrawList* draw, ImVec2 min, ImVec2 max, float cut);
75
76/// A panel, as every window has: dark, in a shape with its corners cut, a red
77/// glow under its title, and trimmed in brass with a thin light inside it.
78void DrawPanel(ImDrawList* draw, ImVec2 min, ImVec2 max, float alpha = 0.96f);
79
80/// A diamond, filled, with an outline.
81void DrawDiamond(ImDrawList* draw, ImVec2 centre, float radius, ImU32 fill,
82 ImU32 outline);
83
84/// A line that fades in from its ends, with a diamond in its middle, under a
85/// title.
86void DrawDivider(ImDrawList* draw, ImVec2 left, float width);
87
88/// Text with a shadow under it.
89void DrawShadowedText(ImDrawList* draw, ImFont* font, float size, ImVec2 at,
90 ImU32 color, const char* text);
91
92/// Text that goes from one colour at its top to another at its bottom, with
93/// a shadow, as titles have in gold.
94void DrawGradientText(ImDrawList* draw, ImFont* font, float size, ImVec2 at,
95 ImU32 top, ImU32 bottom, const char* text);
96
97/// A title in carved gold capitals, centred on the point at its top.
98void DrawTitle(ImDrawList* draw, ImVec2 top_centre, float size,
99 const char* text);
100
101/// The part of an ImGui label that's shown: what's before any "##".
102std::string Shown(const char* label);
103
104/// Begins a window drawn as one of our panels, with its title at the top, in
105/// the player's language, and a close button that sets open to false, if open
106/// isn't null. Always call EndPanel after it, as ImGui's End.
107bool BeginPanel(const char* name, bool* open, ImGuiWindowFlags flags = 0,
108 float alpha = 0.96f);
109void EndPanel();
110
111/// A button with its corners cut, in a dark red, or, for what a screen is
112/// there for, such as entering the world, in the colours of a fire, with its
113/// label in the player's language. Returns whether it was clicked. A width of
114/// zero fits the label, and one below zero takes the rest of the line.
115bool GameButton(const char* label, ImVec2 size, bool primary = false,
116 bool enabled = true);
117
118/// A bar that's full by the share, in its colour, in a dark trough with brass
119/// round it and its words in the middle.
120void DrawBar(ImDrawList* draw, ImVec2 min, ImVec2 max, float share, ImU32 color,
121 ImU32 dark, const char* text);
122
123/// A slot, as the bag's and the hotbar's are: a dark well in brass, which a
124/// colour lights round its edge, such as gold while the mouse is over it, or
125/// green or red while something dragged over it would go there or not.
126void DrawSlot(ImDrawList* draw, ImVec2 min, ImVec2 max, ImU32 edge);
127
128/// A round button, as the chat's in the bottom left and the windows' in the
129/// bottom right are: a wine-red disc in brass, with its icon, lit while the
130/// mouse is over it, and ringed in ember while what it opens is open. Its rim
131/// reaches a little past the radius, so its window wants room round it.
132void DrawRoundButton(ImDrawList* draw, ImVec2 centre, float radius,
133 const char* icon, bool hovered, bool on = false);
134
135/// An icon in the middle of a slot, in its colour, on a glow of that colour.
136void DrawSlotIcon(ImDrawList* draw, ImVec2 min, ImVec2 max, const char* icon,
137 ImU32 color, float alpha = 1.0f);
138
139/// What the player's dragging, under the mouse, over everything else: its
140/// icon in a slot of the size, where the mouse took hold of it.
141void DrawDragged(const char* icon, ImU32 color, float size, ImVec2 grab);
142
143/// The screens before the world: the dark of a fire gone low, red at the
144/// bottom, with embers rising through it, and darker at the edges. Time is in
145/// seconds, which the embers rise by.
146void DrawBackdrop(ImDrawList* draw, ImVec2 size, float time);
147
148/// The game's name, in gold capitals, with a glow behind it, centred on the
149/// point at its top, as tall as the size.
150void DrawLogo(ImDrawList* draw, ImVec2 top_centre, float size);
151
152} // namespace nanommo
153
154#endif // NANOMMO_CLIENT_THEME_H_
constexpr ImU32 kFaint
Definition theme.h:28
constexpr ImU32 kEmber
Definition theme.h:19
constexpr ImU32 kCrimson
Definition theme.h:17
constexpr ImU32 kRed
Definition theme.h:18
constexpr ImU32 kGoldDark
Definition theme.h:23
constexpr ImU32 kGood
Definition theme.h:32
constexpr ImU32 kShadow
Definition theme.h:29
constexpr ImU32 kGoldLight
Definition theme.h:22
constexpr ImU32 kFlame
Definition theme.h:20
constexpr ImU32 kNight
Definition theme.h:14
constexpr ImU32 kMuted
Definition theme.h:27
constexpr ImU32 kWine
Definition theme.h:16
constexpr ImU32 kPaper
Definition theme.h:26
constexpr ImU32 kBrass
The trim round every panel: gold gone dark with age.
Definition theme.h:25
constexpr ImU32 kCoal
Definition theme.h:15
constexpr ImU32 kGold
Definition theme.h:21
constexpr ImU32 kHealth
Definition theme.h:30
constexpr ImU32 kHealthDark
Definition theme.h:31
Definition chat.cc:9
bool BeginPanel(const char *name, bool *open, ImGuiWindowFlags flags, float alpha)
Definition theme.cc:320
void DrawPanel(ImDrawList *draw, ImVec2 min, ImVec2 max, float alpha)
Definition theme.cc:223
void DrawLogo(ImDrawList *draw, ImVec2 top_centre, float size)
Definition theme.cc:606
void DrawBar(ImDrawList *draw, ImVec2 min, ImVec2 max, float share, ImU32 color, ImU32 dark, const char *text)
Definition theme.cc:452
constexpr float kTextSize
In points, at a scale of one.
Definition theme.h:56
void DrawDivider(ImDrawList *draw, ImVec2 left, float width)
Definition theme.cc:257
float Ui(float points)
Definition theme.h:67
void EndPanel()
Definition theme.cc:379
void DrawRoundButton(ImDrawList *draw, ImVec2 centre, float radius, const char *icon, bool hovered, bool on)
Definition theme.cc:503
void DrawSlotIcon(ImDrawList *draw, ImVec2 min, ImVec2 max, const char *icon, ImU32 color, float alpha)
An icon in the middle of a slot, in its colour, on a glow of that colour.
Definition theme.cc:519
std::string FontFolder()
Where the client's fonts are, next to it.
Definition theme.cc:89
void LoadFonts(const std::string &folder)
Definition theme.cc:75
void DrawDragged(const char *icon, ImU32 color, float size, ImVec2 grab)
Definition theme.cc:536
void ApplyTheme(float at)
ImGui's style in our colours, with its sizes and its text at the scale.
Definition theme.cc:102
ImU32 Faded(ImU32 color, float share)
The same colour, with its alpha times the share.
Definition theme.cc:59
float InterfaceScale(float height, float player)
Definition theme.cc:93
void DrawDiamond(ImDrawList *draw, ImVec2 centre, float radius, ImU32 fill, ImU32 outline)
A diamond, filled, with an outline.
Definition theme.cc:213
void DrawBackdrop(ImDrawList *draw, ImVec2 size, float time)
Definition theme.cc:563
void DrawTitle(ImDrawList *draw, ImVec2 top_centre, float size, const char *text)
A title in carved gold capitals, centred on the point at its top.
Definition theme.cc:299
bool GameButton(const char *label, ImVec2 size, bool primary, bool enabled)
Definition theme.cc:381
void DrawGradientText(ImDrawList *draw, ImFont *font, float size, ImVec2 at, ImU32 top, ImU32 bottom, const char *text)
Definition theme.cc:283
void DrawShadowedText(ImDrawList *draw, ImFont *font, float size, ImVec2 at, ImU32 color, const char *text)
Text with a shadow under it.
Definition theme.cc:272
void DrawSlot(ImDrawList *draw, ImVec2 min, ImVec2 max, ImU32 edge)
Definition theme.cc:480
float UiScale()
Definition theme.cc:100
void PathPanel(ImDrawList *draw, ImVec2 min, ImVec2 max, float cut)
A panel's shape: a rectangle with its corners cut off.
Definition theme.cc:202
const Fonts & GetFonts()
Definition theme.cc:66
std::string Shown(const char *label)
The part of an ImGui label that's shown: what's before any "##".
Definition theme.cc:308
ImFont * text
Definition theme.h:42
ImFont * bold
Definition theme.h:43
ImFont * title
Definition theme.h:44