summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/fill_layer_properties.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-10-30 11:06:59 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-17 15:13:38 -0800
commit38fcbe21d48186c4630a3b8a76d1b20e156faadd (patch)
tree098f73bfea98deb5202fe1c13b1277e43e322755 /src/mbgl/style/layers/fill_layer_properties.hpp
parentd4fc66af3924805d40576989c1e139ddafcc4670 (diff)
downloadqtlocation-mapboxgl-38fcbe21d48186c4630a3b8a76d1b20e156faadd.tar.gz
[core] Convert style properties to a tuple-based approach
This converts the style property classes (CirclePaintProperties and so on) to the same tuple-based approach as gl::Attribute and gl::Uniform. The approach is outlined in https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md. The main advantage of this approach is it allows writing algorithms that work on sets of style properties, without resorting to code generation or manually repetitive code. This lets us iterate on approaches to data-driven properties more easily. Another advantage is that the cascading, unevaluated, and evaluated states of a set of properties exist as independent structures, instead of individual properties holding their own state. This is a more functional approach that makes data flow clearer and reduces state.
Diffstat (limited to 'src/mbgl/style/layers/fill_layer_properties.hpp')
-rw-r--r--src/mbgl/style/layers/fill_layer_properties.hpp51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp
index d12eb8d6f4..b2d926c31e 100644
--- a/src/mbgl/style/layers/fill_layer_properties.hpp
+++ b/src/mbgl/style/layers/fill_layer_properties.hpp
@@ -9,22 +9,43 @@
namespace mbgl {
namespace style {
-class CascadeParameters;
-class CalculationParameters;
-
-class FillPaintProperties {
-public:
- void cascade(const CascadeParameters&);
- bool recalculate(const CalculationParameters&);
-
- PaintProperty<bool> fillAntialias { true };
- PaintProperty<float> fillOpacity { 1 };
- PaintProperty<Color> fillColor { Color::black() };
- PaintProperty<Color> fillOutlineColor { {} };
- PaintProperty<std::array<float, 2>> fillTranslate { {{ 0, 0 }} };
- PaintProperty<TranslateAnchorType> fillTranslateAnchor { TranslateAnchorType::Map };
- PaintProperty<std::string, CrossFadedPropertyEvaluator> fillPattern { "" };
+struct FillAntialias : PaintProperty<bool> {
+ static bool defaultValue() { return true; }
};
+struct FillOpacity : PaintProperty<float> {
+ static float defaultValue() { return 1; }
+};
+
+struct FillColor : PaintProperty<Color> {
+ static Color defaultValue() { return Color::black(); }
+};
+
+struct FillOutlineColor : PaintProperty<Color> {
+ static Color defaultValue() { return {}; }
+};
+
+struct FillTranslate : PaintProperty<std::array<float, 2>> {
+ static std::array<float, 2> defaultValue() { return {{ 0, 0 }}; }
+};
+
+struct FillTranslateAnchor : PaintProperty<TranslateAnchorType> {
+ static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; }
+};
+
+struct FillPattern : CrossFadedPaintProperty<std::string> {
+ static std::string defaultValue() { return ""; }
+};
+
+class FillPaintProperties : public PaintProperties<
+ FillAntialias,
+ FillOpacity,
+ FillColor,
+ FillOutlineColor,
+ FillTranslate,
+ FillTranslateAnchor,
+ FillPattern
+> {};
+
} // namespace style
} // namespace mbgl