summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-15 13:22:00 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-15 13:22:00 -0700
commita020e535cac36d69a8939fb7956260d2217c65b4 (patch)
tree7acef00fd8aa1e85dae8ff5491e40f42659b5fd6 /include
parentd48333f26d9111d8f4f8420b477c36cece0d14a5 (diff)
downloadqtlocation-mapboxgl-a020e535cac36d69a8939fb7956260d2217c65b4.tar.gz
[core] Add a few conveniences to Color
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/annotation/annotation.hpp4
-rw-r--r--include/mbgl/gl/gl_values.hpp7
-rw-r--r--include/mbgl/util/color.hpp18
3 files changed, 19 insertions, 10 deletions
diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp
index fc0595af0f..e8ac9a2fb7 100644
--- a/include/mbgl/annotation/annotation.hpp
+++ b/include/mbgl/annotation/annotation.hpp
@@ -30,14 +30,14 @@ public:
ShapeAnnotationGeometry geometry;
float opacity = 1;
float width = 1;
- Color color = { 0, 0, 0, 1 };
+ Color color = Color::black();
};
class FillAnnotation {
public:
ShapeAnnotationGeometry geometry;
float opacity = 1;
- Color color = { 0, 0, 0, 1 };
+ Color color = Color::black();
Color outlineColor = { 0, 0, 0, -1 };
};
diff --git a/include/mbgl/gl/gl_values.hpp b/include/mbgl/gl/gl_values.hpp
index 4204ca8e13..0d7d294cf7 100644
--- a/include/mbgl/gl/gl_values.hpp
+++ b/include/mbgl/gl/gl_values.hpp
@@ -5,6 +5,7 @@
#include <array>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/util/color.hpp>
namespace mbgl {
namespace gl {
@@ -23,7 +24,7 @@ struct ClearDepth {
};
struct ClearColor {
- struct Type { GLfloat r, g, b, a; };
+ using Type = Color;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glClearColor(value.r, value.g, value.b, value.a));
@@ -35,10 +36,6 @@ struct ClearColor {
}
};
-inline bool operator!=(const ClearColor::Type& a, const ClearColor::Type& b) {
- return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
-}
-
struct ClearStencil {
using Type = GLint;
static const Type Default;
diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp
index 82cd3c42e7..87d3175178 100644
--- a/include/mbgl/util/color.hpp
+++ b/include/mbgl/util/color.hpp
@@ -11,14 +11,26 @@ public:
float g = 0.0f;
float b = 0.0f;
float a = 0.0f;
+
+ static constexpr Color black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; };
+ static constexpr Color white() { return { 1.0f, 1.0f, 1.0f, 1.0f }; };
};
-inline bool operator== (const Color& colorA, const Color& colorB) {
+inline bool operator==(const Color& colorA, const Color& colorB) {
return colorA.r == colorB.r && colorA.g == colorB.g && colorA.b == colorB.b && colorA.a == colorB.a;
}
-inline bool operator!= (const Color& colorA, const Color& colorB) {
- return !(colorA.r == colorB.r && colorA.g == colorB.g && colorA.b == colorB.b && colorA.a == colorB.a);
+inline bool operator!=(const Color& colorA, const Color& colorB) {
+ return !(colorA == colorB);
+}
+
+inline Color operator*(const Color& color, float alpha) {
+ return {
+ color.r * alpha,
+ color.g * alpha,
+ color.b * alpha,
+ color.a * alpha
+ };
}
} // namespace mbgl