From 0f34fd437efb936ef29ac91186321aa7251fbfb1 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 23 May 2023 11:22:33 +0200 Subject: Massive changes in initial port away from Qt. --- colorscale.h | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'colorscale.h') diff --git a/colorscale.h b/colorscale.h index ffc3439..c50deb0 100644 --- a/colorscale.h +++ b/colorscale.h @@ -2,20 +2,41 @@ #define COLORSCALE_H #include +#include -#include -#include +class Color +{ +public: + Color(); + Color(int r, int g, int b); + Color(int r, int g, int b, int a); + Color(float r, float g, float b); + Color(float r, float g, float b, float a); + + void getRgbF(float *r, float *g, float *b) const; + void getRgbF(float *r, float *g, float *b, float *a) const; + + void setRgb(int r, int g, int b); + void setRgb(int r, int g, int b, int a); + + void setRgbF(float r, float g, float b); + void setRgbF(float r, float g, float b, float a); + + float r, g, b, a; +}; + +using QColor = Color; class ColorScale { public: - ColorScale(const QColor &firstColor, const QColor &lastColor); - ColorScale(std::initializer_list colors); - ColorScale(const QList &colors); + ColorScale(const Color &firstColor, const Color &lastColor); + ColorScale(std::initializer_list colors); + ColorScale(const std::vector &colors); virtual ~ColorScale(); - QColor operator ()(float t) const { return color(t); } - virtual QColor color(float t) const; + Color operator ()(float t) const { return color(t); } + virtual Color color(float t) const; void setExtents(float min, float max); float min() const { return m_min; } @@ -25,11 +46,11 @@ public: template void sample(int samples, OutputIterator it) const; - static QColor lerp(const QColor &c1, const QColor &c2, float _t); + static Color lerp(const Color &c1, const Color &c2, float _t); protected: float m_min, m_max; - QList m_colors; + std::vector m_colors; }; template @@ -40,7 +61,7 @@ void ColorScale::sample(int samples, OutputIterator it) const } float step = (max() - min()) / samples; - qreal r, g, b; + float r, g, b; for (float t = min(); samples-- > 0; t += step) { color(t).getRgbF(&r, &g, &b); *it++ = r; -- cgit v1.2.3