introduce ColorInt
diff --git a/include/rive/math/color.hpp b/include/rive/math/color.hpp index 2cd3676..94bf314 100644 --- a/include/rive/math/color.hpp +++ b/include/rive/math/color.hpp
@@ -89,4 +89,4 @@ float a() const { return m_Buffer[3]; } }; } // namespace rive -#endif \ No newline at end of file +#endif
diff --git a/include/rive/renderer.hpp b/include/rive/renderer.hpp index 9992de3..db35ebb 100644 --- a/include/rive/renderer.hpp +++ b/include/rive/renderer.hpp
@@ -1,6 +1,7 @@ #ifndef _RIVE_RENDERER_HPP_ #define _RIVE_RENDERER_HPP_ +#include "rive/shapes/paint/color.hpp" #include "rive/command_path.hpp" #include "rive/layout.hpp" #include "rive/math/aabb.hpp" @@ -26,7 +27,7 @@ { public: virtual void style(RenderPaintStyle style) = 0; - virtual void color(unsigned int value) = 0; + virtual void color(ColorInt value) = 0; virtual void thickness(float value) = 0; virtual void join(StrokeJoin value) = 0; virtual void cap(StrokeCap value) = 0; @@ -34,7 +35,7 @@ virtual void linearGradient(float sx, float sy, float ex, float ey) = 0; virtual void radialGradient(float sx, float sy, float ex, float ey) = 0; - virtual void addStop(unsigned int color, float stop) = 0; + virtual void addStop(ColorInt color, float stop) = 0; virtual void completeGradient() = 0; virtual ~RenderPaint() {} }; @@ -172,4 +173,4 @@ extern RenderPaint* makeRenderPaint(); extern RenderImage* makeRenderImage(); } // namespace rive -#endif \ No newline at end of file +#endif
diff --git a/include/rive/shapes/paint/color.hpp b/include/rive/shapes/paint/color.hpp index 298f714..740c7ba 100644 --- a/include/rive/shapes/paint/color.hpp +++ b/include/rive/shapes/paint/color.hpp
@@ -1,27 +1,30 @@ #ifndef _RIVE_PAINT_COLOR_HPP_ #define _RIVE_PAINT_COLOR_HPP_ #include <cmath> +#include <cstdint> namespace rive { - unsigned int colorARGB(int a, int r, int g, int b); + using ColorInt = uint32_t; - unsigned int colorRed(unsigned int value); + ColorInt colorARGB(int a, int r, int g, int b); - unsigned int colorGreen(unsigned int value); + unsigned int colorRed(ColorInt value); - unsigned int colorBlue(unsigned int value); + unsigned int colorGreen(ColorInt value); - unsigned int colorAlpha(unsigned int value); + unsigned int colorBlue(ColorInt value); + + unsigned int colorAlpha(ColorInt value); float colorOpacity(unsigned int value); - unsigned int colorWithAlpha(unsigned int value, unsigned int a); + ColorInt colorWithAlpha(ColorInt value, unsigned int a); - unsigned int colorWithOpacity(unsigned int value, float opacity); + ColorInt colorWithOpacity(ColorInt value, float opacity); - unsigned int colorModulateOpacity(unsigned int value, float opacity); + ColorInt colorModulateOpacity(ColorInt value, float opacity); - unsigned int colorLerp(unsigned int from, unsigned int to, float mix); + ColorInt colorLerp(ColorInt from, ColorInt to, float mix); } // namespace rive #endif
diff --git a/src/shapes/paint/color.cpp b/src/shapes/paint/color.cpp index 6de2d06..06fbd52 100644 --- a/src/shapes/paint/color.cpp +++ b/src/shapes/paint/color.cpp
@@ -10,43 +10,43 @@ 0xFFFFFFFF; } - unsigned int colorRed(unsigned int value) + unsigned int colorRed(ColorInt value) { return (0x00ff0000 & value) >> 16; } - unsigned int colorGreen(unsigned int value) + unsigned int colorGreen(ColorInt value) { return (0x0000ff00 & value) >> 8; } - unsigned int colorBlue(unsigned int value) + unsigned int colorBlue(ColorInt value) { return (0x000000ff & value) >> 0; } - unsigned int colorAlpha(unsigned int value) + unsigned int colorAlpha(ColorInt value) { return (0xff000000 & value) >> 24; } - float colorOpacity(unsigned int value) + float colorOpacity(ColorInt value) { return (float)colorAlpha(value) / 0xFF; } - unsigned int colorWithAlpha(unsigned int value, unsigned int a) + ColorInt colorWithAlpha(ColorInt value, unsigned int a) { return colorARGB( a, colorRed(value), colorGreen(value), colorBlue(value)); } - unsigned int colorWithOpacity(unsigned int value, float opacity) + ColorInt colorWithOpacity(ColorInt value, float opacity) { return colorWithAlpha(value, std::round(255.0 * opacity)); } - unsigned int colorModulateOpacity(unsigned int value, float opacity) + ColorInt colorModulateOpacity(ColorInt value, float opacity) { return colorWithAlpha( value, std::round(255.0f * colorOpacity(value) * opacity)); @@ -57,11 +57,11 @@ return a * (1.0f - mix) + b * mix; } - unsigned int colorLerp(unsigned int from, unsigned int to, float mix) + ColorInt colorLerp(ColorInt from, ColorInt to, float mix) { return colorARGB(lerp(colorAlpha(from), colorAlpha(to), mix), lerp(colorRed(from), colorRed(to), mix), lerp(colorGreen(from), colorGreen(to), mix), lerp(colorBlue(from), colorBlue(to), mix)); } -} // namespace rive \ No newline at end of file +} // namespace rive
diff --git a/src/shapes/paint/linear_gradient.cpp b/src/shapes/paint/linear_gradient.cpp index 1b36f39..77ae49d 100644 --- a/src/shapes/paint/linear_gradient.cpp +++ b/src/shapes/paint/linear_gradient.cpp
@@ -132,8 +132,7 @@ return true; } for (const auto stop : m_Stops) { - unsigned alpha = stop->colorValue() >> 24; // helper for this? - if (alpha != 0xFF) { + if (colorAlpha(stop->colorValue()) != 0xFF) { return true; } }
diff --git a/src/shapes/paint/solid_color.cpp b/src/shapes/paint/solid_color.cpp index 6278ebc..377888e 100644 --- a/src/shapes/paint/solid_color.cpp +++ b/src/shapes/paint/solid_color.cpp
@@ -27,12 +27,11 @@ return; } renderPaint()->color( - colorModulateOpacity((unsigned int)colorValue(), renderOpacity())); + colorModulateOpacity(colorValue(), renderOpacity())); } void SolidColor::colorValueChanged() { renderOpacityChanged(); } bool SolidColor::internalIsTranslucent() const { - unsigned alpha = colorValue() >> 24; - return alpha != 0xFF; + return colorAlpha(colorValue()) != 0xFF; }