enabled docking

This commit is contained in:
timerix 2023-03-31 18:48:29 +06:00
parent 21709b788a
commit 0be4c42896
2 changed files with 47 additions and 16 deletions

View File

@ -10,6 +10,11 @@ Maybe main_window_open();
Maybe main_window_loop_start(); Maybe main_window_loop_start();
Maybe main_window_close(); Maybe main_window_close();
/// converts hex color to float vector
#define RGBAHexToF(R8,G8,B8,A8) ImVec4(((u8)35)/255.0f, ((u8)35)/255.0f, ((u8)50)/255.0f, ((u8)255)/255.0f)
/// converts float vector to hex color
#define RGBAFToHex(VEC4) {(u8)(VEC4.x*255), (u8)(VEC4.y*255), (u8)(VEC4.z*255), (u8)(VEC4.w*255)}
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@ -7,7 +7,7 @@ SDL_GLContext gl_context;
#define SDL_ERROR_SAFETHROW() { \ #define SDL_ERROR_SAFETHROW() { \
const char* sdl_error=SDL_GetError(); \ const char* sdl_error=SDL_GetError(); \
throw_msg(cptr_concat("SDL Error: ", sdl_error)); \ safethrow_msg(cptr_concat("SDL Error: ", sdl_error),;); \
SDL_ClearError(); \ SDL_ClearError(); \
} }
#define SDL_TRY_ZERO(FUNC_CALL) if(FUNC_CALL != 0) SDL_ERROR_SAFETHROW(); #define SDL_TRY_ZERO(FUNC_CALL) if(FUNC_CALL != 0) SDL_ERROR_SAFETHROW();
@ -42,11 +42,23 @@ Maybe main_window_open(){
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io; ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
io.ConfigViewportsNoDecoration=false;
// Setup Dear ImGui style // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
ImGuiStyle& style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
// Setup Platform/Renderer backends // Setup Platform/Renderer backends
if(ImGui_ImplSDL2_InitForOpenGL(sdl_window, gl_context) != true) if(ImGui_ImplSDL2_InitForOpenGL(sdl_window, gl_context) != true)
SDL_ERROR_SAFETHROW(); SDL_ERROR_SAFETHROW();
@ -64,7 +76,7 @@ Maybe main_window_loop_start(){
// Our state // Our state
bool show_demo_window = true; bool show_demo_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); ImVec4 clear_color = RGBAHexToF(35,35,50,255);
// main loop // main loop
while(loop_running){ while(loop_running){
@ -77,10 +89,12 @@ Maybe main_window_loop_start(){
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
ImGui_ImplSDL2_ProcessEvent(&event); ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT){
loop_running = false; try_cpp(main_window_close(),_9914,;);
if (event.type==SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(sdl_window)) }
loop_running = false; if (event.type==SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(sdl_window)){
try_cpp(main_window_close(),_9915,;);
}
} }
// Start the Dear ImGui frame // Start the Dear ImGui frame
@ -133,18 +147,22 @@ Maybe main_window_loop_start(){
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
// Update and Render additional Platform Windows
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
// For this specific demo app we could also call SDL_GL_MakeCurrent(window, gl_context) directly)
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
}
SDL_GL_SwapWindow(sdl_window); SDL_GL_SwapWindow(sdl_window);
} }
try_cpp(main_window_close(),_999,;);
return MaybeNull;
}
Maybe main_window_close(){
if(!loop_running)
return MaybeNull;
loop_running=false;
// Cleanup // Cleanup
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
@ -155,3 +173,11 @@ Maybe main_window_close(){
return MaybeNull; return MaybeNull;
} }
Maybe main_window_close(){
if(!loop_running)
return MaybeNull;
loop_running=false;
return MaybeNull;
}