Euphoria
imguilibrary.cc
Go to the documentation of this file.
1 #include "window/imguilibrary.h"
2 
3 #include <cstdint>
4 
5 #include "imgui/imgui.h"
6 #include "imgui_impl_sdl.h"
7 #include "imgui_impl_opengl3.h"
8 
9 #include "font_material_icons.h"
10 #include "font_noto_sans_display.h"
11 
12 #include "log/log.h"
13 
14 #include "window/sdlglcontext.h"
15 #include "window/imgui_icons.h"
16 #include "window/imguizmo.h"
17 
18 
19 namespace eu::window::imgui
20 {
21  void
23  {
24  ImGuiIO &io = ImGui::GetIO();
25 
26  // io.Fonts->AddFontDefault();
27  io.Fonts->AddFontFromMemoryCompressedTTF
28  (
29  NotoSansDisplay_compressed_data,
30  NotoSansDisplay_compressed_size,
31  16
32  );
33 
34  const uint64_t min_mdi = ICON_MIN_MD;
35  const uint64_t max_mdi = ICON_MAX_MD;
36  constexpr const auto min_imgui = static_cast<uint64_t>(std::numeric_limits<ImWchar>::min());
37  constexpr const auto max_imgui = static_cast<uint64_t>(std::numeric_limits<ImWchar>::max());
38  const auto max_arg = static_cast<ImWchar>(std::min(max_mdi, max_imgui));
39  if constexpr (max_mdi > max_imgui)
40  {
41  LOG_ERROR("imgui is missing {0} icons!", (max_mdi - max_imgui));
42 
43  LOG_INFO("mdi range: {0}", (max_mdi - min_mdi));
44  LOG_INFO("imgui range: {0}", (max_imgui - min_imgui));
45  LOG_INFO("Supplied range: {0}", (max_arg - min_mdi));
46  }
47 
48 
49  static const ImWchar icons_ranges[] = {ICON_MIN_MD, max_arg, 0};
50  ImFontConfig icons_config;
51  icons_config.MergeMode = true;
52  icons_config.PixelSnapH = true;
53  icons_config.GlyphMinAdvanceX = 13.0f;
54 
55  io.Fonts->AddFontFromMemoryCompressedTTF
56  (
57  MaterialIcons_compressed_data,
58  MaterialIcons_compressed_size,
59  13.0f,
60  &icons_config,
61  icons_ranges
62  );
63  }
64 
65 
66  Library::Library(SDL_Window *the_window, SdlOpenglContext *context, const std::string &the_path)
67  : path_to_imgui_ini(the_path + "imgui.ini")
68  {
69  // hrm... euphoria is using #version 330 core
70  // todo(Gustav): look into this...
71 #if __APPLE__
72  // GL 3.2 Core + GLSL 150
73  const char* glsl_version = "#version 150";
74 #else
75  // GL 3.0 + GLSL 130
76  const char *glsl_version = "#version 130";
77 #endif
78  IMGUI_CHECKVERSION();
79  ImGui::CreateContext();
80 
81  ImGui_ImplSDL2_InitForOpenGL(the_window, context->context);
82  ImGui_ImplOpenGL3_Init(glsl_version);
84 
86 
87  ImGui::GetIO().IniFilename = path_to_imgui_ini.c_str();
88  }
89 
91  {
92  ImGui_ImplOpenGL3_Shutdown();
93  ImGui_ImplSDL2_Shutdown();
94  ImGui::DestroyContext();
95  }
96 
97  void
99  {
100  ImGui_ImplSDL2_ProcessEvent(event);
101  }
102 
103  void
105  {
106  ImGui_ImplOpenGL3_NewFrame();
107  ImGui_ImplSDL2_NewFrame();
108  ImGui::NewFrame();
110  }
111 
112  void
114  {
115  // ImGui::ShowTestWindow();
116  ImGui::Render();
117  ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
118  }
119 
120 }
union SDL_Event SDL_Event
Definition: fakesdlevent.h:4
#define LOG_INFO(...)
Definition: log.h:7
#define LOG_ERROR(...)
Definition: log.h:9
void send_events_to_imgui(const SDL_Event *event)
Definition: imguilibrary.cc:98
size2f min(const size2f lhs, const size2f rhs)
Definition: size2.cc:140
size2f max(const size2f lhs, const size2f rhs)
Definition: size2.cc:149
Library(SDL_Window *the_window, SdlOpenglContext *context, const std::string &the_path)
Definition: imguilibrary.cc:66