From 4be5aa04b2423cb52075a62efbf900ac21895f18 Mon Sep 17 00:00:00 2001 From: Joeyrp Date: Tue, 2 Nov 2021 16:26:05 -0400 Subject: [PATCH] Main Editor window improved: No longer hiding the application window behind the imgui window. App window is now actually hidden (so no trailing when moving the editor panel). --- src/core/core.cpp | 6 ++++ src/run_modes/editor/editor.cpp | 37 +++++++++++++++------ src/run_modes/editor/editor.h | 12 ++++++- src/run_modes/editor/panels/mainPanel.cpp | 39 +++++++++++++++++++++-- src/run_modes/editor/panels/mainPanel.h | 4 +++ src/run_modes/editor/project/project.h | 0 src/window/window.cpp | 6 ++++ src/window/window.h | 1 + 8 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/run_modes/editor/project/project.h diff --git a/src/core/core.cpp b/src/core/core.cpp index 422a3a1..9c02c86 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -229,9 +229,15 @@ namespace lunarium { mpRunMode = new Tester; } + else if (RunMode::MODE_EDITOR == mState.Mode) { +#if BUILD_NO_EDITOR + Logger::Log(mLogCat, LogLevel::FATAL_ERROR, "The Editor is not available with this build"); + return; +#else mpRunMode = new Editor; +#endif } // Initialize the Run Mode diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index aade936..3b1f577 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -17,7 +17,6 @@ namespace lunarium Editor::Editor() : mLogCat(-1), mpMainPanel(nullptr) { - } OpRes Editor::Initialize() @@ -28,6 +27,7 @@ namespace lunarium mpMainPanel = &MainPanel::GetInstance(); mpMainPanel->SetEditor(this); + Core::MainWindow().GetPosition(&sx, &sy); return OpRes::OK(); } @@ -38,15 +38,26 @@ namespace lunarium void Editor::OnTick(double delta) { - int x, y, w, h; - mpMainPanel->GetPosition(x, y); - mpMainPanel->GetSize(w, h); + //int x, y, w, h; + //mpMainPanel->GetPosition(x, y); + // mpMainPanel->GetSize(w, h); - if (w > 0 && h > 0) - { - // NOTE TODO: Hardcoding fullscreen to false! - Core::MainWindow().ChangeDisplayMode(false, x, y, w, h); - } + // if (w > 0 && h > 0) + // { + // // NOTE: Should not be able to run in full screen while in editor mode + // // Unless testing the game maybe? + // Core::MainWindow().ChangeDisplayMode(false, x, y, w, h); + // } + + // if (x > 0 && y > 0) + // { + // if (sx != x || sy != y) + // { + // Core::MainWindow().Hide(); + // mpMainPanel->Focus(); + // } + + // } } void Editor::OnRender(IGraphics* g) @@ -61,4 +72,12 @@ namespace lunarium { return mLogCat; } + + //////////////////////////////////////////////////////////// + // HELPER METHODS + //////////////////////////////////////////////////////////// + void Editor::CreatePanels() + { + + } } \ No newline at end of file diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index 6f0e9db..bc0fe88 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -12,8 +12,11 @@ #include #include +#include + namespace lunarium { + class Panel; class MainPanel; class Editor : public iRunMode { @@ -26,7 +29,7 @@ namespace lunarium uint32_t GetLogCat() const; - + private: Editor(const Editor&) = delete; const Editor& operator=(const Editor&) = delete; @@ -34,6 +37,13 @@ namespace lunarium private: // Data uint32_t mLogCat; MainPanel* mpMainPanel; + std::vector mpPanels; + + // TEST + int sx, sy; + + private: // HELPERS + void CreatePanels(); }; } diff --git a/src/run_modes/editor/panels/mainPanel.cpp b/src/run_modes/editor/panels/mainPanel.cpp index cff7aa8..475e414 100644 --- a/src/run_modes/editor/panels/mainPanel.cpp +++ b/src/run_modes/editor/panels/mainPanel.cpp @@ -17,11 +17,16 @@ namespace lunarium { MainPanel* MainPanel::mpInstance = nullptr; MainPanel::MainPanel() - : Panel(PT_MAIN, true), mpEditor(nullptr) + : Panel(PT_MAIN, true), mpEditor(nullptr), mSetFocus(false) { Core::MainWindow().GetFramebufferSize(&mStartWidth, &mStartHeight); Core::MainWindow().GetPosition(&mStartX, &mStartY); + + // Make the application window small so that the imgui window will start outside of + // it's bounds and be detached from it. This prevents the window from disappearing + // and/or losing focus when the application window disappears. + Core::MainWindow().ChangeDisplayMode(false, mStartX + 10, mStartY + 10, 10, 10); } @@ -47,19 +52,47 @@ namespace lunarium mpEditor = e; } + void MainPanel::Focus() + { + mSetFocus = true; + } + bool MainPanel::DoFrame() { if (!mIsOpen) return false; + + if (mSetFocus) + { + ImGui::SetNextWindowFocus(); + mSetFocus = false; + } ImGui::SetNextWindowSize(ImVec2(mStartWidth, mStartHeight), ImGuiCond_Appearing); ImGui::SetNextWindowPos(ImVec2(mStartX, mStartY), ImGuiCond_Appearing); - if (!ImGui::Begin("Lunarium Editor", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_DockNodeHost)) + if (!ImGui::Begin("Lunarium Editor", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking)) { ImGui::End(); return false; } - // Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO, "EDITOR WINDOW SHOWING"); + ImGui::BeginMenuBar(); + + // File + if (ImGui::BeginMenu("File")) + { + ImGui::MenuItem("New Project"); + ImGui::MenuItem("Open Project"); + ImGui::MenuItem("Save Project"); + ImGui::MenuItem("Save Project As"); + ImGui::Separator(); + if (ImGui::MenuItem("Exit")) + { + Core::GetInstance().SignalShutdown(); + } + ImGui::EndMenu(); + } + + ImGui::EndMenuBar(); // NOTE: Must always update these values! Panel::UpdateMetaInfo(); diff --git a/src/run_modes/editor/panels/mainPanel.h b/src/run_modes/editor/panels/mainPanel.h index 3c9cd40..b546223 100644 --- a/src/run_modes/editor/panels/mainPanel.h +++ b/src/run_modes/editor/panels/mainPanel.h @@ -22,6 +22,7 @@ namespace lunarium static void FreeInstance(); void SetEditor(Editor* e); + void Focus(); // Returns false if the window is closed bool DoFrame(); @@ -37,6 +38,9 @@ namespace lunarium int mStartHeight; int mStartX; int mStartY; + + // Menu Items + bool mSetFocus; }; } diff --git a/src/run_modes/editor/project/project.h b/src/run_modes/editor/project/project.h new file mode 100644 index 0000000..e69de29 diff --git a/src/window/window.cpp b/src/window/window.cpp index 41d4129..54851c7 100644 --- a/src/window/window.cpp +++ b/src/window/window.cpp @@ -60,6 +60,7 @@ namespace lunarium if (state.Mode == RunMode::MODE_EDITOR) { glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); } mpWindow = glfwCreateWindow( state.Display.WindowedSize.Width, state.Display.WindowedSize.Height, "Lunarium", NULL, NULL ); @@ -189,6 +190,11 @@ namespace lunarium } } + bool Window::IsFullScreen() const + { + return glfwGetWindowMonitor(mpWindow) != nullptr; + } + void Window::GetFramebufferSize(int* width, int* height) const { glfwGetFramebufferSize(mpWindow, width, height); diff --git a/src/window/window.h b/src/window/window.h index 25d9da6..ba4decc 100644 --- a/src/window/window.h +++ b/src/window/window.h @@ -37,6 +37,7 @@ namespace lunarium // TODO: See https://www.glfw.org/docs/latest/window_guide.html#window_full_screen void ChangeDisplayMode(bool fullscreen, int xPos, int yPos, int width, int height); + bool IsFullScreen() const; void GetFramebufferSize(int* width, int* height) const; void GetPosition(int* x, int* y) const;