Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
ImGuiLayer.h
Go to the documentation of this file.
1#pragma once
2/// @file ImGuiLayer.h
3/// @author Damon S. Green II
4/// @brief Defines the ImGuiLayer class, which is responsible for rendering the ImGui interface. Derives from the Layer class.
5
6#include "Core/Base.h"
7#include "Events/Event.h"
8#include "Events/ApplicationEvent.h"
9#include "Events/KeyEvent.h"
10#include "Events/MouseEvent.h"
11#include "App/Layer.h"
12
13namespace Muto {
14
15 class ImGuiLayer : public Layer
16 {
17 public:
18 ImGuiLayer();
19 ~ImGuiLayer();
20
21 virtual void OnAttach() override;
22 virtual void OnDetach() override;
23 virtual void OnImGuiRender() override;
24 virtual void OnEvent(Event& e) override;
25
26 virtual void Begin();
27 virtual void End();
28
29 virtual void SetBlockEvents(bool block) { m_BlockEvents = block; }
30 virtual void SetDarkThemeColors();
31 protected:
32 bool m_BlockEvents = true;
33 float m_Time = 0.0f;
34 };
35
36}
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
#define BIND_EVENT_FN(x)
Binds the given member function of the Application class as an event handler.
Definition Defines_Macros.h:21
#define EVENT_CLASS_TYPE(type)
Macro to define event type in event subclasses.
Definition Defines_Macros.h:25
#define EVENT_CLASS_CATEGORY(category)
Macro to define event category in event subclasses.
Definition Defines_Macros.h:31
#define BIT(x)
Macro to shift 1 by x positions to create a bitmask.
Definition Defines_Macros.h:13
#define MU_PROFILE
Definition Instrumentor.h:211
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
#define MU_FUNC_SIG
Definition Instrumentor.h:231
#define MU_PROFILE_SCOPE_LINE2(name, line)
Definition Instrumentor.h:236
#define MU_PROFILE_SCOPE_LINE(name, line)
Definition Instrumentor.h:238
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
#define MU_CORE_WARN(...)
warn: indicates a potential issue or important event
Definition Log.h:40
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
Event for registering application render.
Definition ApplicationEvent.h:82
AppRenderEvent()
Definition ApplicationEvent.h:84
Event for registering application tick.
Definition ApplicationEvent.h:60
AppTickEvent()
Definition ApplicationEvent.h:62
Event for registering application update.
Definition ApplicationEvent.h:71
AppUpdateEvent()
Definition ApplicationEvent.h:73
The core application class that manages the main loop, window, layers, and event handling.
Definition Application.h:70
void OnEvent(Event &e)
Handles incoming events and dispatches them to the appropriate handlers.
Definition Application.cpp:108
float m_LastFrameTime
Time of the last frame, used for calculating timestep.
Definition Application.h:171
const ApplicationSettings & GetSettings() const
Retrieves the application settings as a const reference.
Definition Application.h:116
void PushLayer(Layer *layer)
Adds a layer to the application layer stack.
Definition Application.cpp:89
virtual ~Application()
Definition Application.cpp:85
void PushOverlay(Layer *overlay)
Adds an overlay layer to the application layer stack.
Definition Application.cpp:96
bool m_Running
Flag indicating whether the application is running.
Definition Application.h:162
Application(ApplicationSettings settings)
Constructs the Application with the given settings.
Definition Application.cpp:48
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
std::string ResolvePath_AssetsDirectory(const std::string &Path) const
Resolves the full path to a resource based on the application's assets directory.
Definition Application.cpp:246
void Close()
Closes the application.
Definition Application.cpp:103
Scope< ApplicationSettings > m_Settings
Scoped pointer to the application settings.
Definition Application.h:174
static Application * s_Instance
Definition Application.h:177
ApplicationSettings & GetSettings()
Retrieves the application settings.
Definition Application.h:113
Window & GetWindow()
Retrieves the application window.
Definition Application.h:110
std::string ResolvePath_WorkingDirectory(const std::string &Path) const
Resolves the full path to a resource based on the application's working directory.
Definition Application.cpp:194
ImGuiLayer * m_ImGuiLayer
ImGui layer for rendering GUI elements.
Definition Application.h:159
bool m_Minimized
Flag indicating whether the application is minimized.
Definition Application.h:165
ImGuiLayer * GetImGuiLayer()
Retrieves the ImGui layer.
Definition Application.h:104
Application(const std::string &name="")
Constructs the Application with the given name.
Definition Application.cpp:19
std::string ResolvePath_ProjectDirectory(const std::string &Path) const
Resolves the full path to a resource based on the application's project directory.
Definition Application.cpp:220
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107
bool OnWindowClose(WindowCloseEvent &e)
Event handler for window close events.
Definition Application.cpp:272
bool OnWindowResize(WindowResizeEvent &e)
Event handler for window resize events.
Definition Application.cpp:279
Scope< Window > m_Window
Scoped pointer to the applications underlying window.
Definition Application.h:156
MutoResult InitFileSystem(ApplicationSettings &Settings)
Initializes the file system for the application with the given settings.
Definition Application.cpp:416
LayerStack m_LayerStack
Stack of layers managed by the application.
Definition Application.h:168
MutoResult InitFileSystem()
Initializes the file system for the application.
Definition Application.cpp:295
void Run()
Starts the main application loop.
Definition Application.cpp:125
Stack-based templated event dispatcher.
Definition Event.h:66
bool Dispatch(EventFn< T > func)
Dispatch the event to the appropriate handler if the types match.
Definition Event.h:87
Event & m_Event
The event to be dispatched.
Definition Event.h:98
EventDispatcher(Event &event)
Construct an EventDispatcher for a specific event.
Definition Event.h:76
Abstract base class for all events.
Definition Event.h:35
bool Handled
Indicates whether the event has been handled.
Definition Event.h:60
virtual int GetCategoryFlags() const =0
Get the category flags of the event.
virtual std::string ToString() const
Convert the event to a string representation.
Definition Event.h:50
virtual ~Event()=default
virtual const char * GetName() const =0
Get the name of the event.
virtual EventType GetEventType() const =0
Get the type of the event.
bool IsInCategory(EventCategory category)
Check if the event is in a specific category.
Definition Event.h:53
Definition ImGuiLayer.h:16
virtual void End()
Definition ImGuiLayer.cpp:111
virtual void SetBlockEvents(bool block)
Definition ImGuiLayer.h:29
bool m_BlockEvents
Definition ImGuiLayer.h:32
virtual void SetDarkThemeColors()
Definition ImGuiLayer.cpp:127
virtual void OnImGuiRender() override
Called when the layer should render its ImGui components.
Definition ImGuiLayer.cpp:88
float m_Time
Definition ImGuiLayer.h:33
virtual void OnEvent(Event &e) override
Called when an event is dispatched to the layer.
Definition ImGuiLayer.cpp:93
~ImGuiLayer()
Definition ImGuiLayer.cpp:26
virtual void OnDetach() override
Called when the layer is detached from the application.
Definition ImGuiLayer.cpp:76
ImGuiLayer()
Definition ImGuiLayer.cpp:22
virtual void Begin()
Definition ImGuiLayer.cpp:102
virtual void OnAttach() override
Called when the layer is attached to the application.
Definition ImGuiLayer.cpp:30
Definition Instrumentor.h:146
void Stop()
Definition Instrumentor.h:160
~InstrumentationTimer()
Definition Instrumentor.h:154
const char * m_Name
Definition Instrumentor.h:173
std::chrono::time_point< std::chrono::high_resolution_clock > m_StartTimepoint
Definition Instrumentor.h:174
InstrumentationTimer(const char *name)
Definition Instrumentor.h:148
bool m_Stopped
Definition Instrumentor.h:175
Definition Instrumentor.h:47
std::ofstream m_OutputStream
Definition Instrumentor.h:50
void WriteHeader()
Definition Instrumentor.h:115
static Instrumentor & Get()
Definition Instrumentor.h:138
std::mutex m_Mutex
Definition Instrumentor.h:51
void WriteProfile(const ProfileResult &result)
Definition Instrumentor.h:90
void InternalEndSession()
Definition Instrumentor.h:127
void WriteFooter()
Definition Instrumentor.h:121
void BeginSession(const std::string &name, const std::string &filepath="results.json")
Definition Instrumentor.h:58
void EndSession()
Definition Instrumentor.h:84
InstrumentationSession * m_CurrentSession
Definition Instrumentor.h:49
Instrumentor()
Definition Instrumentor.h:53
Manages an ordered stack of Layer pointers. Layers can be pushed or popped and the stack can be itera...
Definition LayerStack.h:16
std::vector< Layer * >::reverse_iterator rend()
Returns a reverse iterator to the end of the layer stack.
Definition LayerStack.h:48
std::vector< Layer * >::iterator end()
Returns an iterator to the end of the layer stack.
Definition LayerStack.h:44
std::vector< Layer * > m_Layers
Vector holding pointers to the layers in the stack.
Definition LayerStack.h:53
void PopLayer(Layer *layer)
Removes the specified layer from the stack.
Definition LayerStack.cpp:32
std::vector< Layer * >::reverse_iterator rbegin()
Returns a reverse iterator to the beginning of the layer stack.
Definition LayerStack.h:46
void PushLayer(Layer *layer)
Adds the layer to the stack at the position before the first overlay.
Definition LayerStack.cpp:19
LayerStack()
Definition LayerStack.cpp:6
std::vector< Layer * >::iterator begin()
Returns an iterator to the beginning of the layer stack.
Definition LayerStack.h:42
void PushOverlay(Layer *overlay)
Pushes the overlay layer on top of all other layers.
Definition LayerStack.cpp:26
~LayerStack()
Definition LayerStack.cpp:10
unsigned int m_LayerInsertIndex
Index indicating where to insert new layers (before overlays).
Definition LayerStack.h:55
void PopOverlay(Layer *overlay)
Removes the specified overlay layer from the stack.
Definition LayerStack.cpp:42
Represents a reusable application layer that receives lifecycle callbacks (attach,...
Definition Layer.h:17
Layer(const std::string &name="Layer")
Constructs a Layer with an optional name for debugging purposes.
Definition Layer.cpp:6
virtual void OnEvent(Event &event)
Called when an event is dispatched to the layer.
Definition Layer.h:41
virtual void OnDetach()
Called when the layer is detached from the application.
Definition Layer.h:31
virtual ~Layer()
Definition Layer.cpp:11
const std::string & GetName() const
Retrieves the name of the layer for debugging purposes.
Definition Layer.h:53
virtual void OnUpdate(Timestep ts)
Called every frame to update the layer with the given timestep.
Definition Layer.h:36
virtual void OnAttach()
Called when the layer is attached to the application.
Definition Layer.h:28
virtual void OnImGuiRender()
Called when the layer should render its ImGui components.
Definition Layer.h:50
std::string m_DebugName
The name of the layer assigned at creation, used for debugging.
Definition Layer.h:57
virtual void OnRender()
Called when the layer should render its contents.
Definition Layer.h:47
A logging utility class for the Vesper engine.
Definition Log.h:17
static std::shared_ptr< spdlog::logger > & GetClientLogger()
Returns the client logger instance.
Definition Log.h:26
static void Init()
Initializes the logging system.
Definition Log.cpp:16
static std::shared_ptr< spdlog::logger > & GetCoreLogger()
Returns the core logger instance.
Definition Log.h:24
static std::shared_ptr< spdlog::logger > s_CoreLogger
Definition Log.h:28
static std::shared_ptr< spdlog::logger > s_ClientLogger
Definition Log.h:29
An abstract class defining the interface for a rendering API.
Definition RendererAPI.h:17
API
API that can be used by the Renderer.
Definition RendererAPI.h:21
The main renderer class responsible for managing rendering operations.
Definition Renderer.h:15
static void OnWindowResize(uint32_t width, uint32_t height)
Handles window resize events by resizing the viewport.
Definition Renderer.cpp:24
static void Init()
Initializes the renderer.
Definition Renderer.cpp:16
Represents a time step in seconds.
Definition Timestep.h:11
operator float() const
Definition Timestep.h:22
float GetMilliseconds() const
Returns the time in milliseconds.
Definition Timestep.h:27
float m_Time
Definition Timestep.h:29
float GetSeconds() const
Returns the time in seconds.
Definition Timestep.h:25
Timestep(float time=0.0f)
Constructs a Timestep with the given time in seconds.
Definition Timestep.h:17
Event for registering window close.
Definition ApplicationEvent.h:49
WindowCloseEvent()
Definition ApplicationEvent.h:51
Event for registering window resize.
Definition ApplicationEvent.h:16
WindowResizeEvent(unsigned int width, unsigned int height)
Construct a WindowResizeEvent with the specified width and height.
Definition ApplicationEvent.h:23
unsigned int m_Height
Definition ApplicationEvent.h:43
unsigned int m_Width
Definition ApplicationEvent.h:43
unsigned int GetWidth() const
Get the new width of the window.
Definition ApplicationEvent.h:27
std::string ToString() const override
Convert the event to a string representation.
Definition ApplicationEvent.h:32
unsigned int GetHeight() const
Get the new height of the window.
Definition ApplicationEvent.h:29
Abstract interface representing an application window.
Definition Window.h:42
virtual uint32_t GetHeight() const =0
Retrieves the height of the window.
virtual bool IsVSync() const =0
Checks if vertical synchronization (VSync) is enabled.
virtual void SetEventCallback(const EventCallbackFn &callback)=0
Sets the callback function for window events.
virtual void SetVSync(bool enabled)=0
Sets whether vertical synchronization (VSync) is enabled.
virtual ~Window()
Definition Window.h:46
static Scope< Window > Create(const WindowProps &props=WindowProps())
Creates a window instance with the specified properties.
Definition WindowsWindow.cpp:20
virtual uint32_t GetWidth() const =0
Retrieves the width of the window.
virtual void OnUpdate()=0
Called every frame to update the window.
virtual void * GetNativeWindow() const =0
Retrieves the native window handle.
Definition Instrumentor.h:181
char Data[N]
Definition Instrumentor.h:186
constexpr auto CleanupOutputString(const char(&expr)[N], const char(&remove)[K])
Definition Instrumentor.h:190
Definition Instrumentor.h:185
The main namespace for the Muto engine.
Definition Application.cpp:15
long long Start
Definition Instrumentor.h:37
WindowMode Mode
The window mode of the application (e.g., windowed, fullscreen, borderless).
Definition Application.h:53
std::string ProjectDirectory
The project directory of the application.
Definition Application.h:38
RenderAPI::API RendererAPIType
The renderer API to use for the application.
Definition Application.h:44
uint32_t ThreadID
Definition Instrumentor.h:38
MU_RETURN
Definition Enums.h:6
static std::string NormalizePath(const std::string &path)
Normalizes path separators to forward slashes for cross-platform consistency.
Definition ResourceManager.h:10
static std::string JoinPaths(const std::string &base, const std::string &relative)
Joins two path segments with proper separator handling.
Definition ResourceManager.h:22
static bool IsAbsolutePath(const std::string &path)
Determines whether the given path is an absolute path (Unix-style, Windows-style, or drive-letter).
Definition ResourceManager.h:47
uint32_t Height
The height of the application window.
Definition Application.h:50
PathResolveMode
Specifies the mode for resolving resource paths in the application.
Definition Application.h:22
std::string Name
Definition Instrumentor.h:43
constexpr Ref< T > CreateRef(Args &&... args)
Creates a Ref (shared_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:71
std::string WorkingDirectory
The working directory of the application.
Definition Application.h:35
WindowMode
WIP.
Definition Window.h:15
bool EnableImGui
Flag indicating whether ImGui is enabled for the application.
Definition Application.h:56
long long End
Definition Instrumentor.h:37
std::string ApplicationName
The name of the application.
Definition Application.h:32
std::string AssetsDirectory
The assets directory of the application.
Definition Application.h:41
EventCategory
Enumeration of event categories.
Definition Event.h:22
@ EC_Keyboard
Definition Event.h:26
@ EC_Input
Definition Event.h:25
@ EC_None
Definition Event.h:23
@ EC_MouseButton
Definition Event.h:28
@ EC_Application
Definition Event.h:24
@ EC_Mouse
Definition Event.h:27
std::string Name
Definition Instrumentor.h:36
Application * CreateApplication()
Definition SandboxApp.cpp:200
GW::SYSTEM::GFile FileSystem
The file system interface for the application.
Definition Application.h:62
bool EnableVSync
Flag indicating whether vertical synchronization (VSync) is enabled for the application.
Definition Application.h:59
uint32_t Width
The width of the application window.
Definition Application.h:47
EventType
Enumeration of event types.
Definition Event.h:12
std::string format_as(const Event &e)
Format an event as a string.
Definition Event.h:102
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51
Holds configuration settings for the application.
Definition Application.h:30
Definition Instrumentor.h:42
Definition Instrumentor.h:35
Definition MutoResult.h:8
MU_RETURN Return
Definition MutoResult.h:9
std::string ResultMessage
Definition MutoResult.h:10
std::string ReturnError()
Definition MutoResult.h:21
MutoResult(MU_RETURN RETURN, std::string MESSAGE)
Definition MutoResult.h:13
MutoResult()=default
bool IsSuccess()
Definition MutoResult.h:16
Holds the data for window configuration.
Definition Window.h:22
uint32_t Width
Definition Window.h:24
WindowProps(const std::string &title="Vesper Engine", uint32_t width=1600, uint32_t height=900)
Constructor to initialize WindowProps with given or default values.
Definition Window.h:32
uint32_t Height
Definition Window.h:25
std::string Title
Definition Window.h:23