CoriEngine
Loading...
Searching...
No Matches
ImGuiPresets.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace Cori {
9 namespace ImGuiPresets {
10
21 [[maybe_unused]] static void Box2dDebugDraw(const glm::vec2 cameraSize, const glm::vec2 cameraPos, const int32_t pixelsPerMeter, Core::Layer* layer, const bool mouseDrag, const float mouseForce = 1000.0f) {
22 layer->m_DebugImGuiRenderer.ViewportCalc(cameraSize, pixelsPerMeter, cameraPos);
24 if (system) {
25 layer->m_DebugImGuiRenderer.DrawShapes(system->lock()->GetWorld());
26 if (mouseDrag) {
27 if (!ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow) && !ImGui::IsAnyItemActive()) {
28 layer->m_DebugImGuiRenderer.HandleMouseDrag(system->lock()->GetWorld(), mouseForce);
29 }
30 layer->m_DebugImGuiRenderer.DrawModeToggles();
31 }
32 }
33 }
34
35
40 [[maybe_unused]] static void ScreenModeAndResolutionDropdowns() {
41 const char* items[] = {"Windowed", "Borderless Windowed", "Exclusive Fullscreen"};
42
43 int32_t oneToDisplay = 0;
45 if (currentMode == Core::WindowMode::WINDOWED) {
46 oneToDisplay = 0;
47 }
48 else if (currentMode == Core::WindowMode::BORDERLESS_WINDOWED) {
49 oneToDisplay = 1;
50 }
51 else if (currentMode == Core::WindowMode::EXCLUSIVE_FULLSCREEN) {
52 oneToDisplay = 2;
53 }
54
55 const char* windowModeDropdownPreview = items[oneToDisplay];
56 if (ImGui::BeginCombo("Window Mode", windowModeDropdownPreview)) {
57 for (int32_t i = 0; i < IM_ARRAYSIZE(items); i++) {
58 const bool isSelected = oneToDisplay == i;
59 if (ImGui::Selectable(items[i], isSelected)) {
60 if (i == 0) {
61 if (currentMode != Core::WindowMode::WINDOWED) {
63 if (!result) {
64 CORI_ERROR("Failed to set window mode. Error: {}", result.error().what());
65 }
66 }
67 }
68 else if (i == 1) {
69 if (currentMode != Core::WindowMode::BORDERLESS_WINDOWED) {
71 if (!result) {
72 CORI_ERROR("Failed to set window mode. Error: {}", result.error().what());
73 }
74 }
75 }
76 else if (i == 2) {
77 if (currentMode != Core::WindowMode::EXCLUSIVE_FULLSCREEN) {
79 if (!result) {
80 CORI_ERROR("Failed to set window mode. Error: {}", result.error().what());
81 }
82 }
83 }
84 }
85
86 if (isSelected) {
87 ImGui::SetItemDefaultFocus();
88 }
89 }
90 ImGui::EndCombo();
91 }
92
94
95 ImGui::BeginDisabled(currentMode == Core::WindowMode::BORDERLESS_WINDOWED);
96 const char* resolutionDropdownPreview = window.GetScreenModes().at(window.GetCurrentScreenMode()).m_ModeName.c_str();
97 if (ImGui::BeginCombo("Resolution", resolutionDropdownPreview)) {
98 for (int32_t i = 0; i < window.GetScreenModes().size(); i++) {
99 const bool isSelected = window.GetCurrentScreenMode() == i;
100 if (ImGui::Selectable(window.GetScreenModes()[i].m_ModeName.c_str(), isSelected)) {
101 const auto result = window.SetScreenMode(i);
102 if (!result) {
103 CORI_ERROR("Failed to set screen mode. Error: {}", result.error().what());
104 }
105 }
106
107 if (isSelected)
108 ImGui::SetItemDefaultFocus();
109 }
110 ImGui::EndCombo();
111 }
112
113 ImGui::EndDisabled();
114 }
115
116 [[maybe_unused]] static void FpsCounter(const Core::GameTimer& timer) {
117 static int frameCount = 0;
118 static double lastTime = 0.0;
119 static float fps = 0.0f;
120
121 frameCount++;
122 double currentTime = timer.GetElapsedSeconds();
123 double elapsed = currentTime - lastTime;
124
125 if (elapsed >= 1.0) {
126 fps = static_cast<float>(frameCount / elapsed);
127 frameCount = 0;
128 lastTime = currentTime;
129 }
130
131 ImGui::Separator();
132
133 ImGui::Text("FPS: %.2f", fps);
134
135 ImGui::Separator();
136
137 }
138 }
139}
#define CORI_ERROR(...)
Definition Logger.hpp:1056
static Window & GetWindow()
Getter for the main Window.
A GameTimer is responsible for managing everything that is connected with time, ticks,...
Definition Time.hpp:8
double GetElapsedSeconds() const
Gets the time in seconds since application start.
Definition Time.hpp:48
An abstract class that is ment to be used as a template for defining layers.
Definition Layer.hpp:13
World::SceneHandle ActiveScene
A SceneHandle to the Scene that is currently bound.
Definition Layer.hpp:90
static Physics::DebugImguiRenderer m_DebugImGuiRenderer
Definition Layer.hpp:92
This class manages everything that is connected with physical Window management, i might add multiwin...
Definition Window.hpp:43
std::expected< void, CoriError<> > SetScreenMode(const uint32_t modeIndex)
Changes the current ScreenMode.
Definition Window.cpp:274
const std::vector< ScreenMode > & GetScreenModes() const
Retrieves a list of all available ScreenMode.
Definition Window.cpp:270
uint32_t GetCurrentScreenMode() const
Retrieves the current screen mode index.
Definition Window.cpp:283
WindowMode GetWindowMode() const
Gets the current WindowMode;.
Definition Window.cpp:279
std::expected< void, CoriError<> > SetWindowMode(WindowMode mode)
Changes the current WindowMode.
Definition Window.cpp:288
std::expected< std::weak_ptr< T >, Core::CoriError<> > GetSystem()
Retries a registered system instance from the scene.
Here are stored all predefined ImGui window presets, you can only use this functions in Layer OnImGui...
static void Box2dDebugDraw(const glm::vec2 cameraSize, const glm::vec2 cameraPos, const int32_t pixelsPerMeter, Core::Layer *layer, const bool mouseDrag, const float mouseForce=1000.0f)
Enables the debug draw of Box2D physics.
static void FpsCounter(const Core::GameTimer &timer)
static void ScreenModeAndResolutionDropdowns()
Displays a window mode and screen mode selection window.
Global engine namespace.