Sync push
This commit is contained in:
parent
d521c609b3
commit
7e37210e82
7 changed files with 91 additions and 35 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <ostd/string/String.hpp>
|
||||
#include <functional>
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Color> m_colors;
|
||||
|
|
|
|||
|
|
@ -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<Vec2>(&v))
|
||||
return *p;
|
||||
else if (auto p = std::get_if<ColorGradient>(&v))
|
||||
return *p;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace ostd
|
|||
{
|
||||
public: using QualifierList = stdvec<std::pair<const 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:
|
||||
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<String> parseGroup(const String& selector, const stdvec<String>& group);
|
||||
ColorGradient parseColorGradient(const String& _value);
|
||||
|
||||
private:
|
||||
stdumap<String, TypeVariant> m_values;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue