OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
FontImGui.cpp
Go to the documentation of this file.
1 
8 #include "imgui/imgui.h"
9 
10 #include "global.h"
11 #include "UI.h"
12 #include "system/FontImGui.h"
13 
14 #define SCALE_CALC 30.0f
15 #define SCALE_DRAW SCALE_CALC
16 
17 unsigned int FontImGui::widthText(float scale, std::string s) {
18  ImGuiIO& io = ImGui::GetIO();
19  ImFont* font = io.Fonts->Fonts.at(0);
20  ImVec2 size = font->CalcTextSizeA(scale * SCALE_CALC, FLT_MAX, io.DisplaySize.y, s.c_str(),
21  s.c_str() + s.length());
22  return size.x;
23 }
24 
25 void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
26  glm::vec4 color, std::string s) {
27  ImGuiIO& io = ImGui::GetIO();
28  ImFont* font = io.Fonts->Fonts.at(0);
29  ImVec2 pos = ImVec2(x, y);
30  ImU32 col = (ImU32(color.r * 255)) | (ImU32(color.g * 255) << 8) | (ImU32(color.b * 255) << 16) |
31  (ImU32(color.a * 255) << 24);
32 
33  ImDrawList dl;
35  dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
36  dl.AddText(font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length());
37 
38  ImDrawList* dlp = &dl;
39  UI::renderImGui(&dlp, 1);
40 }
41 
42 unsigned int FontImGui::heightText(float scale, unsigned int maxWidth, std::string s) {
43  ImGuiIO& io = ImGui::GetIO();
44  ImFont* font = io.Fonts->Fonts.at(0);
45  ImVec2 size = font->CalcTextSizeA(scale * SCALE_CALC, FLT_MAX, maxWidth, s.c_str(),
46  s.c_str() + s.length());
47  return size.y;
48 }
49 
50 void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
51  glm::vec4 color, unsigned int maxWidth, std::string s) {
52  ImGuiIO& io = ImGui::GetIO();
53  ImFont* font = io.Fonts->Fonts.at(0);
54  ImVec2 pos = ImVec2(x, y);
55  ImU32 col = (ImU32(color.r * 255)) | (ImU32(color.g * 255) << 8) | (ImU32(color.b * 255) << 16) |
56  (ImU32(color.a * 255) << 24);
57 
58  ImDrawList dl;
60  dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
61  dl.AddText(font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length(), maxWidth);
62 
63  ImDrawList* dlp = &dl;
64  UI::renderImGui(&dlp, 1);
65 }
66 
Default Font Implementation.
unsigned int ImU32
Definition: imgui.h:34
static void drawTextWrapped(unsigned int x, unsigned int y, float scale, glm::vec4 color, unsigned int maxWidth, std::string s)
Definition: FontImGui.cpp:50
IMGUI_API void PushTextureID(const ImTextureID &texture_id)
Definition: imgui.cpp:6919
void * TexID
Definition: imgui.h:905
Definition: imgui.h:61
IMGUI_API void PushClipRect(const ImVec4 &clip_rect)
Definition: imgui.cpp:6892
Included everywhere.
static void drawText(unsigned int x, unsigned int y, float scale, glm::vec4 color, std::string s)
Definition: FontImGui.cpp:25
IMGUI_API void AddText(ImFont *font, float font_size, const ImVec2 &pos, ImU32 col, const char *text_begin, const char *text_end=NULL, float wrap_width=0.0f, const ImVec2 *cpu_clip_max=NULL)
Definition: imgui.cpp:7153
Definition: imgui.h:50
Definition: imgui.h:925
static unsigned int widthText(float scale, std::string s)
Definition: FontImGui.cpp:17
Definition: imgui.h:546
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:1736
value_type & at(size_t i)
Definition: imgui.h:103
ImFontAtlas * ContainerAtlas
Definition: imgui.h:942
ImVec2 DisplaySize
Definition: imgui.h:552
static void renderImGui(ImDrawList **const draw_lists, int count)
Definition: UI.cpp:459
ImVector< ImFont * > Fonts
Definition: imgui.h:912
UI/Event Manager.
#define SCALE_CALC
Definition: FontImGui.cpp:14
static const float scale
Definition: Sprite.cpp:15
float x
Definition: imgui.h:52
#define SCALE_DRAW
Definition: FontImGui.cpp:15
float y
Definition: imgui.h:52
IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char *text_begin, const char *text_end=NULL, const char **remaining=NULL) const
Definition: imgui.cpp:8015
static unsigned int heightText(float scale, unsigned int maxWidth, std::string s)
Definition: FontImGui.cpp:42
ImFontAtlas * Fonts
Definition: imgui.h:562