Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::ImGuiLayer Class Reference

#include <ImGuiLayer.h>

Inheritance diagram for Muto::ImGuiLayer:
Muto::Layer Muto::OpenGLImGuiLayer

Public Member Functions

virtual void Begin ()
 
virtual void End ()
 
 ImGuiLayer ()
 
virtual void OnAttach () override
 Called when the layer is attached to the application.
 
virtual void OnDetach () override
 Called when the layer is detached from the application.
 
virtual void OnEvent (Event &e) override
 Called when an event is dispatched to the layer.
 
virtual void OnImGuiRender () override
 Called when the layer should render its ImGui components.
 
virtual void SetBlockEvents (bool block)
 
virtual void SetDarkThemeColors ()
 
 ~ImGuiLayer ()
 
- Public Member Functions inherited from Muto::Layer
const std::string & GetName () const
 Retrieves the name of the layer for debugging purposes.
 
 Layer (const std::string &name="Layer")
 Constructs a Layer with an optional name for debugging purposes.
 
virtual void OnRender ()
 Called when the layer should render its contents.
 
virtual void OnUpdate (Timestep ts)
 Called every frame to update the layer with the given timestep.
 
virtual ~Layer ()
 

Protected Attributes

bool m_BlockEvents = true
 
float m_Time = 0.0f
 
- Protected Attributes inherited from Muto::Layer
std::string m_DebugName
 The name of the layer assigned at creation, used for debugging.
 

Constructor & Destructor Documentation

◆ ImGuiLayer()

Muto::ImGuiLayer::ImGuiLayer ( )
22 : Layer("ImGuiLayer")
23 {
24 }
Layer(const std::string &name="Layer")
Constructs a Layer with an optional name for debugging purposes.
Definition Layer.cpp:6

Referenced by Muto::Application::Application(), Muto::Application::Application(), and Muto::OpenGLImGuiLayer::OpenGLImGuiLayer().

◆ ~ImGuiLayer()

Muto::ImGuiLayer::~ImGuiLayer ( )
27 {
28 }

Member Function Documentation

◆ Begin()

void Muto::ImGuiLayer::Begin ( )
virtual

Reimplemented in Muto::OpenGLImGuiLayer.

103 {
107 ImGui::NewFrame();
108 ImGuizmo::BeginFrame();
109 }
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

Referenced by Muto::OpenGLImGuiLayer::Begin(), and Muto::Application::Run().

◆ End()

void Muto::ImGuiLayer::End ( )
virtual

Reimplemented in Muto::OpenGLImGuiLayer.

112 {
114 ImGuiIO& io = ImGui::GetIO();
115 Application& app = Application::Get();
116 io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());
117 ImGui::Render();
118 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
119 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
120 {
122 ImGui::UpdatePlatformWindows();
123 ImGui::RenderPlatformWindowsDefault();
125 }
126 }
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107

References Muto::Application::Get(), Muto::Window::GetHeight(), Muto::Window::GetWidth(), and Muto::Application::GetWindow().

Referenced by Muto::OpenGLImGuiLayer::End(), and Muto::Application::Run().

◆ OnAttach()

void Muto::ImGuiLayer::OnAttach ( )
overridevirtual

Called when the layer is attached to the application.

Todo:
: Remove to openGL specific ImGui Implementation
Todo:
: Remove to openGL specific ImGui Implementation

Reimplemented from Muto::Layer.

Reimplemented in Muto::OpenGLImGuiLayer.

31 {
34 ImGui::CreateContext();
35 ImGuiIO& io = ImGui::GetIO(); (void)io;
36 //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
37 //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
38 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
39 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
40 //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; // Disable Platform Windows task bar icons
41 //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; // Disable Platform Windows merging into host window
42
43 std::filesystem::path fontPath = Muto::Application::Get().ResolvePath("fonts/RedHatMono/static/RedHatMono-Bold.ttf", Muto::PathResolveMode::AssetsDirectory);
44 if (!std::filesystem::exists(fontPath))
45 fontPath = std::filesystem::path("Muto/src/Editor/assets") / "fonts/RedHatMono/static/RedHatMono-Bold.ttf";
46
47 if (std::filesystem::exists(fontPath))
48 io.FontDefault = io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 18.0f);
49 else
50 io.FontDefault = io.Fonts->AddFontDefault();
51
52
53 ImGui::StyleColorsDark();
54
55 // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
56 ImGuiStyle& style = ImGui::GetStyle();
57 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
58 {
59 style.WindowRounding = 0.0f;
60 style.Colors[ImGuiCol_WindowBg].w = 1.0f;
61 }
62
64
65
67 {
68 Application& app = Application::Get();
69 GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());
71 ImGui_ImplOpenGL3_Init("#version 410");
72 }
73
74 }
std::string ResolvePath(const std::string &Path, PathResolveMode Mode=PathResolveMode::AssetsDirectory) const
Resolves the full path to a resource based on a relative path and the application's settings.
Definition Application.cpp:166
virtual void SetDarkThemeColors()
Definition ImGuiLayer.cpp:127

References Muto::AssetsDirectory, Muto::Application::Get(), Muto::Application::ResolvePath(), and SetDarkThemeColors().

Referenced by Muto::OpenGLImGuiLayer::OnAttach().

◆ OnDetach()

void Muto::ImGuiLayer::OnDetach ( )
overridevirtual

Called when the layer is detached from the application.

Todo:
: Remove to openGL specific ImGui Implementation
Todo:
: Remove to openGL specific ImGui Implementation

Reimplemented from Muto::Layer.

Reimplemented in Muto::OpenGLImGuiLayer.

77 {
79
81 {
84 ImGui::DestroyContext();
85 }
86 }

Referenced by Muto::OpenGLImGuiLayer::OnDetach().

◆ OnEvent()

void Muto::ImGuiLayer::OnEvent ( Event &  event)
overridevirtual

Called when an event is dispatched to the layer.

Parameters
eventThe event being dispatched.

Reimplemented from Muto::Layer.

Reimplemented in Muto::OpenGLImGuiLayer.

94 {
95 if (m_BlockEvents) {
96 ImGuiIO& io = ImGui::GetIO();
97 e.Handled |= e.IsInCategory(EC_Mouse) & io.WantCaptureMouse;
98 e.Handled |= e.IsInCategory(EC_Keyboard) & io.WantCaptureKeyboard;
99 }
100 }
bool m_BlockEvents
Definition ImGuiLayer.h:32
@ EC_Keyboard
Definition Event.h:26
@ EC_Mouse
Definition Event.h:27

References Muto::EC_Keyboard, Muto::EC_Mouse, Muto::Event::Handled, Muto::Event::IsInCategory(), and m_BlockEvents.

Referenced by Muto::OpenGLImGuiLayer::OnEvent().

◆ OnImGuiRender()

void Muto::ImGuiLayer::OnImGuiRender ( )
overridevirtual

Called when the layer should render its ImGui components.

Reimplemented from Muto::Layer.

Reimplemented in Muto::OpenGLImGuiLayer.

89 {
90
91 }

Referenced by Muto::OpenGLImGuiLayer::OnImGuiRender().

◆ SetBlockEvents()

virtual void Muto::ImGuiLayer::SetBlockEvents ( bool  block)
inlinevirtual

Reimplemented in Muto::OpenGLImGuiLayer.

References m_BlockEvents.

Referenced by Muto::EditorLayer::OnImGuiRender().

◆ SetDarkThemeColors()

void Muto::ImGuiLayer::SetDarkThemeColors ( )
virtual

Reimplemented in Muto::OpenGLImGuiLayer.

128 {
129 auto& colors = ImGui::GetStyle().Colors;
130 colors[ImGuiCol_WindowBg] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f };
131
132 // Header
133 colors[ImGuiCol_Header] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
134 colors[ImGuiCol_HeaderHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
135 colors[ImGuiCol_HeaderActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
136
137 // Buttons
138 colors[ImGuiCol_Button] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
139 colors[ImGuiCol_ButtonHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
140 colors[ImGuiCol_ButtonActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
141
142 // Frame BG
143 colors[ImGuiCol_FrameBg] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
144 colors[ImGuiCol_FrameBgHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
145 colors[ImGuiCol_FrameBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
146
147 // Tabs
148 colors[ImGuiCol_Tab] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
149 colors[ImGuiCol_TabHovered] = ImVec4{ 0.38f, 0.3805f, 0.381f, 1.0f };
150 colors[ImGuiCol_TabActive] = ImVec4{ 0.28f, 0.2805f, 0.281f, 1.0f };
151 colors[ImGuiCol_TabUnfocused] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
152 colors[ImGuiCol_TabUnfocusedActive] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
153
154 // Title
155 colors[ImGuiCol_TitleBg] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f };
156 colors[ImGuiCol_TitleBgActive] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f };
157 colors[ImGuiCol_TitleBgCollapsed] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f };
158 }

Referenced by OnAttach(), and Muto::OpenGLImGuiLayer::SetDarkThemeColors().

Member Data Documentation

◆ m_BlockEvents

bool Muto::ImGuiLayer::m_BlockEvents = true
protected

◆ m_Time

float Muto::ImGuiLayer::m_Time = 0.0f
protected

The documentation for this class was generated from the following files: