Main editor window working
parent
90afa2d908
commit
cd4f23b732
@ -0,0 +1,11 @@
|
||||
add_library(editor editor.cpp panels/iPanel.cpp panels/mainPanel.cpp)
|
||||
|
||||
target_include_directories(editor
|
||||
PUBLIC "${PROJECT_BINARY_DIR}"
|
||||
PUBLIC ../../
|
||||
PUBLIC ../../internal_libs
|
||||
PUBLIC ../../../external/glm
|
||||
PUBLIC ../../../external/glad/include
|
||||
PUBLIC ../../../external/glfw/include
|
||||
PUBLIC ../../../external/box2d/include
|
||||
)
|
||||
@ -0,0 +1,64 @@
|
||||
/******************************************************************************
|
||||
* File - editor.cpp
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/11/01 (y/m/d)
|
||||
* Mod Date - 2021/11/01 (y/m/d)
|
||||
* Description - Entry point for the editor run mode.
|
||||
******************************************************************************/
|
||||
|
||||
#include "editor.h"
|
||||
|
||||
#include "panels/mainPanel.h"
|
||||
#include <core/core.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
Editor::Editor()
|
||||
: mLogCat(-1), mpMainPanel(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
OpRes Editor::Initialize()
|
||||
{
|
||||
//Core::MainWindow().Hide();
|
||||
|
||||
mLogCat = Logger::RegisterCategory("EDITOR");
|
||||
mpMainPanel = &MainPanel::GetInstance();
|
||||
mpMainPanel->SetEditor(this);
|
||||
|
||||
return OpRes::OK();
|
||||
}
|
||||
|
||||
void Editor::Shutdown()
|
||||
{
|
||||
MainPanel::FreeInstance();
|
||||
}
|
||||
|
||||
void Editor::OnTick(double delta)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::OnRender(IGraphics* g)
|
||||
{
|
||||
if (!mpMainPanel->DoFrame())
|
||||
{
|
||||
Core::GetInstance().SignalShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Editor::GetLogCat() const
|
||||
{
|
||||
return mLogCat;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/******************************************************************************
|
||||
* File - editor.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/11/01 (y/m/d)
|
||||
* Mod Date - 2021/11/01 (y/m/d)
|
||||
* Description - Entry point for the editor run mode.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef EDITOR_H_
|
||||
#define EDITOR_H_
|
||||
|
||||
#include <core/iRunMode.h>
|
||||
#include <utils/opRes.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
class MainPanel;
|
||||
class Editor : public iRunMode
|
||||
{
|
||||
public:
|
||||
Editor();
|
||||
OpRes Initialize();
|
||||
void Shutdown();
|
||||
void OnTick(double delta);
|
||||
void OnRender(IGraphics* g);
|
||||
|
||||
|
||||
uint32_t GetLogCat() const;
|
||||
|
||||
private:
|
||||
Editor(const Editor&) = delete;
|
||||
const Editor& operator=(const Editor&) = delete;
|
||||
|
||||
private: // Data
|
||||
uint32_t mLogCat;
|
||||
MainPanel* mpMainPanel;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // EDITOR_H_
|
||||
@ -0,0 +1,59 @@
|
||||
/******************************************************************************
|
||||
* File - iPanel.cpp
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/11/01 (y/m/d)
|
||||
* Mod Date - 2021/11/01 (y/m/d)
|
||||
* Description - Base class for all editor panels
|
||||
******************************************************************************/
|
||||
|
||||
#include "iPanel.h"
|
||||
|
||||
#include <dearimgui/imgui.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
Panel::Panel(PanelType type, bool isOpen)
|
||||
: mType(type), mIsOpen(isOpen)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PanelType Panel::GetType() const
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
void Panel::SetOpen(bool isOpen)
|
||||
{
|
||||
mIsOpen = isOpen;
|
||||
}
|
||||
|
||||
bool Panel::IsOpen()
|
||||
{
|
||||
return mIsOpen;
|
||||
}
|
||||
|
||||
|
||||
void Panel::GetPosition(int& x, int& y) const
|
||||
{
|
||||
x = mX;
|
||||
y = mY;
|
||||
}
|
||||
|
||||
void Panel::GetSize(int& w, int& h) const
|
||||
{
|
||||
w = mWidth;
|
||||
h = mHeight;
|
||||
}
|
||||
|
||||
void Panel::UpdateMetaInfo()
|
||||
{
|
||||
ImVec2 p = ImGui::GetWindowPos();
|
||||
ImVec2 s = ImGui::GetWindowSize();
|
||||
|
||||
mX = p.x;
|
||||
mY = p.y;
|
||||
mWidth = s.x;
|
||||
mHeight = s.y;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/******************************************************************************
|
||||
* File - iPanel.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/11/01 (y/m/d)
|
||||
* Mod Date - 2021/11/01 (y/m/d)
|
||||
* Description - Base class for all editor panels
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef PANEL_H_
|
||||
#define PANEL_H_
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
enum PanelType
|
||||
{
|
||||
PT_MAIN,
|
||||
PT_UNKNOWN,
|
||||
};
|
||||
|
||||
class Panel
|
||||
{
|
||||
public:
|
||||
Panel(PanelType type, bool isOpen = false);
|
||||
PanelType GetType() const;
|
||||
|
||||
virtual bool DoFrame() = 0;
|
||||
void SetOpen(bool isOpen);
|
||||
bool IsOpen();
|
||||
void GetPosition(int& x, int& y) const;
|
||||
void GetSize(int& w, int& h) const;
|
||||
|
||||
protected:
|
||||
PanelType mType;
|
||||
bool mIsOpen;
|
||||
|
||||
int mX;
|
||||
int mY;
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
protected:
|
||||
void UpdateMetaInfo();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PANEL_H_
|
||||
@ -0,0 +1,69 @@
|
||||
/******************************************************************************
|
||||
* File - mainPanel.cpp
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/11/01 (y/m/d)
|
||||
* Mod Date - 2021/11/01 (y/m/d)
|
||||
* Description - The main window for the editor.
|
||||
******************************************************************************/
|
||||
|
||||
#include "mainPanel.h"
|
||||
|
||||
#include "../editor.h"
|
||||
#include <core/core.h>
|
||||
#include <dearimgui/imgui.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
MainPanel* MainPanel::mpInstance = nullptr;
|
||||
MainPanel::MainPanel()
|
||||
: Panel(PT_MAIN, true), mpEditor(nullptr)
|
||||
{
|
||||
|
||||
Core::MainWindow().GetFramebufferSize(&mStartWidth, &mStartHeight);
|
||||
Core::MainWindow().GetPosition(&mStartX, &mStartY);
|
||||
}
|
||||
|
||||
|
||||
MainPanel& MainPanel::GetInstance()
|
||||
{
|
||||
if (!mpInstance)
|
||||
{
|
||||
mpInstance = new MainPanel;
|
||||
}
|
||||
|
||||
return *mpInstance;
|
||||
}
|
||||
|
||||
|
||||
void MainPanel::FreeInstance()
|
||||
{
|
||||
delete mpInstance;
|
||||
mpInstance = nullptr;
|
||||
}
|
||||
|
||||
void MainPanel::SetEditor(Editor* e)
|
||||
{
|
||||
mpEditor = e;
|
||||
}
|
||||
|
||||
bool MainPanel::DoFrame()
|
||||
{
|
||||
if (!mIsOpen)
|
||||
return 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))
|
||||
{
|
||||
ImGui::End();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO, "EDITOR WINDOW SHOWING");
|
||||
|
||||
// NOTE: Must always update these values!
|
||||
Panel::UpdateMetaInfo();
|
||||
ImGui::End();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/******************************************************************************
|
||||
* File - mainPanel.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/11/01 (y/m/d)
|
||||
* Mod Date - 2021/11/01 (y/m/d)
|
||||
* Description - The main window for the editor.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef PANEL_MAIN_H_
|
||||
#define PANEL_MAIN_H_
|
||||
|
||||
#include "iPanel.h"
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
class Editor;
|
||||
class MainPanel : public Panel
|
||||
{
|
||||
public:
|
||||
MainPanel();
|
||||
static MainPanel& GetInstance();
|
||||
static void FreeInstance();
|
||||
|
||||
void SetEditor(Editor* e);
|
||||
|
||||
// Returns false if the window is closed
|
||||
bool DoFrame();
|
||||
|
||||
private:
|
||||
static MainPanel* mpInstance;
|
||||
MainPanel(const MainPanel&) = delete;
|
||||
MainPanel& operator=(const MainPanel&) = delete;
|
||||
|
||||
private:
|
||||
Editor* mpEditor;
|
||||
int mStartWidth;
|
||||
int mStartHeight;
|
||||
int mStartX;
|
||||
int mStartY;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PANEL_MAIN_H_
|
||||
Loading…
Reference in New Issue