Main editor window working

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 90afa2d908
commit cd4f23b732

@ -119,6 +119,9 @@ add_subdirectory(external/box2d)
# add run mode tester # add run mode tester
add_subdirectory(src/run_modes/tester) add_subdirectory(src/run_modes/tester)
# add run mode editor
add_subdirectory(src/run_modes/editor)
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PUBLIC "${PROJECT_BINARY_DIR}" PUBLIC "${PROJECT_BINARY_DIR}"
PUBLIC src PUBLIC src
@ -146,7 +149,7 @@ target_link_directories(${PROJECT_NAME}
PRIVATE external/box2d/src PRIVATE external/box2d/src
) )
target_link_libraries(${PROJECT_NAME} glfw glad glm dearimgui utils assets lua_static pugixml freetype box2d tester) target_link_libraries(${PROJECT_NAME} glfw glad glm dearimgui utils assets lua_static pugixml freetype box2d tester editor)
if(WIN32) if(WIN32)
target_link_libraries(${PROJECT_NAME} opengl32.lib) target_link_libraries(${PROJECT_NAME} opengl32.lib)

@ -1,7 +1,7 @@
Editor: @high Editor:
✔ Come up with project directory structure @done (9/17/2021, 6:46:44 PM) ✔ Come up with project directory structure @done (9/17/2021, 6:46:44 PM)
☐ Make the editor a separate module @high ✔ Make the editor a separate module @high @done (11/1/2021, 2:24:35 PM)
☐ Implement Run Mode interface class @high ☐ Implement Run Mode interface class @high
☐ Reference raw asset files in a "content" folder@high ☐ Reference raw asset files in a "content" folder@high
☐ Platform independant file browsing ☐ Platform independant file browsing

@ -27,6 +27,7 @@ Game:
☐ Collider (maybe via Box2D?) ☐ Collider (maybe via Box2D?)
☐ Script ☐ Script
☐ RigidBody (via Box2D) ☐ RigidBody (via Box2D)
☐ Audio Listener
Animations: Animations:
☐ Animated Sprite clas ☐ Animated Sprite clas

@ -14,6 +14,7 @@
// Run modes // Run modes
#include <run_modes/tester/tester.h> #include <run_modes/tester/tester.h>
#include <run_modes/editor/editor.h>
// Sub Systems // Sub Systems
#include <window/window.h> #include <window/window.h>
@ -62,6 +63,11 @@ namespace lunarium
&mpInstance->mState.Display.WindowStartPosition.Y); &mpInstance->mState.Display.WindowStartPosition.Y);
mpInstance->mState.SaveToFile("lunarium_state.xml"); mpInstance->mState.SaveToFile("lunarium_state.xml");
// Run Mode shuts down first
mpInstance->mpRunMode->Shutdown();
delete mpInstance->mpRunMode;
mpInstance->mpRunMode = nullptr;
// Shutdown subsystems // Shutdown subsystems
CoreAPI::FreeInstance(); CoreAPI::FreeInstance();
@ -86,10 +92,6 @@ namespace lunarium
delete mpInstance->mpArgs; delete mpInstance->mpArgs;
mpInstance->mpArgs = nullptr; mpInstance->mpArgs = nullptr;
mpInstance->mpRunMode->Shutdown();
delete mpInstance->mpRunMode;
mpInstance->mpRunMode = nullptr;
mpInstance->mbIsInit = false; mpInstance->mbIsInit = false;
delete mpInstance; delete mpInstance;
@ -102,6 +104,11 @@ namespace lunarium
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Core::Initialize(int argc, char** argv) void Core::Initialize(int argc, char** argv)
{ {
if (mbIsInit)
{
return;
}
// Setup the log system // Setup the log system
mMasterLogFile.open("Lunarium_Master.log", std::ios_base::app); mMasterLogFile.open("Lunarium_Master.log", std::ios_base::app);
mMasterLogFile << "\n\n"; mMasterLogFile << "\n\n";
@ -139,23 +146,6 @@ namespace lunarium
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Loaded state file: engine_state.xml"); Logger::Log(LogCategory::CORE, LogLevel::INFO, "Loaded state file: engine_state.xml");
} }
// RUN MODE
const char* types[] = { "game", "editor", "test" };
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running in mode: %s", types[mState.Mode]);
if (RunMode::MODE_TEST == mState.Mode)
{
mpRunMode = new Tester;
}
// Initialize the Run Mode
result = mpRunMode->Initialize();
if (Failed(result))
{
Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR,
"Could not initialize the Run Mode: %s", result.Description.c_str());
return;
}
// Parse command line args -- None right now // Parse command line args -- None right now
std::vector<Args::SwitchDesc> sd; std::vector<Args::SwitchDesc> sd;
mpArgs = new Args(argc, argv, '-', sd); mpArgs = new Args(argc, argv, '-', sd);
@ -232,6 +222,26 @@ namespace lunarium
"Could not initialized the LUA Core API: %s", result.Description); "Could not initialized the LUA Core API: %s", result.Description);
} }
// RUN MODE
const char* types[] = { "game", "editor", "test" };
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running in mode: %s", types[mState.Mode]);
if (RunMode::MODE_TEST == mState.Mode)
{
mpRunMode = new Tester;
}
else if (RunMode::MODE_EDITOR == mState.Mode)
{
mpRunMode = new Editor;
}
// Initialize the Run Mode
result = mpRunMode->Initialize();
if (Failed(result))
{
Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR,
"Could not initialize the Run Mode: %s", result.Description.c_str());
return;
}
mbIsInit = true; mbIsInit = true;
} }

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

@ -56,6 +56,11 @@ namespace lunarium
Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO,
"Creating OpenGL Context version %d, %d and glsl %s", "Creating OpenGL Context version %d, %d and glsl %s",
OPENGL_MAJOR_VERSION, OPENGL_MINOR_VERSION, System::GetGLSLVersionString().c_str()); OPENGL_MAJOR_VERSION, OPENGL_MINOR_VERSION, System::GetGLSLVersionString().c_str());
if (state.Mode == RunMode::MODE_EDITOR)
{
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
}
mpWindow = glfwCreateWindow( state.Display.WindowedSize.Width, state.Display.WindowedSize.Height, "Lunarium", NULL, NULL ); mpWindow = glfwCreateWindow( state.Display.WindowedSize.Width, state.Display.WindowedSize.Height, "Lunarium", NULL, NULL );
if (!mpWindow) if (!mpWindow)
@ -68,6 +73,7 @@ namespace lunarium
return OpRes::Fail(oss.str().c_str()); return OpRes::Fail(oss.str().c_str());
} }
glfwSetWindowPos(mpWindow, state.Display.WindowStartPosition.X, state.Display.WindowStartPosition.Y); glfwSetWindowPos(mpWindow, state.Display.WindowStartPosition.X, state.Display.WindowStartPosition.Y);
glfwMakeContextCurrent(mpWindow); glfwMakeContextCurrent(mpWindow);
@ -109,6 +115,17 @@ namespace lunarium
return { (float)x, (float)y }; return { (float)x, (float)y };
} }
void Window::Hide()
{
glfwHideWindow(mpWindow);
}
void Window::Show()
{
glfwShowWindow(mpWindow);
}
void Window::SetCursorPos(glm::vec2 pos) void Window::SetCursorPos(glm::vec2 pos)
{ {
glfwSetCursorPos(mpWindow, pos.x, pos.y); glfwSetCursorPos(mpWindow, pos.x, pos.y);

@ -40,6 +40,9 @@ namespace lunarium
void GetFramebufferSize(int* width, int* height) const; void GetFramebufferSize(int* width, int* height) const;
void GetPosition(int* x, int* y) const; void GetPosition(int* x, int* y) const;
void Hide();
void Show();
void SetShouldCloseFlag(bool should_close); void SetShouldCloseFlag(bool should_close);
bool ShouldWindowClose() const; bool ShouldWindowClose() const;
static void PollEvents(); static void PollEvents();

@ -1,6 +1,6 @@
<State> <State>
<DataDirectory>data/</DataDirectory> <DataDirectory>data/</DataDirectory>
<Mode Type="test" /> <Mode Type="editor" />
<Display Renderer="opengl" IsFullScreen="false" VSyncEnabled="true"> <Display Renderer="opengl" IsFullScreen="false" VSyncEnabled="true">
<FullScreenResolution Width="1920" Height="1080" /> <FullScreenResolution Width="1920" Height="1080" />
<WindowedSize Width="1280" Height="720" /> <WindowedSize Width="1280" Height="720" />

Loading…
Cancel
Save