Added basic debug log window

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 84cb646512
commit b0142f3348

@ -36,6 +36,7 @@ set(LUNARIUM_SRC
"src/input/keyboard.cpp" "src/input/keyboard.cpp"
"src/input/inputManager.cpp" "src/input/inputManager.cpp"
"src/graphics/gui/gui.cpp" "src/graphics/gui/gui.cpp"
"src/graphics/gui/logGui.cpp"
) )
# add the executable # add the executable

@ -13,8 +13,11 @@ Core:
✔ Implement the Image creation methods @done (9/9/2021, 2:50:20 PM) ✔ Implement the Image creation methods @done (9/9/2021, 2:50:20 PM)
Dear ImGui: GUI:
☐ Dear ImGui class with basic initialization ✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM)
✔ Debug log window @done (9/10/2021, 4:44:48 PM)
☐ Add key to show debug log window
.
Input: Input:
✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM) ✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM)

@ -13,6 +13,7 @@
#include <window/window.h> #include <window/window.h>
#include <graphics/opengl/glGraphics.h> #include <graphics/opengl/glGraphics.h>
#include <graphics/gui/gui.h> #include <graphics/gui/gui.h>
#include <graphics/gui/logGui.h>
namespace lunarium namespace lunarium
{ {
@ -42,6 +43,7 @@ namespace lunarium
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!"); Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!");
// Shutdown subsystems // Shutdown subsystems
LogGui::FreeInstance();
GUI::GetInstance().Shutdown(); GUI::GetInstance().Shutdown();
GUI::FreeInstance(); GUI::FreeInstance();
@ -83,6 +85,15 @@ namespace lunarium
if (mErrorLogFile.is_open()) if (mErrorLogFile.is_open())
Logger::GetInstance()->AddListener(new FileListener(mErrorLogFile, LogLevel::ERROR | LogLevel::FATAL_ERROR)); Logger::GetInstance()->AddListener(new FileListener(mErrorLogFile, LogLevel::ERROR | LogLevel::FATAL_ERROR));
// Init the Debug log window
OpRes result;
result = LogGui::GetInstance().Initialize();
if (Failed(result))
{
Logger::Log(LogCategory::CORE, LogLevel::WARNING,
"Could not initialized the debug log window: %s", result.Description);
}
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running Lunarium version %s", Version::GetVersion().ToString().c_str()); Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running Lunarium version %s", Version::GetVersion().ToString().c_str());
// Attempt to load the engine state file. This file should be placed in the same directory as the lunarium program. // Attempt to load the engine state file. This file should be placed in the same directory as the lunarium program.
@ -100,8 +111,6 @@ namespace lunarium
std::vector<Args::SwitchDesc> sd; std::vector<Args::SwitchDesc> sd;
mpArgs = new Args(argc, argv, '-', sd); mpArgs = new Args(argc, argv, '-', sd);
OpRes result;
// Init Graphics/Window system // Init Graphics/Window system
mpWindow = new Window; mpWindow = new Window;
result = mpWindow->Initialize(mState); result = mpWindow->Initialize(mState);
@ -151,6 +160,12 @@ namespace lunarium
// GUI // GUI
mGUI.Initialize(mpWindow); mGUI.Initialize(mpWindow);
result = LogGui::GetInstance().Initialize();
if (Failed(result))
{
Logger::Log(LogCategory::CORE, LogLevel::WARNING,
"Could not initialized the debug log window: %s", result.Description);
}
mbIsInit = true; mbIsInit = true;
} }
@ -208,13 +223,15 @@ namespace lunarium
mpGraphics->BeginDraw(); mpGraphics->BeginDraw();
// DEBUG: Render test ImGUI window // DEBUG: Render test ImGUI window
mGUI.ShowDemoWindow(); // mGUI.ShowDemoWindow();
LogGui::GetInstance().Show();
// DEBUG: Graphics tests // DEBUG: Graphics tests
mpGraphics->DrawFilledEllipse(glm::vec2(600, 300), glm::vec2(100, 150), Color(1.0f, 0.0f, 1.0f, 1.0f), 100); mpGraphics->DrawFilledEllipse(glm::vec2(600, 300), glm::vec2(100, 150), Color(1.0f, 0.0f, 1.0f, 1.0f), 100);
mpGraphics->DrawString("This is a test of the text renderer!", Rectangle(100, 200, width, 300), mpGraphics->DrawString("This is a test of the text renderer!", Rectangle(100, 200, width, 300),
Color(0.0f, 1.0f, 1.0f, 1.0f), 0.5f, mpGraphics->DefaultFont()); Color(0.0f, 1.0f, 1.0f, 1.0f), 0.5f, mpGraphics->DefaultFont());
mGUI.EndFrame();
mpGraphics->EndDraw(); mpGraphics->EndDraw();
} }
} }

@ -98,22 +98,25 @@ namespace lunarium
ImGui::NewFrame(); ImGui::NewFrame();
} }
void GUI::ShowDemoWindow() void GUI::EndFrame()
{ {
if (!mbIsInit)
return;
ImGui::ShowDemoWindow(&mbShowDemo);
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{ {
//GLFWwindow* backup_current_context = glfwGetCurrentContext(); GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows(); ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault(); ImGui::RenderPlatformWindowsDefault();
//glfwMakeContextCurrent(backup_current_context); glfwMakeContextCurrent(backup_current_context);
} }
} }
void GUI::ShowDemoWindow()
{
if (!mbIsInit)
return;
ImGui::ShowDemoWindow(&mbShowDemo);
}
} }

@ -23,6 +23,7 @@ namespace lunarium
void Shutdown(); void Shutdown();
void NewFrame(); void NewFrame();
void EndFrame();
void ShowDemoWindow(); void ShowDemoWindow();
private: private:

@ -0,0 +1,116 @@
/******************************************************************************
* File - logGui.cpp
* Author - Joey Pollack
* Date - 2021/09/09 (y/m/d)
* Mod Date - 2021/09/10 (y/m/d)
* Description - A debug log window
******************************************************************************/
#include "logGui.h"
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <sstream>
namespace lunarium
{
////////////////////////////////////////////////////////////
// GUI LOG LISTENER
////////////////////////////////////////////////////////////
GuiListener::GuiListener(LogGui* pGui, uint32_t acceptedLogLevels, uint32_t acceptedLogCategories, const char* myName)
: LogListener(acceptedLogLevels, acceptedLogCategories, myName), mpGui(pGui)
{
}
bool GuiListener::Log(LogMessage& message)
{
if (!LevelIsSet(message.LogLevel) ||
!CategoryIsSet(message.LogCategory))
return false;
std::ostringstream oss;
oss << std::endl << Logger::TimeStamp() << Logger::GetCategoryName(message.LogCategory)
<< Logger::GetLevelName(message.LogLevel) << message.Message << std::flush;
mpGui->mMsgHistory.push_back(oss.str());
return true;
}
////////////////////////////////////////////////////////////
// GUI LOGGER
////////////////////////////////////////////////////////////
LogGui* LogGui::mpInstance = nullptr;
LogGui::LogGui()
: mbShow(true), mListener(this)
{
}
LogGui& LogGui::GetInstance()
{
if (!mpInstance)
{
mpInstance = new LogGui;
}
return *mpInstance;
}
void LogGui::FreeInstance()
{
Logger::GetInstance()->RemoveListener(&mpInstance->mListener);
delete mpInstance;
mpInstance = nullptr;
}
OpRes LogGui::Initialize()
{
Logger::GetInstance()->AddListener(&mListener);
return OpRes::OK();
}
void LogGui::Show()
{
if (!mbShow)
return;
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Debug Log", &mbShow))
{
ImGui::End();
return;
}
ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
for (int i = 0; i < mMsgHistory.size(); i++)
{
const char* msg = mMsgHistory[i].c_str();
int len = strlen(msg);
ImGui::TextUnformatted(msg);
}
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
ImGui::EndChild();
ImGui::End();
}
void LogGui::Clear()
{
mMsgHistory.clear();
}
void LogGui::SetShow(bool show)
{
mbShow = show;
}
bool LogGui::IsShown() const
{
return mbShow;
}
}

@ -0,0 +1,57 @@
/******************************************************************************
* File - logGui.h
* Author - Joey Pollack
* Date - 2021/09/09 (y/m/d)
* Mod Date - 2021/09/10 (y/m/d)
* Description - A debug log window
******************************************************************************/
#ifndef LOG_GUI_H_
#define LOG_GUI_H_
#include <utils/opRes.h>
#include <vector>
#include <string>
#include <utils/logger.h>
namespace lunarium
{
class LogGui;
class GuiListener : public LogListener
{
public:
GuiListener(LogGui* pGui, uint32_t acceptedLogLevels = LogLevel::ANY, uint32_t acceptedLogCategories = LogLevel::ANY, const char* myName = "Gui Listener");
virtual bool Log(LogMessage& message);
private:
LogGui* mpGui;
};
class LogGui
{
public:
static LogGui& GetInstance();
static void FreeInstance();
OpRes Initialize();
void Show();
void Clear();
void SetShow(bool show);
bool IsShown() const;
private:
static LogGui* mpInstance;
bool mbShow;
std::vector<std::string> mMsgHistory;
friend GuiListener;
GuiListener mListener;
private:
LogGui();
LogGui(const LogGui&) = delete;
const LogGui& operator=(const LogGui&) = delete;
};
}
#endif // LOG_GUI_H_
Loading…
Cancel
Save