diff --git a/CMakeLists.txt b/CMakeLists.txt
index df306bc..1681f2d 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -87,8 +87,8 @@ list(APPEND OGFX_SOURCE_FILES
# gui
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp
- ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/WindowBase.cpp
- ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/WindowBaseOutputHandler.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Window.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/WindowOutputHandler.cpp
# render
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/BasicRenderer.cpp
@@ -102,7 +102,8 @@ list(APPEND OGFX_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/utils/Animation.cpp
)
list(APPEND TEST_SOURCE_FILES
- ${CMAKE_CURRENT_LIST_DIR}/src/test.cpp
+ # ${CMAKE_CURRENT_LIST_DIR}/src/test/GraphicsWindowTest.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/src/test/GuiTest.cpp
)
#-----------------------------------------------------------------------------------------
diff --git a/other/build.nr b/other/build.nr
index b29009a..6be8278 100644
--- a/other/build.nr
+++ b/other/build.nr
@@ -1 +1 @@
-2038
+2039
diff --git a/src/ogfx/gui/Events.hpp b/src/ogfx/gui/Events.hpp
new file mode 100644
index 0000000..b2040d9
--- /dev/null
+++ b/src/ogfx/gui/Events.hpp
@@ -0,0 +1,76 @@
+/*
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
+
+ This file is part of OmniaFramework.
+
+ OmniaFramework is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OmniaFramework is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
+*/
+
+#pragma once
+
+#include
+
+namespace ogfx
+{
+ class WindowCore;
+ class WindowResizedData : public ostd::BaseObject
+ {
+ public:
+ inline WindowResizedData(WindowCore& parent, int32_t _oldx, int32_t _oldy, int32_t _newx, int32_t _newy) : parentWindow(parent), old_width(_oldx), old_height(_oldy), new_width(_newx), new_height(_newy)
+ {
+ setTypeName("ogfx::WindowResizedData");
+ validate();
+ }
+
+ public:
+ int32_t new_width;
+ int32_t new_height;
+ int32_t old_width;
+ int32_t old_height;
+ WindowCore& parentWindow;
+ };
+ class MouseEventData : public ostd::BaseObject
+ {
+ public: enum class eButton { None = 0, Left, Middle, Right };
+ public:
+ inline MouseEventData(WindowCore& parent, float mousex, float mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
+ {
+ setTypeName("ogfx::MouseEventData");
+ validate();
+ }
+
+ public:
+ float position_x;
+ float position_y;
+ eButton button;
+ WindowCore& parentWindow;
+ };
+ class KeyEventData : public ostd::BaseObject
+ {
+ public: enum class eKeyEvent { Pressed = 0, Released, Text };
+ public:
+ inline KeyEventData(WindowCore& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt)
+ {
+ setTypeName("ogfx::KeyEventData");
+ validate();
+ }
+
+ public:
+ int32_t keyCode;
+ char text;
+ eKeyEvent eventType;
+ WindowCore& parentWindow;
+ };
+}
diff --git a/src/ogfx/gui/GuiWindow.cpp b/src/ogfx/gui/GuiWindow.cpp
deleted file mode 100644
index a90b8fb..0000000
--- a/src/ogfx/gui/GuiWindow.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
-
- This file is part of OmniaFramework.
-
- OmniaFramework is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- OmniaFramework is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with OmniaFramework. If not, see .
-*/
-
-#include "GuiWindow.hpp"
-
-namespace ogfx
-{
- namespace gui
- {
- Window::~Window(void)
- {
- onDestroy();
- SDL_DestroyCursor(m_cursor_IBeam);
- SDL_DestroyCursor(m_cursor_Arrow);
- SDL_DestroyRenderer(m_renderer);
- SDL_DestroyWindow(m_window);
- SDL_Quit();
- TTF_Quit();
- }
-
- void Window::initialize(int32_t width, int32_t height, const ostd::String& windowTitle)
- {
- if (m_initialized) return;
- m_windowWidth = width;
- m_windowHeight = height;
- m_title = windowTitle;
- if (!SDL_Init(SDL_INIT_VIDEO))
- {
- printf( "SDL could not initialize! Error: %s\n", SDL_GetError() );
- exit(ErrorCodes::SDLInitFailed);
- }
- m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE);
- setSize(m_windowWidth, m_windowHeight);
- m_renderer = SDL_CreateRenderer(m_window, nullptr);
- SDL_SetWindowMinimumSize(m_window, m_windowWidth, m_windowHeight);
- SDL_SetWindowTitle(m_window, m_title.c_str());
- SDL_StartTextInput(m_window);
-
- m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_DEFAULT);
- m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_TEXT);
-
- m_initialized = true;
- m_running = true;
-
- setTypeName("ogfx::gui::Window");
- enableSignals(true);
- validate();
-
- onInitialize();
- }
-
- void Window::close(void)
- {
- m_running = false;
- onClose();
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::RealTime, *this);
- }
-
- int32_t Window::startMainLoop(void)
- {
- if (!m_initialized) return ErrorCodes::Uninitialized;
- while (m_running)
- {
- __handle_events();
- SDL_SetRenderDrawColor(m_renderer, m_clearColor.r, m_clearColor.g, m_clearColor.b, m_clearColor.a);
- SDL_RenderClear(m_renderer);
-
- SDL_RenderPresent(m_renderer);
- }
- return ErrorCodes::ExitSuccess;
- }
-
- void Window::setSize(int32_t width, int32_t height)
- {
- if (!isInitialized()) return;
- SDL_SetWindowSize(m_window, width, height);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime);
- }
-
- void Window::setTitle(const ostd::String& title)
- {
- if (!isInitialized()) return;
- m_title = title;
- SDL_SetWindowTitle(m_window, m_title.c_str());
- }
-
- void Window::setCursor(eCursor cursor)
- {
- switch (cursor)
- {
- case eCursor::Arrow:
- SDL_SetCursor(m_cursor_Arrow);
- break;
- case eCursor::IBeam:
- SDL_SetCursor(m_cursor_IBeam);
- break;
- default:
- SDL_SetCursor(m_cursor_Arrow);
- break;
- }
- }
-
- void Window::enableResizable(bool enable)
- {
- SDL_SetWindowResizable(m_window, enable);
- m_resizeable = enable;
- }
-
- void Window::setIcon(const ostd::String& iconFilePath)
- {
- SDL_Surface* appIcon = IMG_Load(iconFilePath);
- if (appIcon == nullptr)
- {
- //TODO: Error
- return;
- }
- SDL_SetWindowIcon(m_window, appIcon);
- SDL_DestroySurface(appIcon);
- }
-
- void Window::__handle_events(void)
- {
- if (!m_initialized) return;
- auto l_getMouseState = [this](void) -> MouseEventData {
- float mx = 0, my = 0;
- uint32_t btn = SDL_GetMouseState(&mx, &my);
- MouseEventData::eButton button = MouseEventData::eButton::None;
- switch (btn)
- {
- case SDL_BUTTON_MASK(1): button = MouseEventData::eButton::Left; break;
- case SDL_BUTTON_MASK(2): button = MouseEventData::eButton::Middle; break;
- case SDL_BUTTON_MASK(3): button = MouseEventData::eButton::Right; break;
- default: button = MouseEventData::eButton::None; break;
- }
- MouseEventData mmd(*this, mx, my, button);
- return mmd;
- };
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_EVENT_QUIT)
- {
- m_running = false;
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
- }
- else if (event.type == SDL_EVENT_WINDOW_RESIZED)
- {
- WindowResizedData wrd(*this, m_windowWidth, m_windowHeight, 0, 0);
- SDL_GetWindowSize(m_window, &m_windowWidth, &m_windowHeight);
- wrd.new_width = m_windowWidth;
- wrd.new_height = m_windowHeight;
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime, wrd);
- }
- else if (event.type == SDL_EVENT_MOUSE_MOTION)
- {
- MouseEventData mmd = l_getMouseState();
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
- }
- else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
- {
- MouseEventData mmd = l_getMouseState();
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
- }
- else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
- {
- MouseEventData mmd = l_getMouseState();
- switch (event.button.button)
- {
- case SDL_BUTTON_MASK(1): mmd.button = MouseEventData::eButton::Left; break;
- case SDL_BUTTON_MASK(2): mmd.button = MouseEventData::eButton::Middle; break;
- case SDL_BUTTON_MASK(3): mmd.button = MouseEventData::eButton::Right; break;
- default: mmd.button = MouseEventData::eButton::None; break;
- }
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseReleased, ostd::tSignalPriority::RealTime, mmd);
- }
- else if (event.type == SDL_EVENT_KEY_DOWN)
- {
- KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Pressed);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked);
- }
- else if (event.type == SDL_EVENT_KEY_UP)
- {
- KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Released);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked);
- }
- else if (event.type == SDL_EVENT_TEXT_INPUT)
- {
- KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked);
- }
- }
- }
- }
-}
diff --git a/src/ogfx/gui/GuiWindow.hpp b/src/ogfx/gui/GuiWindow.hpp
deleted file mode 100644
index 5c2a99d..0000000
--- a/src/ogfx/gui/GuiWindow.hpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
-
- This file is part of OmniaFramework.
-
- OmniaFramework is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- OmniaFramework is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with OmniaFramework. If not, see .
-*/
-
-#pragma once
-
-#include
-#include
-#include
-#include
-
-namespace ogfx
-{
- namespace gui
- {
- class Window : public ostd::BaseObject
- {
- public: enum class eCursor { Arrow = 0, IBeam };
- public: struct ErrorCodes {
- inline static constexpr uint16_t ExitSuccess { 0 };
- inline static constexpr uint16_t SDLInitFailed { 1 };
- inline static constexpr uint16_t SDLImageInitFailed { 2 };
- inline static constexpr uint16_t Uninitialized { 3 };
- };
- public:
- inline Window(void) { }
- ~Window(void);
- inline Window(int32_t width, int32_t height, const ostd::String& windowTitle) { initialize(width, height, windowTitle); }
- void initialize(int32_t width, int32_t height, const ostd::String& windowTitle);
- void close(void);
- int32_t startMainLoop(void);
- void setSize(int32_t width, int32_t height);
- void setTitle(const ostd::String& title);
- void setCursor(eCursor cursor);
- void enableResizable(bool enable = true);
- void setIcon(const ostd::String& iconFilePath);
-
- inline virtual void onInitialize(void) { }
- inline virtual void onDestroy(void) { }
- inline virtual void onClose(void) { }
-
- inline bool isInitialized(void) const { return m_initialized; }
- inline bool isRunning(void) const { return m_running; }
- inline bool isVisible(void) const { return m_visible; }
- inline bool isResizeable(void) const { return m_resizeable; }
- inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; }
- inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; }
- inline ostd::String getTitle(void) const { return m_title; }
- inline int32_t getWindowWidth(void) const { return m_windowWidth; }
- inline int32_t getWindowHeight(void) const { return m_windowHeight; }
- inline ostd::Color getClearColor(void) const { return m_clearColor; }
- inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
- inline SDL_Renderer* getSDLRenderer(void) const { return m_renderer; }
- private:
- void __handle_events(void);
-
- protected:
- SDL_Window* m_window { nullptr };
- SDL_Renderer* m_renderer { nullptr };
-
- private:
- ostd::Color m_clearColor { 10, 10, 10, 255 };
-
- int32_t m_windowWidth { 0 };
- int32_t m_windowHeight { 0 };
- ostd::String m_title { "" };
-
- bool m_running { false };
- bool m_initialized { false };
- bool m_visible { true };
- bool m_resizeable { true };
-
- SDL_Cursor* m_cursor_IBeam { nullptr };
- SDL_Cursor* m_cursor_Arrow { nullptr };
- };
- class WindowResizedData : public ostd::BaseObject
- {
- public:
- inline WindowResizedData(Window& parent, int32_t _oldx, int32_t _oldy, int32_t _newx, int32_t _newy) : parentWindow(parent), old_width(_oldx), old_height(_oldy), new_width(_newx), new_height(_newy)
- {
- setTypeName("ogfx::gui::WindowResizedData");
- validate();
- }
-
- public:
- int32_t new_width;
- int32_t new_height;
- int32_t old_width;
- int32_t old_height;
- Window& parentWindow;
- };
- class MouseEventData : public ostd::BaseObject
- {
- public: enum class eButton { None = 0, Left, Middle, Right };
- public:
- inline MouseEventData(Window& parent, int32_t mousex, int32_t mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
- {
- setTypeName("ogfx::gui::MouseEventData");
- validate();
- }
-
- public:
- int32_t position_x;
- int32_t position_y;
- eButton button;
- Window& parentWindow;
- };
- class KeyEventData : public ostd::BaseObject
- {
- public: enum class eKeyEvent { Pressed = 0, Released, Text };
- public:
- inline KeyEventData(Window& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt)
- {
- setTypeName("ogfx::gui::KeyEventData");
- validate();
- }
-
- public:
- int32_t keyCode;
- char text;
- eKeyEvent eventType;
- Window& parentWindow;
- };
- }
-}
diff --git a/src/ogfx/gui/RawTextInput.cpp b/src/ogfx/gui/RawTextInput.cpp
index cb0661c..6b715e1 100644
--- a/src/ogfx/gui/RawTextInput.cpp
+++ b/src/ogfx/gui/RawTextInput.cpp
@@ -19,7 +19,7 @@
*/
#include "RawTextInput.hpp"
-#include "../gui/WindowBase.hpp"
+#include "../gui/Window.hpp"
#include "../../io/Logger.hpp"
namespace ogfx
@@ -292,13 +292,13 @@ namespace ogfx
if (getParent().isMouseInside())
{
if (!m_ibeamCursorSet)
- window.setCursor(ogfx::WindowBase::eCursor::IBeam);
+ window.setCursor(ogfx::WindowCore::eCursor::IBeam);
m_ibeamCursorSet = true;
}
else
{
if (m_ibeamCursorSet)
- window.setCursor(ogfx::WindowBase::eCursor::Arrow);
+ window.setCursor(ogfx::WindowCore::eCursor::Arrow);
m_ibeamCursorSet = false;
}
}
diff --git a/src/ogfx/gui/RawTextInput.hpp b/src/ogfx/gui/RawTextInput.hpp
index 7a412e6..0310201 100644
--- a/src/ogfx/gui/RawTextInput.hpp
+++ b/src/ogfx/gui/RawTextInput.hpp
@@ -170,11 +170,11 @@ namespace ogfx
class RawTextInputEventListener : public RawTextInput::EventListener
{
public:
- inline RawTextInputEventListener(ogfx::gui::RawTextInput& _parent, ogfx::WindowBase& _window) : ogfx::gui::RawTextInput::EventListener::EventListener(_parent), window(_window) { }
+ inline RawTextInputEventListener(ogfx::gui::RawTextInput& _parent, ogfx::WindowCore& _window) : ogfx::gui::RawTextInput::EventListener::EventListener(_parent), window(_window) { }
void onSignalHandled(ostd::tSignal& signal) override;
public:
- ogfx::WindowBase& window;
+ ogfx::WindowCore& window;
bool m_ibeamCursorSet { false };
};
class RawTextInputNumberCharacterFilter : public RawTextInput::CharacterFilter
diff --git a/src/ogfx/gui/Window.cpp b/src/ogfx/gui/Window.cpp
new file mode 100644
index 0000000..9aa2d75
--- /dev/null
+++ b/src/ogfx/gui/Window.cpp
@@ -0,0 +1,321 @@
+/*
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
+
+ This file is part of OmniaFramework.
+
+ OmniaFramework is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OmniaFramework is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
+*/
+
+#include "Window.hpp"
+#include "../../ostd/utils/Time.hpp"
+#include
+#include
+#include
+#include
+
+namespace ogfx
+{
+ WindowCore::~WindowCore(void)
+ {
+ __on_window_destroy();
+ SDL_DestroyCursor(m_cursor_IBeam);
+ SDL_DestroyCursor(m_cursor_Arrow);
+ SDL_DestroyRenderer(m_renderer);
+ SDL_DestroyWindow(m_window);
+ SDL_Quit();
+ TTF_Quit();
+ }
+
+ void WindowCore::initialize(int32_t width, int32_t height, const ostd::String& title)
+ {
+ if (m_initialized) return;
+ m_windowWidth = width;
+ m_windowHeight = height;
+ m_title = title;
+ if (!SDL_Init(SDL_INIT_VIDEO))
+ {
+ printf( "SDL could not initialize! Error: %s\n", SDL_GetError() );
+ exit(1);
+ }
+ m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE);
+ m_renderer = SDL_CreateRenderer(m_window, nullptr);
+ SDL_SetWindowMinimumSize(m_window, m_windowWidth, m_windowHeight);
+ SDL_SetWindowTitle(m_window, m_title.c_str());
+ SDL_StartTextInput(m_window);
+
+ m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_DEFAULT);
+ m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_TEXT);
+
+ m_initialized = true;
+ m_running = true;
+
+ setTypeName("ogfx::WindowCore");
+ enableSignals(true);
+ validate();
+ setSize(m_windowWidth, m_windowHeight);
+
+ connectSignal(ostd::tBuiltinSignals::KeyPressed);
+ connectSignal(ostd::tBuiltinSignals::KeyReleased);
+ connectSignal(ostd::tBuiltinSignals::TextEntered);
+ connectSignal(ostd::tBuiltinSignals::MousePressed);
+ connectSignal(ostd::tBuiltinSignals::MouseReleased);
+ connectSignal(ostd::tBuiltinSignals::MouseMoved);
+ connectSignal(ostd::tBuiltinSignals::OnGuiEvent);
+ connectSignal(ostd::tBuiltinSignals::WindowClosed);
+ connectSignal(ostd::tBuiltinSignals::WindowResized);
+
+ __on_window_init(width, height, title);
+ }
+
+ void WindowCore::close(void)
+ {
+ __on_window_close();
+ m_running = false;
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
+ }
+
+ void WindowCore::setSize(int32_t width, int32_t height)
+ {
+ if (!isInitialized()) return;
+ SDL_SetWindowSize(m_window, width, height);
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime);
+ }
+
+ void WindowCore::setTitle(const ostd::String& title)
+ {
+ if (!isInitialized()) return;
+ m_title = title;
+ SDL_SetWindowTitle(m_window, m_title.c_str());
+ }
+
+ void WindowCore::setCursor(eCursor cursor)
+ {
+ switch (cursor)
+ {
+ case eCursor::Arrow:
+ SDL_SetCursor(m_cursor_Arrow);
+ break;
+ case eCursor::IBeam:
+ SDL_SetCursor(m_cursor_IBeam);
+ break;
+ default:
+ SDL_SetCursor(m_cursor_Arrow);
+ break;
+ }
+ }
+
+ void WindowCore::enableResizable(bool enable)
+ {
+ SDL_SetWindowResizable(m_window, enable);
+ m_resizeable = enable;
+ }
+
+ void WindowCore::setIcon(const ostd::String& iconFilePath)
+ {
+ SDL_Surface* appIcon = IMG_Load(iconFilePath);
+ if (appIcon == nullptr)
+ {
+ //TODO: Error
+ return;
+ }
+ SDL_SetWindowIcon(m_window, appIcon);
+ SDL_DestroySurface(appIcon);
+ }
+
+ MouseEventData WindowCore::get_mouse_state(void)
+ {
+ float mx = 0, my = 0;
+ uint32_t btn = SDL_GetMouseState(&mx, &my);
+ MouseEventData::eButton button = MouseEventData::eButton::None;
+ switch (btn)
+ {
+ case SDL_BUTTON_MASK(1): button = MouseEventData::eButton::Left; break;
+ case SDL_BUTTON_MASK(2): button = MouseEventData::eButton::Middle; break;
+ case SDL_BUTTON_MASK(3): button = MouseEventData::eButton::Right; break;
+ default: button = MouseEventData::eButton::None; break;
+ }
+ MouseEventData mmd(*this, mx, my, button);
+ return mmd;
+ }
+
+ void WindowCore::handle_events(void)
+ {
+ if (!isInitialized()) return;
+ SDL_Event event;
+
+ if (isBlockingEventsEnabled())
+ {
+ if (SDL_WaitEvent(&event))
+ __handle_event(event);
+ }
+ else
+ {
+ while (SDL_PollEvent(&event))
+ __handle_event(event);
+ }
+ }
+
+ void WindowCore::__handle_event(SDL_Event& event)
+ {
+ if (event.type == SDL_EVENT_QUIT)
+ {
+ close();
+ }
+ else if (event.type == SDL_EVENT_WINDOW_RESIZED)
+ {
+ WindowResizedData wrd(*this, m_windowWidth, m_windowHeight, 0, 0);
+ SDL_GetWindowSize(m_window, &m_windowWidth, &m_windowHeight);
+ wrd.new_width = m_windowWidth;
+ wrd.new_height = m_windowHeight;
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime, wrd);
+ }
+ else if (event.type == SDL_EVENT_MOUSE_MOTION)
+ {
+ MouseEventData mmd = get_mouse_state();
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
+ }
+ else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
+ {
+ MouseEventData mmd = get_mouse_state();
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
+ }
+ else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
+ {
+ MouseEventData mmd = get_mouse_state();
+ switch (event.button.button)
+ {
+ case SDL_BUTTON_MASK(1): mmd.button = MouseEventData::eButton::Left; break;
+ case SDL_BUTTON_MASK(2): mmd.button = MouseEventData::eButton::Middle; break;
+ case SDL_BUTTON_MASK(3): mmd.button = MouseEventData::eButton::Right; break;
+ default: mmd.button = MouseEventData::eButton::None; break;
+ }
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseReleased, ostd::tSignalPriority::RealTime, mmd);
+ }
+ else if (event.type == SDL_EVENT_KEY_DOWN)
+ {
+ KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Pressed);
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked);
+ }
+ else if (event.type == SDL_EVENT_KEY_UP)
+ {
+ KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Released);
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked);
+ }
+ else if (event.type == SDL_EVENT_TEXT_INPUT)
+ {
+ KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text);
+ ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked);
+ }
+ __on_event(event);
+ }
+
+
+
+
+ void GraphicsWindow::__on_window_init(int32_t width, int32_t height, const ostd::String& title)
+ {
+ SDL_SetWindowResizable(m_window, false);
+
+ m_fixedUpdateTImer.create(60.0, [this](double frameTime_s){
+ this->onFixedUpdate(frameTime_s);
+ });
+
+ m_fpsUpdateTimer.create(1.0, [this](double frameTime_s){
+ if (this->m_frameCount == 0) return;
+ if (this->m_frameTimeAcc == 0) return;
+ this->m_fps = (int32_t)(1.0f / (static_cast(this->m_frameTimeAcc) / static_cast(this->m_frameCount)));
+ this->m_frameTimeAcc = 0;
+ this->m_frameCount = 0;
+ });
+
+ setTypeName("ogfx::GraphicsWindow");
+ onInitialize();
+ }
+
+ void GraphicsWindow::__on_window_close(void)
+ {
+ onClose();
+ }
+
+ void GraphicsWindow::__main_loop(void)
+ {
+ handle_events();
+ SDL_SetRenderDrawColor(m_renderer, getClearColor().r, getClearColor().g, getClearColor().b, getClearColor().a);
+ if (m_refreshScreen)
+ SDL_RenderClear(m_renderer);
+ m_fixedUpdateTImer.update();
+ onUpdate();
+ onRender();
+ SDL_RenderPresent(m_renderer);
+ m_frameTimeAcc += m_fpsUpdateClock.restart(ostd::eTimeUnits::Seconds);
+ m_frameCount++;
+ m_fpsUpdateTimer.update();
+ }
+
+ void GraphicsWindow::__on_event(SDL_Event& event)
+ {
+ onSDLEvent(event);
+ }
+
+ void GraphicsWindow::__on_window_destroy(void)
+ {
+ onDestroy();
+ }
+
+
+
+
+ namespace gui
+ {
+ void Window::__on_window_init(int32_t width, int32_t height, const ostd::String& title)
+ {
+ enableBlockingEvents();
+ setTypeName("ogfx::gui::Window");
+ onInitialize();
+ }
+
+ void Window::__on_window_close(void)
+ {
+ onClose();
+ }
+
+ void Window::__main_loop(void)
+ {
+ while (isRunning())
+ {
+ handle_events();
+ SDL_SetRenderDrawColor(m_renderer, getClearColor().r, getClearColor().g, getClearColor().b, getClearColor().a);
+ SDL_RenderClear(m_renderer);
+
+ SDL_RenderPresent(m_renderer);
+ }
+ }
+
+ void Window::__on_event(SDL_Event& event)
+ {
+ if (event.type == SDL_EVENT_KEY_UP)
+ {
+ if (event.key.key == SDLK_ESCAPE)
+ close();
+ }
+ onSDLEvent(event);
+ }
+
+ void Window::__on_window_destroy(void)
+ {
+ onDestroy();
+ }
+ }
+}
diff --git a/src/ogfx/gui/Window.hpp b/src/ogfx/gui/Window.hpp
new file mode 100644
index 0000000..ddfb5bc
--- /dev/null
+++ b/src/ogfx/gui/Window.hpp
@@ -0,0 +1,152 @@
+/*
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
+
+ This file is part of OmniaFramework.
+
+ OmniaFramework is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OmniaFramework is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
+*/
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace ogfx
+{
+ class WindowCore : public ostd::BaseObject
+ {
+ public: enum class eCursor { Arrow = 0, IBeam };
+ public:
+ inline WindowCore(void) { }
+ virtual ~WindowCore(void);
+ inline WindowCore(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); }
+ void initialize(int32_t width, int32_t height, const ostd::String& title);
+ inline void mainLoop(void) { if (isInitialized()) __main_loop(); }
+ void close(void);
+ void setSize(int32_t width, int32_t height);
+ void setTitle(const ostd::String& title);
+ void setCursor(eCursor cursor);
+ void enableResizable(bool enable = true);
+ void setIcon(const ostd::String& iconFilePath);
+
+ inline bool isInitialized(void) const { return m_initialized; }
+ inline bool isRunning(void) const { return m_running; }
+ inline bool isVisible(void) const { return m_visible; }
+ inline bool isResizeable(void) const { return m_resizeable; }
+ inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; }
+ inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; }
+ inline ostd::String getTitle(void) const { return m_title; }
+ inline int32_t getWindowWidth(void) const { return m_windowWidth; }
+ inline int32_t getWindowHeight(void) const { return m_windowHeight; }
+ inline ostd::Color getClearColor(void) const { return m_clearColor; }
+ inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
+ inline SDL_Renderer* getSDLRenderer(void) { return m_renderer; }
+ inline void enableBlockingEvents(bool enable = true) { m_blockingEvents = enable; }
+ inline bool isBlockingEventsEnabled(void) const { return m_blockingEvents; }
+
+ protected:
+ MouseEventData get_mouse_state(void);
+ virtual void handle_events(void);
+ inline virtual void __on_event(SDL_Event& event) { }
+ inline virtual void __on_window_init(int32_t width, int32_t height, const ostd::String& title) { }
+ inline virtual void __on_window_destroy(void) { }
+ inline virtual void __on_window_close(void) { }
+ inline virtual void __main_loop(void) = 0;
+
+ private:
+ void __handle_event(SDL_Event& event);
+
+ protected:
+ SDL_Window* m_window { nullptr };
+ SDL_Renderer* m_renderer { nullptr };
+
+ private:
+ ostd::Color m_clearColor { 10, 10, 10, 255 };
+
+ int32_t m_windowWidth { 0 };
+ int32_t m_windowHeight { 0 };
+ ostd::String m_title { "" };
+
+ bool m_running { false };
+ bool m_initialized { false };
+ bool m_visible { true };
+ bool m_blockingEvents { false };
+ bool m_resizeable { true };
+
+ SDL_Cursor* m_cursor_IBeam { nullptr };
+ SDL_Cursor* m_cursor_Arrow { nullptr };
+ };
+ class GraphicsWindow : public WindowCore
+ {
+ public: enum class eCursor { Arrow = 0, IBeam };
+ public:
+ inline GraphicsWindow(void) { }
+ inline GraphicsWindow(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); }
+
+ inline virtual void onRender(void) { }
+ inline virtual void onUpdate(void) { }
+ inline virtual void onFixedUpdate(double frameTime_s) { }
+ inline virtual void onInitialize(void) { }
+ inline virtual void onDestroy(void) { }
+ inline virtual void onClose(void) { }
+ inline virtual void onSDLEvent(SDL_Event& event) { }
+
+ inline int32_t getFPS(void) const { return m_fps; }
+
+ protected:
+ void __on_window_init(int32_t width, int32_t height, const ostd::String& title) override;
+ void __on_event(SDL_Event& event) override;
+ void __on_window_destroy(void) override;
+ void __on_window_close(void) override;
+ void __main_loop(void) override;
+
+ private:
+ int32_t m_fps { 0 };
+ ostd::StepTimer m_fixedUpdateTImer;
+ ostd::StepTimer m_fpsUpdateTimer;
+ ostd::Timer m_fpsUpdateClock;
+ uint64_t m_frameTimeAcc { 0 };
+ int32_t m_frameCount { 0 };
+ bool m_refreshScreen { true };
+ };
+ namespace gui
+ {
+ class Window : public WindowCore
+ {
+ public: enum class eCursor { Arrow = 0, IBeam };
+ public:
+ inline Window(void) { }
+ inline Window(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); }
+
+ inline virtual void onInitialize(void) { }
+ inline virtual void onDestroy(void) { }
+ inline virtual void onClose(void) { }
+ inline virtual void onSDLEvent(SDL_Event& event) { }
+
+ protected:
+ void __on_window_init(int32_t width, int32_t height, const ostd::String& title) override;
+ void __on_event(SDL_Event& event) override;
+ void __on_window_destroy(void) override;
+ void __on_window_close(void) override;
+ void __main_loop(void) override;
+
+ private:
+ };
+ }
+}
diff --git a/src/ogfx/gui/WindowBase.cpp b/src/ogfx/gui/WindowBase.cpp
deleted file mode 100644
index f170428..0000000
--- a/src/ogfx/gui/WindowBase.cpp
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
-
- This file is part of OmniaFramework.
-
- OmniaFramework is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- OmniaFramework is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with OmniaFramework. If not, see .
-*/
-
-#include "WindowBase.hpp"
-#include "../../ostd/utils/Time.hpp"
-#include
-#include
-#include
-
-namespace ogfx
-{
- WindowBase::~WindowBase(void)
- {
- onDestroy();
- SDL_DestroyCursor(m_cursor_IBeam);
- SDL_DestroyCursor(m_cursor_Arrow);
- SDL_DestroyRenderer(m_renderer);
- SDL_DestroyWindow(m_window);
- SDL_Quit();
- TTF_Quit();
- }
-
- void WindowBase::initialize(int32_t width, int32_t height, const ostd::String& windowTitle)
- {
- if (m_initialized) return;
- m_windowWidth = width;
- m_windowHeight = height;
- m_title = windowTitle;
- if (!SDL_Init(SDL_INIT_VIDEO))
- {
- printf( "SDL could not initialize! Error: %s\n", SDL_GetError() );
- exit(1);
- }
- m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE);
- SDL_SetWindowResizable(m_window, false);
- m_renderer = SDL_CreateRenderer(m_window, nullptr);
- SDL_SetWindowMinimumSize(m_window, m_windowWidth, m_windowHeight);
- SDL_SetWindowTitle(m_window, m_title.c_str());
- SDL_StartTextInput(m_window);
-
- m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_DEFAULT);
- m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_TEXT);
-
- m_initialized = true;
- m_running = true;
-
- m_fixedUpdateTImer.create(60.0, [this](double frameTime_s){
- this->onFixedUpdate(frameTime_s);
- });
-
- m_fpsUpdateTimer.create(1.0, [this](double frameTime_s){
- if (this->m_frameCount == 0) return;
- if (this->m_frameTimeAcc == 0) return;
- this->m_fps = (int32_t)(1.0f / (static_cast(this->m_frameTimeAcc) / static_cast(this->m_frameCount)));
- this->m_frameTimeAcc = 0;
- this->m_frameCount = 0;
- });
-
- setTypeName("ogfx::WindowBase");
- enableSignals(true);
- validate();
- setSize(m_windowWidth, m_windowHeight);
-
- onInitialize();
- }
-
- void WindowBase::close(void)
- {
- m_running = false;
- onClose();
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::RealTime, *this);
- }
-
- void WindowBase::update(void)
- {
- if (!m_initialized) return;
- __handle_events();
- SDL_SetRenderDrawColor(m_renderer, m_clearColor.r, m_clearColor.g, m_clearColor.b, m_clearColor.a);
- if (m_refreshScreen)
- SDL_RenderClear(m_renderer);
- m_fixedUpdateTImer.update();
- onUpdate();
- onRender();
- SDL_RenderPresent(m_renderer);
- m_frameTimeAcc += m_fpsUpdateClock.restart(ostd::eTimeUnits::Seconds);
- m_frameCount++;
- m_fpsUpdateTimer.update();
- }
-
- void WindowBase::setSize(int32_t width, int32_t height)
- {
- if (!isInitialized()) return;
- SDL_SetWindowSize(m_window, width, height);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime);
- }
-
- void WindowBase::setTitle(const ostd::String& title)
- {
- if (!isInitialized()) return;
- m_title = title;
- SDL_SetWindowTitle(m_window, m_title.c_str());
- }
-
- void WindowBase::setCursor(eCursor cursor)
- {
- switch (cursor)
- {
- case eCursor::Arrow:
- SDL_SetCursor(m_cursor_Arrow);
- break;
- case eCursor::IBeam:
- SDL_SetCursor(m_cursor_IBeam);
- break;
- default:
- SDL_SetCursor(m_cursor_Arrow);
- break;
- }
- }
-
- void WindowBase::enableResizable(bool enable)
- {
- SDL_SetWindowResizable(m_window, enable);
- }
-
- void WindowBase::setIcon(const ostd::String& iconFilePath)
- {
- SDL_Surface* appIcon = IMG_Load(iconFilePath);
- if (appIcon == nullptr)
- {
- //TODO: Error
- return;
- }
- SDL_SetWindowIcon(m_window, appIcon);
- SDL_DestroySurface(appIcon);
- }
-
- void WindowBase::__handle_events(void)
- {
- if (!m_initialized) return;
- auto l_getMouseState = [this](void) -> MouseEventData {
- float mx = 0, my = 0;
- uint32_t btn = SDL_GetMouseState(&mx, &my);
- MouseEventData::eButton button = MouseEventData::eButton::None;
- switch (btn)
- {
- case SDL_BUTTON_MASK(1): button = MouseEventData::eButton::Left; break;
- case SDL_BUTTON_MASK(2): button = MouseEventData::eButton::Middle; break;
- case SDL_BUTTON_MASK(3): button = MouseEventData::eButton::Right; break;
- default: button = MouseEventData::eButton::None; break;
- }
- MouseEventData mmd(*this, mx, my, button);
- return mmd;
- };
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_EVENT_QUIT)
- {
- m_running = false;
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
- }
- else if (event.type == SDL_EVENT_WINDOW_RESIZED)
- {
- WindowResizedData wrd(*this, m_windowWidth, m_windowHeight, 0, 0);
- SDL_GetWindowSize(m_window, &m_windowWidth, &m_windowHeight);
- wrd.new_width = m_windowWidth;
- wrd.new_height = m_windowHeight;
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime, wrd);
- }
- else if (event.type == SDL_EVENT_MOUSE_MOTION)
- {
- MouseEventData mmd = l_getMouseState();
- if (isMouseDragEventEnabled() && mmd.button != MouseEventData::eButton::None)
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseDragged, ostd::tSignalPriority::RealTime, mmd);
- else
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
- }
- else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
- {
- MouseEventData mmd = l_getMouseState();
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
- }
- else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
- {
- MouseEventData mmd = l_getMouseState();
- switch (event.button.button)
- {
- case SDL_BUTTON_MASK(1): mmd.button = MouseEventData::eButton::Left; break;
- case SDL_BUTTON_MASK(2): mmd.button = MouseEventData::eButton::Middle; break;
- case SDL_BUTTON_MASK(3): mmd.button = MouseEventData::eButton::Right; break;
- default: mmd.button = MouseEventData::eButton::None; break;
- }
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseReleased, ostd::tSignalPriority::RealTime, mmd);
- }
- else if (event.type == SDL_EVENT_KEY_DOWN)
- {
- KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Pressed);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked);
- }
- else if (event.type == SDL_EVENT_KEY_UP)
- {
- KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Released);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked);
- }
- else if (event.type == SDL_EVENT_TEXT_INPUT)
- {
- KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text);
- ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked);
- }
- }
- }
-}
diff --git a/src/ogfx/gui/WindowBase.hpp b/src/ogfx/gui/WindowBase.hpp
deleted file mode 100644
index 5d02f70..0000000
--- a/src/ogfx/gui/WindowBase.hpp
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
-
- This file is part of OmniaFramework.
-
- OmniaFramework is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- OmniaFramework is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with OmniaFramework. If not, see .
-*/
-
-#pragma once
-
-#include
-#include
-#include
-#include
-
-namespace ogfx
-{
- // class WindowCore : public ostd::BaseObject
- // {
- // public: enum class eCursor { Arrow = 0, IBeam };
- // public:
- // inline WindowCore(void) { }
- // virtual ~WindowCore(void);
- // inline WindowCore(int32_t width, int32_t height, const ostd::String& windowTitle) { initialize(width, height, windowTitle); }
- // void initialize(int32_t width, int32_t height, const ostd::String& windowTitle);
- // void close(void);
- // void update(void);
- // void setSize(int32_t width, int32_t height);
- // void setTitle(const ostd::String& title);
- // void setCursor(eCursor cursor);
- // void enableResizable(bool enable = true);
- // void setIcon(const ostd::String& iconFilePath);
-
- // inline virtual void onWindowInitialize(void) { }
- // inline virtual void onWindowDestroy(void) { }
- // inline virtual void onWindowClose(void) { }
-
- // inline bool isInitialized(void) const { return m_initialized; }
- // inline bool isRunning(void) const { return m_running; }
- // inline bool isVisible(void) const { return m_visible; }
- // inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; }
- // inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; }
- // inline ostd::String getTitle(void) const { return m_title; }
- // inline int32_t getWindowWidth(void) const { return m_windowWidth; }
- // inline int32_t getWindowHeight(void) const { return m_windowHeight; }
- // inline ostd::Color getClearColor(void) const { return m_clearColor; }
- // inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
- // inline SDL_Renderer* getSDLRenderer(void) { return m_renderer; }
- // private:
- // void __handle_events(void);
-
- // protected:
- // ostd::ConsoleOutputHandler out;
-
- // SDL_Window* m_window { nullptr };
- // SDL_Renderer* m_renderer { nullptr };
- // bool m_refreshScreen { true };
-
- // private:
- // ostd::Color m_clearColor { 10, 10, 10, 255 };
-
- // int32_t m_windowWidth { 0 };
- // int32_t m_windowHeight { 0 };
- // ostd::String m_title { "" };
-
- // bool m_running { false };
- // bool m_initialized { false };
- // bool m_visible { true };
-
- // SDL_Cursor* m_cursor_IBeam { nullptr };
- // SDL_Cursor* m_cursor_Arrow { nullptr };
- // };
- class WindowBase : public ostd::BaseObject
- {
- public: enum class eCursor { Arrow = 0, IBeam };
- public:
- inline WindowBase(void) { }
- ~WindowBase(void);
- inline WindowBase(int32_t width, int32_t height, const ostd::String& windowTitle) { initialize(width, height, windowTitle); }
- void initialize(int32_t width, int32_t height, const ostd::String& windowTitle);
- void close(void);
- void update(void);
- void setSize(int32_t width, int32_t height);
- void setTitle(const ostd::String& title);
- void setCursor(eCursor cursor);
- void enableResizable(bool enable = true);
- void setIcon(const ostd::String& iconFilePath);
-
- inline virtual void onRender(void) { }
- inline virtual void onUpdate(void) { }
- inline virtual void onFixedUpdate(double frameTime_s) { }
- inline virtual void onInitialize(void) { }
- inline virtual void onDestroy(void) { }
- inline virtual void onClose(void) { }
-
- inline bool isInitialized(void) const { return m_initialized; }
- inline bool isRunning(void) const { return m_running; }
- inline bool isVisible(void) const { return m_visible; }
- inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; }
- inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; }
- inline ostd::String getTitle(void) const { return m_title; }
- inline int32_t getFPS(void) const { return m_fps; }
- inline int32_t getWindowWidth(void) const { return m_windowWidth; }
- inline int32_t getWindowHeight(void) const { return m_windowHeight; }
- inline bool isMouseDragEventEnabled(void) const { return m_deagEventEnabled; }
- inline void enableMouseDragEvent(bool enable = true) { m_deagEventEnabled = enable; }
- inline ostd::Color getClearColor(void) const { return m_clearColor; }
- inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
- inline SDL_Renderer* getSDLRenderer(void) { return m_renderer; }
- private:
- void __handle_events(void);
-
- protected:
- ostd::ConsoleOutputHandler out;
-
- SDL_Window* m_window { nullptr };
- SDL_Renderer* m_renderer { nullptr };
- bool m_refreshScreen { true };
-
- private:
- ostd::Color m_clearColor { 10, 10, 10, 255 };
-
- int32_t m_windowWidth { 0 };
- int32_t m_windowHeight { 0 };
- ostd::String m_title { "" };
- int32_t m_fps { 0 };
-
- ostd::StepTimer m_fixedUpdateTImer;
- ostd::StepTimer m_fpsUpdateTimer;
- ostd::Timer m_fpsUpdateClock;
- uint64_t m_frameTimeAcc { 0 };
- int32_t m_frameCount { 0 };
-
- bool m_deagEventEnabled { false };
- bool m_running { false };
- bool m_initialized { false };
- bool m_visible { true };
-
- SDL_Cursor* m_cursor_IBeam { nullptr };
- SDL_Cursor* m_cursor_Arrow { nullptr };
- };
- class WindowResizedData : public ostd::BaseObject
- {
- public:
- inline WindowResizedData(WindowBase& parent, int32_t _oldx, int32_t _oldy, int32_t _newx, int32_t _newy) : parentWindow(parent), old_width(_oldx), old_height(_oldy), new_width(_newx), new_height(_newy)
- {
- setTypeName("ogfx::WindowResizedData");
- validate();
- }
-
- public:
- int32_t new_width;
- int32_t new_height;
- int32_t old_width;
- int32_t old_height;
- WindowBase& parentWindow;
- };
- class MouseEventData : public ostd::BaseObject
- {
- public: enum class eButton { None = 0, Left, Middle, Right };
- public:
- inline MouseEventData(WindowBase& parent, float mousex, float mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
- {
- setTypeName("ogfx::MouseEventData");
- validate();
- }
-
- public:
- float position_x;
- float position_y;
- eButton button;
- WindowBase& parentWindow;
- };
- class KeyEventData : public ostd::BaseObject
- {
- public: enum class eKeyEvent { Pressed = 0, Released, Text };
- public:
- inline KeyEventData(WindowBase& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt)
- {
- setTypeName("ogfx::KeyEventData");
- validate();
- }
-
- public:
- int32_t keyCode;
- char text;
- eKeyEvent eventType;
- WindowBase& parentWindow;
- };
-}
diff --git a/src/ogfx/gui/WindowBaseOutputHandler.cpp b/src/ogfx/gui/WindowOutputHandler.cpp
similarity index 63%
rename from src/ogfx/gui/WindowBaseOutputHandler.cpp
rename to src/ogfx/gui/WindowOutputHandler.cpp
index 55aca03..dfc994a 100644
--- a/src/ogfx/gui/WindowBaseOutputHandler.cpp
+++ b/src/ogfx/gui/WindowOutputHandler.cpp
@@ -18,7 +18,7 @@
along with OmniaFramework. If not, see .
*/
-#include "WindowBaseOutputHandler.hpp"
+#include "WindowOutputHandler.hpp"
#include "../render/BasicRenderer.hpp"
#include "../../string/TextStyleParser.hpp"
@@ -26,25 +26,25 @@ namespace ogfx
{
using namespace ostd;
- WindowBaseOutputHandler::WindowBaseOutputHandler(void)
+ GraphicsWindowOutputHandler::GraphicsWindowOutputHandler(void)
{
}
- void WindowBaseOutputHandler::attachWindow(ogfx::WindowBase& window)
+ void GraphicsWindowOutputHandler::attachWindow(ogfx::GraphicsWindow& window)
{
if (m_window != nullptr) return;
m_window = &window;
m_renderer.init(window);
}
- void WindowBaseOutputHandler::setMonospaceFont(const String& filePath)
+ void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath)
{
m_renderer.setFont(filePath);
m_renderer.setFontSize(m_fontSize);
__update_char_size();
}
- Vec2 WindowBaseOutputHandler::getStringSize(const String& str)
+ Vec2 GraphicsWindowOutputHandler::getStringSize(const String& str)
{
Vec2 size = { 0.0f, m_charSize.y };
if (str.len() == 0) return size;
@@ -52,23 +52,23 @@ namespace ogfx
return size;
}
- bool WindowBaseOutputHandler::isReady(void)
+ bool GraphicsWindowOutputHandler::isReady(void)
{
return m_window != nullptr && m_renderer.getTTFRenderer().hasOpenFont() && m_fontSize > 0;
}
- void WindowBaseOutputHandler::resetCursorPosition(void)
+ void GraphicsWindowOutputHandler::resetCursorPosition(void)
{
m_curosrPosition = { 0, 0 };
}
- void WindowBaseOutputHandler::resetColors(void)
+ void GraphicsWindowOutputHandler::resetColors(void)
{
m_foregroundColor = m_defaultForegroundColor;
m_backgroundColor = m_defaultBackgroundColor;
}
- void WindowBaseOutputHandler::beginFrame(void)
+ void GraphicsWindowOutputHandler::beginFrame(void)
{
resetColors();
resetCursorPosition();
@@ -77,37 +77,37 @@ namespace ogfx
- void WindowBaseOutputHandler::setConsoleMaxCharacters(const IPoint& size)
+ void GraphicsWindowOutputHandler::setConsoleMaxCharacters(const IPoint& size)
{
m_consoleSize = size;
}
- void WindowBaseOutputHandler::setConsolePosition(const Vec2& pos)
+ void GraphicsWindowOutputHandler::setConsolePosition(const Vec2& pos)
{
m_consolePosition = pos;
}
- void WindowBaseOutputHandler::setWrapMode(eWrapMode wrapMode)
+ void GraphicsWindowOutputHandler::setWrapMode(eWrapMode wrapMode)
{
m_wrapMode = wrapMode;
}
- void WindowBaseOutputHandler::setPadding(const Rectangle& rect)
+ void GraphicsWindowOutputHandler::setPadding(const Rectangle& rect)
{
m_padding = rect;
}
- void WindowBaseOutputHandler::setDefaultBackgorundColor(const Color& color)
+ void GraphicsWindowOutputHandler::setDefaultBackgorundColor(const Color& color)
{
m_defaultBackgroundColor = color;
}
- void WindowBaseOutputHandler::setDefaultForegroundColor(const Color& color)
+ void GraphicsWindowOutputHandler::setDefaultForegroundColor(const Color& color)
{
m_defaultForegroundColor = color;
}
- void WindowBaseOutputHandler::setTabWidth(uint8_t tw)
+ void GraphicsWindowOutputHandler::setTabWidth(uint8_t tw)
{
m_tabWidth = tw;
}
@@ -115,19 +115,19 @@ namespace ogfx
- void WindowBaseOutputHandler::setFontSize(int32_t fontSize)
+ void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize)
{
m_fontSize = fontSize;
m_renderer.setFontSize(m_fontSize);
__update_char_size();
}
- int32_t WindowBaseOutputHandler::getFontSize(void)
+ int32_t GraphicsWindowOutputHandler::getFontSize(void)
{
return m_fontSize;
}
- Vec2 WindowBaseOutputHandler::getCharacterSize(int32_t fontSize)
+ Vec2 GraphicsWindowOutputHandler::getCharacterSize(int32_t fontSize)
{
if (fontSize > 0)
{
@@ -137,37 +137,37 @@ namespace ogfx
return m_charSize;
}
- Vec2 WindowBaseOutputHandler::getConsolePosition(void)
+ Vec2 GraphicsWindowOutputHandler::getConsolePosition(void)
{
return m_consolePosition;
}
- WindowBaseOutputHandler::eWrapMode WindowBaseOutputHandler::getWrapMode(void)
+ GraphicsWindowOutputHandler::eWrapMode GraphicsWindowOutputHandler::getWrapMode(void)
{
return m_wrapMode;
}
- Rectangle WindowBaseOutputHandler::getPadding(void)
+ Rectangle GraphicsWindowOutputHandler::getPadding(void)
{
return m_padding;
}
- Color WindowBaseOutputHandler::getDefaultBackgroundColor(void)
+ Color GraphicsWindowOutputHandler::getDefaultBackgroundColor(void)
{
return m_defaultBackgroundColor;
}
- Color WindowBaseOutputHandler::getDefaultForegroundColor(void)
+ Color GraphicsWindowOutputHandler::getDefaultForegroundColor(void)
{
return m_defaultForegroundColor;
}
- uint8_t WindowBaseOutputHandler::getTabWidth(void)
+ uint8_t GraphicsWindowOutputHandler::getTabWidth(void)
{
return m_tabWidth;
}
- Rectangle WindowBaseOutputHandler::getConsoleBounds(void)
+ Rectangle GraphicsWindowOutputHandler::getConsoleBounds(void)
{
float console_w = ((float)m_consoleSize.x * getCharacterSize().x) + getPadding().x + getPadding().w;
float console_h = ((float)m_consoleSize.y * getCharacterSize().y) + getPadding().y + getPadding().h;
@@ -177,54 +177,54 @@ namespace ogfx
- WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const Color& color)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::bg(const Color& color)
{
m_backgroundColor = color;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
{
m_backgroundColor = color.fullColor;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const String& color)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::bg(const String& color)
{
m_backgroundColor = ConsoleColors::getFromName(color).fullColor;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const Color& color)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::fg(const Color& color)
{
m_foregroundColor = color;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
{
m_foregroundColor = color.fullColor;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const String& color)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::fg(const String& color)
{
m_foregroundColor = ConsoleColors::getFromName(color).fullColor;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::pChar(char c)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pChar(char c)
{
__print_string(ostd::String("").addChar(c));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(const String& styled)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pStyled(const String& styled)
{
return pStyled(TextStyleParser::parse(styled, { m_backgroundColor, "", true }, { m_foregroundColor, "", false }));
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
{
if (!styled.validate()) return *this;
Color oldBgCol = m_backgroundColor;
@@ -236,7 +236,7 @@ namespace ogfx
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(TextStyleBuilder::IRichStringBase& styled)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pStyled(TextStyleBuilder::IRichStringBase& styled)
{
auto oldBg = styled.getDefaultBackgroundColor();
auto oldFg = styled.getDefaultForegroundColor();
@@ -248,79 +248,79 @@ namespace ogfx
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::pObject(const BaseObject& bo)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pObject(const BaseObject& bo)
{
__print_string(bo.toString());
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(const String& se)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(const String& se)
{
__print_string(se);
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint8_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint8_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(int8_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int8_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint16_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint16_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(int16_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int16_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint32_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint32_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(int32_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int32_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint64_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint64_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(int64_t i)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int64_t i)
{
__print_string(ostd::String("").add(i));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(float f, uint8_t precision)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(float f, uint8_t precision)
{
__print_string(ostd::String("").add(f, precision));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::p(double f, uint8_t precision)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(double f, uint8_t precision)
{
__print_string(ostd::String("").add(f, precision));
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::nl(void)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::nl(void)
{
if (m_curosrPosition.y >= getConsoleSize().y) return *this;
m_curosrPosition.y++;
@@ -328,7 +328,7 @@ namespace ogfx
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::tab(void)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::tab(void)
{
if (m_curosrPosition.x == 0)
{
@@ -343,68 +343,68 @@ namespace ogfx
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::flush(void)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::flush(void)
{
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::clear(void)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::clear(void)
{
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::reset(void)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::reset(void)
{
resetColors();
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::xy(IPoint position)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(IPoint position)
{
m_curosrPosition = { (float)position.x, (float)position.y };
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::xy(int32_t x, int32_t y)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(int32_t x, int32_t y)
{
m_curosrPosition = { (float)x, (float)y };
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::x(int32_t x)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::x(int32_t x)
{
m_curosrPosition.x = (float)x;
return *this;
}
- WindowBaseOutputHandler& WindowBaseOutputHandler::y(int32_t y)
+ GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::y(int32_t y)
{
m_curosrPosition.y = (float)y;
return *this;
}
- IPoint WindowBaseOutputHandler::getCursorPosition(void)
+ IPoint GraphicsWindowOutputHandler::getCursorPosition(void)
{
return { (int32_t)std::round(m_curosrPosition.x), (int32_t)std::round(m_curosrPosition.y) };
}
- void WindowBaseOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY)
+ void GraphicsWindowOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY)
{
outX = (int32_t)std::round(m_curosrPosition.x);
outY = (int32_t)std::round(m_curosrPosition.y);
}
- int32_t WindowBaseOutputHandler::getCursorX(void)
+ int32_t GraphicsWindowOutputHandler::getCursorX(void)
{
return (int32_t)std::round(m_curosrPosition.x);
}
- int32_t WindowBaseOutputHandler::getCursorY(void)
+ int32_t GraphicsWindowOutputHandler::getCursorY(void)
{
return (int32_t)std::round(m_curosrPosition.y);
}
- void WindowBaseOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows)
+ void GraphicsWindowOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows)
{
int32_t console_rows = std::numeric_limits::max();
int32_t console_cols = std::numeric_limits::max();
@@ -414,7 +414,7 @@ namespace ogfx
outRows = console_rows;
}
- IPoint WindowBaseOutputHandler::getConsoleSize(void)
+ IPoint GraphicsWindowOutputHandler::getConsoleSize(void)
{
int32_t console_rows = std::numeric_limits::max();
int32_t console_cols = std::numeric_limits::max();
@@ -423,13 +423,13 @@ namespace ogfx
return { console_cols, console_rows };
}
- void WindowBaseOutputHandler::__update_char_size(void)
+ void GraphicsWindowOutputHandler::__update_char_size(void)
{
auto size = m_renderer.getStringSize("A", m_fontSize);
m_charSize = { (float)size.x, (float)size.y };
}
- void WindowBaseOutputHandler::__print_string(const String& str)
+ void GraphicsWindowOutputHandler::__print_string(const String& str)
{
if (!isReady()) return;
auto l_endOfConsole = [&](void) -> bool {
diff --git a/src/ogfx/gui/WindowBaseOutputHandler.hpp b/src/ogfx/gui/WindowOutputHandler.hpp
similarity index 57%
rename from src/ogfx/gui/WindowBaseOutputHandler.hpp
rename to src/ogfx/gui/WindowOutputHandler.hpp
index 5bd98be..48813a5 100644
--- a/src/ogfx/gui/WindowBaseOutputHandler.hpp
+++ b/src/ogfx/gui/WindowOutputHandler.hpp
@@ -26,12 +26,12 @@
namespace ogfx
{
- class WindowBaseOutputHandler : public ostd::OutputHandlerBase
+ class GraphicsWindowOutputHandler : public ostd::OutputHandlerBase
{
public: enum class eWrapMode { TripleDots, NewLine };
public:
- WindowBaseOutputHandler(void);
- void attachWindow(WindowBase& window);
+ GraphicsWindowOutputHandler(void);
+ void attachWindow(GraphicsWindow& window);
void setMonospaceFont(const ostd::String& filePath);
ostd::Vec2 getStringSize(const ostd::String& str);
bool isReady(void);
@@ -58,41 +58,41 @@ namespace ogfx
uint8_t getTabWidth(void);
ostd::Rectangle getConsoleBounds(void);
- WindowBaseOutputHandler& bg(const ostd::Color& color) override;
- WindowBaseOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override;
- WindowBaseOutputHandler& bg(const ostd::String& color) override;
- WindowBaseOutputHandler& fg(const ostd::Color& color) override;
- WindowBaseOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override;
- WindowBaseOutputHandler& fg(const ostd::String& color) override;
+ GraphicsWindowOutputHandler& bg(const ostd::Color& color) override;
+ GraphicsWindowOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override;
+ GraphicsWindowOutputHandler& bg(const ostd::String& color) override;
+ GraphicsWindowOutputHandler& fg(const ostd::Color& color) override;
+ GraphicsWindowOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override;
+ GraphicsWindowOutputHandler& fg(const ostd::String& color) override;
- WindowBaseOutputHandler& pChar(char c) override;
- WindowBaseOutputHandler& pStyled(const ostd::String& styled) override;
- WindowBaseOutputHandler& pStyled(const ostd::TextStyleParser::tStyledString& styled) override;
- WindowBaseOutputHandler& pStyled(ostd::TextStyleBuilder::IRichStringBase& styled) override;
- WindowBaseOutputHandler& pObject(const ostd::BaseObject& bo) override;
+ GraphicsWindowOutputHandler& pChar(char c) override;
+ GraphicsWindowOutputHandler& pStyled(const ostd::String& styled) override;
+ GraphicsWindowOutputHandler& pStyled(const ostd::TextStyleParser::tStyledString& styled) override;
+ GraphicsWindowOutputHandler& pStyled(ostd::TextStyleBuilder::IRichStringBase& styled) override;
+ GraphicsWindowOutputHandler& pObject(const ostd::BaseObject& bo) override;
- WindowBaseOutputHandler& p(const ostd::String& se) override;
- WindowBaseOutputHandler& p(uint8_t i) override;
- WindowBaseOutputHandler& p(int8_t i) override;
- WindowBaseOutputHandler& p(uint16_t i) override;
- WindowBaseOutputHandler& p(int16_t i) override;
- WindowBaseOutputHandler& p(uint32_t i) override;
- WindowBaseOutputHandler& p(int32_t i) override;
- WindowBaseOutputHandler& p(uint64_t i) override;
- WindowBaseOutputHandler& p(int64_t i) override;
- WindowBaseOutputHandler& p(float f, uint8_t precision = 0) override;
- WindowBaseOutputHandler& p(double f, uint8_t precision = 0) override;
+ GraphicsWindowOutputHandler& p(const ostd::String& se) override;
+ GraphicsWindowOutputHandler& p(uint8_t i) override;
+ GraphicsWindowOutputHandler& p(int8_t i) override;
+ GraphicsWindowOutputHandler& p(uint16_t i) override;
+ GraphicsWindowOutputHandler& p(int16_t i) override;
+ GraphicsWindowOutputHandler& p(uint32_t i) override;
+ GraphicsWindowOutputHandler& p(int32_t i) override;
+ GraphicsWindowOutputHandler& p(uint64_t i) override;
+ GraphicsWindowOutputHandler& p(int64_t i) override;
+ GraphicsWindowOutputHandler& p(float f, uint8_t precision = 0) override;
+ GraphicsWindowOutputHandler& p(double f, uint8_t precision = 0) override;
- WindowBaseOutputHandler& nl(void) override;
- WindowBaseOutputHandler& tab(void) override;
- WindowBaseOutputHandler& flush(void) override;
- WindowBaseOutputHandler& clear(void) override;
- WindowBaseOutputHandler& reset(void) override;
+ GraphicsWindowOutputHandler& nl(void) override;
+ GraphicsWindowOutputHandler& tab(void) override;
+ GraphicsWindowOutputHandler& flush(void) override;
+ GraphicsWindowOutputHandler& clear(void) override;
+ GraphicsWindowOutputHandler& reset(void) override;
- WindowBaseOutputHandler& xy(ostd::IPoint position) override;
- WindowBaseOutputHandler& xy(int32_t x, int32_t y) override;
- WindowBaseOutputHandler& x(int32_t x) override;
- WindowBaseOutputHandler& y(int32_t y) override;
+ GraphicsWindowOutputHandler& xy(ostd::IPoint position) override;
+ GraphicsWindowOutputHandler& xy(int32_t x, int32_t y) override;
+ GraphicsWindowOutputHandler& x(int32_t x) override;
+ GraphicsWindowOutputHandler& y(int32_t y) override;
ostd::IPoint getCursorPosition(void) override;
void getCursorPosition(int32_t& outX, int32_t& outY) override;
@@ -113,7 +113,7 @@ namespace ogfx
ostd::Color m_defaultForegroundColor { 0, 220, 0, 255 };
ostd::Vec2 m_curosrPosition;
BasicRenderer2D m_renderer;
- WindowBase* m_window { nullptr };
+ GraphicsWindow* m_window { nullptr };
int32_t m_fontSize { 20 };
ostd::Vec2 m_charSize;
ostd::IPoint m_consoleSize { 0, 0 };
diff --git a/src/ogfx/ogfx.hpp b/src/ogfx/ogfx.hpp
index c726c99..d6d6612 100644
--- a/src/ogfx/ogfx.hpp
+++ b/src/ogfx/ogfx.hpp
@@ -23,8 +23,8 @@
#include
#include
-#include
-#include
+#include
+#include
#include
#include
diff --git a/src/ogfx/render/BasicRenderer.cpp b/src/ogfx/render/BasicRenderer.cpp
index 71e65d0..9576aff 100644
--- a/src/ogfx/render/BasicRenderer.cpp
+++ b/src/ogfx/render/BasicRenderer.cpp
@@ -19,11 +19,11 @@
*/
#include "BasicRenderer.hpp"
-#include "../gui/WindowBase.hpp"
+#include "../gui/Window.hpp"
namespace ogfx
{
- void BasicRenderer2D::init(WindowBase& window)
+ void BasicRenderer2D::init(WindowCore& window)
{
m_window = &window;
m_ttfr.init(window.getSDLRenderer());
diff --git a/src/ogfx/render/BasicRenderer.hpp b/src/ogfx/render/BasicRenderer.hpp
index 1018382..38d6d78 100644
--- a/src/ogfx/render/BasicRenderer.hpp
+++ b/src/ogfx/render/BasicRenderer.hpp
@@ -20,6 +20,7 @@
#pragma once
+#include "gui/Window.hpp"
#include
#include
#include
@@ -27,16 +28,16 @@
namespace ogfx
{
- class WindowBase;
+ class WindowCore;
class BasicRenderer2D
{
public:
BasicRenderer2D(void) = default;
- void init(WindowBase& window);
+ void init(WindowCore& window);
inline TTFRenderer& getTTFRenderer(void) { return m_ttfr; }
inline ostd::IPoint getStringSize(const ostd::String str, int32_t fontSize = 0) { return m_ttfr.getStringDimensions(str, fontSize); }
- inline WindowBase& getWindow(void) { return *m_window; }
+ inline WindowCore& getWindow(void) { return *m_window; }
inline bool isInitialized(void) { return m_initialized; }
void setFont(const ostd::String& fontFilePath);
void setFontSize(int32_t fontSize);
@@ -63,7 +64,7 @@ namespace ogfx
private:
TTFRenderer m_ttfr;
- WindowBase* m_window { nullptr };
+ WindowCore* m_window { nullptr };
bool m_initialized { false };
};
}
diff --git a/src/ogfx/render/PixelRenderer.cpp b/src/ogfx/render/PixelRenderer.cpp
index 3ef2e90..e28a80a 100644
--- a/src/ogfx/render/PixelRenderer.cpp
+++ b/src/ogfx/render/PixelRenderer.cpp
@@ -19,7 +19,7 @@
*/
#include "PixelRenderer.hpp"
-#include "../gui/WindowBase.hpp"
+#include "../gui/Window.hpp"
#include "../../ostd/io/Memory.hpp"
#include
@@ -132,7 +132,7 @@ namespace ogfx
SDL_DestroyTexture(m_texture);
}
- void PixelRenderer::initialize(WindowBase& parent)
+ void PixelRenderer::initialize(WindowCore& parent)
{
if (isValid()) return; //TODO: Error
if (!parent.isValid() || !parent.isInitialized())
diff --git a/src/ogfx/render/PixelRenderer.hpp b/src/ogfx/render/PixelRenderer.hpp
index b68d846..d0ba46c 100644
--- a/src/ogfx/render/PixelRenderer.hpp
+++ b/src/ogfx/render/PixelRenderer.hpp
@@ -28,7 +28,7 @@
namespace ogfx
{
- class WindowBase;
+ class WindowCore;
class PixelRenderer : public ostd::BaseObject
{
public: class TextRenderer
@@ -83,7 +83,7 @@ namespace ogfx
public:
inline PixelRenderer(void) { invalidate(); }
~PixelRenderer(void);
- void initialize(WindowBase& parent);
+ void initialize(WindowCore& parent);
void handleSignal(ostd::tSignal& signal) override;
void updateBuffer(void);
void displayBuffer(void);
@@ -94,7 +94,7 @@ namespace ogfx
private:
uint32_t* m_pixels { nullptr };
SDL_Texture* m_texture { nullptr };
- WindowBase* m_parent { nullptr };
+ WindowCore* m_parent { nullptr };
int32_t m_windowWidth { 0 };
int32_t m_windowHeight { 0 };
};
diff --git a/src/ogfx/resources/Image.cpp b/src/ogfx/resources/Image.cpp
index b1a6775..f05f635 100644
--- a/src/ogfx/resources/Image.cpp
+++ b/src/ogfx/resources/Image.cpp
@@ -21,7 +21,7 @@
#include "Image.hpp"
#include "../../io/Logger.hpp"
#include "../render/BasicRenderer.hpp"
-#include "../gui/WindowBase.hpp"
+#include "../gui/Window.hpp"
namespace ogfx
{
diff --git a/src/ostd/io/IOHandlers.hpp b/src/ostd/io/IOHandlers.hpp
index f1cd8ad..110cb25 100644
--- a/src/ostd/io/IOHandlers.hpp
+++ b/src/ostd/io/IOHandlers.hpp
@@ -27,7 +27,7 @@
namespace ogfx
{
- class WindowBase;
+ class WindowCore;
class BasicRenderer2D;
};
diff --git a/src/test.cpp b/src/test/GraphicsWindowTest.cpp
similarity index 90%
rename from src/test.cpp
rename to src/test/GraphicsWindowTest.cpp
index 97ee44d..0f083af 100644
--- a/src/test.cpp
+++ b/src/test/GraphicsWindowTest.cpp
@@ -18,36 +18,16 @@
along with OmniaFramework. If not, see .
*/
-
-
-
-/*
- * Label
- * Button
- * Panel / Container
- * Checkbox
- * Radio Button (Group)
- * Text Input
- * Horizontal Slider
- * Image / Icon
- * ScrollView
- * ListBox
- * ComboBox
- * TreeView
- */
-
#include
ostd::ConsoleOutputHandler out;
-class Window : public ogfx::WindowBase
+class Window : public ogfx::GraphicsWindow
{
public:
inline Window(void) : m_sigHandler(m_textInput, *this) { }
inline void onInitialize(void) override
{
- enableSignals();
- connectSignal(ostd::tBuiltinSignals::KeyReleased);
connectSignal(ogfx::gui::RawTextInput::actionEventSignalID);
m_gfx.init(*this);
@@ -117,7 +97,7 @@ int main(int argc, char** argv)
while (window.isRunning())
{
- window.update();
+ window.mainLoop();
}
return 0;
}
diff --git a/src/test/GuiTest.cpp b/src/test/GuiTest.cpp
new file mode 100644
index 0000000..baff5e7
--- /dev/null
+++ b/src/test/GuiTest.cpp
@@ -0,0 +1,71 @@
+/*
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
+
+ This file is part of OmniaFramework.
+
+ OmniaFramework is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OmniaFramework is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
+*/
+
+
+
+
+/*
+ * Label
+ * Button
+ * Panel / Container
+ * Checkbox
+ * Radio Button (Group)
+ * Text Input
+ * Horizontal Slider
+ * Image / Icon
+ * ScrollView
+ * ListBox
+ * ComboBox
+ * TreeView
+ */
+
+#include
+
+ostd::ConsoleOutputHandler out;
+
+class Window : public ogfx::gui::Window
+{
+ public:
+ inline Window(void) { }
+ inline void onInitialize(void) override
+ {
+ }
+
+ inline void handleSignal(ostd::tSignal& signal) override
+ {
+ if (signal.ID == ostd::tBuiltinSignals::KeyReleased)
+ {
+ auto& evtData = (ogfx::KeyEventData&)signal.userData;
+ if (evtData.keyCode == SDLK_ESCAPE)
+ close();
+ }
+ }
+
+ private:
+};
+
+int main(int argc, char** argv)
+{
+ Window window;
+ window.initialize(800, 600, "OmniaFramework - Test Window");
+ window.setClearColor({ 0, 0, 0 });
+ window.mainLoop();
+ return 0;
+}