14 #include "imgui_internal.h"
21 #include <backends/imgui_impl_opengl3.h>
47 ImGui::CreateContext();
48 ImGuiIO& io = ImGui::GetIO();
50 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
51 io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
52 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
53 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
54 ImGui::StyleColorsDark();
57 ImGuiStyle& style = ImGui::GetStyle();
58 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
60 style.WindowRounding = 0.0f;
61 style.Colors[ImGuiCol_WindowBg].w = 1.0f;
65 ImGui_ImplOpenGL3_Init(
nullptr);
91 ImGuiIO& io = ImGui::GetIO();
92 io.IniSavingRate = 1.0f;
93 io.IniFilename = NULL;
94 io.KeyMap[ImGuiKey_Tab] =
K_tab;
95 io.KeyMap[ImGuiKey_LeftArrow] =
K_left;
96 io.KeyMap[ImGuiKey_RightArrow] =
K_right;
97 io.KeyMap[ImGuiKey_UpArrow] =
K_up;
98 io.KeyMap[ImGuiKey_DownArrow] =
K_down;
99 io.KeyMap[ImGuiKey_PageUp] =
K_pageUp;
100 io.KeyMap[ImGuiKey_PageDown] =
K_pageUp;
101 io.KeyMap[ImGuiKey_Home] =
K_home;
102 io.KeyMap[ImGuiKey_End] =
K_end;
103 io.KeyMap[ImGuiKey_Delete] =
K_delete;
105 io.KeyMap[ImGuiKey_Enter] =
K_enter;
106 io.KeyMap[ImGuiKey_Escape] =
K_esc;
107 io.KeyMap[ImGuiKey_Space] =
K_space;
108 io.KeyMap[ImGuiKey_A] =
'A';
109 io.KeyMap[ImGuiKey_C] =
'C';
110 io.KeyMap[ImGuiKey_V] =
'V';
111 io.KeyMap[ImGuiKey_X] =
'X';
112 io.KeyMap[ImGuiKey_Y] =
'Y';
113 io.KeyMap[ImGuiKey_Z] =
'Z';
116 io.DisplaySize = ImVec2(0, 0);
117 io.DisplayFramebufferScale = ImVec2(1, 1);
119 #if defined(SL_OS_ANDROID) || defined(SL_OS_MACIOS) || defined(SL_EMSCRIPTEN)
120 io.MouseDrawCursor =
false;
122 io.MouseDrawCursor =
true;
126 ImGuiStyle& style = ImGui::GetStyle();
127 style.FrameBorderSize = 1;
130 SLstring iniFile = configPath +
"imgui.ini";
135 ImGui::LoadIniSettingsFromMemory(iniContents.c_str(),
143 ImGui::SetCurrentContext(ImGui::GetCurrentContext());
146 ImGui_ImplOpenGL3_Shutdown();
147 ImGui::DestroyContext();
157 ImGuiIO& io = ImGui::GetIO();
165 io.Fonts->AddFontFromMemoryTTF(fontDataProp.
data,
166 static_cast<int>(fontDataProp.
size),
170 io.Fonts->AddFontFromMemoryTTF(fontDataFixed.
data,
171 static_cast<int>(fontDataFixed.
size),
172 fontFixedDotsToLoad);
173 ImGui_ImplOpenGL3_DestroyDeviceObjects();
174 ImGui_ImplOpenGL3_CreateDeviceObjects();
189 ImGui_ImplOpenGL3_NewFrame();
191 ImGuiIO& io = ImGui::GetIO();
196 if (io.DeltaTime < 0) io.DeltaTime = 1.0f / 60.0f;
206 if (ImGui::GetIO().WantSaveIniSettings)
209 size_t iniContentsSize;
210 const char* rawIniContents = ImGui::SaveIniSettingsToMemory(&iniContentsSize);
211 SLstring iniContents(rawIniContents, rawIniContents + iniContentsSize);
213 ImGui::GetIO().WantSaveIniSettings =
false;
228 ImGuiIO& io = ImGui::GetIO();
230 io.DisplayFramebufferScale = ImVec2(1, 1);
236 ImGuiIO& io = ImGui::GetIO();
238 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
244 ImGuiIO& io = ImGui::GetIO();
246 if (button ==
MB_left) io.MouseDown[0] =
true;
247 if (button ==
MB_right) io.MouseDown[1] =
true;
248 if (button ==
MB_middle) io.MouseDown[2] =
true;
255 ImGuiIO& io = ImGui::GetIO();
257 if (button ==
MB_left) io.MouseDown[0] =
false;
258 if (button ==
MB_right) io.MouseDown[1] =
false;
259 if (button ==
MB_middle) io.MouseDown[2] =
false;
280 ImGuiIO& io = ImGui::GetIO();
281 io.KeysDown[key] =
true;
282 io.KeyCtrl =
mod &
K_ctrl ? true :
false;
284 io.KeyAlt =
mod &
K_alt ? true :
false;
290 ImGuiIO& io = ImGui::GetIO();
291 io.KeysDown[key] =
false;
292 io.KeyCtrl =
mod &
K_ctrl ? true :
false;
294 io.KeyAlt =
mod &
K_alt ? true :
false;
300 ImGuiIO& io = ImGui::GetIO();
301 if (c > 0 && c < 0x10000)
302 io.AddInputCharacter((
unsigned short)c);
static SLint mouseX
Last mouse position x in pixels.
static SLint mouseY
Last mouse position y in pixels.
static SLint dpi
Dot per inch resolution of screen.
SLMouseButton
Mouse button codes.
SLKey
Keyboard key codes enumeration.
void(SL_STDCALL * cbOnImGuiSaveConfig)()
Callback function typedef for ImGui save config function.
void(SL_STDCALL * cbOnImGuiLoadConfig)(int dpi)
Callback function typedef for ImGui load config function.
typedef void(SL_STDCALL *cbOnImGuiBuild)(SLScene *s
Callback function typedef for ImGui build function.
Singleton class for global render state.
Wrapper Class around the external ImGui GUI-framework.
Singleton class holding all OpenGL states.
static SLGLState * instance()
Public static instance getter for singleton pattern.
void onKeyRelease(SLKey key, SLKey mod) override
Callback on key release event.
void onMouseDown(SLMouseButton button, SLint x, SLint y) override
Callback on mouse button down event.
SLIOBuffer _fontDataFixed
Raw data of fixed size font file.
void loadFonts(SLfloat fontPropDots, SLfloat fontFixedDots)
Loads the proportional and fixed size font depending on the passed DPI.
void onMouseWheel(SLfloat yoffset) override
Callback for the mouse scroll movement.
static SLfloat fontPropDots
Default font size of proportional font.
SLfloat _timeSec
Time in seconds.
void onPaint(const SLRecti &viewport) override
Callback for main rendering for the ImGui GUI system.
SLbool _mousePressed[3]
Mouse button press state.
void onCharInput(SLuint c) override
Callback on character input.
void onMouseUp(SLMouseButton button, SLint x, SLint y) override
Callback on mouse button up event.
void printCompileErrors(SLint shaderHandle, const SLchar *src)
Prints the compile errors in case of a GLSL compile failure.
void onMouseMove(SLint xPos, SLint yPos) override
Updates the mouse cursor position.
void onKeyPress(SLKey key, SLKey mod) override
Callback on key press event.
SLfloat _fontFixedDots
Active font size of fixed size font.
SLfloat _mouseWheel
Mouse wheel position.
SLstring _configPath
Path to config files.
void init(const string &configPath) override
Initializes OpenGL handles to zero and sets the ImGui key map.
void onClose() override
Callback on closing the application.
void onResize(const SLRecti &viewport) override
Callback if window got resized.
SLfloat _fontPropDots
Active font size of proportional font.
SLIOBuffer _fontDataProp
Raw data of proportional font file.
static SLfloat fontFixedDots
Default font size of fixed size font.
void onInitNewFrame(SLScene *s, SLSceneView *sv) override
Inits a new frame for the ImGui system.
void renderExtraFrame(SLScene *s, SLSceneView *sv, SLint mouseX, SLint mouseY) override
Renders an extra frame with the current mouse position.
cbOnImGuiSaveConfig _saveConfig
SLImGui(cbOnImGuiBuild buildCB, cbOnImGuiLoadConfig loadConfigCB, cbOnImGuiSaveConfig saveConfigCB, int dpi, SLIOBuffer fontDataProp, SLIOBuffer fontDataFixed)
The SLScene class represents the top level instance holding the scene structure.
SceneView class represents a dynamic real time 3D view onto the scene.
SLRecti viewportRect() const
bool exists(std::string path, SLIOStreamKind kind)
Checks whether a given file exists.
std::string readIntoString(std::string path, SLIOStreamKind kind)
Reads an entire file into a string.
void writeString(std::string path, SLIOStreamKind kind, const std::string &string)
Writes a string to a file.
Utility struct that holds a pointer and its length.
SLIOBuffer copy()
Creates a copy of the data in the buffer.