CoriEngine
Loading...
Searching...
No Matches
ImGuiLayer.cpp
Go to the documentation of this file.
1#include "ImGuiLayer.hpp"
2#include <imgui.h>
3#include <backends/imgui_impl_opengl3.h>
4#include <backends/imgui_impl_sdl3.h>
6
7namespace Cori {
8 namespace Core {
9 namespace Internal {
10 ImGuiLayer::ImGuiLayer() : Layer("ImGuiLayer") {
11 IMGUI_CHECKVERSION();
12 ImGui::CreateContext();
13
14 ImGuiIO& io = ImGui::GetIO(); (void)io;
15
16 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
17 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable docking
18 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable multi-viewport
19 // big L wayland
20
21 ImGui::StyleColorsDark();
22
23 ImGuiStyle& style = ImGui::GetStyle();
24 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
25 style.WindowRounding = 0.0f;
26 style.Colors[ImGuiCol_WindowBg].w = 1.0f;
27 }
28
29 ImGui_ImplSDL3_InitForOpenGL(static_cast<SDL_Window*>(Core::Application::GetWindow().GetNativeWindow()), Core::Application::GetWindow().GetNativeContext());
30
31 const bool success = ImGui_ImplOpenGL3_Init("#version 460");
32 CORI_CORE_ASSERT(success, "Failed to initialize ImGui with OpenGL.");
33
35 }
36
40
44
46 ImGui_ImplOpenGL3_Shutdown();
47 ImGui_ImplSDL3_Shutdown();
48 ImGui::DestroyContext();
49
51 }
52
54 const ImGuiIO& io = ImGui::GetIO();
55
56 if (event.IsInCategory(EventCategoryMouse) && io.WantCaptureMouse) {
57 event.m_Handled = true;
58 }
59 else if (event.IsInCategory(EventCategoryKeyboard) && io.WantCaptureKeyboard) {
60 event.m_Handled = true;
61 }
62 }
63
64 // ReSharper disable once CppMemberFunctionMayBeStatic
67 ImGui_ImplOpenGL3_NewFrame();
68 ImGui_ImplSDL3_NewFrame();
69 ImGui::NewFrame();
70 }
71
72 // ReSharper disable once CppMemberFunctionMayBeStatic
75 ImGui::Render();
76 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
77
78 const ImGuiIO& io = ImGui::GetIO();
79 (void)io;
80
81 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
82 {
83 SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
84 const SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
85 ImGui::UpdatePlatformWindows();
86 ImGui::RenderPlatformWindowsDefault();
87 SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
88 }
89 }
90 }
91 }
92}
#define CORI_CORE_DEBUG_TAGGED(...)
Definition Logger.hpp:1026
#define CORI_CORE_ASSERT(x,...)
Definition Logger.hpp:1029
#define CORI_CORE_INFO_TAGGED(...)
Definition Logger.hpp:1027
#define CORI_PROFILE_FUNCTION()
Definition Profiler.hpp:9
static Window & GetWindow()
Getter for the main Window.
An abstract class that is ment to be used as a template for defining events.
Definition Event.hpp:18
bool IsInCategory(const EventCategory category) const
Checks if the Event is in specific category.
Definition Event.hpp:59
void OnEvent(Event &event) override
This is the method to handle all the event at.
void OnAttach() override
Method that runs when the layer gets attached to the LayerStack.
void OnDetach() override
Method that runs when the layer gets detached to the LayerStack.
Layer(std::string name)
Definition Layer.cpp:7
Core systems of the engine are here.
@ EventCategoryMouse
Definition Event.hpp:11
@ EventCategoryKeyboard
Definition Event.hpp:10
Global engine namespace.
static constexpr char Self[]
Definition Logger.hpp:83
static constexpr char ImGui[]
Definition Logger.hpp:98