Added Layer Based Dynamic Window Titles
This commit is contained in:
parent
623aa4694b
commit
f6e80b5ad0
8
main.cpp
8
main.cpp
@ -9,10 +9,12 @@
|
||||
int main()
|
||||
{
|
||||
|
||||
constexpr const char* VERSION = "0.0.7"; // Format: 0.<release><commit_count>
|
||||
constexpr const char* TITLE = "Obsidian Editor - Onyx Engine (2025.1)";
|
||||
constexpr const char* VERSION = "0.1.0"; // Format: 0.<release><commit_count>
|
||||
|
||||
OX::Core core(std::string(TITLE) + " (" + VERSION + ")");
|
||||
|
||||
OX::Core core(std::string(OX_ENGINE_VERSION) + " (" + VERSION + ")");
|
||||
|
||||
core.AddLayer(std::make_unique<OX::DummyLayer>("Dummy Layer"));
|
||||
|
||||
core.AddLayer(std::make_unique<OX::Editor>("Obsidian Editor"));
|
||||
|
||||
|
@ -21,25 +21,31 @@ namespace OX
|
||||
if (!window.Init(m_name, 1280, 720))
|
||||
return;
|
||||
|
||||
|
||||
OX_ASSERT(!m_layers.empty(), "No Layers Attached");
|
||||
for (const auto &layer: m_layers) {
|
||||
|
||||
std::string layerTitle;
|
||||
for (size_t i = 0; i < m_layers.size(); ++i) {
|
||||
if (i > 0)
|
||||
layerTitle += " - ";
|
||||
layerTitle += m_layers[i]->GetName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (const auto &layer : m_layers) {
|
||||
Logger::LogDebug("Initializing Layer: '%s'", layer->GetName().c_str());
|
||||
layer->Init(*this);
|
||||
}
|
||||
|
||||
|
||||
Logger::LogOk("Core Initialization Complete.");
|
||||
std::string fullTitle = layerTitle + " - " + m_name;
|
||||
window.SetWindowTitle(fullTitle);
|
||||
|
||||
Logger::LogInfo("Info: This is an informational message.");
|
||||
Logger::LogWarning("Warning: Something might be wrong.");
|
||||
Logger::LogError("Error: Something went wrong!");
|
||||
Logger::LogDebug("Debug: Internal debug information.");
|
||||
Logger::LogVerbose("Verbose: Extra detailed logs.");
|
||||
Logger::LogOk("Ok: Everything succeeded!");
|
||||
Logger::LogOk("Core Initialization Complete.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Core::Run()
|
||||
{
|
||||
m_running = true;
|
||||
|
@ -14,36 +14,69 @@
|
||||
#include "systems/WindowManager.h"
|
||||
#include "systems/MACROS.h"
|
||||
|
||||
#define OX_ENGINE_VERSION "Onyx Engine (2025.1)"
|
||||
|
||||
namespace OX
|
||||
{
|
||||
class Core {
|
||||
class Core
|
||||
{
|
||||
public:
|
||||
Core(std::string name) : m_name(std::move(name)) {};
|
||||
Core(std::string name) : m_name(std::move(name))
|
||||
{
|
||||
};
|
||||
|
||||
~Core() = default;
|
||||
|
||||
void Init();
|
||||
|
||||
void Run();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
|
||||
WindowManager& GetWindow() {return window;}
|
||||
|
||||
|
||||
WindowManager &GetWindow() { return window; }
|
||||
|
||||
|
||||
void AddLayer(std::unique_ptr<Layer> layer);
|
||||
|
||||
private:
|
||||
void Update();
|
||||
|
||||
void Draw();
|
||||
|
||||
|
||||
std::vector<std::unique_ptr<Layer>> m_layers;
|
||||
std::vector<std::unique_ptr<Layer> > m_layers;
|
||||
WindowManager window;
|
||||
|
||||
bool m_running = false;
|
||||
std::string m_name = "Application";
|
||||
};
|
||||
|
||||
class DummyLayer : public Layer
|
||||
{
|
||||
public:
|
||||
explicit DummyLayer(const std::string &name = "Dummy Layer")
|
||||
: Layer(name)
|
||||
{
|
||||
}
|
||||
|
||||
void Init(Core &core) override
|
||||
{
|
||||
Logger::LogInfo("DummyLayer '%s' initialized.", m_name.c_str());
|
||||
}
|
||||
|
||||
void Update(Core &core) override
|
||||
{
|
||||
}
|
||||
|
||||
void Draw(Core &core) override
|
||||
{
|
||||
}
|
||||
|
||||
void Shutdown(Core &core) override
|
||||
{
|
||||
Logger::LogInfo("DummyLayer '%s' shutting down.", m_name.c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // CORE_H
|
||||
|
||||
|
@ -4,101 +4,120 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "Profiler.h"
|
||||
|
||||
namespace OX
|
||||
{
|
||||
bool WindowManager::Init(const std::string& title, int width, int height) {
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
bool WindowManager::Init(const std::string &title, int width, int height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
if (!glfwInit()) {
|
||||
Logger::LogError("Failed to initialize GLFW");
|
||||
return false;
|
||||
if (!glfwInit()) {
|
||||
Logger::LogError("Failed to initialize GLFW");
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // REM title bar
|
||||
|
||||
|
||||
m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
||||
if (!m_window) {
|
||||
Logger::LogError("Failed to create GLFW window");
|
||||
glfwTerminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(m_window);
|
||||
glfwSwapInterval(1); // Enable vsync
|
||||
|
||||
glewExperimental = GL_TRUE;
|
||||
GLenum err = glewInit();
|
||||
if (err != GLEW_OK) {
|
||||
Logger::LogError("Failed to initialize GLEW: %s", reinterpret_cast<const char *>(glewGetErrorString(err)));
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(m_window, FramebufferSizeCallback);
|
||||
glfwSetWindowUserPointer(m_window, this);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // REM title bar
|
||||
void WindowManager::SetWindowTitle(const std::string &title) const
|
||||
{
|
||||
if (m_window) {
|
||||
glfwSetWindowTitle(m_window, title.c_str());
|
||||
}
|
||||
else {
|
||||
Logger::LogWarning("Failed to set Window Title: 'Not Initialized'");
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::FramebufferSizeCallback(GLFWwindow *window, int width, int height)
|
||||
{
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
||||
if (!m_window) {
|
||||
Logger::LogError("Failed to create GLFW window");
|
||||
auto *wm = static_cast<WindowManager *>(glfwGetWindowUserPointer(window));
|
||||
if (wm) {
|
||||
wm->SetSize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::SetSize(int width, int height)
|
||||
{
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void WindowManager::PollEvents() const
|
||||
{
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
bool WindowManager::ShouldClose() const
|
||||
{
|
||||
return glfwWindowShouldClose(m_window);
|
||||
}
|
||||
|
||||
void WindowManager::BeginFrame() const
|
||||
{
|
||||
OX_PROFILE_FUNCTION();
|
||||
PollEvents();
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
glClearColor(0.07f, 0.07f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void WindowManager::EndFrame() const
|
||||
{
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
|
||||
void WindowManager::Shutdown()
|
||||
{
|
||||
if (m_window) {
|
||||
glfwDestroyWindow(m_window);
|
||||
m_window = nullptr;
|
||||
}
|
||||
glfwTerminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(m_window);
|
||||
glfwSwapInterval(1); // Enable vsync
|
||||
|
||||
glewExperimental = GL_TRUE;
|
||||
GLenum err = glewInit();
|
||||
if (err != GLEW_OK) {
|
||||
Logger::LogError("Failed to initialize GLEW: %s", reinterpret_cast<const char*>(glewGetErrorString(err)));
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(m_window, FramebufferSizeCallback);
|
||||
glfwSetWindowUserPointer(m_window, this);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void WindowManager::FramebufferSizeCallback(GLFWwindow* window, int width, int height) {
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
auto* wm = static_cast<WindowManager*>(glfwGetWindowUserPointer(window));
|
||||
if (wm) {
|
||||
wm->SetSize(width, height);
|
||||
WindowManager::~WindowManager()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::SetSize(int width, int height) {
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void WindowManager::PollEvents() const {
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
bool WindowManager::ShouldClose() const {
|
||||
return glfwWindowShouldClose(m_window);
|
||||
}
|
||||
|
||||
void WindowManager::BeginFrame() const {
|
||||
OX_PROFILE_FUNCTION();
|
||||
PollEvents();
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
glClearColor(0.07f, 0.07f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void WindowManager::EndFrame() const {
|
||||
OX_PROFILE_FUNCTION();
|
||||
|
||||
glfwSwapBuffers(m_window);
|
||||
|
||||
}
|
||||
|
||||
void WindowManager::Shutdown() {
|
||||
if (m_window) {
|
||||
glfwDestroyWindow(m_window);
|
||||
m_window = nullptr;
|
||||
}
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
WindowManager::~WindowManager() {
|
||||
Shutdown();
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ namespace OX
|
||||
|
||||
void PollEvents() const;
|
||||
[[nodiscard]] bool ShouldClose() const;
|
||||
void SetWindowTitle(const std::string& title) const;
|
||||
|
||||
void BeginFrame() const;
|
||||
void EndFrame() const;
|
||||
|
Loading…
Reference in New Issue
Block a user