Basic about window added, status bar added, docking seems to work correctly

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 7c0eb5a77a
commit 97db356d66

@ -14,6 +14,7 @@
#include <imgui.h> #include <imgui.h>
#include <imgui_impl_glfw.h> #include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
#include <graphics/internalFont.h>
namespace lunarium namespace lunarium
{ {
@ -55,6 +56,10 @@ namespace lunarium
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows 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 // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();

@ -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 target_include_directories(editor
PUBLIC "${PROJECT_BINARY_DIR}" PUBLIC "${PROJECT_BINARY_DIR}"

@ -12,10 +12,14 @@
#include <core/core.h> #include <core/core.h>
#include <utils/logger.h> #include <utils/logger.h>
// Panels
#include "panels/about.h"
namespace lunarium namespace lunarium
{ {
Editor::Editor() 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 = &MainPanel::GetInstance();
mpMainPanel->SetEditor(this); mpMainPanel->SetEditor(this);
CreatePanels();
return OpRes::OK(); return OpRes::OK();
} }
@ -35,14 +41,19 @@ namespace lunarium
void Editor::OnTick(double delta) void Editor::OnTick(double delta)
{ {
HandleMenuEvents();
} }
void Editor::OnRender(IGraphics* g) 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() 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);
} }
} }

@ -11,12 +11,12 @@
#include <core/iRunMode.h> #include <core/iRunMode.h>
#include <utils/opRes.h> #include <utils/opRes.h>
#include "panels/iPanel.h"
#include <vector> #include <map>
namespace lunarium namespace lunarium
{ {
class Panel;
class MainPanel; class MainPanel;
class Editor : public iRunMode class Editor : public iRunMode
{ {
@ -30,6 +30,15 @@ namespace lunarium
uint32_t GetLogCat() const; uint32_t GetLogCat() const;
// Menu Bar Events
void NewProject();
void OpenProject();
void SaveProject();
void SaveAs();
void Exit();
void ShowAboutPanel();
private: private:
Editor(const Editor&) = delete; Editor(const Editor&) = delete;
const Editor& operator=(const Editor&) = delete; const Editor& operator=(const Editor&) = delete;
@ -37,10 +46,19 @@ namespace lunarium
private: // Data private: // Data
uint32_t mLogCat; uint32_t mLogCat;
MainPanel* mpMainPanel; MainPanel* mpMainPanel;
std::vector<Panel*> mpPanels; std::map<PanelType, Panel*> mPanels;
// Menu Bar Events
// Don't want to handles these events during rendering
bool mDoNewProject;
bool mDoOpenProject;
bool mDoSaveProject;
bool mDoSaveAs;
private: // HELPERS private: // HELPERS
void CreatePanels(); void CreatePanels();
void HandleMenuEvents();
}; };
} }

@ -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 <dearimgui/imgui.h>
#include <core/version.h>
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;
}
}

@ -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_

@ -14,6 +14,7 @@ namespace lunarium
enum PanelType enum PanelType
{ {
PT_MAIN, PT_MAIN,
PT_ABOUT,
PT_UNKNOWN, PT_UNKNOWN,
}; };

@ -17,16 +17,8 @@ namespace lunarium
{ {
MainPanel* MainPanel::mpInstance = nullptr; MainPanel* MainPanel::mpInstance = nullptr;
MainPanel::MainPanel() 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; mpEditor = e;
} }
void MainPanel::Focus()
{
mSetFocus = true;
}
bool MainPanel::DoFrame() bool MainPanel::DoFrame()
{ {
if (!mIsOpen) if (!mIsOpen)
return false; return false;
DoMainMenu();
Core::MainWindow().GetFramebufferSize(&mWidth, &mHeight);
Core::MainWindow().GetPosition(&mX, &mY);
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_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();
}
ImGui::End();
return true;
}
void MainPanel::DoMainMenu()
{
ImGui::BeginMainMenuBar(); ImGui::BeginMainMenuBar();
// File // File
if (ImGui::BeginMenu("File")) if (ImGui::BeginMenu("File"))
{ {
ImGui::MenuItem("New Project"); if (ImGui::MenuItem("New Project"))
ImGui::MenuItem("Open Project"); {
ImGui::MenuItem("Save Project"); mpEditor->NewProject();
ImGui::MenuItem("Save Project As"); }
if (ImGui::MenuItem("Open Project"))
{
mpEditor->OpenProject();
}
if (ImGui::MenuItem("Save Project"))
{
mpEditor->SaveProject();
}
if (ImGui::MenuItem("Save Project As"))
{
mpEditor->SaveAs();
}
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("Exit")) if (ImGui::MenuItem("Exit"))
{ {
Core::GetInstance().SignalShutdown(); mpEditor->Exit();
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::EndMainMenuBar(); if (ImGui::BeginMenu("Windows"))
{
if (mSetFocus)
{
ImGui::SetNextWindowFocus();
mSetFocus = false;
}
Core::MainWindow().GetFramebufferSize(&mWidth, &mHeight); ImGui::EndMenu();
Core::MainWindow().GetPosition(&mX, &mY); }
ImGui::SetNextWindowSize(ImVec2(mWidth, mHeight - ImGui::GetFrameHeight()), ImGuiCond_Always); if (ImGui::BeginMenu("Help"))
ImGui::SetNextWindowPos(ImVec2(mX, mY + ImGui::GetFrameHeight()), ImGuiCond_Always); {
if (!ImGui::Begin("Lunarium Editor", &mIsOpen, ImGuiWindowFlags_NoCollapse if (ImGui::MenuItem("About"))
| ImGuiWindowFlags_NoMove {
| ImGuiWindowFlags_NoTitleBar )) mpEditor->ShowAboutPanel();
{ }
ImGui::End();
return false;
}
ImGui::EndMenu();
}
// NOTE: Must always update these values! ImGui::EndMainMenuBar();
Panel::UpdateMetaInfo();
ImGui::End();
return true;
} }
} }

@ -22,7 +22,6 @@ namespace lunarium
static void FreeInstance(); static void FreeInstance();
void SetEditor(Editor* e); void SetEditor(Editor* e);
void Focus();
// Returns false if the window is closed // Returns false if the window is closed
bool DoFrame(); bool DoFrame();
@ -34,13 +33,9 @@ namespace lunarium
private: private:
Editor* mpEditor; Editor* mpEditor;
// int mStartWidth;
// int mStartHeight;
// int mStartX;
// int mStartY;
// Menu Items private: // HELPERS
bool mSetFocus; void DoMainMenu();
}; };
} }

Loading…
Cancel
Save