diff --git a/other/TODO.txt b/other/TODO.txt index 4039f0a..b90c147 100644 --- a/other/TODO.txt +++ b/other/TODO.txt @@ -20,6 +20,7 @@ Implement global scale (probably query desktop scale and adjust accordingly) Implement show/hide functionality for widgets Implement Panel title Create reliable default stylesheet +Implement cursors in Stylesheet diff --git a/src/ogfx/gui/RawTextInput.cpp b/src/ogfx/gui/RawTextInput.cpp index 1b5b258..0cd228d 100644 --- a/src/ogfx/gui/RawTextInput.cpp +++ b/src/ogfx/gui/RawTextInput.cpp @@ -157,7 +157,7 @@ namespace ogfx if (data.button == ogfx::MouseEventData::eButton::Left && parent.m_gfx != nullptr && parent.m_mouseInside) { String text = parent.m_text; - ostd::Vec2 relativePosition = { (f32)data.position_x, (f32)data.position_y }; + Vec2 relativePosition = { (f32)data.position_x, (f32)data.position_y }; relativePosition -= (parent.getPosition() + parent.m_paddingX + parent.m_theme.extraPaddingLeft); if (text.len() > 0) { @@ -196,7 +196,7 @@ namespace ogfx - RawTextInput& RawTextInput::create(const ostd::Vec2& position, const ostd::Vec2& size, const String& name) + RawTextInput& RawTextInput::create(const Vec2& position, const Vec2& size, const String& name) { setPosition(position); setSize(size); @@ -217,7 +217,7 @@ namespace ogfx m_fontSize = (i32)(geth() * 0.66); f32 cursor_height_scale = 0.75f; - ostd::IPoint strSize { 0, 0 }; + IPoint strSize { 0, 0 }; if (m_cursorPosition > 0 && m_text != "") { String s1 = m_text.new_substr(0, m_cursorPosition); @@ -226,7 +226,7 @@ namespace ogfx gfx.outlinedRect(*this, m_theme.backgroundColor, m_theme.borderColor, 2); if (m_text.len() > 0) - gfx.drawString(m_text, getPosition() + ostd::Vec2 { m_paddingX + m_theme.extraPaddingLeft, m_paddingX + m_theme.extraPaddingTop}, m_theme.textColor, m_fontSize); + gfx.drawString(m_text, getPosition() + Vec2 { m_paddingX + m_theme.extraPaddingLeft, m_paddingX + m_theme.extraPaddingTop}, m_theme.textColor, m_fontSize); if (m_cursorState || !m_theme.cursorBlink) gfx.fillRect({ getx() + m_paddingX + m_theme.extraPaddingLeft + strSize.x - 1, gety() + m_paddingX + m_theme.extraPaddingTop, (f32)m_theme.cursorWidth, (f32)m_fontSize * cursor_height_scale }, m_theme.cursorColor); diff --git a/src/ogfx/gui/RawTextInput.hpp b/src/ogfx/gui/RawTextInput.hpp index 7713f34..67a3f50 100644 --- a/src/ogfx/gui/RawTextInput.hpp +++ b/src/ogfx/gui/RawTextInput.hpp @@ -27,7 +27,7 @@ namespace ogfx { namespace gui { - class RawTextInput : public ostd::Rectangle + class RawTextInput : public Rectangle { public: class EventListener : public ostd::BaseObject { @@ -50,10 +50,10 @@ namespace ogfx public: class Theme { public: - ostd::Color textColor { 0, 0, 0, 0 }; - ostd::Color borderColor { 0, 0, 0, 0 }; - ostd::Color backgroundColor { 0, 0, 0, 0 }; - ostd::Color cursorColor { 0, 0, 0, 0 }; + Color textColor { 0, 0, 0, 0 }; + Color borderColor { 0, 0, 0, 0 }; + Color backgroundColor { 0, 0, 0, 0 }; + Color cursorColor { 0, 0, 0, 0 }; u8 cursorWidth { 0 }; u8 extraPaddingTop { 0 }; @@ -114,8 +114,8 @@ namespace ogfx public: inline RawTextInput(void) { create({ 0.0f, 0.0f }, { 200.0f, 30.0f }, "UnnamedRawTextInput"); } - inline RawTextInput(const ostd::Vec2& position, const ostd::Vec2& size, const String& name) { create(position, size, name); } - RawTextInput& create(const ostd::Vec2& position, const ostd::Vec2& size, const String& name); + inline RawTextInput(const Vec2& position, const Vec2& size, const String& name) { create(position, size, name); } + RawTextInput& create(const Vec2& position, const Vec2& size, const String& name); virtual void render(ogfx::BasicRenderer2D& gfx); virtual void update(void); diff --git a/src/ogfx/gui/Window.cpp b/src/ogfx/gui/Window.cpp index cac5189..a8d8cab 100644 --- a/src/ogfx/gui/Window.cpp +++ b/src/ogfx/gui/Window.cpp @@ -445,55 +445,55 @@ namespace ogfx m_defaultStylesheetVariables["cursor_w_resize"] = { String("").add(cast(eCursor::W_Resize)), true }; // Colors - m_defaultStylesheetVariables["color_transparent"] = { "Color(" + ostd::Colors::Transparent.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_black"] = { "Color(" + ostd::Colors::Black.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_white"] = { "Color(" + ostd::Colors::White.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_gray"] = { "Color(" + ostd::Colors::Gray.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_lightgray"] = { "Color(" + ostd::Colors::LightGray.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkgray"] = { "Color(" + ostd::Colors::DarkGray.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_red"] = { "Color(" + ostd::Colors::Red.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_green"] = { "Color(" + ostd::Colors::Green.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_blue"] = { "Color(" + ostd::Colors::Blue.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_yellow"] = { "Color(" + ostd::Colors::Yellow.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_cyan"] = { "Color(" + ostd::Colors::Cyan.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_magenta"] = { "Color(" + ostd::Colors::Magenta.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_orange"] = { "Color(" + ostd::Colors::Orange.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_purple"] = { "Color(" + ostd::Colors::Purple.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_brown"] = { "Color(" + ostd::Colors::Brown.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_pink"] = { "Color(" + ostd::Colors::Pink.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_lime"] = { "Color(" + ostd::Colors::Lime.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_olive"] = { "Color(" + ostd::Colors::Olive.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_teal"] = { "Color(" + ostd::Colors::Teal.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_navy"] = { "Color(" + ostd::Colors::Navy.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_maroon"] = { "Color(" + ostd::Colors::Maroon.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_indigo"] = { "Color(" + ostd::Colors::Indigo.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_gold"] = { "Color(" + ostd::Colors::Gold.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_silver"] = { "Color(" + ostd::Colors::Silver.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_beige"] = { "Color(" + ostd::Colors::Beige.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_coral"] = { "Color(" + ostd::Colors::Coral.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_salmon"] = { "Color(" + ostd::Colors::Salmon.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_chocolate"] = { "Color(" + ostd::Colors::Chocolate.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_khaki"] = { "Color(" + ostd::Colors::Khaki.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_lavender"] = { "Color(" + ostd::Colors::Lavender.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_mint"] = { "Color(" + ostd::Colors::Mint.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_skyblue"] = { "Color(" + ostd::Colors::SkyBlue.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_royalblue"] = { "Color(" + ostd::Colors::RoyalBlue.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_deepskyblue"] = { "Color(" + ostd::Colors::DeepSkyBlue.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_turquoise"] = { "Color(" + ostd::Colors::Turquoise.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_aquamarine"] = { "Color(" + ostd::Colors::Aquamarine.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_forestgreen"] = { "Color(" + ostd::Colors::ForestGreen.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_seagreen"] = { "Color(" + ostd::Colors::SeaGreen.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_springgreen"] = { "Color(" + ostd::Colors::SpringGreen.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_firebrick"] = { "Color(" + ostd::Colors::Firebrick.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_crimson"] = { "Color(" + ostd::Colors::Crimson.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_tomato"] = { "Color(" + ostd::Colors::Tomato.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkorange"] = { "Color(" + ostd::Colors::DarkOrange.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkred"] = { "Color(" + ostd::Colors::DarkRed.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkblue"] = { "Color(" + ostd::Colors::DarkBlue.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkgreen"] = { "Color(" + ostd::Colors::DarkGreen.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkcyan"] = { "Color(" + ostd::Colors::DarkCyan.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkmagenta"] = { "Color(" + ostd::Colors::DarkMagenta.hexString(true, "#") + ")", true }; - m_defaultStylesheetVariables["color_darkyellow"] = { "Color(" + ostd::Colors::DarkYellow.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_transparent"] = { "Color(" + Colors::Transparent.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_black"] = { "Color(" + Colors::Black.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_white"] = { "Color(" + Colors::White.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_gray"] = { "Color(" + Colors::Gray.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_lightgray"] = { "Color(" + Colors::LightGray.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkgray"] = { "Color(" + Colors::DarkGray.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_red"] = { "Color(" + Colors::Red.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_green"] = { "Color(" + Colors::Green.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_blue"] = { "Color(" + Colors::Blue.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_yellow"] = { "Color(" + Colors::Yellow.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_cyan"] = { "Color(" + Colors::Cyan.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_magenta"] = { "Color(" + Colors::Magenta.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_orange"] = { "Color(" + Colors::Orange.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_purple"] = { "Color(" + Colors::Purple.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_brown"] = { "Color(" + Colors::Brown.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_pink"] = { "Color(" + Colors::Pink.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_lime"] = { "Color(" + Colors::Lime.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_olive"] = { "Color(" + Colors::Olive.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_teal"] = { "Color(" + Colors::Teal.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_navy"] = { "Color(" + Colors::Navy.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_maroon"] = { "Color(" + Colors::Maroon.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_indigo"] = { "Color(" + Colors::Indigo.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_gold"] = { "Color(" + Colors::Gold.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_silver"] = { "Color(" + Colors::Silver.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_beige"] = { "Color(" + Colors::Beige.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_coral"] = { "Color(" + Colors::Coral.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_salmon"] = { "Color(" + Colors::Salmon.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_chocolate"] = { "Color(" + Colors::Chocolate.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_khaki"] = { "Color(" + Colors::Khaki.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_lavender"] = { "Color(" + Colors::Lavender.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_mint"] = { "Color(" + Colors::Mint.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_skyblue"] = { "Color(" + Colors::SkyBlue.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_royalblue"] = { "Color(" + Colors::RoyalBlue.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_deepskyblue"] = { "Color(" + Colors::DeepSkyBlue.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_turquoise"] = { "Color(" + Colors::Turquoise.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_aquamarine"] = { "Color(" + Colors::Aquamarine.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_forestgreen"] = { "Color(" + Colors::ForestGreen.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_seagreen"] = { "Color(" + Colors::SeaGreen.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_springgreen"] = { "Color(" + Colors::SpringGreen.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_firebrick"] = { "Color(" + Colors::Firebrick.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_crimson"] = { "Color(" + Colors::Crimson.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_tomato"] = { "Color(" + Colors::Tomato.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkorange"] = { "Color(" + Colors::DarkOrange.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkred"] = { "Color(" + Colors::DarkRed.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkblue"] = { "Color(" + Colors::DarkBlue.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkgreen"] = { "Color(" + Colors::DarkGreen.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkcyan"] = { "Color(" + Colors::DarkCyan.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkmagenta"] = { "Color(" + Colors::DarkMagenta.hexString(true, "#") + ")", true }; + m_defaultStylesheetVariables["color_darkyellow"] = { "Color(" + Colors::DarkYellow.hexString(true, "#") + ")", true }; } diff --git a/src/ogfx/gui/Window.hpp b/src/ogfx/gui/Window.hpp index b45b450..2d8cdd3 100644 --- a/src/ogfx/gui/Window.hpp +++ b/src/ogfx/gui/Window.hpp @@ -89,8 +89,8 @@ namespace ogfx inline String getTitle(void) const { return m_title; } inline i32 getWindowWidth(void) const { return m_windowWidth; } inline i32 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 Color getClearColor(void) const { return m_clearColor; } + inline void setClearColor(const 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; } @@ -123,7 +123,7 @@ namespace ogfx const ostd::Stylesheet* m_guiTheme { nullptr }; private: - ostd::Color m_clearColor { 10, 10, 10, 255 }; + Color m_clearColor { 10, 10, 10, 255 }; i32 m_windowWidth { 0 }; i32 m_windowHeight { 0 }; diff --git a/src/ogfx/gui/WindowOutputHandler.cpp b/src/ogfx/gui/WindowOutputHandler.cpp index f30bd23..9a588b1 100644 --- a/src/ogfx/gui/WindowOutputHandler.cpp +++ b/src/ogfx/gui/WindowOutputHandler.cpp @@ -440,7 +440,7 @@ namespace ogfx if (l_endOfConsole()) return; if (string.len() == 0) return; f32 vertical_margin = 4; - Vec2 pos = m_consolePosition + ostd::Vec2 { m_charSize.x * m_curosrPosition.x, m_charSize.y * m_curosrPosition.y }; + Vec2 pos = m_consolePosition + Vec2 { m_charSize.x * m_curosrPosition.x, m_charSize.y * m_curosrPosition.y }; if (m_backgroundColor.a > 0) m_renderer.fillRect({ pos.x, pos.y + vertical_margin, m_charSize.x * string.len(), m_charSize.y - vertical_margin }, m_backgroundColor); if (m_foregroundColor.a > 0) diff --git a/src/ogfx/gui/WindowOutputHandler.hpp b/src/ogfx/gui/WindowOutputHandler.hpp index 5355222..278fe5d 100644 --- a/src/ogfx/gui/WindowOutputHandler.hpp +++ b/src/ogfx/gui/WindowOutputHandler.hpp @@ -34,35 +34,35 @@ namespace ogfx GraphicsWindowOutputHandler(void); void attachWindow(WindowCore& window); void setMonospaceFont(const String& filePath); - ostd::Vec2 getStringSize(const String& str); + Vec2 getStringSize(const String& str); bool isReady(void); void resetCursorPosition(void); void resetColors(void); void beginFrame(void); void setFontSize(i32 fontSize); - void setConsoleMaxCharacters(const ostd::IPoint& size); - void setConsolePosition(const ostd::Vec2& pos); + void setConsoleMaxCharacters(const IPoint& size); + void setConsolePosition(const Vec2& pos); void setWrapMode(eWrapMode wrapMode); - void setPadding(const ostd::Rectangle& rect); - void setDefaultForegroundColor(const ostd::Color& color); - void setDefaultBackgorundColor(const ostd::Color& color); + void setPadding(const Rectangle& rect); + void setDefaultForegroundColor(const Color& color); + void setDefaultBackgorundColor(const Color& color); void setTabWidth(u8 tw); i32 getFontSize(void); - ostd::Vec2 getCharacterSize(i32 fontSize = 0); - ostd::Vec2 getConsolePosition(void); + Vec2 getCharacterSize(i32 fontSize = 0); + Vec2 getConsolePosition(void); eWrapMode getWrapMode(void); - ostd::Rectangle getPadding(void); - ostd::Color getDefaultBackgroundColor(void); - ostd::Color getDefaultForegroundColor(void); + Rectangle getPadding(void); + Color getDefaultBackgroundColor(void); + Color getDefaultForegroundColor(void); u8 getTabWidth(void); - ostd::Rectangle getConsoleBounds(void); + Rectangle getConsoleBounds(void); - GraphicsWindowOutputHandler& bg(const ostd::Color& color) override; + GraphicsWindowOutputHandler& bg(const Color& color) override; GraphicsWindowOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override; GraphicsWindowOutputHandler& bg(const String& color) override; - GraphicsWindowOutputHandler& fg(const ostd::Color& color) override; + GraphicsWindowOutputHandler& fg(const Color& color) override; GraphicsWindowOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override; GraphicsWindowOutputHandler& fg(const String& color) override; @@ -90,38 +90,38 @@ namespace ogfx GraphicsWindowOutputHandler& clear(void) override; GraphicsWindowOutputHandler& reset(void) override; - GraphicsWindowOutputHandler& xy(ostd::IPoint position) override; + GraphicsWindowOutputHandler& xy(IPoint position) override; GraphicsWindowOutputHandler& xy(i32 x, i32 y) override; GraphicsWindowOutputHandler& x(i32 x) override; GraphicsWindowOutputHandler& y(i32 y) override; - ostd::IPoint getCursorPosition(void) override; + IPoint getCursorPosition(void) override; void getCursorPosition(i32& outX, i32& outY) override; i32 getCursorX(void) override; i32 getCursorY(void) override; void getConsoleSize(i32& outColumns, i32& outRows) override; - ostd::IPoint getConsoleSize(void) override; + IPoint getConsoleSize(void) override; private: void __update_char_size(void); void __print_string(const String& str); private: - ostd::Color m_backgroundColor; - ostd::Color m_foregroundColor; - ostd::Color m_defaultBackgroundColor { 0, 0, 0, 0 }; - ostd::Color m_defaultForegroundColor { 0, 220, 0, 255 }; - ostd::Vec2 m_curosrPosition; + Color m_backgroundColor; + Color m_foregroundColor; + Color m_defaultBackgroundColor { 0, 0, 0, 0 }; + Color m_defaultForegroundColor { 0, 220, 0, 255 }; + Vec2 m_curosrPosition; BasicRenderer2D m_renderer; WindowCore* m_window { nullptr }; i32 m_fontSize { 20 }; - ostd::Vec2 m_charSize; - ostd::IPoint m_consoleSize { 0, 0 }; + Vec2 m_charSize; + IPoint m_consoleSize { 0, 0 }; bool m_ready { false }; - ostd::Vec2 m_consolePosition { 0.0f, 0.0f }; + Vec2 m_consolePosition { 0.0f, 0.0f }; eWrapMode m_wrapMode { eWrapMode::TripleDots }; - ostd::Rectangle m_padding { 10, 10, 10, 10 }; + Rectangle m_padding { 10, 10, 10, 10 }; u8 m_tabWidth { 8 }; }; } diff --git a/src/ogfx/gui/widgets/CheckBox.cpp b/src/ogfx/gui/widgets/CheckBox.cpp index b610de4..fbd8ab8 100644 --- a/src/ogfx/gui/widgets/CheckBox.cpp +++ b/src/ogfx/gui/widgets/CheckBox.cpp @@ -41,18 +41,18 @@ namespace ogfx void CheckBox::applyTheme(const ostd::Stylesheet& theme) { - setCheckBorderColor(getThemeValue(theme, "checkbox.checkBorderColor", ostd::Colors::White)); - setCheckBoxColor(getThemeValue(theme, "checkbox.checkBoxColor", ostd::Colors::White)); - setTextColor(getThemeValue(theme, "checkbox.textColor", ostd::Colors::Black)); - setBackGroundColor(getThemeValue(theme, "checkbox.backgroundColor", ostd::Colors::Transparent)); + setCheckBorderColor(getThemeValue(theme, "checkbox.checkBorderColor", Colors::White)); + setCheckBoxColor(getThemeValue(theme, "checkbox.checkBoxColor", Colors::White)); + setTextColor(getThemeValue(theme, "checkbox.textColor", Colors::Black)); + setBackGroundColor(getThemeValue(theme, "checkbox.backgroundColor", Colors::Transparent)); setFontSize(getThemeValue(theme, "checkbox.fontSize", 28)); setBorderRadius(getThemeValue(theme, "checkbox.borderRadius", 10)); setBorderWidth(getThemeValue(theme, "checkbox.borderWidth", 2)); enableBorder(getThemeValue(theme, "checkbox.showBorder", false)); - setBorderColor(getThemeValue(theme, "checkbox.borderColor", ostd::Colors::White)); + setBorderColor(getThemeValue(theme, "checkbox.borderColor", Colors::White)); enableBackground(getThemeValue(theme, "checkbox.showBackground", false)); - setPadding(getThemeValue(theme, "checkbox.padding", { 5, 5, 5, 5 })); - setMargin(getThemeValue(theme, "checkbox.margin", { 0, 0, 0, 0 })); + setPadding(getThemeValue(theme, "checkbox.padding", { 5, 5, 5, 5 })); + setMargin(getThemeValue(theme, "checkbox.margin", { 0, 0, 0, 0 })); m_checkBorderRadius = getThemeValue(theme, "checkbox.checkBorderRadius", 5); m_checkBorderWidth = getThemeValue(theme, "checkbox.checkBorderWidth", 1); } @@ -64,7 +64,7 @@ namespace ogfx gfx.drawRoundRect({ getGlobalContentPosition(), m_checkSize }, getCheckBorderColor(), m_checkBorderRadius, m_checkBorderWidth); if (isChecked()) gfx.fillRoundRect({ getGlobalContentPosition() + 5, m_checkSize - 10 }, getCheckBoxColor(), m_checkBorderRadius / 2.0f); - gfx.drawString(getText(), getGlobalContentPosition() + ostd::Vec2 { m_checkSize.x + m_spacing, 0 }, getTextColor(), getFontSize()); + gfx.drawString(getText(), getGlobalContentPosition() + Vec2 { m_checkSize.x + m_spacing, 0 }, getTextColor(), getFontSize()); } void CheckBox::onMouseReleased(const Event& event) diff --git a/src/ogfx/gui/widgets/CheckBox.hpp b/src/ogfx/gui/widgets/CheckBox.hpp index de48b62..6d58522 100644 --- a/src/ogfx/gui/widgets/CheckBox.hpp +++ b/src/ogfx/gui/widgets/CheckBox.hpp @@ -42,12 +42,12 @@ namespace ogfx void setText(const String& text); void setChecked(bool checked); inline String getText(void) const { return m_text; } - inline ostd::Color getCheckBorderColor(void) const { return m_checkBorderColor; } - inline void setCheckBorderColor(const ostd::Color& color) { m_checkBorderColor = color; } - inline ostd::Color getCheckBoxColor(void) const { return m_checkBoxColor; } - inline void setCheckBoxColor(const ostd::Color& color) { m_checkBoxColor = color; } - inline ostd::Color getTextColor(void) const { return m_textColor; } - inline void setTextColor(const ostd::Color& color) { m_textColor = color; } + inline Color getCheckBorderColor(void) const { return m_checkBorderColor; } + inline void setCheckBorderColor(const Color& color) { m_checkBorderColor = color; } + inline Color getCheckBoxColor(void) const { return m_checkBoxColor; } + inline void setCheckBoxColor(const Color& color) { m_checkBoxColor = color; } + inline Color getTextColor(void) const { return m_textColor; } + inline void setTextColor(const Color& color) { m_textColor = color; } inline i32 getFontSize(void) const { return m_fontSize; } inline void setFontSize(i32 fontSize) { m_fontSize = fontSize; } inline bool isChecked(void) const { return m_checked; } @@ -61,13 +61,13 @@ namespace ogfx String m_text { "" }; bool m_textChanged { false }; i32 m_fontSize { 20 }; - ostd::Color m_textColor { 255, 255, 255 }; + Color m_textColor { 255, 255, 255 }; f32 m_spacing { 10 }; - ostd::Vec2 m_checkSize { 0, 0 }; + Vec2 m_checkSize { 0, 0 }; i32 m_checkBorderRadius { 5 }; i32 m_checkBorderWidth { 1 }; - ostd::Color m_checkBorderColor { 255, 255, 255 }; - ostd::Color m_checkBoxColor { 255, 255, 255 }; + Color m_checkBorderColor { 255, 255, 255 }; + Color m_checkBoxColor { 255, 255, 255 }; std::function callback_onStateChanged { nullptr }; }; diff --git a/src/ogfx/gui/widgets/Containers.cpp b/src/ogfx/gui/widgets/Containers.cpp index 33bc6dc..a6fab02 100644 --- a/src/ogfx/gui/widgets/Containers.cpp +++ b/src/ogfx/gui/widgets/Containers.cpp @@ -40,17 +40,17 @@ namespace ogfx void Panel::applyTheme(const ostd::Stylesheet& theme) { - setBackGroundColor(getThemeValue(theme, "panel.backgroundColor", ostd::Colors::Gray)); + setBackGroundColor(getThemeValue(theme, "panel.backgroundColor", Colors::Gray)); setBorderRadius(getThemeValue(theme, "panel.borderRadius", 8)); setBorderWidth(getThemeValue(theme, "panel.borderWidth", 2)); enableBorder(getThemeValue(theme, "panel.showBorder", true)); enableBackground(getThemeValue(theme, "panel.showBackground", true)); - setBorderColor(getThemeValue(theme, "panel.borderColor", ostd::Colors::Black)); - m_titleColor = getThemeValue(theme, "panel.titleColor", ostd::Colors::Black); + setBorderColor(getThemeValue(theme, "panel.borderColor", Colors::Black)); + m_titleColor = getThemeValue(theme, "panel.titleColor", Colors::Black); m_showTitle = getThemeValue(theme, "panel.showTitle", false); m_titleHeight = getThemeValue(theme, "panel.titleHeight", 30); - m_titleType = getThemeValue(theme, "panel.titleHeight", "text"); - setPadding(getThemeValue(theme, "panel.padding", { 15, 15, 15, 15 })); + m_titleType = getThemeValue(theme, "panel.titlebarType", TitleBarTypes::None); + setPadding(getThemeValue(theme, "panel.padding", { 15, 15, 15, 15 })); } void Panel::onDraw(ogfx::BasicRenderer2D& gfx) diff --git a/src/ogfx/gui/widgets/Containers.hpp b/src/ogfx/gui/widgets/Containers.hpp index d841c3e..51d12d1 100644 --- a/src/ogfx/gui/widgets/Containers.hpp +++ b/src/ogfx/gui/widgets/Containers.hpp @@ -30,18 +30,26 @@ namespace ogfx { class Panel : public Widget { + public: struct TitleBarTypes + { + inline static const String None { "none" }; + inline static const String Full { "full" }; + inline static const String Minimal { "monimal" }; + }; public: inline Panel(WindowCore& window) : Widget({ 0, 0, 0, 0 }, window) { create(); } Panel& create(void); void applyTheme(const ostd::Stylesheet& theme) override; void onDraw(ogfx::BasicRenderer2D& gfx) override; - inline void setBackGroundColor(const ostd::Color& color) { m_backgroundColor = color; } - inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; } + void setTitlebarType(const String& type); + inline void setBackGroundColor(const Color& color) { m_backgroundColor = color; } + inline Color getBackgroundColor(void) { return m_backgroundColor; } + inline String getTitlebarType(void) const { return m_titleType; } private: - ostd::Color m_titleColor { 0, 0, 0 }; + Color m_titleColor { 0, 0, 0 }; bool m_showTitle { false }; - String m_titleType = "full"; + String m_titleType = TitleBarTypes::None; f32 m_titleHeight { 30 }; }; } diff --git a/src/ogfx/gui/widgets/Label.cpp b/src/ogfx/gui/widgets/Label.cpp index 36f6e92..869571e 100644 --- a/src/ogfx/gui/widgets/Label.cpp +++ b/src/ogfx/gui/widgets/Label.cpp @@ -41,16 +41,16 @@ namespace ogfx void Label::applyTheme(const ostd::Stylesheet& theme) { - setColor(getThemeValue(theme, "label.textColor", ostd::Colors::White)); - setBackGroundColor(getThemeValue(theme, "label.backgroundColor", ostd::Colors::Transparent)); + setColor(getThemeValue(theme, "label.textColor", Colors::White)); + setBackGroundColor(getThemeValue(theme, "label.backgroundColor", Colors::Transparent)); setFontSize(getThemeValue(theme, "label.fontSize", 20)); setBorderRadius(getThemeValue(theme, "label.borderRadius", 10)); setBorderWidth(getThemeValue(theme, "label.borderWidth", 2)); enableBorder(getThemeValue(theme, "label.showBorder", false)); - setBorderColor(getThemeValue(theme, "label.borderColor", ostd::Colors::White)); + setBorderColor(getThemeValue(theme, "label.borderColor", Colors::White)); enableBackground(getThemeValue(theme, "label.showBackground", false)); - setPadding(getThemeValue(theme, "label.padding", { 5, 5, 5, 5 })); - setMargin(getThemeValue(theme, "label.margin", { 0, 0, 0, 0 })); + setPadding(getThemeValue(theme, "label.padding", { 5, 5, 5, 5 })); + setMargin(getThemeValue(theme, "label.margin", { 0, 0, 0, 0 })); } void Label::onDraw(ogfx::BasicRenderer2D& gfx) diff --git a/src/ogfx/gui/widgets/Label.hpp b/src/ogfx/gui/widgets/Label.hpp index 455adcf..e51e71a 100644 --- a/src/ogfx/gui/widgets/Label.hpp +++ b/src/ogfx/gui/widgets/Label.hpp @@ -39,8 +39,8 @@ namespace ogfx void onDraw(ogfx::BasicRenderer2D& gfx) override; void setText(const String& text); inline String getText(void) const { return m_text; } - inline ostd::Color getColor(void) const { return m_color; } - inline void setColor(const ostd::Color& color) { m_color = color; } + inline Color getColor(void) const { return m_color; } + inline void setColor(const Color& color) { m_color = color; } inline i32 getFontSize(void) const { return m_fontSize; } inline void setFontSize(i32 fontSize) { m_fontSize = fontSize; } @@ -51,7 +51,7 @@ namespace ogfx String m_text { "" }; bool m_textChanged { false }; i32 m_fontSize { 20 }; - ostd::Color m_color { 255, 255, 255 }; + Color m_color { 255, 255, 255 }; }; } } diff --git a/src/ogfx/gui/widgets/RootWidget.cpp b/src/ogfx/gui/widgets/RootWidget.cpp index 3840368..d668dc3 100644 --- a/src/ogfx/gui/widgets/RootWidget.cpp +++ b/src/ogfx/gui/widgets/RootWidget.cpp @@ -43,7 +43,7 @@ namespace ogfx void RootWidget::applyTheme(const ostd::Stylesheet& theme) { - m_color = getThemeValue(theme, "window.backgroundColor", getWindow().getClearColor()); + m_color = getThemeValue(theme, "window.backgroundColor", getWindow().getClearColor()); } void RootWidget::onDraw(ogfx::BasicRenderer2D& gfx) diff --git a/src/ogfx/gui/widgets/RootWidget.hpp b/src/ogfx/gui/widgets/RootWidget.hpp index 06a91b0..6adb1d4 100644 --- a/src/ogfx/gui/widgets/RootWidget.hpp +++ b/src/ogfx/gui/widgets/RootWidget.hpp @@ -37,7 +37,7 @@ namespace ogfx void onDraw(ogfx::BasicRenderer2D& gfx) override; private: - ostd::Color m_color { ostd::Colors::Transparent }; + Color m_color { Colors::Transparent }; }; } } diff --git a/src/ogfx/gui/widgets/Widget.cpp b/src/ogfx/gui/widgets/Widget.cpp index 6f4956b..69f8b44 100644 --- a/src/ogfx/gui/widgets/Widget.cpp +++ b/src/ogfx/gui/widgets/Widget.cpp @@ -31,7 +31,7 @@ namespace ogfx ostd::BaseObject* Widget::s_dragAndDropData { nullptr }; bool Widget::s_hasDragAndDropData { false }; - Widget::Widget(const ostd::Rectangle& bounds, WindowCore& window) : Rectangle(bounds), m_widgets(window, *this) + Widget::Widget(const Rectangle& bounds, WindowCore& window) : Rectangle(bounds), m_widgets(window, *this) { m_window = &window; } @@ -44,40 +44,40 @@ namespace ogfx return m_widgets.addWidget(child); } - ostd::Vec2 Widget::getGlobalPosition(void) const + Vec2 Widget::getGlobalPosition(void) const { - ostd::Vec2 glob = getPosition(); + Vec2 glob = getPosition(); if (!m_rootChild && m_parent != nullptr) glob += m_parent->getGlobalPosition() + m_parent->getPadding().getPosition(); glob += m_margin.getPosition(); return glob; } - ostd::Vec2 Widget::getGlobalContentPosition(void) const + Vec2 Widget::getGlobalContentPosition(void) const { return getGlobalPosition() + getContentBounds().getPosition(); } - ostd::Rectangle Widget::getGlobalBounds(void) const + Rectangle Widget::getGlobalBounds(void) const { return { getGlobalPosition(), getSize() + (m_margin.getSize() * 2) }; } - ostd::Rectangle Widget::getContentBounds(void) const + Rectangle Widget::getContentBounds(void) const { auto pad = getPadding(); return { pad.getPosition(), (getSize() - (pad.getSize() * 2)) }; } - ostd::Rectangle Widget::getGlobalContentBounds(void) const + Rectangle Widget::getGlobalContentBounds(void) const { auto pad = getPadding(); return { getGlobalContentPosition(), getContentBounds().getSize() }; } - bool Widget::contains(ostd::Vec2 p, bool includeBounds) const + bool Widget::contains(Vec2 p, bool includeBounds) const { - return ostd::Rectangle(getGlobalPosition(), getSize()).contains(p, includeBounds); + return Rectangle(getGlobalPosition(), getSize()).contains(p, includeBounds); } void Widget::enable(bool enable) diff --git a/src/ogfx/gui/widgets/Widget.hpp b/src/ogfx/gui/widgets/Widget.hpp index 40f5e87..18a23a3 100644 --- a/src/ogfx/gui/widgets/Widget.hpp +++ b/src/ogfx/gui/widgets/Widget.hpp @@ -31,7 +31,7 @@ namespace ogfx { namespace gui { - class Widget : public ostd::BaseObject, public ostd::Rectangle + class Widget : public ostd::BaseObject, public Rectangle { private: struct ThemeOverride { @@ -40,15 +40,15 @@ namespace ogfx }; public: using EventCallback = std::function; public: - Widget(const ostd::Rectangle& bounds, WindowCore& window); + Widget(const Rectangle& bounds, WindowCore& window); bool addChild(Widget& child); - virtual ostd::Vec2 getGlobalPosition(void) const; - virtual ostd::Vec2 getGlobalContentPosition(void) const; - virtual ostd::Rectangle getGlobalBounds(void) const; - virtual ostd::Rectangle getContentBounds(void) const; - virtual ostd::Rectangle getGlobalContentBounds(void) const; - using ostd::Rectangle::contains; - bool contains(ostd::Vec2 p, bool includeBounds = false) const override; + virtual Vec2 getGlobalPosition(void) const; + virtual Vec2 getGlobalContentPosition(void) const; + virtual Rectangle getGlobalBounds(void) const; + virtual Rectangle getContentBounds(void) const; + virtual Rectangle getGlobalContentBounds(void) const; + using Rectangle::contains; + bool contains(Vec2 p, bool includeBounds = false) const override; void enable(bool enable = true); virtual void applyTheme(const ostd::Stylesheet& theme) = 0; void addThemeOverride(const String& fullKey, ostd::Stylesheet::TypeVariant value); @@ -124,8 +124,8 @@ namespace ogfx inline Widget* getParent(void) { return m_parent; } inline i32 getZIndex(void) const { return m_zIndex; } inline bool isChildrenEnabled(void) const { return m_allowChildren; } - inline void setPadding(const ostd::Rectangle& pad) { m_padding = pad; } - inline void setMargin(const ostd::Rectangle& margin) { m_margin = margin; } + inline void setPadding(const Rectangle& pad) { m_padding = pad; } + inline void setMargin(const Rectangle& margin) { m_margin = margin; } inline Rectangle getPadding(void) const { return m_padding; } inline Rectangle getMargin(void) const { return m_margin; } inline bool isMouseInside(void) const { return m_mouseInside; } @@ -140,12 +140,12 @@ namespace ogfx inline bool isDragAndDropEnabled(void) const { return m_acceptDragAndDrop; } inline void enableDragAndDrop(bool enable = true) { m_acceptDragAndDrop = enable; } inline void disableDragAndDrop(void) { enableDragAndDrop(false); } - inline void setBackGroundColor(const ostd::Color& color) { m_backgroundColor = color; } - inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; } + inline void setBackGroundColor(const Color& color) { m_backgroundColor = color; } + inline Color getBackgroundColor(void) { return m_backgroundColor; } inline void enableBackground(bool enable = true) { m_showBackground = enable; } inline bool isBackgoundEnabled(void) const { return m_showBackground; } - inline void setBorderColor(const ostd::Color& color) { m_borderColor = color; } - inline ostd::Color getBorderColor(void) { return m_borderColor; } + inline void setBorderColor(const Color& color) { m_borderColor = color; } + inline Color getBorderColor(void) { return m_borderColor; } inline void enableBorder(bool enable = true) { m_showBorder = enable; } inline bool isBorderEnabled(void) const { return m_showBorder; } inline void setBorderRadius(i32 br) { m_borderRadius = br; } @@ -168,16 +168,16 @@ namespace ogfx inline void disableDrawBox(void) { m_drawBox = false; } inline void enableDrawBox(void) { m_drawBox = true; } inline bool isDrawBoxEnabled(void) const { return m_drawBox; } - inline void setDrawBoxColor(const ostd::Color& color) { m_drawBoxColor = color; } - inline ostd::Color getDrawBoxColor(void) { return m_drawBoxColor; } + inline void setDrawBoxColor(const Color& color) { m_drawBoxColor = color; } + inline Color getDrawBoxColor(void) { return m_drawBoxColor; } protected: bool m_rootChild { false }; i32 m_borderRadius { 10 }; i32 m_borderWidth { 2 }; - ostd::Color m_borderColor { 255, 255, 255 }; + Color m_borderColor { 255, 255, 255 }; bool m_showBorder { false }; - ostd::Color m_backgroundColor { ostd::Colors::Transparent }; + Color m_backgroundColor { Colors::Transparent }; bool m_showBackground { false }; EventCallback callback_onMousePressed { nullptr }; @@ -223,10 +223,10 @@ namespace ogfx stdvec m_themeOverrides; bool m_drawBox { true }; - ostd::Color m_drawBoxColor { 255, 0, 0 }; + Color m_drawBoxColor { 255, 0, 0 }; - ostd::Rectangle m_padding { 0, 0, 0, 0 }; - ostd::Rectangle m_margin { 0, 0, 0, 0 }; + Rectangle m_padding { 0, 0, 0, 0 }; + Rectangle m_margin { 0, 0, 0, 0 }; static ostd::BaseObject* s_dragAndDropData; static bool s_hasDragAndDropData; diff --git a/src/ogfx/render/BasicRenderer.cpp b/src/ogfx/render/BasicRenderer.cpp index 29966a8..64f1290 100644 --- a/src/ogfx/render/BasicRenderer.cpp +++ b/src/ogfx/render/BasicRenderer.cpp @@ -91,11 +91,11 @@ namespace ogfx m_drawCallCount = 0; } - void BasicRenderer2D::pushClippingRect(const ostd::Rectangle& rect, bool additive) + void BasicRenderer2D::pushClippingRect(const Rectangle& rect, bool additive) { if (!m_initialized) return; - ostd::Rectangle finalRect = rect; + Rectangle finalRect = rect; if (additive && !m_clipStack.empty()) finalRect = m_clipStack.back().getIntersection(rect, false); @@ -212,7 +212,7 @@ namespace ogfx return set_error_state(tErrors::NoError); } - ostd::Vec2 BasicRenderer2D::getStringDimensions(const String& message, i32 fontSize, TTF_Font* font) + Vec2 BasicRenderer2D::getStringDimensions(const String& message, i32 fontSize, TTF_Font* font) { if (!isValid()) return { 0, 0 }; if (fontSize <= 0) fontSize = m_fontSize; @@ -244,7 +244,7 @@ namespace ogfx // ===================================================== SPECIALIZED ===================================================== - void BasicRenderer2D::drawImage(const ogfx::Image& image, const ostd::Vec2& position, const ostd::Vec2& size, const ostd::Rectangle& srcRect) + void BasicRenderer2D::drawImage(const ogfx::Image& image, const Vec2& position, const Vec2& size, const Rectangle& srcRect) { if (!m_initialized || !image.isLoaded()) return; @@ -253,7 +253,7 @@ namespace ogfx if (!tex) return; - ostd::Vec2 texSize = image.getSize(); + Vec2 texSize = image.getSize(); // 1. Resolve source rectangle f32 sx, sy, sw, sh; @@ -284,7 +284,7 @@ namespace ogfx f32 y2 = dy + dh; // 3. Build quad vertices - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x1, y1 }, { x2, y1 }, { x2, y2 }, @@ -292,7 +292,7 @@ namespace ogfx }; // 4. Build UVs (normalized) - ostd::Vec2 uvs[4] = { + Vec2 uvs[4] = { { sx / texSize.x, sy / texSize.y }, { (sx + sw) / texSize.x, sy / texSize.y }, { (sx + sw) / texSize.x, (sy + sh) / texSize.y }, @@ -301,10 +301,10 @@ namespace ogfx // 5. Push quad u32 inds[6] = QUAD_INDICES_ARR; - push_polygon(verts, uvs, 4, inds, 6, ostd::Colors::White, tex); + push_polygon(verts, uvs, 4, inds, 6, Colors::White, tex); } - void BasicRenderer2D::drawAnimation(const Animation& anim, const ostd::Vec2& position, const ostd::Vec2& size) + void BasicRenderer2D::drawAnimation(const Animation& anim, const Vec2& position, const Vec2& size) { if (!m_initialized) return; if (!anim.hasImage()) return; @@ -313,7 +313,7 @@ namespace ogfx drawImage(img, position, size, anim.getFrameRect()); } - void BasicRenderer2D::drawString(const String& str, const ostd::Vec2& position, const ostd::Color& color, i32 fontSize, f32 scale) + void BasicRenderer2D::drawString(const String& str, const Vec2& position, const Color& color, i32 fontSize, f32 scale) { if (!isValid()) return; if (fontSize <= 0) @@ -339,7 +339,7 @@ namespace ogfx x += (kern * scale); } - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x, y }, { x + g->size.x * scale, y }, { x + g->size.x * scale, y + g->size.y * scale }, @@ -353,15 +353,15 @@ namespace ogfx setFontSize(oldFontSize); } - void BasicRenderer2D::drawCenteredString(const String& str, const ostd::Vec2& center, const ostd::Color& color, i32 fontSize, f32 scale) + void BasicRenderer2D::drawCenteredString(const String& str, const Vec2& center, const Color& color, i32 fontSize, f32 scale) { auto dims = getStringDimensions(str, fontSize); drawString(str, { center.x - (dims.x * scale) * 0.5f, center.y - (dims.y * scale) * 0.5f }, color, fontSize, scale); } - void BasicRenderer2D::drawCenteredString(const String& str, const ostd::Rectangle& bounds, const ostd::Color& color, i32 fontSize, f32 scale) + void BasicRenderer2D::drawCenteredString(const String& str, const Rectangle& bounds, const Color& color, i32 fontSize, f32 scale) { - drawCenteredString(str, ostd::Vec2 { bounds.x + bounds.w * 0.5f, bounds.y + bounds.h * 0.5f }, color, fontSize, scale); + drawCenteredString(str, Vec2 { bounds.x + bounds.w * 0.5f, bounds.y + bounds.h * 0.5f }, color, fontSize, scale); } // ===================================================== SPECIALIZED ===================================================== @@ -370,7 +370,7 @@ namespace ogfx // ===================================================== PRIMITIVES ===================================================== - void BasicRenderer2D::drawLine(const ostd::FLine& line, const ostd::Color& color, i32 thickness, bool rounded) + void BasicRenderer2D::drawLine(const FLine& line, const Color& color, i32 thickness, bool rounded) { if (!m_initialized || thickness <= 0) return; @@ -384,7 +384,7 @@ namespace ogfx f32 half = thickness * 0.5f; Vec2 off = perp * half; - std::array verts = {{ + std::array verts = {{ p1 - off, p1 + off, p2 + off, @@ -402,7 +402,7 @@ namespace ogfx generate_half_circle(p2, dir, half, segments, color); } - void BasicRenderer2D::drawRect(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness) + void BasicRenderer2D::drawRect(const Rectangle& rect, const Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; @@ -428,12 +428,12 @@ namespace ogfx drawLine({ {x1, y2 + half}, {x1, y1 - half} }, color, thickness, false); } - void BasicRenderer2D::drawRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, i32 thickness) + void BasicRenderer2D::drawRect(const Vec2& center, const Vec2& size, const Color& color, i32 thickness) { drawRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color, thickness); } - void BasicRenderer2D::drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius, i32 thickness) + void BasicRenderer2D::drawRoundRect(const Rectangle& rect, const Color& color, f32 radius, i32 thickness) { if (!m_initialized || thickness <= 0) return; @@ -450,10 +450,10 @@ namespace ogfx f32 y2 = rect.y + rect.h - half; // Corner centers - ostd::Vec2 TL { x1 + radius, y1 + radius }; - ostd::Vec2 TR { x2 - radius, y1 + radius }; - ostd::Vec2 BR { x2 - radius, y2 - radius }; - ostd::Vec2 BL { x1 + radius, y2 - radius }; + Vec2 TL { x1 + radius, y1 + radius }; + Vec2 TR { x2 - radius, y1 + radius }; + Vec2 BR { x2 - radius, y2 - radius }; + Vec2 BL { x1 + radius, y2 - radius }; // Straight edges (shortened to meet the arcs cleanly) drawLine({ {x1 + radius, y1}, {x2 - radius, y1} }, color, thickness, false); // top @@ -471,12 +471,12 @@ namespace ogfx generate_ellipse_stroke(BL, radius, radius, thickness, M_PI * 0.5f, M_PI, color, segments); // BL } - void BasicRenderer2D::drawRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius, i32 thickness) + void BasicRenderer2D::drawRoundRect(const Vec2& center, const Vec2& size, const Color& color, f32 radius, i32 thickness) { drawRoundRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color, radius, thickness); } - void BasicRenderer2D::drawCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color, i32 thickness) + void BasicRenderer2D::drawCircle(const Vec2& center, f32 radius, const Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; @@ -484,12 +484,12 @@ namespace ogfx generate_ellipse_stroke(center, radius, radius, thickness, 0.0f, 2.0f * M_PI, color, segments); } - void BasicRenderer2D::drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness) + void BasicRenderer2D::drawCircle(const Rectangle& rect, const Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; - ostd::Vec2 center { + Vec2 center { rect.x + rect.w * 0.5f, rect.y + rect.h * 0.5f }; @@ -498,12 +498,12 @@ namespace ogfx drawCircle(center, radius, color, thickness); } - void BasicRenderer2D::drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness) + void BasicRenderer2D::drawEllipse(const Rectangle& rect, const Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; - ostd::Vec2 center = { rect.x + rect.w*0.5f, rect.y + rect.h*0.5f }; + Vec2 center = { rect.x + rect.w*0.5f, rect.y + rect.h*0.5f }; f32 rx = rect.w * 0.5f; f32 ry = rect.h * 0.5f; @@ -511,7 +511,7 @@ namespace ogfx generate_ellipse_stroke(center, rx, ry, thickness, 0.0f, 2.0f * M_PI, color, segments); } - void BasicRenderer2D::fillRect(const ostd::Rectangle& rect, const ostd::Color& color) + void BasicRenderer2D::fillRect(const Rectangle& rect, const Color& color) { if (!m_initialized) return; @@ -521,7 +521,7 @@ namespace ogfx f32 x2 = rect.x + rect.w; f32 y2 = rect.y + rect.h; - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x1, y1 }, { x2, y1 }, { x2, y2 }, @@ -531,12 +531,12 @@ namespace ogfx push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } - void BasicRenderer2D::fillRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color) + void BasicRenderer2D::fillRect(const Vec2& center, const Vec2& size, const Color& color) { fillRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color); } - void BasicRenderer2D::fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius) + void BasicRenderer2D::fillRoundRect(const Rectangle& rect, const Color& color, f32 radius) { if (!m_initialized) return; @@ -561,7 +561,7 @@ namespace ogfx // 1. Fill the center rectangle // { - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { cx1, cy1 }, { cx2, cy1 }, { cx2, cy2 }, @@ -578,7 +578,7 @@ namespace ogfx // Top if (radius > 0) { - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x1 + radius, y1 }, { x2 - radius, y1 }, { x2 - radius, y1 + radius }, @@ -590,7 +590,7 @@ namespace ogfx // Bottom { - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x1 + radius, y2 - radius }, { x2 - radius, y2 - radius }, { x2 - radius, y2 }, @@ -602,7 +602,7 @@ namespace ogfx // Left { - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x1, y1 + radius }, { x1 + radius, y1 + radius }, { x1 + radius, y2 - radius }, @@ -614,7 +614,7 @@ namespace ogfx // Right { - ostd::Vec2 verts[4] = { + Vec2 verts[4] = { { x2 - radius, y1 + radius }, { x2, y1 + radius }, { x2, y2 - radius }, @@ -634,12 +634,12 @@ namespace ogfx generate_filled_ellipse_stroke({cx1, cy2}, radius, radius, 0.5f * M_PI, color, segments); // BL } - void BasicRenderer2D::fillRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius) + void BasicRenderer2D::fillRoundRect(const Vec2& center, const Vec2& size, const Color& color, f32 radius) { fillRoundRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color, radius); } - void BasicRenderer2D::fillCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color) + void BasicRenderer2D::fillCircle(const Vec2& center, f32 radius, const Color& color) { if (!m_initialized) return; @@ -648,12 +648,12 @@ namespace ogfx generate_filled_ellipse(center, radius, radius, color, segments); } - void BasicRenderer2D::fillCircle(const ostd::Rectangle& rect, const ostd::Color& color) + void BasicRenderer2D::fillCircle(const Rectangle& rect, const Color& color) { if (!m_initialized) return; - ostd::Vec2 center { + Vec2 center { rect.x + rect.w * 0.5f, rect.y + rect.h * 0.5f }; @@ -662,12 +662,12 @@ namespace ogfx fillCircle(center, radius, color); } - void BasicRenderer2D::fillEllipse(const ostd::Rectangle& rect, const ostd::Color& color) + void BasicRenderer2D::fillEllipse(const Rectangle& rect, const Color& color) { if (!m_initialized) return; - ostd::Vec2 center { + Vec2 center { rect.x + rect.w * 0.5f, rect.y + rect.h * 0.5f }; @@ -679,45 +679,45 @@ namespace ogfx generate_filled_ellipse(center, radiusX, radiusY, color, segments); } - void BasicRenderer2D::outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) + void BasicRenderer2D::outlinedRect(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; - ostd::Rectangle offset = { 1, 1, -2, -2 }; + Rectangle offset = { 1, 1, -2, -2 }; fillRect(rect + offset, fillColor); drawRect(rect, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) + void BasicRenderer2D::outlinedRect(const Vec2& center, const Vec2& size, const Color& fillColor, const Color& outlineColor, i32 outlineThickness) { outlinedRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, fillColor, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness) + void BasicRenderer2D::outlinedRoundRect(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, f32 radius, i32 outlineThickness) { if (!m_initialized) return; - ostd::Rectangle offset = { 1, 1, -2, -2 }; + Rectangle offset = { 1, 1, -2, -2 }; fillRoundRect(rect + offset, fillColor, radius); drawRoundRect(rect, outlineColor, radius, outlineThickness); } - void BasicRenderer2D::outlinedRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness) + void BasicRenderer2D::outlinedRoundRect(const Vec2& center, const Vec2& size, const Color& fillColor, const Color& outlineColor, f32 radius, i32 outlineThickness) { outlinedRoundRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, fillColor, outlineColor, radius, outlineThickness); } - void BasicRenderer2D::outlinedCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) + void BasicRenderer2D::outlinedCircle(const Vec2& center, f32 radius, const Color& fillColor, const Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; fillCircle(center, radius - 1, fillColor); drawCircle(center, radius, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) + void BasicRenderer2D::outlinedCircle(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; - ostd::Vec2 center { + Vec2 center { rect.x + rect.w * 0.5f, rect.y + rect.h * 0.5f }; @@ -726,10 +726,10 @@ namespace ogfx outlinedCircle(center, radius, fillColor, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) + void BasicRenderer2D::outlinedEllipse(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; - ostd::Rectangle offset = { 1, 1, -2, -2 }; + Rectangle offset = { 1, 1, -2, -2 }; fillEllipse(rect + offset, fillColor); drawEllipse(rect, outlineColor, outlineThickness); } @@ -744,7 +744,7 @@ namespace ogfx { for (auto& v : m_vertices) { - v.color = COLOR_CAST(ostd::Colors::Transparent); + v.color = COLOR_CAST(Colors::Transparent); v.position = { 0, 0 }; v.tex_coord = { 0, 0 }; } @@ -752,7 +752,7 @@ namespace ogfx i = 0; } - void BasicRenderer2D::generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, f32 radius, i32 segments, const ostd::Color& color) + void BasicRenderer2D::generate_half_circle(const Vec2& center, const Vec2& dir, f32 radius, i32 segments, const Color& color) { // Ensure we have room if (m_vertexCount + segments + 2 >= MaxVertices || m_indexCount + segments * 3 >= MaxIndices) @@ -802,7 +802,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_quarter_circle(const ostd::Vec2& center, f32 radius, f32 thickness, f32 startAngle, const ostd::Color& color, i32 segments) + void BasicRenderer2D::generate_quarter_circle(const Vec2& center, f32 radius, f32 thickness, f32 startAngle, const Color& color, i32 segments) { f32 half = thickness * 0.5f; @@ -866,7 +866,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_circle_stroke(const ostd::Vec2& center, f32 radius, f32 thickness, const ostd::Color& color, i32 segments) + void BasicRenderer2D::generate_circle_stroke(const Vec2& center, f32 radius, f32 thickness, const Color& color, i32 segments) { f32 half = thickness * 0.5f; @@ -927,7 +927,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 thickness, f32 startAngle, f32 endAngle, const ostd::Color& color, i32 segments) + void BasicRenderer2D::generate_ellipse_stroke(const Vec2& center, f32 radiusX, f32 radiusY, f32 thickness, f32 startAngle, f32 endAngle, const Color& color, i32 segments) { f32 half = thickness * 0.5f; @@ -993,7 +993,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_filled_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 startAngle, const ostd::Color& color, i32 segments) + void BasicRenderer2D::generate_filled_ellipse_stroke(const Vec2& center, f32 radiusX, f32 radiusY, f32 startAngle, const Color& color, i32 segments) { // Ensure capacity if (m_vertexCount + segments + 2 >= MaxVertices || m_indexCount + segments * 3 >= MaxIndices) @@ -1036,7 +1036,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_filled_ellipse(const ostd::Vec2& center, f32 radiusX, f32 radiusY, const ostd::Color& color, i32 segments) + void BasicRenderer2D::generate_filled_ellipse(const Vec2& center, f32 radiusX, f32 radiusY, const Color& color, i32 segments) { // Ensure capacity if (m_vertexCount + segments + 2 >= MaxVertices || m_indexCount + segments * 3 >= MaxIndices) @@ -1078,7 +1078,7 @@ namespace ogfx } } - void BasicRenderer2D::push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, u32 vertCount, const u32* inds, u32 indexCount, const ostd::Color& color, SDL_Texture* texture) + void BasicRenderer2D::push_polygon(const Vec2* verts, const Vec2* texCoords, u32 vertCount, const u32* inds, u32 indexCount, const Color& color, SDL_Texture* texture) { if (!m_initialized || vertCount <= 0 || indexCount <= 0) return; @@ -1100,7 +1100,7 @@ namespace ogfx bool hasTexCoords = texCoords != nullptr; for (i32 i = 0; i < vertCount; i++) { - ostd::Vec2 tc { 0.0f, 0.0f }; + Vec2 tc { 0.0f, 0.0f }; if (hasTexCoords) tc = texCoords[i]; m_vertices[m_vertexCount++] = { diff --git a/src/ogfx/render/BasicRenderer.hpp b/src/ogfx/render/BasicRenderer.hpp index 9ce521d..600f77a 100644 --- a/src/ogfx/render/BasicRenderer.hpp +++ b/src/ogfx/render/BasicRenderer.hpp @@ -61,14 +61,14 @@ namespace ogfx SDL_Renderer* getSDLRenderer(void) const; void flushBatch(void); void endFrame(void); - void pushClippingRect(const ostd::Rectangle& rect, bool additive = false); + void pushClippingRect(const Rectangle& rect, bool additive = false); void popClippingRect(void); i32 loadDefaultFont(i32 fontSize = 0); void closeFont(void); i32 openFont(const String& fontPath, i32 fontSize = 0); i32 openFont(const ostd::UByte resource_data[], u32 data_size, i32 fontSize = 0); i32 setFontSize(i32 fontSize); - ostd::Vec2 getStringDimensions(const String& message, i32 fontSize = 0, TTF_Font* font = nullptr); + Vec2 getStringDimensions(const String& message, i32 fontSize = 0, TTF_Font* font = nullptr); inline u32 getDrawCallCount(void) { return m_drawCallCount; } inline bool hasOpenFont(void) { return m_fontOpen; } @@ -80,48 +80,48 @@ namespace ogfx inline bool isInitialized(void) { return m_initialized; } inline FontGlyphAtlas& getFontGlyphAtlas(void) { return m_fontGlyphAtlas; } - void drawImage(const ogfx::Image& image, const ostd::Vec2& position, const ostd::Vec2& size = { 0, 0 }, const ostd::Rectangle& srcRect = { 0, 0, 0, 0 }); - void drawAnimation(const Animation& anim, const ostd::Vec2& position, const ostd::Vec2& size = { 0, 0 }); + void drawImage(const ogfx::Image& image, const Vec2& position, const Vec2& size = { 0, 0 }, const Rectangle& srcRect = { 0, 0, 0, 0 }); + void drawAnimation(const Animation& anim, const Vec2& position, const Vec2& size = { 0, 0 }); - void drawString(const String& str, const ostd::Vec2& position, const ostd::Color& color, i32 fontSize = 0, f32 scale = 1.0f); - void drawCenteredString(const String& str, const ostd::Vec2& center, const ostd::Color& color, i32 fontSize = 0, f32 scale = 1.0f); - void drawCenteredString(const String& str, const ostd::Rectangle& bounds, const ostd::Color& color, i32 fontSize = 0, f32 scale = 1.0f); + void drawString(const String& str, const Vec2& position, const Color& color, i32 fontSize = 0, f32 scale = 1.0f); + void drawCenteredString(const String& str, const Vec2& center, const Color& color, i32 fontSize = 0, f32 scale = 1.0f); + void drawCenteredString(const String& str, const Rectangle& bounds, const Color& color, i32 fontSize = 0, f32 scale = 1.0f); - void drawLine(const ostd::FLine& line, const ostd::Color& color, i32 thickness = 1, bool rounded = true); + void drawLine(const FLine& line, const Color& color, i32 thickness = 1, bool rounded = true); - void drawRect(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness = 1); - void drawRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, i32 thickness = 1); - void drawRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius, i32 thickness = 1); - void drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius, i32 thickness = 1); - void drawCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color, i32 thickness = 1); - void drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness = 1); - void drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness = 1); + void drawRect(const Rectangle& rect, const Color& color, i32 thickness = 1); + void drawRect(const Vec2& center, const Vec2& size, const Color& color, i32 thickness = 1); + void drawRoundRect(const Vec2& center, const Vec2& size, const Color& color, f32 radius, i32 thickness = 1); + void drawRoundRect(const Rectangle& rect, const Color& color, f32 radius, i32 thickness = 1); + void drawCircle(const Vec2& center, f32 radius, const Color& color, i32 thickness = 1); + void drawCircle(const Rectangle& rect, const Color& color, i32 thickness = 1); + void drawEllipse(const Rectangle& rect, const Color& color, i32 thickness = 1); - void fillRect(const ostd::Rectangle& rect, const ostd::Color& color); - void fillRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color); - void fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius); - void fillRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius); - void fillCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color); - void fillCircle(const ostd::Rectangle& rect, const ostd::Color& color); - void fillEllipse(const ostd::Rectangle& rect, const ostd::Color& color); + void fillRect(const Rectangle& rect, const Color& color); + void fillRect(const Vec2& center, const Vec2& size, const Color& color); + void fillRoundRect(const Rectangle& rect, const Color& color, f32 radius); + void fillRoundRect(const Vec2& center, const Vec2& size, const Color& color, f32 radius); + void fillCircle(const Vec2& center, f32 radius, const Color& color); + void fillCircle(const Rectangle& rect, const Color& color); + void fillEllipse(const Rectangle& rect, const Color& color); - void outlinedRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); - void outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); - void outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness = 1); - void outlinedRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness = 1); - void outlinedCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); - void outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); - void outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); + void outlinedRect(const Vec2& center, const Vec2& size, const Color& fillColor, const Color& outlineColor, i32 outlineThickness = 1); + void outlinedRect(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, i32 outlineThickness = 1); + void outlinedRoundRect(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, f32 radius, i32 outlineThickness = 1); + void outlinedRoundRect(const Vec2& center, const Vec2& size, const Color& fillColor, const Color& outlineColor, f32 radius, i32 outlineThickness = 1); + void outlinedCircle(const Vec2& center, f32 radius, const Color& fillColor, const Color& outlineColor, i32 outlineThickness = 1); + void outlinedCircle(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, i32 outlineThickness = 1); + void outlinedEllipse(const Rectangle& rect, const Color& fillColor, const Color& outlineColor, i32 outlineThickness = 1); private: void init_arrays(void); - void generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, f32 radius, i32 segments, const ostd::Color& color); - void generate_quarter_circle(const ostd::Vec2& center, f32 radius, f32 thickness, f32 startAngle, const ostd::Color& color, i32 segments); - void generate_circle_stroke(const ostd::Vec2& center, f32 radius, f32 thickness, const ostd::Color& color, i32 segments); - void generate_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 thickness, f32 startAngle, f32 endAngle, const ostd::Color& color, i32 segments); - void generate_filled_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 startAngle, const ostd::Color& color, i32 segments); - void generate_filled_ellipse(const ostd::Vec2& center, f32 radiusX, f32 radiusY, const ostd::Color& color, i32 segments); - void push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, u32 vertCount, const u32* inds, u32 indexCount, const ostd::Color& color, SDL_Texture* texture); + void generate_half_circle(const Vec2& center, const Vec2& dir, f32 radius, i32 segments, const Color& color); + void generate_quarter_circle(const Vec2& center, f32 radius, f32 thickness, f32 startAngle, const Color& color, i32 segments); + void generate_circle_stroke(const Vec2& center, f32 radius, f32 thickness, const Color& color, i32 segments); + void generate_ellipse_stroke(const Vec2& center, f32 radiusX, f32 radiusY, f32 thickness, f32 startAngle, f32 endAngle, const Color& color, i32 segments); + void generate_filled_ellipse_stroke(const Vec2& center, f32 radiusX, f32 radiusY, f32 startAngle, const Color& color, i32 segments); + void generate_filled_ellipse(const Vec2& center, f32 radiusX, f32 radiusY, const Color& color, i32 segments); + void push_polygon(const Vec2* verts, const Vec2* texCoords, u32 vertCount, const u32* inds, u32 indexCount, const Color& color, SDL_Texture* texture); void print_ttf_error(const String& funcName); inline i32 set_error_state(i32 err) { m_errorState = err; return m_errorState; } @@ -132,7 +132,7 @@ namespace ogfx WindowCore* m_window { nullptr }; ostd::ConsoleOutputHandler m_out; bool m_initialized { false }; - stdvec m_clipStack; + stdvec m_clipStack; std::array m_vertices; std::array m_indices; diff --git a/src/ogfx/render/FontGlyphAtlas.hpp b/src/ogfx/render/FontGlyphAtlas.hpp index a113dc1..04877a6 100644 --- a/src/ogfx/render/FontGlyphAtlas.hpp +++ b/src/ogfx/render/FontGlyphAtlas.hpp @@ -31,9 +31,9 @@ namespace ogfx { public: struct GlyphInfo { - ostd::Vec2 uvs[4]; + Vec2 uvs[4]; SDL_Texture* atlas { nullptr }; - ostd::Vec2 size; + Vec2 size; u32 codepoint { 0 }; i32 advance { 0 }; }; diff --git a/src/ogfx/render/PixelRenderer.cpp b/src/ogfx/render/PixelRenderer.cpp index 2f63700..0e07acc 100644 --- a/src/ogfx/render/PixelRenderer.cpp +++ b/src/ogfx/render/PixelRenderer.cpp @@ -31,7 +31,7 @@ namespace ogfx characterMap[c] = getCharacterIndex(c); } - bool PixelRenderer::TextRenderer::drawString(const String& str, u32 column, u32 row, u32* screenPixels, i32 screenWidth, i32 screenHeight, u32* fontPixels, const ostd::Color& color, const ostd::Color& background) + bool PixelRenderer::TextRenderer::drawString(const String& str, u32 column, u32 row, u32* screenPixels, i32 screenWidth, i32 screenHeight, u32* fontPixels, const Color& color, const Color& background) { String se(str); if (se == "") return false; @@ -64,7 +64,7 @@ namespace ogfx return charIndex; } - ostd::Color PixelRenderer::TextRenderer::applyTint(const ostd::Color& baseColor, const ostd::Color& tintColor) + Color PixelRenderer::TextRenderer::applyTint(const Color& baseColor, const Color& tintColor) { auto nBase = baseColor.getNormalizedColor(); auto nTint = tintColor.getNormalizedColor(); @@ -73,12 +73,12 @@ namespace ogfx f32 g = nBase.r * nTint.g; f32 b = nBase.r * nTint.b; - ostd::Color::FloatCol nTinted(r, g, b, 1.0f); + Color::FloatCol nTinted(r, g, b, 1.0f); - return ostd::Color(nTinted); + return Color(nTinted); } - void PixelRenderer::TextRenderer::drawCharacter(u8* screenPixels, i32 screenWidth, i32 screenHeight, u8* fontPixels, i32 x, i32 y, char c, const ostd::Color& color, const ostd::Color& background) + void PixelRenderer::TextRenderer::drawCharacter(u8* screenPixels, i32 screenWidth, i32 screenHeight, u8* fontPixels, i32 x, i32 y, char c, const Color& color, const Color& background) { using namespace ostd; i32 charIndex = characterMap[c]; @@ -86,7 +86,7 @@ namespace ogfx i32 screenx = x * 4, screeny = y; - ostd::Color tintedColor; + Color tintedColor; bool applyBackground = false; for (i32 y = charCoords.y; y < charCoords.y + (FONT_CHAR_H); y += 1) @@ -176,7 +176,7 @@ namespace ogfx SDL_RenderTexture(m_parent->getSDLRenderer(), m_texture, NULL, &rect); } - void PixelRenderer::clear(const ostd::Color& color) + void PixelRenderer::clear(const Color& color) { if (isInvalid()) return; for (i32 y = 0; y < m_windowHeight; y++) @@ -184,7 +184,7 @@ namespace ogfx for (u32 x = 0; x < m_windowWidth; x++) { i32 index = CONVERT_2D_1D(x, y, m_windowWidth); - m_pixels[index] = color.asInteger(ostd::Color::eColorFormat::ARGB); + m_pixels[index] = color.asInteger(Color::eColorFormat::ARGB); } } } diff --git a/src/ogfx/render/PixelRenderer.hpp b/src/ogfx/render/PixelRenderer.hpp index 41080f6..8fae9a9 100644 --- a/src/ogfx/render/PixelRenderer.hpp +++ b/src/ogfx/render/PixelRenderer.hpp @@ -38,12 +38,12 @@ namespace ogfx public: static void initialize(void); - static bool drawString(const String& str, u32 column, u32 row, u32* screenPixels, i32 screenWidth, i32 screenHeight, u32* fontPixels, const ostd::Color& color = { 255, 255, 255, 255 }, const ostd::Color& background = { 255, 255, 255, 0 }); + static bool drawString(const String& str, u32 column, u32 row, u32* screenPixels, i32 screenWidth, i32 screenHeight, u32* fontPixels, const Color& color = { 255, 255, 255, 255 }, const Color& background = { 255, 255, 255, 0 }); private: static i32 getCharacterIndex(char c); - static ostd::Color applyTint(const ostd::Color& baseColor, const ostd::Color& tintColor); - static void drawCharacter(u8* screenPixels, i32 screenWidth, i32 screenHeight, u8* fontPixels, i32 x, i32 y, char c, const ostd::Color& color = { 255, 255, 255, 255 }, const ostd::Color& background = { 255, 255, 255, 0 }); + static Color applyTint(const Color& baseColor, const Color& tintColor); + static void drawCharacter(u8* screenPixels, i32 screenWidth, i32 screenHeight, u8* fontPixels, i32 x, i32 y, char c, const Color& color = { 255, 255, 255, 255 }, const Color& background = { 255, 255, 255, 0 }); public: inline static constexpr i32 FONT_CHAR_W = 11; @@ -89,7 +89,7 @@ namespace ogfx void displayBuffer(void); inline u32* getScreenPixels(void) { return m_pixels; } - void clear(const ostd::Color& color); + void clear(const Color& color); private: u32* m_pixels { nullptr }; diff --git a/src/ogfx/resources/Image.hpp b/src/ogfx/resources/Image.hpp index 3ab631b..a949370 100644 --- a/src/ogfx/resources/Image.hpp +++ b/src/ogfx/resources/Image.hpp @@ -35,7 +35,7 @@ namespace ogfx inline ~Image(void) { destroy(); } void destroy(void); Image& loadFromFile(const String& filePath, BasicRenderer2D& gfx); - inline ostd::Vec2 getSize(void) const { return { m_width, m_height }; } + inline Vec2 getSize(void) const { return { m_width, m_height }; } inline bool isLoaded(void) const { return m_loaded; } inline SDL_Texture* getSDLTexture(void) const { return m_sdl_texture; } diff --git a/src/ogfx/utils/Animation.hpp b/src/ogfx/utils/Animation.hpp index 8654742..4b98d36 100644 --- a/src/ogfx/utils/Animation.hpp +++ b/src/ogfx/utils/Animation.hpp @@ -87,7 +87,7 @@ namespace ogfx inline i32 getColumnOffset(void) const { return m_column_offset; } inline i32 getRowOffset(void) const { return m_row_offset; } inline bool isStill(void) const { return m_still; } - inline ostd::Rectangle getFrameRect(void) const { return m_frame_rect; } + inline Rectangle getFrameRect(void) const { return m_frame_rect; } inline const Image& getSpriteSheet(void) const { return (m_spriteSheet != nullptr ? *m_spriteSheet : InvalidImage); } inline Image& getSpriteSheet(void) { return (m_spriteSheet != nullptr ? *m_spriteSheet : InvalidImage); } inline bool hasImage(void) const { return m_spriteSheet != nullptr; } @@ -114,6 +114,6 @@ namespace ogfx bool m_still; bool m_random; - ostd::Rectangle m_frame_rect; + Rectangle m_frame_rect; }; } diff --git a/src/ostd/data/Color.hpp b/src/ostd/data/Color.hpp index 2553893..1e7d05b 100755 --- a/src/ostd/data/Color.hpp +++ b/src/ostd/data/Color.hpp @@ -154,3 +154,9 @@ namespace ostd inline static const Color DarkYellow { 204, 204, 0, 255 }; }; } + +using Colors = ostd::Colors; +namespace ogfx +{ + using Color = ostd::Color; +} diff --git a/src/ostd/io/Json.cpp b/src/ostd/io/Json.cpp index 09ecd34..76b8382 100644 --- a/src/ostd/io/Json.cpp +++ b/src/ostd/io/Json.cpp @@ -46,10 +46,10 @@ namespace ostd catch (const json::exception&) { return String(""); } } }; - // ----- ostd::Color ------------------------------------------------- - template<> struct Getter + // ----- Color ------------------------------------------------- + template<> struct Getter { - static ostd::Color exec_impl(const std::string& p, const json& root) + static Color exec_impl(const std::string& p, const json& root) { try { const json& node = root.at(p); @@ -59,8 +59,8 @@ namespace ostd { const std::string& hex = node.get(); if (hex.starts_with("#") && hex.size() == 9) // 9 for #RRGGBBAA - return ostd::Color(hex); - return ostd::Color(); // Not a valid hex format + return Color(hex); + return Color(); // Not a valid hex format } // Case 2: Array of integers @@ -69,31 +69,31 @@ namespace ostd stdvec vals; for (const auto& v : node) { - if (!v.is_number_integer()) return ostd::Color(); + if (!v.is_number_integer()) return Color(); i32 iv = v.get(); - if (iv < 0 || iv > 255) return ostd::Color(); + if (iv < 0 || iv > 255) return Color(); vals.push_back(iv); } switch (vals.size()) { - case 1: return ostd::Color(vals[0], vals[0], vals[0]); - case 3: return ostd::Color(vals[0], vals[1], vals[2]); - case 4: return ostd::Color(vals[0], vals[1], vals[2], vals[3]); - default: return ostd::Color(); + case 1: return Color(vals[0], vals[0], vals[0]); + case 3: return Color(vals[0], vals[1], vals[2]); + case 4: return Color(vals[0], vals[1], vals[2], vals[3]); + default: return Color(); } } // Anything else → default color - return ostd::Color(); + return Color(); } - catch (...) { return ostd::Color(); } + catch (...) { return Color(); } } }; - // ----- ostd::Rectangle ------------------------------------------------- - template<> struct Getter + // ----- Rectangle ------------------------------------------------- + template<> struct Getter { - static ostd::Rectangle exec_impl(const std::string& p, const json& root) + static Rectangle exec_impl(const std::string& p, const json& root) { try { @@ -105,16 +105,16 @@ namespace ostd for (const auto& v : node) { if (!v.is_number_float() && !v.is_number_integer()) - return ostd::Rectangle(); + return Rectangle(); vals.push_back(v.get()); } - return ostd::Rectangle(vals[0], vals[1], vals[2], vals[3]); + return Rectangle(vals[0], vals[1], vals[2], vals[3]); } - return ostd::Rectangle(); + return Rectangle(); } catch (...) { - return ostd::Rectangle(); + return Rectangle(); } } }; @@ -175,12 +175,12 @@ namespace ostd return result; } }; - // ----- stdvec ----------------------------------- - template<> struct Getter> + // ----- stdvec ----------------------------------- + template<> struct Getter> { - static stdvec exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - stdvec result; + stdvec result; try { const json& node = root.at(p); @@ -190,9 +190,9 @@ namespace ostd for (const auto& element : node) { // We temporarily create a fake "sub-root" that only contains one key "color" - // This lets us call the existing Getter without modifying it + // This lets us call the existing Getter without modifying it json fake_root = { { "color", element } }; - ostd::Color color = Getter::exec_impl("color", fake_root); + Color color = Getter::exec_impl("color", fake_root); result.push_back(color); } return result; @@ -203,30 +203,30 @@ namespace ostd } } }; - // ----- stdvec ----------------------------------- - template<> struct Getter + // ----- stdvec ----------------------------------- + template<> struct Getter { - static ostd::Vec2 exec_impl(const std::string& p, const json& root) + static Vec2 exec_impl(const std::string& p, const json& root) { try { const json& arr = root.at(p); if (!arr.is_array() || arr.size() != 2) - return ostd::Vec2(); - return ostd::Vec2(arr[0].get(), arr[1].get()); + return Vec2(); + return Vec2(arr[0].get(), arr[1].get()); } catch (...) { - return ostd::Vec2(); + return Vec2(); } } }; - // ----- stdvec ----------------------------------- - template<> struct Getter> + // ----- stdvec ----------------------------------- + template<> struct Getter> { - static stdvec exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - stdvec result; + stdvec result; try { const json& node = root.at(p); @@ -236,7 +236,7 @@ namespace ostd for (const auto& element : node) { json fake_root = { { "rect", element } }; - ostd::Rectangle rect = Getter::exec_impl("rect", fake_root); + Rectangle rect = Getter::exec_impl("rect", fake_root); result.push_back(rect); } return result; @@ -310,10 +310,10 @@ namespace ostd catch (...) { return false; } } }; - // ----- ostd::Color ------------------------------------------------- - template<> struct Setter + // ----- Color ------------------------------------------------- + template<> struct Setter { - static bool exec_impl(const std::string& p, json& root, const ostd::Color& value) + static bool exec_impl(const std::string& p, json& root, const Color& value) { try { @@ -327,10 +327,10 @@ namespace ostd } catch (...) { return false; } } }; - // ----- stdvec ----------------------------------- - template<> struct Setter + // ----- stdvec ----------------------------------- + template<> struct Setter { - static bool exec_impl(const std::string& p, json& root, const ostd::Vec2& value) + static bool exec_impl(const std::string& p, json& root, const Vec2& value) { try { @@ -346,10 +346,10 @@ namespace ostd } } }; - // ----- ostd::Rectangle ------------------------------------------------- - template<> struct Setter + // ----- Rectangle ------------------------------------------------- + template<> struct Setter { - static bool exec_impl(const std::string& p, json& root, const ostd::Rectangle& value) + static bool exec_impl(const std::string& p, json& root, const Rectangle& value) { try { @@ -409,10 +409,10 @@ namespace ostd } catch (...) { return false; } } }; - // ----- stdvec ----------------------------------- - template<> struct Setter> + // ----- stdvec ----------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const stdvec& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { @@ -428,10 +428,10 @@ namespace ostd } } }; - // ----- stdvec ----------------------------------- - template<> struct Setter> + // ----- stdvec ----------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const stdvec& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { @@ -534,27 +534,27 @@ namespace ostd i32 JsonFile::get_int(const String& name) { return get(name); } f64 JsonFile::get_double(const String& name) { return get(name); } String JsonFile::get_string(const String& name) { return get(name); } - ostd::Color JsonFile::get_color(const String& name) { return get(name); } - ostd::Vec2 JsonFile::get_vec2(const String& name) { return get(name); } - ostd::Rectangle JsonFile::get_rect(const String& name) { return get(name); } + Color JsonFile::get_color(const String& name) { return get(name); } + Vec2 JsonFile::get_vec2(const String& name) { return get(name); } + Rectangle JsonFile::get_rect(const String& name) { return get(name); } stdvec JsonFile::get_int_array(const String& name) { return get>(name); } stdvec JsonFile::get_double_array(const String& name) { return get>(name); } stdvec JsonFile::get_string_array(const String& name) { return get>(name); } - stdvec JsonFile::get_color_array(const String& name) { return get>(name); } - stdvec JsonFile::get_rect_array(const String& name) { return get>(name); } + stdvec JsonFile::get_color_array(const String& name) { return get>(name); } + stdvec JsonFile::get_rect_array(const String& name) { return get>(name); } bool JsonFile::set_bool(const String& name, bool value) { return set(name, value); } bool JsonFile::set_int(const String& name, i32 value) { return set(name, value); } bool JsonFile::set_double(const String& name, f64 value) { return set(name, value); } bool JsonFile::set_string(const String& name, const String& value) { return set(name, value); } - bool JsonFile::set_color(const String& name, const ostd::Color& value) { return set(name, value); } - bool JsonFile::set_vec2(const String& name, const ostd::Vec2& value) { return set(name, value); } - bool JsonFile::set_rect(const String& name, const ostd::Rectangle& value) { return set(name, value); } + bool JsonFile::set_color(const String& name, const Color& value) { return set(name, value); } + bool JsonFile::set_vec2(const String& name, const Vec2& value) { return set(name, value); } + bool JsonFile::set_rect(const String& name, const Rectangle& value) { return set(name, value); } bool JsonFile::set_int_array(const String& name, const stdvec& value) { return set>(name, value); } bool JsonFile::set_double_array(const String& name, const stdvec& value) { return set>(name, value); } bool JsonFile::set_string_array(const String& name, const stdvec& value) { return set>(name, value); } - bool JsonFile::set_color_array(const String& name, const stdvec& value) { return set>(name, value); } - bool JsonFile::set_rect_array(const String& name, const stdvec& value) { return set>(name, value); } + bool JsonFile::set_color_array(const String& name, const stdvec& value) { return set>(name, value); } + bool JsonFile::set_rect_array(const String& name, const stdvec& value) { return set>(name, value); } bool JsonFile::init(const String& filePath, bool writeable, const json* obj) diff --git a/src/ostd/io/Json.hpp b/src/ostd/io/Json.hpp index 59dae30..a158c3e 100644 --- a/src/ostd/io/Json.hpp +++ b/src/ostd/io/Json.hpp @@ -46,28 +46,28 @@ namespace ostd i32 get_int(const String& name); f64 get_double(const String& name); String get_string(const String& name); - ostd::Color get_color(const String& name); - ostd::Vec2 get_vec2(const String& name); - ostd::Rectangle get_rect(const String& name); + Color get_color(const String& name); + Vec2 get_vec2(const String& name); + Rectangle get_rect(const String& name); stdvec get_int_array(const String& name); stdvec get_double_array(const String& name); stdvec get_string_array(const String& name); - stdvec get_color_array(const String& name); - stdvec get_rect_array(const String& name); + stdvec get_color_array(const String& name); + stdvec get_rect_array(const String& name); // --- SETTERS --- bool set_bool(const String& name, bool value); bool set_int(const String& name, i32 value); bool set_double(const String& name, f64 value); bool set_string(const String& name, const String& value); - bool set_color(const String& name, const ostd::Color& value); - bool set_vec2(const String& name, const ostd::Vec2& value); - bool set_rect(const String& name, const ostd::Rectangle& value); + bool set_color(const String& name, const Color& value); + bool set_vec2(const String& name, const Vec2& value); + bool set_rect(const String& name, const Rectangle& value); bool set_int_array(const String& name, const stdvec& value); bool set_double_array(const String& name, const stdvec& value); bool set_string_array(const String& name, const stdvec& value); - bool set_color_array(const String& name, const stdvec& value); - bool set_rect_array(const String& name, const stdvec& value); + bool set_color_array(const String& name, const stdvec& value); + bool set_rect_array(const String& name, const stdvec& value); // --- WRAPPERS --- inline f32 get_float(const String& name) { return cast(get_double(name)); } diff --git a/src/ostd/io/Stylesheet.cpp b/src/ostd/io/Stylesheet.cpp index 92aceae..19f6b97 100644 --- a/src/ostd/io/Stylesheet.cpp +++ b/src/ostd/io/Stylesheet.cpp @@ -252,7 +252,7 @@ custom_continue: else if (value.startsWith("color(") && value.endsWith(")")) { value.substr(6, value.len() - 1).trim(); - set(key, ostd::Color(value), themeID); + set(key, Color(value), themeID); } else if (value.startsWith("vec2(") && value.endsWith(")")) { @@ -267,7 +267,7 @@ custom_continue: return false; vec.push_back(tok.toFloat()); } - set(key, ostd::Vec2(vec[0], vec[1]), themeID); + set(key, Vec2(vec[0], vec[1]), themeID); } else if (value.startsWith("rect(") && value.endsWith(")")) { @@ -282,7 +282,7 @@ custom_continue: return false; vec.push_back(tok.toFloat()); } - set(key, ostd::Rectangle(vec[0], vec[1], vec[2], vec[3]), themeID); + set(key, Rectangle(vec[0], vec[1], vec[2], vec[3]), themeID); } else { @@ -361,11 +361,11 @@ custom_continue: return STR_BOOL(*p); else if (auto p = std::get_if(&v)) return *p; - else if (auto p = std::get_if(&v)) + else if (auto p = std::get_if(&v)) return *p; - else if (auto p = std::get_if(&v)) + else if (auto p = std::get_if(&v)) return *p; - else if (auto p = std::get_if(&v)) + else if (auto p = std::get_if(&v)) return *p; return ""; } diff --git a/src/ostd/io/Stylesheet.hpp b/src/ostd/io/Stylesheet.hpp index afeeee2..d773a4f 100644 --- a/src/ostd/io/Stylesheet.hpp +++ b/src/ostd/io/Stylesheet.hpp @@ -32,7 +32,7 @@ namespace ostd { public: using QualifierList = stdvec>; public: using VariableList = stdumap>; - public: using TypeVariant = std::variant; + public: using TypeVariant = std::variant; public: Stylesheet(void); Stylesheet& clear(void); diff --git a/src/ostd/math/Geometry.hpp b/src/ostd/math/Geometry.hpp index 86d042d..464e966 100755 --- a/src/ostd/math/Geometry.hpp +++ b/src/ostd/math/Geometry.hpp @@ -1,21 +1,21 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + 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 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. + 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 . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once @@ -53,79 +53,79 @@ namespace ostd //==================== Construction ==================== - inline Vec2(f32 xx = 0, f32 yy = 0) : x(xx), y(yy) { } - inline Vec2(const Vec2& v2) { set(v2); } - inline Vec2& set(const Vec2& v2) { x = v2.x; y = v2.y; return *this; } - inline Vec2& set(f32 xx, f32 yy) { x = xx; y = yy; return *this; } + inline Vec2(f32 xx = 0, f32 yy = 0) : x(xx), y(yy) { } + inline Vec2(const Vec2& v2) { set(v2); } + inline Vec2& set(const Vec2& v2) { x = v2.x; y = v2.y; return *this; } + inline Vec2& set(f32 xx, f32 yy) { x = xx; y = yy; return *this; } //====================================================== //================== Static Functions ================== - inline static Vec2 fromAngle(f32 angle) { return Vec2(std::cos(angle), std::sin(angle)); } + inline static Vec2 fromAngle(f32 angle) { return Vec2(std::cos(angle), std::sin(angle)); } inline static f32 angleBetween(const Vec2& v1, const Vec2& v2) { return std::acos(v1.dot(v2) / (v1.mag() * v2.mag())); } //====================================================== //===================== Conversion ===================== - inline Vec2 toIsometric(void) const { return Vec2(x - y, (x + y) / 2.0f); } - inline Vec2 toCartesian(void) const { return Vec2((2 * y + x) / 2.0f, (2 * y - x) / 2.0f); } - inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); } + inline Vec2 toIsometric(void) const { return Vec2(x - y, (x + y) / 2.0f); } + inline Vec2 toCartesian(void) const { return Vec2((2 * y + x) / 2.0f, (2 * y - x) / 2.0f); } + inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); } //====================================================== //===================== Operations ===================== - inline f32 mag(void) const { return std::sqrt((x * x) + (y * y)); } + inline f32 mag(void) const { return std::sqrt((x * x) + (y * y)); } - inline Vec2 add(Vec2 v2) const { return { x + v2.x, y + v2.y }; } - inline Vec2 add(f32 x2, f32 y2) const { return { x + x2, y + y2 }; } - inline Vec2 sub(Vec2 v2) const { return { x - v2.x, y - v2.y }; } - inline Vec2 sub(f32 x2, f32 y2) const { return { x - x2, y - y2 }; } - inline Vec2 mul(f32 scalar) const { return { x * scalar, y * scalar }; } - inline Vec2 div(f32 scalar) const { return { x / scalar, y / scalar }; } + inline Vec2 add(Vec2 v2) const { return { x + v2.x, y + v2.y }; } + inline Vec2 add(f32 x2, f32 y2) const { return { x + x2, y + y2 }; } + inline Vec2 sub(Vec2 v2) const { return { x - v2.x, y - v2.y }; } + inline Vec2 sub(f32 x2, f32 y2) const { return { x - x2, y - y2 }; } + inline Vec2 mul(f32 scalar) const { return { x * scalar, y * scalar }; } + inline Vec2 div(f32 scalar) const { return { x / scalar, y / scalar }; } - inline Vec2 normalize(void) const { f32 m = _zp(mag()); return { x / m, y / m }; } - inline f32 dist(Vec2 v2) const { return std::sqrt((f32)((v2.x - x) * (v2.x - x)) + ((v2.y - y) * (v2.y - y))); } - inline f32 heading(void) const { return std::atan2(y, x); } - inline Vec2 rotate(f32 angle) const { return Vec2(*this).rotate(angle); } - inline f32 dot(const Vec2& v2) const { return (x * v2.x) + (y * v2.y); } - inline f32 cross(const Vec2& v2) const { return (x * v2.y) - (v2.x * y); } + inline Vec2 normalize(void) const { f32 m = _zp(mag()); return { x / m, y / m }; } + inline f32 dist(Vec2 v2) const { return std::sqrt((f32)((v2.x - x) * (v2.x - x)) + ((v2.y - y) * (v2.y - y))); } + inline f32 heading(void) const { return std::atan2(y, x); } + inline Vec2 rotate(f32 angle) const { return Vec2(*this).rotate(angle); } + inline f32 dot(const Vec2& v2) const { return (x * v2.x) + (y * v2.y); } + inline f32 cross(const Vec2& v2) const { return (x * v2.y) - (v2.x * y); } //====================================================== //===================== Modifiers ====================== - inline Vec2& addm(const Vec2& v2) { x += v2.x; y += v2.y; return *this; } - inline Vec2& addm(const f32& x2, const f32& y2) { x += x2; y += y2; return *this; } - inline Vec2& subm(const Vec2& v2) { x -= v2.x; y -= v2.y; return *this; } - inline Vec2& subm(const f32& x2, const f32& y2) { x -= x2; y -= y2; return *this; } - inline Vec2& mulm(const f32& scalar) { x *= scalar; y *= scalar; return *this; } - inline Vec2& divm(const f32& scalar) { x /= scalar; y /= scalar; return *this; } + inline Vec2& addm(const Vec2& v2) { x += v2.x; y += v2.y; return *this; } + inline Vec2& addm(const f32& x2, const f32& y2) { x += x2; y += y2; return *this; } + inline Vec2& subm(const Vec2& v2) { x -= v2.x; y -= v2.y; return *this; } + inline Vec2& subm(const f32& x2, const f32& y2) { x -= x2; y -= y2; return *this; } + inline Vec2& mulm(const f32& scalar) { x *= scalar; y *= scalar; return *this; } + inline Vec2& divm(const f32& scalar) { x /= scalar; y /= scalar; return *this; } - inline Vec2& normalizem(void) { f32 m = _zp(mag()); x /= m; y /= m; return *this; } - inline Vec2& setMag(const f32& mag) { return normalizem().mulm(mag); } - inline Vec2& setHeading(const f32& angle) { f32 m = mag(); set(m * std::cos(angle), m * std::sin(angle)); return *this; } - inline Vec2& rotate(const f32& angle) { return setHeading(heading() + angle); } - inline Vec2& limit(const f32& max) { f32 msq = mag(); msq *= msq; if (msq > (max * max)) divm(std::sqrt(msq)).mulm(max); return *this; } + inline Vec2& normalizem(void) { f32 m = _zp(mag()); x /= m; y /= m; return *this; } + inline Vec2& setMag(const f32& mag) { return normalizem().mulm(mag); } + inline Vec2& setHeading(const f32& angle) { f32 m = mag(); set(m * std::cos(angle), m * std::sin(angle)); return *this; } + inline Vec2& rotate(const f32& angle) { return setHeading(heading() + angle); } + inline Vec2& limit(const f32& max) { f32 msq = mag(); msq *= msq; if (msq > (max * max)) divm(std::sqrt(msq)).mulm(max); return *this; } //====================================================== //===================== Operators ====================== - inline bool operator==(const Vec2& op2 ) const { return (x == op2.x && y == op2.y); } - inline bool operator!=(const Vec2& op2 ) const { return (x != op2.x || y != op2.y); } - inline Vec2 operator-() const { return { -x, -y }; } - inline Vec2 operator+ (const Vec2& op2 ) const { return add(op2); } - inline Vec2 operator- (const Vec2& op2 ) const { return sub(op2); } - inline Vec2 operator+ (const f32& op2) const { return add(op2, op2); } - inline Vec2 operator- (const f32& op2) const { return sub(op2, op2); } - inline Vec2 operator* (const f32& op2) const { return mul(op2); } - inline Vec2 operator/ (const f32& op2) const { return div(op2); } - inline Vec2& operator= (const Vec2& val ) { return set(val); } - inline Vec2& operator= (const f32& val) { return set(val, val); } - inline Vec2& operator+=(const Vec2& op2 ) { return addm(op2); } - inline Vec2& operator-=(const Vec2& op2 ) { return subm(op2); } - inline Vec2& operator+=(const f32& op2) { return addm(op2, op2); } - inline Vec2& operator-=(const f32& op2) { return subm(op2, op2); } - inline Vec2& operator*=(const f32& op2) { return mulm(op2); } - inline Vec2& operator/=(const f32& op2) { return divm(op2); } + inline bool operator==(const Vec2& op2 ) const { return (x == op2.x && y == op2.y); } + inline bool operator!=(const Vec2& op2 ) const { return (x != op2.x || y != op2.y); } + inline Vec2 operator-() const { return { -x, -y }; } + inline Vec2 operator+ (const Vec2& op2 ) const { return add(op2); } + inline Vec2 operator- (const Vec2& op2 ) const { return sub(op2); } + inline Vec2 operator+ (const f32& op2) const { return add(op2, op2); } + inline Vec2 operator- (const f32& op2) const { return sub(op2, op2); } + inline Vec2 operator* (const f32& op2) const { return mul(op2); } + inline Vec2 operator/ (const f32& op2) const { return div(op2); } + inline Vec2& operator= (const Vec2& val ) { return set(val); } + inline Vec2& operator= (const f32& val) { return set(val, val); } + inline Vec2& operator+=(const Vec2& op2 ) { return addm(op2); } + inline Vec2& operator-=(const Vec2& op2 ) { return subm(op2); } + inline Vec2& operator+=(const f32& op2) { return addm(op2, op2); } + inline Vec2& operator-=(const f32& op2) { return subm(op2, op2); } + inline Vec2& operator*=(const f32& op2) { return mulm(op2); } + inline Vec2& operator/=(const f32& op2) { return divm(op2); } //====================================================== private: @@ -143,28 +143,28 @@ namespace ostd public: inline Point(void) : x(0), y(0) { } inline Point(T xx, T yy) : x(xx), y(yy) {} - inline Point(const Vec2& vec) { x = vec.x; y = vec.y; } - inline Point& set(const Point& v2) { x = v2.x; y = v2.y; return *this; } - inline Point& set(f32 xx, f32 yy) { x = xx; y = yy; return *this; } + inline Point(const Vec2& vec) { x = vec.x; y = vec.y; } + inline Point& set(const Point& v2) { x = v2.x; y = v2.y; return *this; } + inline Point& set(f32 xx, f32 yy) { x = xx; y = yy; return *this; } //===================== Operators ====================== - inline bool operator==(const Point& op2 ) const { return (x == op2.x && y == op2.y); } - inline bool operator!=(const Point& op2 ) const { return (x != op2.x || y != op2.y); } - inline operator Vec2() const { return { cast(x), cast(y) }; } - inline Point operator+ (const Point& op2 ) const { return { x + op2.x, y + op2.y }; } - inline Point operator- (const Point& op2 ) const { return { x - op2.x, y - op2.y }; } - inline Point operator+ (const T& op2) const { return { x + op2, y + op2 }; } - inline Point operator- (const T& op2) const { return { x + op2, y + op2 }; } - inline Point operator* (const T& op2) const { return { x * op2, y * op2 }; } - inline Point operator/ (const T& op2) const { return { x / op2, y / op2 }; } - inline Point& operator= (const Point& val ) { return set(val); } - inline Point& operator= (const T& val) { return set(val, val); } - inline Point& operator+=(const Point& op2 ) { x += op2.x; y += op2.y; return *this; } - inline Point& operator-=(const Point& op2 ) { x -= op2.x; y -= op2.y; return *this; } - inline Point& operator+=(const T& op2) { x += op2; y += op2; return *this;; } - inline Point& operator-=(const T& op2) { x -= op2; y -= op2; return *this; } - inline Point& operator*=(const T& op2) { return x *= op2; y *= op2; return *this; } - inline Point& operator/=(const T& op2) { return x /= op2; y /= op2; return *this; } + inline bool operator==(const Point& op2 ) const { return (x == op2.x && y == op2.y); } + inline bool operator!=(const Point& op2 ) const { return (x != op2.x || y != op2.y); } + inline operator Vec2() const { return { cast(x), cast(y) }; } + inline Point operator+ (const Point& op2 ) const { return { x + op2.x, y + op2.y }; } + inline Point operator- (const Point& op2 ) const { return { x - op2.x, y - op2.y }; } + inline Point operator+ (const T& op2) const { return { x + op2, y + op2 }; } + inline Point operator- (const T& op2) const { return { x + op2, y + op2 }; } + inline Point operator* (const T& op2) const { return { x * op2, y * op2 }; } + inline Point operator/ (const T& op2) const { return { x / op2, y / op2 }; } + inline Point& operator= (const Point& val ) { return set(val); } + inline Point& operator= (const T& val) { return set(val, val); } + inline Point& operator+=(const Point& op2 ) { x += op2.x; y += op2.y; return *this; } + inline Point& operator-=(const Point& op2 ) { x -= op2.x; y -= op2.y; return *this; } + inline Point& operator+=(const T& op2) { x += op2; y += op2; return *this;; } + inline Point& operator-=(const T& op2) { x -= op2; y -= op2; return *this; } + inline Point& operator*=(const T& op2) { return x *= op2; y *= op2; return *this; } + inline Point& operator/=(const T& op2) { return x /= op2; y /= op2; return *this; } //====================================================== template inline Point(Point copy) @@ -202,9 +202,9 @@ namespace ostd inline Vec2 yz(void) const { return Vec2(y, z); } inline Vec2 zx(void) const { return Vec2(z, x); } inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(", ").add(z).add(" }"); } - inline bool operator==(const Vec3& op2 ) const { return (x == op2.x && y == op2.y && op2.z == z); } - inline bool operator!=(const Vec3& op2 ) const { return (x != op2.x || y != op2.y || op2.z != z); } - inline Vec3& operator+=(const Vec3& op2 ) { x += op2.x; y += op2.y; z += op2.z; return *this; } + inline bool operator==(const Vec3& op2 ) const { return (x == op2.x && y == op2.y && op2.z == z); } + inline bool operator!=(const Vec3& op2 ) const { return (x != op2.x || y != op2.y || op2.z != z); } + inline Vec3& operator+=(const Vec3& op2 ) { x += op2.x; y += op2.y; z += op2.z; return *this; } f32 x; f32 y; @@ -292,7 +292,7 @@ namespace ostd inline bool operator==(const Rectangle& op2) const { return x == op2.x && y == op2.y && w == op2.w && h == op2.h; } inline bool operator!=(const Rectangle& op2) const { return !(*this == op2); } - inline Rectangle operator+(const Rectangle& op2) const { return { x + op2.x, y + op2.y, w + op2.w, h + op2.h }; } + inline Rectangle operator+(const Rectangle& op2) const { return { x + op2.x, y + op2.y, w + op2.w, h + op2.h }; } inline Rectangle operator-(const Rectangle& op2) const { return { x - op2.x, y - op2.y, w - op2.w, h - op2.h }; } inline Rectangle operator+(f32 s) const { return { x + s, y + s, w + s, h + s }; } inline Rectangle operator-(f32 s) const { return { x - s, y - s, w - s, h - s }; } @@ -475,3 +475,45 @@ namespace ostd typedef Line I16Line; typedef Line I8Line; } + +namespace ogfx +{ + using Vec2 = ostd::Vec2; + using Vec3 = ostd::Vec3; + using Vec4 = ostd::Vec4; + using Triangle = ostd::Triangle; + using Rectangle = ostd::Rectangle; + + using FPoint = ostd::FPoint; + using DPoint = ostd::DPoint; + using UIPoint = ostd::UIPoint; + using UI64Point = ostd::UI64Point; + using UI16Point = ostd::UI16Point; + using UI8Point = ostd::UI8Point; + using IPoint = ostd::IPoint; + using I64Point = ostd::I64Point; + using I16Point = ostd::I16Point; + using I8Point = ostd::I8Point; + + using FRect = ostd::FRect; + using DRect = ostd::DRect; + using UIRect = ostd::UIRect; + using UI64Rect = ostd::UI64Rect; + using UI16Rect = ostd::UI16Rect; + using UI8Rect = ostd::UI8Rect; + using IRect = ostd::IRect; + using I64Rect = ostd::I64Rect; + using I16Rect = ostd::I16Rect; + using I8Rect = ostd::I8Rect; + + using FLine = ostd::FLine; + using DLine = ostd::DLine; + using UILine = ostd::UILine; + using UI64Line = ostd::UI64Line; + using UI16Line = ostd::UI16Line; + using UI8Line = ostd::UI8Line; + using ILine = ostd::ILine; + using I64Line = ostd::I64Line; + using I16Line = ostd::I16Line; + using I8Line = ostd::I8Line; +} diff --git a/src/ostd/math/Spline.cpp b/src/ostd/math/Spline.cpp index ae2b4ab..f6202f1 100755 --- a/src/ostd/math/Spline.cpp +++ b/src/ostd/math/Spline.cpp @@ -19,7 +19,7 @@ namespace ostd // ogfx::MouseEventData& evt = cast(signal.userData); // for (auto& node : m_points) // { - // if (ostd::Rectangle(node.position.x - 20, node.position.y - 20, 40, 40).contains((f32)evt.position_x, (f32)evt.position_y)) + // if (Rectangle(node.position.x - 20, node.position.y - 20, 40, 40).contains((f32)evt.position_x, (f32)evt.position_y)) // { // m_selectedNode = &node; // return; diff --git a/src/test/GraphicsWindowTest.cpp b/src/test/GraphicsWindowTest.cpp index a2cb886..320b836 100644 --- a/src/test/GraphicsWindowTest.cpp +++ b/src/test/GraphicsWindowTest.cpp @@ -50,7 +50,7 @@ class Window : public ogfx::GraphicsWindow return rnd::getVec2({ 0, (f32)getWindowWidth() }, { 0, (f32)getWindowHeight() }); }; for (i32 i = 0; i < 10000; i++) - m_gfx.drawLine({ l_rndPoint(), l_rndPoint() }, ostd::Colors::Crimson, 10); + m_gfx.drawLine({ l_rndPoint(), l_rndPoint() }, Colors::Crimson, 10); m_gfx.endFrame(); } diff --git a/src/test/GuiTest.cpp b/src/test/GuiTest.cpp index da47a18..0d0b20e 100644 --- a/src/test/GuiTest.cpp +++ b/src/test/GuiTest.cpp @@ -122,12 +122,12 @@ class Window : public ogfx::gui::Window }); m_panel1.addChild(m_label2); - m_label1.addThemeOverride("@:pressed.label.textColor", ostd::Colors::Crimson); + m_label1.addThemeOverride("@:pressed.label.textColor", Colors::Crimson); m_theme.loadFromFile("./testTheme.txt", true, getDefaultStylesheetVariableList()); m_label2.addThemeOverride("@:hover.label.showBackground", true); - m_label2.addThemeOverride("@:hover.label.backgroundColor", ostd::Colors::DarkGreen); + m_label2.addThemeOverride("@:hover.label.backgroundColor", Colors::DarkGreen); m_label3.setPosition(0, 30); m_label3.setText("Bella!"); @@ -153,7 +153,7 @@ class Window : public ogfx::gui::Window void onRedraw(ogfx::BasicRenderer2D& gfx) override { gfx.drawAnimation(m_anim, { 200, 200 }); - wout().xy(100, 100).fg(ostd::Colors::Crimson).p("CIAO BELLA").resetColors(); + wout().xy(100, 100).fg(Colors::Crimson).p("CIAO BELLA").resetColors(); } void onFixedUpdate(void) override