aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--colorscale.cpp11
-rw-r--r--colorscale.h10
2 files changed, 13 insertions, 8 deletions
diff --git a/colorscale.cpp b/colorscale.cpp
index 85c036d..e4e2063 100644
--- a/colorscale.cpp
+++ b/colorscale.cpp
@@ -22,7 +22,7 @@ ColorScale::~ColorScale()
{
}
-void ColorScale::setExtents(qreal min, qreal max)
+void ColorScale::setExtents(float min, float max)
{
if (min >= max) {
return;
@@ -32,10 +32,11 @@ void ColorScale::setExtents(qreal min, qreal max)
m_max = max;
}
-static QColor lerp(const QColor &c1, const QColor &c2, qreal t)
+static QColor lerp(const QColor &c1, const QColor &c2, float _t)
{
qreal r1, g1, b1, a1;
qreal r2, g2, b2, a2;
+ qreal t = _t;
c1.getRgbF(&r1, &g1, &b1, &a1);
c2.getRgbF(&r2, &g2, &b2, &a2);
@@ -47,7 +48,7 @@ static QColor lerp(const QColor &c1, const QColor &c2, qreal t)
return color;
}
-QColor ColorScale::color(qreal t) const
+QColor ColorScale::color(float t) const
{
if (t < m_min || t > m_max) {
return QColor();
@@ -62,8 +63,8 @@ QColor ColorScale::color(qreal t) const
}
// find which colors in the scale are adjacent to ours
- qreal step = 1.0 / m_colors.size();
- int i = (int) (t / step);
+ float step = 1.0 / m_colors.size();
+ int i = int(t / step);
int j = i + 1;
if (i >= m_colors.size() - 1) {
diff --git a/colorscale.h b/colorscale.h
index 6e65012..af74b5c 100644
--- a/colorscale.h
+++ b/colorscale.h
@@ -13,11 +13,15 @@ public:
ColorScale(const QList<QColor> &colors);
virtual ~ColorScale();
- virtual QColor color(qreal t) const;
- void setExtents(qreal min, qreal max);
+ QColor operator ()(float t) const { return color(t); }
+ virtual QColor color(float t) const;
+
+ void setExtents(float min, float max);
+ float min() const { return m_min; }
+ float max() const { return m_max; }
protected:
- qreal m_min, m_max;
+ float m_min, m_max;
QList<QColor> m_colors;
};