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_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <graphics/internalFont.h>
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();

@ -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}"

@ -12,10 +12,14 @@
#include <core/core.h>
#include <utils/logger.h>
// 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);
}
}

@ -11,12 +11,12 @@
#include <core/iRunMode.h>
#include <utils/opRes.h>
#include "panels/iPanel.h"
#include <vector>
#include <map>
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<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
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
{
PT_MAIN,
PT_ABOUT,
PT_UNKNOWN,
};

@ -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();
}
}

@ -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();
};
}

Loading…
Cancel
Save