summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalkTX <falktx@falktx.com>2022-11-20 12:37:16 +0000
committerfalkTX <falktx@falktx.com>2022-11-20 12:37:16 +0000
commit878a183b59f4467118263c1c760f6ccb8efbe0bd (patch)
tree9ffed5df453138d588dffb90ac867c9c9687759f
parent2ba9190f42161f69c12dd5927084a34e82beb7fc (diff)
Add Color::plus/minus utils
Signed-off-by: falkTX <falktx@falktx.com>
-rw-r--r--dgl/Color.hpp26
-rw-r--r--dgl/src/Color.cpp42
2 files changed, 67 insertions, 1 deletions
diff --git a/dgl/Color.hpp b/dgl/Color.hpp
index 51534734..5ea28fed 100644
--- a/dgl/Color.hpp
+++ b/dgl/Color.hpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -71,6 +71,30 @@ struct Color {
Color withAlpha(float alpha) const noexcept;
/**
+ Create a new color based on this one but with subtracted numeric value on all elements.
+ Value must be in [0..255] range.
+ */
+ Color minus(int value) const noexcept;
+
+ /**
+ Create a new color based on this one but with subtracted floating-point value on all elements.
+ Value must be in [0..1] range.
+ */
+ Color minus(float value) const noexcept;
+
+ /**
+ Create a new color based on this one but with added numeric value on all elements.
+ Value must be in [0..255] range.
+ */
+ Color plus(int value) const noexcept;
+
+ /**
+ Create a new color based on this one but with added floating-point value on all elements.
+ Value must be in [0..1] range.
+ */
+ Color plus(float value) const noexcept;
+
+ /**
Create a color specified by hue, saturation and lightness.
Values must in [0..1] range.
*/
diff --git a/dgl/src/Color.cpp b/dgl/src/Color.cpp
index 454ada38..4c8714ff 100644
--- a/dgl/src/Color.cpp
+++ b/dgl/src/Color.cpp
@@ -121,6 +121,48 @@ Color Color::withAlpha(const float alpha2) const noexcept
return color;
}
+Color Color::minus(const int value) const noexcept
+{
+ const float fvalue = static_cast<float>(value)/255.f;
+ Color color(*this);
+ color.red -= fvalue;
+ color.green -= fvalue;
+ color.blue -= fvalue;
+ color.fixBounds();
+ return color;
+}
+
+Color Color::minus(const float value) const noexcept
+{
+ Color color(*this);
+ color.red -= value;
+ color.green -= value;
+ color.blue -= value;
+ color.fixBounds();
+ return color;
+}
+
+Color Color::plus(const int value) const noexcept
+{
+ const float fvalue = static_cast<float>(value)/255.f;
+ Color color(*this);
+ color.red += fvalue;
+ color.green += fvalue;
+ color.blue += fvalue;
+ color.fixBounds();
+ return color;
+}
+
+Color Color::plus(const float value) const noexcept
+{
+ Color color(*this);
+ color.red += value;
+ color.green += value;
+ color.blue += value;
+ color.fixBounds();
+ return color;
+}
+
Color Color::fromHSL(float hue, float saturation, float lightness, float alpha)
{
float m1, m2;