Sync push

This commit is contained in:
OmniaX-Dev 2026-04-17 06:44:55 +02:00
parent d521c609b3
commit 7e37210e82
7 changed files with 91 additions and 35 deletions

View file

@ -22,6 +22,7 @@
***Implement global scale (probably query desktop scale and adjust accordingly) ***Implement global scale (probably query desktop scale and adjust accordingly)
Add theme caching Add theme caching
Implement cursors in Stylesheet Implement cursors in Stylesheet
FIX: Window getting exponentially bigger when Desktop scale changes

View file

@ -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 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 drawAnimation(const Animation& anim, const Vec2& position, const Vec2& size = { 0, 0 });
void fillGradientRect(const Rectangle& rect, ColorGradient& gradient); 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 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 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 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 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 Rectangle& rect, const Color& color, i32 thickness = 1);
void drawRect(const Vec2& center, const Vec2& size, 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 Vec2& center, const Vec2& size, const Color& color, f32 radius, i32 thickness = 1);

View file

@ -1,26 +1,25 @@
/* /*
OmniaFramework - A collection of useful functionality OmniaFramework - A collection of useful functionality
Copyright (C) 2025 OmniaX-Dev 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 OmniaFramework is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
OmniaFramework is distributed in the hope that it will be useful, OmniaFramework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>. along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <cstdint>
#include <ostd/string/String.hpp> #include <ostd/string/String.hpp>
#include <functional> #include <functional>

View file

@ -112,6 +112,21 @@ namespace ostd
inline void setAngleRad(f32 angle_radians) { m_angleDeg = RAD_TO_DEG(angle_radians); } inline void setAngleRad(f32 angle_radians) { m_angleDeg = RAD_TO_DEG(angle_radians); }
inline f32 getAngleDeg(void) const { return m_angleDeg; } inline f32 getAngleDeg(void) const { return m_angleDeg; }
inline f32 getAngleRad(void) const { return DEG_TO_RAD(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: private:
stdvec<Color> m_colors; stdvec<Color> m_colors;

View file

@ -242,7 +242,6 @@ namespace ostd
if (key == "") if (key == "")
return false; return false;
String themeID = ""; String themeID = "";
auto l_parseColor = [this](const String& _value) -> String { auto l_parseColor = [this](const String& _value) -> String {
String value = _value.new_toLower().trim(); String value = _value.new_toLower().trim();
if (value.startsWith("color(") && value.endsWith(")")) if (value.startsWith("color(") && value.endsWith(")"))
@ -258,6 +257,18 @@ namespace ostd
} }
return ""; 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("@")) if (key.startsWith("@"))
{ {
@ -281,6 +292,13 @@ namespace ostd
{ {
set(key, Color(v), themeID); 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(")")) else if (value.startsWith("vec2(") && value.endsWith(")"))
{ {
value.substr(5, value.len() - 1).trim(); value.substr(5, value.len() - 1).trim();
@ -401,6 +419,45 @@ namespace ostd
return newLines; 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) void Stylesheet::debugPrint(void)
{ {
for (const auto&[key, value] : m_values) for (const auto&[key, value] : m_values)
@ -426,6 +483,8 @@ namespace ostd
return *p; return *p;
else if (auto p = std::get_if<Vec2>(&v)) else if (auto p = std::get_if<Vec2>(&v))
return *p; return *p;
else if (auto p = std::get_if<ColorGradient>(&v))
return *p;
return ""; return "";
} }
} }

View file

@ -32,7 +32,7 @@ namespace ostd
{ {
public: using QualifierList = stdvec<std::pair<const String, bool>>; public: using QualifierList = stdvec<std::pair<const String, bool>>;
public: using VariableList = stdumap<String, std::pair<String, bool>>; public: using VariableList = stdumap<String, std::pair<String, bool>>;
public: using TypeVariant = std::variant<i32, f32, bool, String, Color, Rectangle, Vec2>; public: using TypeVariant = std::variant<i32, f32, bool, String, Color, Rectangle, Vec2, ColorGradient>;
public: public:
Stylesheet(void); Stylesheet(void);
Stylesheet& clear(void); Stylesheet& clear(void);
@ -62,6 +62,7 @@ namespace ostd
bool parseThemeFileLine(const String& line, const VariableList& variables, bool exitCondition = false); bool parseThemeFileLine(const String& line, const VariableList& variables, bool exitCondition = false);
String parseGroupSelector(const String& rawSelector) const; String parseGroupSelector(const String& rawSelector) const;
stdvec<String> parseGroup(const String& selector, const stdvec<String>& group); stdvec<String> parseGroup(const String& selector, const stdvec<String>& group);
ColorGradient parseColorGradient(const String& _value);
private: private:
stdumap<String, TypeVariant> m_values; stdumap<String, TypeVariant> m_values;

View file

@ -108,12 +108,6 @@ class Window : public ogfx::gui::Window
void onRedraw(ogfx::BasicRenderer2D& gfx) override void onRedraw(ogfx::BasicRenderer2D& gfx) override
{ {
// gfx.drawAnimation(m_anim, { 200, 200 }); // 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 void onFixedUpdate(void) override
@ -133,17 +127,6 @@ class Window : public ogfx::gui::Window
ostd::Stylesheet m_theme; ostd::Stylesheet m_theme;
ogfx::Animation m_anim; ogfx::Animation m_anim;
ogfx::Image m_img; 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) i32 main(i32 argc, char** argv)