diff --git a/src/debugoverlay.cpp b/src/debugoverlay.cpp new file mode 100644 index 0000000..12576fc --- /dev/null +++ b/src/debugoverlay.cpp @@ -0,0 +1,50 @@ +#include "debugoverlay.h" + +#include "imgui/imgui.h" +#include "engine.h" + +DebugOverlay::DebugOverlay(): + m_enabled(false) +{ + setID("overlay"); +} + +void DebugOverlay::update(){ + gui(); + SceneNode::update(); +} + +void DebugOverlay::gui() +{ + if(m_enabled) + { + ImGuiIO& io = ImGui::GetIO(); + // io.DeltaTime = float(getEngine().getDeltaTime()) / 1000.; + // ImGui::NewFrame(); + + const float DISTANCE = 10.0f; + ImVec2 window_pos = ImVec2(ImGui::GetIO().DisplaySize.x - DISTANCE,DISTANCE); + ImVec2 window_pos_pivot = ImVec2(1.0f, 0.0f); + + ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 0.3f)); // Transparent background + + bool overlayEnabled = true; + ImGui::Begin("Debug Overlay", + &overlayEnabled, + ImGuiWindowFlags_NoTitleBar| + ImGuiWindowFlags_NoResize| + ImGuiWindowFlags_AlwaysAutoResize| + ImGuiWindowFlags_NoMove| + ImGuiWindowFlags_NoSavedSettings); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::End(); + ImGui::PopStyleColor(); +// ImGui::EndFrame(); + } +} + +void DebugOverlay::toggle() +{ + m_enabled = !m_enabled; +} diff --git a/src/debugoverlay.h b/src/debugoverlay.h new file mode 100644 index 0000000..11ba673 --- /dev/null +++ b/src/debugoverlay.h @@ -0,0 +1,18 @@ +#ifndef DEBUGOVERLAY_H +#define DEBUGOVERLAY_H + +#include "scene/scenenode.h" + +class DebugOverlay : public SceneNode +{ + bool m_enabled; + +public: + DebugOverlay(); + + void update(); + void gui(); + void toggle(); +}; + +#endif // DEBUGOVERLAY_H diff --git a/src/engine.cpp b/src/engine.cpp index 783adbf..538b826 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -15,6 +15,7 @@ #include "tools/loader.h" #include "editor.h" #include "keymapper.h" +#include "debugoverlay.h" #include "tools/loadingthread.h" Engine::Engine() : @@ -70,6 +71,7 @@ void Engine::createWindow(std::string title, m_sparrowshell = new SparrowShell(m_window); m_editor = new Editor(); m_keymapper = new KeyMapper(); + m_overlay = new DebugOverlay(); m_loadingThread = LoadingThread::init(); } @@ -103,7 +105,8 @@ void Engine::update() if(settingsGuiOpen) { ImGui::Begin("Window Settings", &settingsGuiOpen); - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + //moved to overlay + //ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); bool physicsDebugEnabled = (m_physicsDebugNode != nullptr); if(ImGui::Checkbox("Toggle physics debug", &physicsDebugEnabled)) { @@ -135,15 +138,6 @@ static void ShowExampleAppFixedOverlay(bool* p_open) ImGui::Text("Simple overlay\nin the corner of the screen.\n(right-click to change position)"); ImGui::Separator(); ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); - if (ImGui::BeginPopupContextWindow()) - { - if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0; - if (ImGui::MenuItem("Top-right", NULL, corner == 1)) corner = 1; - if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2; - if (ImGui::MenuItem("Bottom-right", NULL, corner == 3)) corner = 3; - if (p_open && ImGui::MenuItem("Close")) *p_open = false; - ImGui::EndPopup(); - } ImGui::End(); } ImGui::PopStyleColor(); @@ -223,6 +217,7 @@ void Engine::setScene(std::string scene) new_scene->getRootObject()->addChild(m_sparrowshell); new_scene->getRootObject()->addChild(m_editor); new_scene->getRootObject()->addChild(m_keymapper); + new_scene->getRootObject()->addChild(m_overlay); } void Engine::enablePhysicsDebug() diff --git a/src/engine.h b/src/engine.h index 9dbee66..c6fb201 100644 --- a/src/engine.h +++ b/src/engine.h @@ -10,6 +10,7 @@ class SparrowShell; class PhysicsDebugNode; class Editor; class KeyMapper; +class DebugOverlay; class LoadingThread; namespace sf @@ -56,6 +57,7 @@ public: PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;} Editor* getEditor() const {return m_editor;} KeyMapper* getKeyMapper() const{return m_keymapper;} + DebugOverlay* getOverlay() const{return m_overlay;} LoadingThread* getLoadingThread() const {return m_loadingThread;} SceneTree* getScene() const; @@ -83,6 +85,7 @@ private: PhysicsDebugNode *m_physicsDebugNode; SparrowRenderer* m_renderer; Editor* m_editor; + DebugOverlay* m_overlay; KeyMapper* m_keymapper; LoadingThread* m_loadingThread; diff --git a/src/sparrowshell/scriptnode.cpp b/src/sparrowshell/scriptnode.cpp index 02de225..2cb5fd8 100644 --- a/src/sparrowshell/scriptnode.cpp +++ b/src/sparrowshell/scriptnode.cpp @@ -10,6 +10,7 @@ #include "tools/utils.h" #include "editor.h" #include "keymapper.h" +#include "debugoverlay.h" #define LUA_DEFINE(var) S[#var]=var #define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var); @@ -30,6 +31,7 @@ ScriptNode::ScriptNode() LUA_SET_FUN(resourcePackEditor); LUA_SET_FUN(editor); LUA_SET_FUN(keymapper); + LUA_SET_FUN(overlay); m_script.new_usertype("Engine", "time",&Engine::getTime, @@ -121,3 +123,7 @@ void ScriptNode::editor(){ void ScriptNode::keymapper(){ this->getEngine().getKeyMapper()->toggle(); } + +void ScriptNode::overlay(){ + this->getEngine().getOverlay()->toggle(); +} diff --git a/src/sparrowshell/scriptnode.h b/src/sparrowshell/scriptnode.h index 93c8558..ac363c3 100644 --- a/src/sparrowshell/scriptnode.h +++ b/src/sparrowshell/scriptnode.h @@ -29,6 +29,7 @@ public: void resourcePackEditor(); void editor(); void keymapper(); + void overlay(); }; #endif // SCRIPTNODE_H