Main Editor window improved: No longer hiding the application window behind the imgui window. App window is now actually hidden (so no trailing when moving the editor panel).

Gui_Panel_Refactor
Joeyrp 4 years ago
parent cd4f23b732
commit 4be5aa04b2

@ -229,9 +229,15 @@ namespace lunarium
{ {
mpRunMode = new Tester; mpRunMode = new Tester;
} }
else if (RunMode::MODE_EDITOR == mState.Mode) else if (RunMode::MODE_EDITOR == mState.Mode)
{ {
#if BUILD_NO_EDITOR
Logger::Log(mLogCat, LogLevel::FATAL_ERROR, "The Editor is not available with this build");
return;
#else
mpRunMode = new Editor; mpRunMode = new Editor;
#endif
} }
// Initialize the Run Mode // Initialize the Run Mode

@ -17,7 +17,6 @@ namespace lunarium
Editor::Editor() Editor::Editor()
: mLogCat(-1), mpMainPanel(nullptr) : mLogCat(-1), mpMainPanel(nullptr)
{ {
} }
OpRes Editor::Initialize() OpRes Editor::Initialize()
@ -28,6 +27,7 @@ namespace lunarium
mpMainPanel = &MainPanel::GetInstance(); mpMainPanel = &MainPanel::GetInstance();
mpMainPanel->SetEditor(this); mpMainPanel->SetEditor(this);
Core::MainWindow().GetPosition(&sx, &sy);
return OpRes::OK(); return OpRes::OK();
} }
@ -38,15 +38,26 @@ namespace lunarium
void Editor::OnTick(double delta) void Editor::OnTick(double delta)
{ {
int x, y, w, h; //int x, y, w, h;
mpMainPanel->GetPosition(x, y); //mpMainPanel->GetPosition(x, y);
mpMainPanel->GetSize(w, h); // mpMainPanel->GetSize(w, h);
if (w > 0 && h > 0) // if (w > 0 && h > 0)
{ // {
// NOTE TODO: Hardcoding fullscreen to false! // // NOTE: Should not be able to run in full screen while in editor mode
Core::MainWindow().ChangeDisplayMode(false, x, y, w, h); // // Unless testing the game maybe?
} // Core::MainWindow().ChangeDisplayMode(false, x, y, w, h);
// }
// if (x > 0 && y > 0)
// {
// if (sx != x || sy != y)
// {
// Core::MainWindow().Hide();
// mpMainPanel->Focus();
// }
// }
} }
void Editor::OnRender(IGraphics* g) void Editor::OnRender(IGraphics* g)
@ -61,4 +72,12 @@ namespace lunarium
{ {
return mLogCat; return mLogCat;
} }
////////////////////////////////////////////////////////////
// HELPER METHODS
////////////////////////////////////////////////////////////
void Editor::CreatePanels()
{
}
} }

@ -12,8 +12,11 @@
#include <core/iRunMode.h> #include <core/iRunMode.h>
#include <utils/opRes.h> #include <utils/opRes.h>
#include <vector>
namespace lunarium namespace lunarium
{ {
class Panel;
class MainPanel; class MainPanel;
class Editor : public iRunMode class Editor : public iRunMode
{ {
@ -26,7 +29,7 @@ namespace lunarium
uint32_t GetLogCat() const; uint32_t GetLogCat() const;
private: private:
Editor(const Editor&) = delete; Editor(const Editor&) = delete;
const Editor& operator=(const Editor&) = delete; const Editor& operator=(const Editor&) = delete;
@ -34,6 +37,13 @@ namespace lunarium
private: // Data private: // Data
uint32_t mLogCat; uint32_t mLogCat;
MainPanel* mpMainPanel; MainPanel* mpMainPanel;
std::vector<Panel*> mpPanels;
// TEST
int sx, sy;
private: // HELPERS
void CreatePanels();
}; };
} }

@ -17,11 +17,16 @@ namespace lunarium
{ {
MainPanel* MainPanel::mpInstance = nullptr; MainPanel* MainPanel::mpInstance = nullptr;
MainPanel::MainPanel() MainPanel::MainPanel()
: Panel(PT_MAIN, true), mpEditor(nullptr) : Panel(PT_MAIN, true), mpEditor(nullptr), mSetFocus(false)
{ {
Core::MainWindow().GetFramebufferSize(&mStartWidth, &mStartHeight); Core::MainWindow().GetFramebufferSize(&mStartWidth, &mStartHeight);
Core::MainWindow().GetPosition(&mStartX, &mStartY); Core::MainWindow().GetPosition(&mStartX, &mStartY);
// 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, mStartX + 10, mStartY + 10, 10, 10);
} }
@ -47,19 +52,47 @@ 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;
if (mSetFocus)
{
ImGui::SetNextWindowFocus();
mSetFocus = false;
}
ImGui::SetNextWindowSize(ImVec2(mStartWidth, mStartHeight), ImGuiCond_Appearing); ImGui::SetNextWindowSize(ImVec2(mStartWidth, mStartHeight), ImGuiCond_Appearing);
ImGui::SetNextWindowPos(ImVec2(mStartX, mStartY), ImGuiCond_Appearing); ImGui::SetNextWindowPos(ImVec2(mStartX, mStartY), ImGuiCond_Appearing);
if (!ImGui::Begin("Lunarium Editor", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_DockNodeHost)) if (!ImGui::Begin("Lunarium Editor", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking))
{ {
ImGui::End(); ImGui::End();
return false; return false;
} }
// Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO, "EDITOR WINDOW SHOWING"); ImGui::BeginMenuBar();
// 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::EndMenuBar();
// NOTE: Must always update these values! // NOTE: Must always update these values!
Panel::UpdateMetaInfo(); Panel::UpdateMetaInfo();

@ -22,6 +22,7 @@ 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();
@ -37,6 +38,9 @@ namespace lunarium
int mStartHeight; int mStartHeight;
int mStartX; int mStartX;
int mStartY; int mStartY;
// Menu Items
bool mSetFocus;
}; };
} }

@ -60,6 +60,7 @@ namespace lunarium
if (state.Mode == RunMode::MODE_EDITOR) if (state.Mode == RunMode::MODE_EDITOR)
{ {
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, 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 );
@ -189,6 +190,11 @@ namespace lunarium
} }
} }
bool Window::IsFullScreen() const
{
return glfwGetWindowMonitor(mpWindow) != nullptr;
}
void Window::GetFramebufferSize(int* width, int* height) const void Window::GetFramebufferSize(int* width, int* height) const
{ {
glfwGetFramebufferSize(mpWindow, width, height); glfwGetFramebufferSize(mpWindow, width, height);

@ -37,6 +37,7 @@ namespace lunarium
// TODO: See https://www.glfw.org/docs/latest/window_guide.html#window_full_screen // TODO: See https://www.glfw.org/docs/latest/window_guide.html#window_full_screen
void ChangeDisplayMode(bool fullscreen, int xPos, int yPos, int width, int height); void ChangeDisplayMode(bool fullscreen, int xPos, int yPos, int width, int height);
bool IsFullScreen() const;
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;

Loading…
Cancel
Save