summaryrefslogtreecommitdiff
path: root/wx+/image_tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'wx+/image_tools.h')
-rw-r--r--wx+/image_tools.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/wx+/image_tools.h b/wx+/image_tools.h
index 23a363df..687025d0 100644
--- a/wx+/image_tools.h
+++ b/wx+/image_tools.h
@@ -9,6 +9,7 @@
#include <numeric>
#include <wx/bitmap.h>
+#include <wx/image.h>
#include <wx/dcmemory.h>
#include <zen/basic_math.h>
@@ -24,7 +25,7 @@ void brighten(wxImage& img, int level); //level: delta per channel in points
bool isEqual(const wxBitmap& lhs, const wxBitmap& rhs); //pixel-wise equality (respecting alpha channel)
-
+wxColor gradient(const wxColor& from, const wxColor& to, double fraction); //maps fraction within [0, 1] to an intermediate color
@@ -152,6 +153,17 @@ bool isEqual(const wxBitmap& lhs, const wxBitmap& rhs)
return std::equal(imLhs.GetData(), imLhs.GetData() + pixelCount * 3, imRhs.GetData());
}
+
+inline
+wxColor gradient(const wxColor& from, const wxColor& to, double fraction)
+{
+ fraction = std::max(0.0, fraction);
+ fraction = std::min(1.0, fraction);
+ return wxColor(from.Red () + (to.Red () - from.Red ()) * fraction,
+ from.Green() + (to.Green() - from.Green()) * fraction,
+ from.Blue () + (to.Blue () - from.Blue ()) * fraction,
+ from.Alpha() + (to.Alpha() - from.Alpha()) * fraction);
+}
}
bgstack15