diff --git a/other/TODO.txt b/other/TODO.txt index 5319a81..79f8df0 100644 --- a/other/TODO.txt +++ b/other/TODO.txt @@ -22,6 +22,7 @@ ***Implement global scale (probably query desktop scale and adjust accordingly) Add theme caching Implement cursors in Stylesheet +FIX: Window getting exponentially bigger when Desktop scale changes diff --git a/src/ogfx/render/BasicRenderer.hpp b/src/ogfx/render/BasicRenderer.hpp index 69d6734..3b7adb1 100644 --- a/src/ogfx/render/BasicRenderer.hpp +++ b/src/ogfx/render/BasicRenderer.hpp @@ -83,13 +83,11 @@ namespace ogfx 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 fillGradientRect(const Rectangle& rect, ColorGradient& gradient); - 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 FLine& line, const Color& color, i32 thickness = 1, bool rounded = true); - 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); diff --git a/src/ostd/data/BaseObject.hpp b/src/ostd/data/BaseObject.hpp index 231fa4a..1b03909 100755 --- a/src/ostd/data/BaseObject.hpp +++ b/src/ostd/data/BaseObject.hpp @@ -1,26 +1,25 @@ /* - 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 -#include #include #include diff --git a/src/ostd/data/Color.hpp b/src/ostd/data/Color.hpp index bd30835..b044179 100755 --- a/src/ostd/data/Color.hpp +++ b/src/ostd/data/Color.hpp @@ -112,6 +112,21 @@ namespace ostd inline void setAngleRad(f32 angle_radians) { m_angleDeg = RAD_TO_DEG(angle_radians); } inline f32 getAngleDeg(void) const { return m_angleDeg; } inline f32 getAngleRad(void) const { return DEG_TO_RAD(m_angleDeg); } + inline void reverse(void) { std::reverse(m_colors.begin(), m_colors.end()); std::reverse(m_weights.begin(), m_weights.end()); } + inline bool isInvalid(void) const override { return (m_colors.size() != m_weights.size() + 1) || (m_colors.size() == 0 || m_weights.size() == 0); } + inline String toString(void) const override + { + if (isInvalid()) + return "{ Invalid Color Gradient }"; + String str = ""; + for (i32 i = 0; i < m_colors.size(); i++) + { + if (i > 0) + str.add(m_weights[i - 1], 2).add(", "); + str.add(m_colors[i].hexString(true, "#")).add(" "); + } + return str.trim(); + } private: stdvec m_colors; diff --git a/src/ostd/io/Stylesheet.cpp b/src/ostd/io/Stylesheet.cpp index 6381e68..958632b 100644 --- a/src/ostd/io/Stylesheet.cpp +++ b/src/ostd/io/Stylesheet.cpp @@ -242,7 +242,6 @@ namespace ostd if (key == "") return false; String themeID = ""; - auto l_parseColor = [this](const String& _value) -> String { String value = _value.new_toLower().trim(); if (value.startsWith("color(") && value.endsWith(")")) @@ -258,6 +257,18 @@ namespace ostd } return ""; }; + auto l_isColorGradientValue = [this](const String& _value) -> bool { + String value = _value.new_toLower().trim(); + if (value.startsWith("gradienth(") && value.endsWith(")")) + return true; + if (value.startsWith("w_gradienth(") && value.endsWith(")")) + return true; + if (value.startsWith("gradientv(") && value.endsWith(")")) + return true; + if (value.startsWith("w_gradientv(") && value.endsWith(")")) + return true; + return false; + }; if (key.startsWith("@")) { @@ -281,6 +292,13 @@ namespace ostd { set(key, Color(v), themeID); } + else if (l_isColorGradientValue(value)) + { + ColorGradient grad = parseColorGradient(value); + if (grad.isInvalid()) + return false; + set(key, grad, themeID); + } else if (value.startsWith("vec2(") && value.endsWith(")")) { value.substr(5, value.len() - 1).trim(); @@ -401,6 +419,45 @@ namespace ostd return newLines; } + ColorGradient parseColorGradient(const String& _value) + { + String value = _value.new_toLower().trim(); + ColorGradient grad; + f32 angle = 0.0f; + bool weighted = false; + String gradientFunc = value.new_substr(0, value.indexOf("(")).trim(); + String gradientVal = value.substr(value.indexOf("(") + 1, value.indexOf(")")).trim(); + + if (gradientVal == "" || !gradientVal.contains(",")) + return grad; + + weighted = gradientFunc.startsWith("w_"); + if (gradientFunc.endsWith("v")) + angle = ColorGradient::VerticalDeg; + else if (gradientFunc.endsWith("h")) + angle = ColorGradient::HorizontalDeg; + else + return grad; + + auto tokens = gradientVal.tokenize(","); + + bool is_color = true; + for (auto& token : tokens) + { + if (is_color) + { + + } + else + { + + } + is_color = !is_color; + } + + return grad; + } + void Stylesheet::debugPrint(void) { for (const auto&[key, value] : m_values) @@ -426,6 +483,8 @@ namespace ostd return *p; else if (auto p = std::get_if(&v)) return *p; + 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 6bf8cf4..1e3207c 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); @@ -62,6 +62,7 @@ namespace ostd bool parseThemeFileLine(const String& line, const VariableList& variables, bool exitCondition = false); String parseGroupSelector(const String& rawSelector) const; stdvec parseGroup(const String& selector, const stdvec& group); + ColorGradient parseColorGradient(const String& _value); private: stdumap m_values; diff --git a/src/test/GuiTest.cpp b/src/test/GuiTest.cpp index f8239d9..ad3e85e 100644 --- a/src/test/GuiTest.cpp +++ b/src/test/GuiTest.cpp @@ -108,12 +108,6 @@ class Window : public ogfx::gui::Window void onRedraw(ogfx::BasicRenderer2D& gfx) override { // gfx.drawAnimation(m_anim, { 200, 200 }); - // static f32 angle = 0.0f; - // angle += 0.5f; // degrees per frame, adjust to taste - // if (angle >= 360.0f) angle = 0.0f; - // m_grad.setAngleDeg(angle); - - // gfx.fillGradientRect({ 200, 200, 300, 300 }, m_grad); } void onFixedUpdate(void) override @@ -133,17 +127,6 @@ class Window : public ogfx::gui::Window ostd::Stylesheet m_theme; ogfx::Animation m_anim; ogfx::Image m_img; - ogfx::ColorGradient m_grad { { - { 255, 0, 0 }, // red - { 255, 165, 0 }, // orange - { 255, 255, 0 }, // yellow - { 0, 255, 0 }, // green - { 0, 0, 255 }, // blue - { 148, 0, 211 }, // violet - { 255, 0, 0 }, // red again to loop cleanly - }, - { 1, 1, 1, 1, 1, 1 }, // equal weights, gets normalized - }; }; i32 main(i32 argc, char** argv)