nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
gui.cc
Go to the documentation of this file.
1#include "client/gui.h"
2
3#include <imgui.h>
4#include <raylib.h>
5#include <rlImGui.h>
6
7#include "client/theme.h"
8
9namespace nanommo {
10
12 // raylib already scales for high-DPI screens, so the fonts need no scaling
13 // for them. Our scale is for the screen's size.
14 rlImGuiSetLoadFontsCallback([] { LoadFonts(FontFolder()); });
15 rlImGuiSetup(true);
16 ImGui::GetIO().IniFilename = nullptr;
17 ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
18 // The cursor is ours, as the world has cursors of its own (see cursor.h).
19 ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
20}
21
22Gui::~Gui() { rlImGuiShutdown(); }
23
24void Gui::Begin(float player_scale) {
25 // In points, as ImGui lays out in, so a Retina screen counts as half its
26 // pixels.
27 const float scale =
28 InterfaceScale(static_cast<float>(GetScreenHeight()), player_scale);
29 if (scale != applied_) {
30 ApplyTheme(scale);
31 applied_ = scale;
32 }
33 rlImGuiBegin();
34}
35
36void Gui::End() { rlImGuiEnd(); }
37
38} // namespace nanommo
void End()
Definition gui.cc:36
void Begin(float player_scale=1.0f)
Definition gui.cc:24
Definition chat.cc:9
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 ApplyTheme(float at)
ImGui's style in our colours, with its sizes and its text at the scale.
Definition theme.cc:102
float InterfaceScale(float height, float player)
Definition theme.cc:93