From 97db356d668c689bfe24821be71c51baaf7389cc Mon Sep 17 00:00:00 2001 From: Joeyrp Date: Wed, 3 Nov 2021 18:57:14 -0400 Subject: [PATCH] Basic about window added, status bar added, docking seems to work correctly --- src/gui/gui.cpp | 5 + src/run_modes/editor/CMakeLists.txt | 2 +- src/run_modes/editor/editor.cpp | 85 ++++++++++++- src/run_modes/editor/editor.h | 24 +++- src/run_modes/editor/panels/about.cpp | 38 ++++++ src/run_modes/editor/panels/about.h | 27 ++++ src/run_modes/editor/panels/iPanel.h | 1 + src/run_modes/editor/panels/mainPanel.cpp | 148 +++++++++++++++------- src/run_modes/editor/panels/mainPanel.h | 9 +- 9 files changed, 281 insertions(+), 58 deletions(-) create mode 100644 src/run_modes/editor/panels/about.cpp create mode 100644 src/run_modes/editor/panels/about.h diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 41a0397..5a9105d 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace lunarium { @@ -55,6 +56,10 @@ namespace lunarium io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows + // NOTE: Generating a font file for now. Late might look into loading directly from memory + GenerateFontFileAt("open.ttf"); + io.Fonts->AddFontFromFileTTF("open.ttf", 16.0f); + // Setup Dear ImGui style ImGui::StyleColorsDark(); diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 123a2ab..786c7b0 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(editor editor.cpp panels/iPanel.cpp panels/mainPanel.cpp) +add_library(editor editor.cpp panels/iPanel.cpp panels/mainPanel.cpp panels/about.cpp) target_include_directories(editor PUBLIC "${PROJECT_BINARY_DIR}" diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index 528e027..065fe49 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -12,10 +12,14 @@ #include #include +// Panels +#include "panels/about.h" + namespace lunarium { Editor::Editor() - : mLogCat(-1), mpMainPanel(nullptr) + : mLogCat(-1), mpMainPanel(nullptr), mDoNewProject(false), mDoOpenProject(false), + mDoSaveProject(false), mDoSaveAs(false) { } @@ -25,6 +29,8 @@ namespace lunarium mpMainPanel = &MainPanel::GetInstance(); mpMainPanel->SetEditor(this); + CreatePanels(); + return OpRes::OK(); } @@ -35,14 +41,19 @@ namespace lunarium void Editor::OnTick(double delta) { - + HandleMenuEvents(); } void Editor::OnRender(IGraphics* g) { - if (!mpMainPanel->DoFrame()) + mpMainPanel->DoFrame(); + + for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) { - Core::GetInstance().SignalShutdown(); + if (iter->second->IsOpen()) + { + iter->second->DoFrame(); + } } } @@ -56,6 +67,72 @@ namespace lunarium //////////////////////////////////////////////////////////// void Editor::CreatePanels() { + mPanels[PanelType::PT_ABOUT] = new AboutPanel; + } + + void Editor::HandleMenuEvents() + { + /////////////////////////// + // FILE + if (mDoNewProject) + { + + mDoNewProject = false; + } + if (mDoOpenProject) + { + + mDoOpenProject = false; + } + + if (mDoSaveProject) + { + + mDoSaveProject = false; + } + + if (mDoSaveAs) + { + + mDoSaveAs = false; + } + /////////////////////////// + + } + + + + //////////////////////////////////////////////////////////// + // MENU BAR EVENTS + //////////////////////////////////////////////////////////// + void Editor::NewProject() + { + mDoNewProject = true; + } + + void Editor::OpenProject() + { + + } + + void Editor::SaveProject() + { + + } + + void Editor::SaveAs() + { + + } + + void Editor::Exit() + { + Core::GetInstance().SignalShutdown(); + } + + void Editor::ShowAboutPanel() + { + mPanels[PanelType::PT_ABOUT]->SetOpen(true); } } \ No newline at end of file diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index da6ec76..250218e 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -11,12 +11,12 @@ #include #include +#include "panels/iPanel.h" -#include +#include namespace lunarium { - class Panel; class MainPanel; class Editor : public iRunMode { @@ -30,6 +30,15 @@ namespace lunarium uint32_t GetLogCat() const; + // Menu Bar Events + void NewProject(); + void OpenProject(); + void SaveProject(); + void SaveAs(); + void Exit(); + + void ShowAboutPanel(); + private: Editor(const Editor&) = delete; const Editor& operator=(const Editor&) = delete; @@ -37,10 +46,19 @@ namespace lunarium private: // Data uint32_t mLogCat; MainPanel* mpMainPanel; - std::vector mpPanels; + std::map mPanels; + + // Menu Bar Events + // Don't want to handles these events during rendering + bool mDoNewProject; + bool mDoOpenProject; + bool mDoSaveProject; + bool mDoSaveAs; + private: // HELPERS void CreatePanels(); + void HandleMenuEvents(); }; } diff --git a/src/run_modes/editor/panels/about.cpp b/src/run_modes/editor/panels/about.cpp new file mode 100644 index 0000000..8d4ee11 --- /dev/null +++ b/src/run_modes/editor/panels/about.cpp @@ -0,0 +1,38 @@ +/****************************************************************************** +* File - about.cpp +* Author - Joey Pollack +* Date - 2021/11/03 (y/m/d) +* Mod Date - 2021/11/03 (y/m/d) +* Description - The About panel +******************************************************************************/ + +#include "about.h" +#include +#include + +namespace lunarium +{ + AboutPanel::AboutPanel() + : Panel(PanelType::PT_ABOUT) + { + + } + + bool AboutPanel::DoFrame() + { + if (!mIsOpen) + return false; + + ImGui::SetNextWindowSize(ImVec2(300, ImGui::GetFrameHeight() * 20)); + if (!ImGui::Begin("About", &mIsOpen, ImGuiWindowFlags_NoCollapse )) + { + ImGui::End(); + return false; + } + + ImGui::TextWrapped("Lunarium Editor Version %s - Written by Joey Pollack", Version::GetVersion().ToString().c_str()); + + ImGui::End(); + return true; + } +} \ No newline at end of file diff --git a/src/run_modes/editor/panels/about.h b/src/run_modes/editor/panels/about.h new file mode 100644 index 0000000..f04edeb --- /dev/null +++ b/src/run_modes/editor/panels/about.h @@ -0,0 +1,27 @@ +/****************************************************************************** +* File - about.h +* Author - Joey Pollack +* Date - 2021/11/03 (y/m/d) +* Mod Date - 2021/11/03 (y/m/d) +* Description - The About panel +******************************************************************************/ + +#ifndef PANEL_ABOUT_H_ +#define PANEL_ABOUT_H_ + +#include "iPanel.h" + +namespace lunarium +{ + class Editor; + class AboutPanel : public Panel + { + public: + AboutPanel(); + + // Returns false if the window is closed + bool DoFrame(); + }; +} + +#endif // PANEL_ABOUT_H_ \ No newline at end of file diff --git a/src/run_modes/editor/panels/iPanel.h b/src/run_modes/editor/panels/iPanel.h index daa1c19..7731c71 100644 --- a/src/run_modes/editor/panels/iPanel.h +++ b/src/run_modes/editor/panels/iPanel.h @@ -14,6 +14,7 @@ namespace lunarium enum PanelType { PT_MAIN, + PT_ABOUT, PT_UNKNOWN, }; diff --git a/src/run_modes/editor/panels/mainPanel.cpp b/src/run_modes/editor/panels/mainPanel.cpp index cb879c9..21b8b9a 100644 --- a/src/run_modes/editor/panels/mainPanel.cpp +++ b/src/run_modes/editor/panels/mainPanel.cpp @@ -17,16 +17,8 @@ namespace lunarium { MainPanel* MainPanel::mpInstance = nullptr; MainPanel::MainPanel() - : Panel(PT_MAIN, true), mpEditor(nullptr), mSetFocus(false) + : Panel(PT_MAIN, true), mpEditor(nullptr) { - - Core::MainWindow().GetFramebufferSize(&mWidth, &mHeight); - Core::MainWindow().GetPosition(&mX, &mY); - - // 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, mX + 10, mY + 10, 10, 10); } @@ -52,58 +44,128 @@ namespace lunarium mpEditor = e; } - void MainPanel::Focus() - { - mSetFocus = true; - } - bool MainPanel::DoFrame() { if (!mIsOpen) return false; - ImGui::BeginMainMenuBar(); - - // 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::EndMainMenuBar(); + DoMainMenu(); - if (mSetFocus) - { - ImGui::SetNextWindowFocus(); - mSetFocus = false; - } - Core::MainWindow().GetFramebufferSize(&mWidth, &mHeight); Core::MainWindow().GetPosition(&mX, &mY); - ImGui::SetNextWindowSize(ImVec2(mWidth, mHeight - ImGui::GetFrameHeight()), ImGuiCond_Always); + float double_frame_height = ImGui::GetFrameHeight() * 2; + + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::SetNextWindowSize(ImVec2(mWidth, mHeight - double_frame_height), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(mX, mY + ImGui::GetFrameHeight()), ImGuiCond_Always); if (!ImGui::Begin("Lunarium Editor", &mIsOpen, ImGuiWindowFlags_NoCollapse - | ImGuiWindowFlags_NoMove - | ImGuiWindowFlags_NoTitleBar )) + | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBringToFrontOnFocus)) { ImGui::End(); return false; } + // const ImGuiViewport* vp = ImGui::GetWindowViewport(); + + // ImGuiID dockspace_id = ImGui::GetID("MyDockSpace"); + // ImGui::DockSpace(dockspace_id, ImVec2(vp->WorkSize.x, vp->WorkSize.y - ImGui::GetFrameHeight() * 2)); + + // float status_bar_pos = (vp->WorkSize.y - ImGui::GetFrameHeight() * 2); + // ImGui::SetCursorPosY(status_bar_pos); + // ImGui::Separator(); + // if (ImGui::BeginTable("status", 3)) + // { + // ImGui::TableNextColumn(); + // ImGui::Text("Lunarium"); + // ImGui::TableNextColumn(); + // ImGui::Text("Testing"); + // ImGui::TableNextColumn(); + // ImGui::Text("Status Bar"); + // ImGui::EndTable(); + // } + ImGui::PopStyleVar(); + ImGui::End(); + + // STATUS BAR + const ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowViewport(viewport->ID); + ImGui::SetNextWindowSize(ImVec2(mWidth, ImGui::GetFrameHeight() - 12.0f), ImGuiCond_Always); + ImGui::SetNextWindowPos(ImVec2(mX, mY + (mHeight - ImGui::GetFrameHeight() - 8.0f)), ImGuiCond_Always); + ImGui::Begin("status bar", &mIsOpen, ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDocking ); + + if (ImGui::BeginTable("status", 3, ImGuiTableFlags_BordersInnerV)) + { + ImGui::AlignTextToFramePadding(); + ImGui::TableNextColumn(); + ImGui::Text("Lunarium"); + ImGui::TableNextColumn(); + ImGui::Text("Testing"); + ImGui::TableNextColumn(); + ImGui::Text("Status Bar"); + ImGui::EndTable(); + } - // NOTE: Must always update these values! - Panel::UpdateMetaInfo(); ImGui::End(); + return true; } + + void MainPanel::DoMainMenu() + { + ImGui::BeginMainMenuBar(); + + // File + if (ImGui::BeginMenu("File")) + { + if (ImGui::MenuItem("New Project")) + { + mpEditor->NewProject(); + } + + if (ImGui::MenuItem("Open Project")) + { + mpEditor->OpenProject(); + } + + if (ImGui::MenuItem("Save Project")) + { + mpEditor->SaveProject(); + } + + if (ImGui::MenuItem("Save Project As")) + { + mpEditor->SaveAs(); + } + + ImGui::Separator(); + + if (ImGui::MenuItem("Exit")) + { + mpEditor->Exit(); + } + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Windows")) + { + + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Help")) + { + if (ImGui::MenuItem("About")) + { + mpEditor->ShowAboutPanel(); + } + + ImGui::EndMenu(); + } + + ImGui::EndMainMenuBar(); + } } \ No newline at end of file diff --git a/src/run_modes/editor/panels/mainPanel.h b/src/run_modes/editor/panels/mainPanel.h index ee3ac2e..14d4861 100644 --- a/src/run_modes/editor/panels/mainPanel.h +++ b/src/run_modes/editor/panels/mainPanel.h @@ -22,7 +22,6 @@ namespace lunarium static void FreeInstance(); void SetEditor(Editor* e); - void Focus(); // Returns false if the window is closed bool DoFrame(); @@ -34,13 +33,9 @@ namespace lunarium private: Editor* mpEditor; - // int mStartWidth; - // int mStartHeight; - // int mStartX; - // int mStartY; - // Menu Items - bool mSetFocus; + private: // HELPERS + void DoMainMenu(); }; }