refactored imgui layer into nonlayer version
it returned to being a member of application with new init and shutdown function which is ran by the con- and destructors, and init is called at the end of the app init, with this it inits before any layer and layers can use the onimguirender to draw with imgui
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "SDL3/SDL_timer.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imguilayer.h"
|
||||
#include "imguiinit.h"
|
||||
|
||||
#define SDL_MAIN_HANDLED 1
|
||||
|
||||
@@ -74,10 +74,7 @@ bool Application::Init() {
|
||||
|
||||
SDL_SetRenderVSync(m_Renderer, 1);
|
||||
|
||||
// m_ImGuiLayer = new SakuraVNE::ImGuiLayer();
|
||||
// PushOverlay(m_ImGuiLayer);
|
||||
|
||||
this->PushOverlay<SakuraVNE::ImGuiLayer>();
|
||||
m_ImGui = new SakuraVNE::ImGuiInit();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -126,8 +123,7 @@ void Application::Run() {
|
||||
}
|
||||
|
||||
// Rendering
|
||||
// m_ImGuiLayer->Begin();
|
||||
this->GetLayer<SakuraVNE::ImGuiLayer>()->Begin();
|
||||
m_ImGui->Begin();
|
||||
|
||||
SDL_SetRenderScale(m_Renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
|
||||
SDL_SetRenderDrawColor(m_Renderer, (Uint8)111, (Uint8)232, (Uint8)168, (Uint8)0);
|
||||
@@ -137,8 +133,7 @@ void Application::Run() {
|
||||
layer->OnImGuiRender();
|
||||
}
|
||||
|
||||
// m_ImGuiLayer->End();
|
||||
this->GetLayer<SakuraVNE::ImGuiLayer>()->End();
|
||||
m_ImGui->End();
|
||||
|
||||
SDL_RenderPresent(m_Renderer);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "LayerStack.h"
|
||||
#include "SDL3/SDL_render.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
// #include "imguilayer.h"
|
||||
#include "imguiinit.h"
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -96,7 +96,7 @@ private:
|
||||
AppData m_AppData;
|
||||
|
||||
SakuraVNE::LayerStack m_LayerStack;
|
||||
// SakuraVNE::ImGuiLayer *m_ImGuiLayer;
|
||||
SakuraVNE::ImGuiInit *m_ImGui;
|
||||
|
||||
static Application *s_Instance;
|
||||
};
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "imguilayer.h"
|
||||
#include "imguiinit.h"
|
||||
#include "Application.h"
|
||||
#include "Log.h"
|
||||
#include "SDL3/SDL_stdinc.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_sdlrenderer3.h"
|
||||
|
||||
namespace SakuraVNE {
|
||||
ImGuiLayer::ImGuiLayer() : Layer("ImGuiLayer") {}
|
||||
ImGuiInit::ImGuiInit() { Init(); }
|
||||
ImGuiInit::~ImGuiInit() { Shutdown(); }
|
||||
|
||||
void ImGuiLayer::OnAttach() {
|
||||
void ImGuiInit::Init() {
|
||||
// Imgui init
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
@@ -26,14 +26,14 @@ void ImGuiLayer::OnAttach() {
|
||||
LOG_INFO("Imgui layer OnAttach ran");
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnDetach() {
|
||||
void ImGuiInit::Shutdown() {
|
||||
ImGui_ImplSDLRenderer3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
LOG_WARN("Imgui on detach ran");
|
||||
}
|
||||
|
||||
void ImGuiLayer::Begin() {
|
||||
void ImGuiInit::Begin() {
|
||||
ImGui_ImplSDLRenderer3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
@@ -41,7 +41,7 @@ void ImGuiLayer::Begin() {
|
||||
ImGui::DockSpaceOverViewport();
|
||||
}
|
||||
|
||||
void ImGuiLayer::End() {
|
||||
void ImGuiInit::End() {
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
Application &app = Application::Get();
|
||||
@@ -51,20 +51,4 @@ void ImGuiLayer::End() {
|
||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), Application::Get().GetSDLRenderer());
|
||||
ImGui::EndFrame();
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnImGuiRender() {
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
bool demoWindow = true;
|
||||
ImGui::Begin("Framerate");
|
||||
ImGui::ShowDemoWindow(&demoWindow);
|
||||
ImGui::Text("Application avg %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
|
||||
if (ImGui::Button("Quit")) {
|
||||
Application::Get().SetRunningState(false);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnFrame(Uint64 time) {}
|
||||
void ImGuiLayer::OnEvent() {}
|
||||
} // namespace SakuraVNE
|
||||
14
SakuraCore/src/imguiinit.h
Normal file
14
SakuraCore/src/imguiinit.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace SakuraVNE {
|
||||
class ImGuiInit {
|
||||
public:
|
||||
ImGuiInit();
|
||||
~ImGuiInit();
|
||||
|
||||
void Init();
|
||||
void Shutdown();
|
||||
void Begin();
|
||||
void End();
|
||||
};
|
||||
} // namespace SakuraVNE
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Layer.h"
|
||||
|
||||
namespace SakuraVNE {
|
||||
class ImGuiLayer : public Layer {
|
||||
public:
|
||||
ImGuiLayer();
|
||||
~ImGuiLayer() = default;
|
||||
|
||||
virtual void OnFrame(Uint64 timestamp) override;
|
||||
virtual void OnAttach() override;
|
||||
virtual void OnDetach() override;
|
||||
virtual void OnImGuiRender() override;
|
||||
virtual void OnEvent() override;
|
||||
|
||||
void Begin();
|
||||
void End();
|
||||
};
|
||||
} // namespace SakuraVNE
|
||||
Reference in New Issue
Block a user