From 58ab8f3636fe246ee5532fdb5bbacfa9eba79980 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Mon, 14 Jul 2025 00:23:45 +0200 Subject: [PATCH] Make some values scriptable color radius color left width color right width color top width color bottom width font shadow displacement x font shadow displacement y font shadow blur --- doc/type/font.txt | 6 +++--- doc/type/style.txt | 4 ++-- src/data/field/color.cpp | 18 +++++++++++++++++- src/data/field/color.hpp | 16 +++++++++------- src/data/font.cpp | 22 +++++++++++++++------- src/data/font.hpp | 7 ++++--- src/util/rotation.cpp | 2 +- 7 files changed, 51 insertions(+), 24 deletions(-) diff --git a/doc/type/font.txt b/doc/type/font.txt index ea3c24f3..5296c62a 100644 --- a/doc/type/font.txt +++ b/doc/type/font.txt @@ -16,9 +16,9 @@ A reference to a normal [[type:font]] for drawing text. | @underline@ [[type:scriptable]] [[type:boolean]] @false@ Should the font be underlined? | @color@ [[type:scriptable]] [[type:color]] @rgb(0,0,0)@ What color should text be drawn in? | @shadow color@ [[type:scriptable]] [[type:color]] @"transparent"@ Color for a shadow below the text. -| @shadow displacement x@ [[type:double]] @0@ Relative position of the shadow in pixels. -| @shadow displacement y@ [[type:double]] @0@ ^^^ -| @shadow blur@ [[type:double]] @0@ How much should the shadow be blurred? +| @shadow displacement x@ [[type:scriptable]] [[type:double]] @0@ Relative position of the shadow in pixels. +| @shadow displacement y@ [[type:scriptable]] [[type:double]] @0@ ^^^ +| @shadow blur@ [[type:scriptable]] [[type:double]] @0@ How much should the shadow be blurred? | @separator color@ [[type:color]] @rgba(0,0,0,128)@ Color for @@ tags inserted by the [[fun:combined_editor]] function. --Example-- diff --git a/doc/type/style.txt b/doc/type/style.txt index 0907c6e4..114dfb2c 100644 --- a/doc/type/style.txt +++ b/doc/type/style.txt @@ -140,8 +140,8 @@ The rest of the properties depend on the type of [[type:field]] this style is fo | ^^^ @font@ [[type:font]] Font to use for rendering text. ! <<< <<< <<< <<< -| @"color"@ @radius@ [[type:double]] @0@ Radius of rounded corners for the box in pixels. -| ^^^ @left width@ [[type:double]] ∞ Draw only this many pixels from the side, creating a box with a hole in it, or a card border. +| @"color"@ @radius@ [[type:scriptable]] [[type:double]] @0@ Radius of rounded corners for the box in pixels. +| ^^^ @left width@ [[type:scriptable]] [[type:double]] ∞ Draw only this many pixels from the side, creating a box with a hole in it, or a card border. | ^^^ @right width@ ^^^ ^^^ ^^^ | ^^^ @top width@ ^^^ ^^^ ^^^ | ^^^ @bottom width@ ^^^ ^^^ ^^^ diff --git a/src/data/field/color.cpp b/src/data/field/color.cpp index 4022f282..7b17e1e1 100644 --- a/src/data/field/color.cpp +++ b/src/data/field/color.cpp @@ -74,9 +74,25 @@ IMPLEMENT_REFLECTION(ColorStyle) { } int ColorStyle::update(Context& ctx) { - return Style::update(ctx); + int changed = 0; + changed |= radius .update(ctx) * CHANGE_OTHER; + changed |= left_width .update(ctx) * CHANGE_OTHER; + changed |= right_width .update(ctx) * CHANGE_OTHER; + changed |= top_width .update(ctx) * CHANGE_OTHER; + changed |= bottom_width.update(ctx) * CHANGE_OTHER; + changed |= Style::update(ctx); + return changed; } +void ColorStyle::checkContentDependencies(Context& ctx, const Dependency& dep) const { + radius .initDependencies(ctx, dep); + left_width .initDependencies(ctx, dep); + right_width .initDependencies(ctx, dep); + top_width .initDependencies(ctx, dep); + bottom_width.initDependencies(ctx, dep); + Style::checkContentDependencies(ctx, dep); +} + // ----------------------------------------------------------------------------- : ColorValue ColorValue::ColorValue(const ColorFieldP& field) diff --git a/src/data/field/color.hpp b/src/data/field/color.hpp index ef206cb9..025664de 100644 --- a/src/data/field/color.hpp +++ b/src/data/field/color.hpp @@ -56,14 +56,16 @@ public: ColorStyle(const ColorFieldP& field); DECLARE_STYLE_TYPE(Color); - double radius; ///< Radius of round corners - double left_width; ///< Width of the colored region on the left side - double right_width; ///< Width of the colored region on the right side - double top_width; ///< Width of the colored region on the top side - double bottom_width; ///< Width of the colored region on the bottom side - ImageCombine combine; ///< How to combine image with the background + Scriptable radius; ///< Radius of round corners + Scriptable left_width; ///< Width of the colored region on the left side + Scriptable right_width; ///< Width of the colored region on the right side + Scriptable top_width; ///< Width of the colored region on the top side + Scriptable bottom_width; ///< Width of the colored region on the bottom side + ImageCombine combine; ///< How to combine image with the background - int update(Context&) override; + int update(Context&) override; + + void checkContentDependencies(Context&, const Dependency&) const override; }; // ----------------------------------------------------------------------------- : ColorValue diff --git a/src/data/font.cpp b/src/data/font.cpp index 89482ea7..82be6083 100644 --- a/src/data/font.cpp +++ b/src/data/font.cpp @@ -21,7 +21,8 @@ Font::Font() , scale_down_to(100000) , max_stretch(1.0) , color(Color(0,0,0)) - , shadow_displacement(0,0) + , shadow_displacement_x(0) + , shadow_displacement_y(0) , shadow_blur(0) , separator_color(Color(0,0,0,128)) , flags(FONT_NORMAL) @@ -89,7 +90,10 @@ bool Font::update(Context& ctx) { changes |= style .update(ctx); changes |= underline .update(ctx); changes |= color .update(ctx); - changes |= shadow_color.update(ctx); + changes |= shadow_color .update(ctx); + changes |= shadow_displacement_x.update(ctx); + changes |= shadow_displacement_y.update(ctx); + changes |= shadow_blur .update(ctx); flags = (flags & ~FONT_BOLD & ~FONT_ITALIC) | (weight() == _("bold") ? FONT_BOLD : FONT_NORMAL) | (style() == _("italic") ? FONT_ITALIC : FONT_NORMAL); @@ -103,7 +107,10 @@ void Font::initDependencies(Context& ctx, const Dependency& dep) const { style .initDependencies(ctx, dep); underline .initDependencies(ctx, dep); color .initDependencies(ctx, dep); - shadow_color.initDependencies(ctx, dep); + shadow_color .initDependencies(ctx, dep); + shadow_displacement_x.initDependencies(ctx, dep); + shadow_displacement_y.initDependencies(ctx, dep); + shadow_blur .initDependencies(ctx, dep); } FontP Font::make(int add_flags, bool add_underline, String const* other_family, Color const* other_color, double const* other_size) const { @@ -121,8 +128,9 @@ FontP Font::make(int add_flags, bool add_underline, String const* other_family, } if (add_flags & FONT_SOFT) { f->color = f->separator_color; - f->shadow_displacement = RealSize(0,0); // no shadow - } + f->shadow_displacement_x = 0; // no shadow + f->shadow_displacement_y = 0; // no shadow + } if (add_underline) { f->underline = true; } @@ -185,8 +193,8 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Font) { REFLECT(color); REFLECT(scale_down_to); REFLECT(max_stretch); - REFLECT_N("shadow_displacement_x", shadow_displacement.width); - REFLECT_N("shadow_displacement_y", shadow_displacement.height); + REFLECT(shadow_displacement_x); + REFLECT(shadow_displacement_y); REFLECT(shadow_color); REFLECT(shadow_blur); REFLECT(separator_color); diff --git a/src/data/font.hpp b/src/data/font.hpp index 49283d54..151202fa 100644 --- a/src/data/font.hpp +++ b/src/data/font.hpp @@ -42,8 +42,9 @@ public: double max_stretch; ///< How much should the font be stretched before scaling down? Scriptable color; ///< Color to use Scriptable shadow_color; ///< Color for shadow - RealSize shadow_displacement; ///< Position of the shadow - double shadow_blur; ///< Blur radius of the shadow + Scriptable shadow_displacement_x;///< Position of the shadow + Scriptable shadow_displacement_y;///< Position of the shadow + Scriptable shadow_blur; ///< Blur radius of the shadow Color separator_color; ///< Color for text int flags; ///< FontFlags for this font @@ -61,7 +62,7 @@ public: /// Does this font have a shadow? inline bool hasShadow() const { - return shadow_displacement.width != 0 || shadow_displacement.height != 0; + return shadow_displacement_x != 0.0 || shadow_displacement_y != 0.0; } /// Add style to a font, and optionally change the font family, color and size diff --git a/src/util/rotation.cpp b/src/util/rotation.cpp index 62dede58..199f38d7 100644 --- a/src/util/rotation.cpp +++ b/src/util/rotation.cpp @@ -219,7 +219,7 @@ void RotatedDC::DrawText(const String& text, const RealPoint& pos, Color color, } void RotatedDC::DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale, double stretch) { - DrawText(text, pos + font.shadow_displacement * scale, font.shadow_color, font.shadow_blur * scale, 1, stretch); + DrawText(text, pos + RealSize(font.shadow_displacement_x, font.shadow_displacement_y) * scale, font.shadow_color, font.shadow_blur * scale, 1, stretch); DrawText(text, pos, font.color, 0, 1, stretch); }