From 38fcbe21d48186c4630a3b8a76d1b20e156faadd Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 30 Oct 2016 11:06:59 -0700 Subject: [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. --- src/mbgl/style/layers/background_layer.cpp | 12 +- src/mbgl/style/layers/background_layer_impl.cpp | 8 +- src/mbgl/style/layers/background_layer_impl.hpp | 2 +- .../style/layers/background_layer_properties.cpp | 16 -- .../style/layers/background_layer_properties.hpp | 23 +- src/mbgl/style/layers/circle_layer.cpp | 28 +- src/mbgl/style/layers/circle_layer_impl.cpp | 16 +- src/mbgl/style/layers/circle_layer_impl.hpp | 2 +- src/mbgl/style/layers/circle_layer_properties.cpp | 24 -- src/mbgl/style/layers/circle_layer_properties.hpp | 51 +++- src/mbgl/style/layers/custom_layer_impl.cpp | 2 +- src/mbgl/style/layers/custom_layer_impl.hpp | 2 +- src/mbgl/style/layers/fill_layer.cpp | 28 +- src/mbgl/style/layers/fill_layer_impl.cpp | 14 +- src/mbgl/style/layers/fill_layer_impl.hpp | 2 +- src/mbgl/style/layers/fill_layer_properties.cpp | 24 -- src/mbgl/style/layers/fill_layer_properties.hpp | 51 +++- src/mbgl/style/layers/layer.cpp.ejs | 10 +- src/mbgl/style/layers/layer_properties.cpp.ejs | 24 -- src/mbgl/style/layers/layer_properties.hpp.ejs | 40 +-- src/mbgl/style/layers/line_layer.cpp | 64 ++--- src/mbgl/style/layers/line_layer_impl.cpp | 30 +- src/mbgl/style/layers/line_layer_impl.hpp | 2 +- src/mbgl/style/layers/line_layer_properties.cpp | 37 --- src/mbgl/style/layers/line_layer_properties.hpp | 102 +++++-- src/mbgl/style/layers/raster_layer.cpp | 28 +- src/mbgl/style/layers/raster_layer_impl.cpp | 8 +- src/mbgl/style/layers/raster_layer_impl.hpp | 2 +- src/mbgl/style/layers/raster_layer_properties.cpp | 24 -- src/mbgl/style/layers/raster_layer_properties.hpp | 51 +++- src/mbgl/style/layers/symbol_layer.cpp | 260 ++++++++--------- src/mbgl/style/layers/symbol_layer_impl.cpp | 95 +++---- src/mbgl/style/layers/symbol_layer_impl.hpp | 6 +- src/mbgl/style/layers/symbol_layer_properties.cpp | 75 ----- src/mbgl/style/layers/symbol_layer_properties.hpp | 306 ++++++++++++++++----- 35 files changed, 768 insertions(+), 701 deletions(-) (limited to 'src/mbgl/style/layers') diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 5e5faf37e6..a54115d1a7 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -42,13 +42,13 @@ PropertyValue BackgroundLayer::getDefaultBackgroundColor() { } PropertyValue BackgroundLayer::getBackgroundColor(const optional& klass) const { - return impl->paint.backgroundColor.get(klass); + return impl->paint.get(klass); } void BackgroundLayer::setBackgroundColor(PropertyValue value, const optional& klass) { if (value == getBackgroundColor(klass)) return; - impl->paint.backgroundColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -57,13 +57,13 @@ PropertyValue BackgroundLayer::getDefaultBackgroundPattern() { } PropertyValue BackgroundLayer::getBackgroundPattern(const optional& klass) const { - return impl->paint.backgroundPattern.get(klass); + return impl->paint.get(klass); } void BackgroundLayer::setBackgroundPattern(PropertyValue value, const optional& klass) { if (value == getBackgroundPattern(klass)) return; - impl->paint.backgroundPattern.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -72,13 +72,13 @@ PropertyValue BackgroundLayer::getDefaultBackgroundOpacity() { } PropertyValue BackgroundLayer::getBackgroundOpacity(const optional& klass) const { - return impl->paint.backgroundOpacity.get(klass); + return impl->paint.get(klass); } void BackgroundLayer::setBackgroundOpacity(PropertyValue value, const optional& klass) { if (value == getBackgroundOpacity(klass)) return; - impl->paint.backgroundOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } diff --git a/src/mbgl/style/layers/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp index ea389b828e..9a7db9416e 100644 --- a/src/mbgl/style/layers/background_layer_impl.cpp +++ b/src/mbgl/style/layers/background_layer_impl.cpp @@ -8,12 +8,12 @@ void BackgroundLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool BackgroundLayer::Impl::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = paint.recalculate(parameters); +bool BackgroundLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { + paint.evaluate(parameters); - passes = paint.backgroundOpacity > 0 ? RenderPass::Translucent : RenderPass::None; + passes = paint.evaluated.get() > 0 ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr BackgroundLayer::Impl::createBucket(BucketParameters&) const { diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp index abbb740f42..6ede1b7d97 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -13,7 +13,7 @@ public: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; - bool recalculate(const CalculationParameters&) override; + bool evaluate(const PropertyEvaluationParameters&) override; std::unique_ptr createBucket(BucketParameters&) const override; diff --git a/src/mbgl/style/layers/background_layer_properties.cpp b/src/mbgl/style/layers/background_layer_properties.cpp index 558093a255..ba3e638977 100644 --- a/src/mbgl/style/layers/background_layer_properties.cpp +++ b/src/mbgl/style/layers/background_layer_properties.cpp @@ -5,21 +5,5 @@ namespace mbgl { namespace style { -void BackgroundPaintProperties::cascade(const CascadeParameters& parameters) { - backgroundColor.cascade(parameters); - backgroundPattern.cascade(parameters); - backgroundOpacity.cascade(parameters); -} - -bool BackgroundPaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= backgroundColor.calculate(parameters); - hasTransitions |= backgroundPattern.calculate(parameters); - hasTransitions |= backgroundOpacity.calculate(parameters); - - return hasTransitions; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer_properties.hpp b/src/mbgl/style/layers/background_layer_properties.hpp index 78a35a4f0c..792bf3de94 100644 --- a/src/mbgl/style/layers/background_layer_properties.hpp +++ b/src/mbgl/style/layers/background_layer_properties.hpp @@ -9,18 +9,23 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; +struct BackgroundColor : PaintProperty { + static Color defaultValue() { return Color::black(); } +}; -class BackgroundPaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); +struct BackgroundPattern : CrossFadedPaintProperty { + static std::string defaultValue() { return ""; } +}; - PaintProperty backgroundColor { Color::black() }; - PaintProperty backgroundPattern { "" }; - PaintProperty backgroundOpacity { 1 }; +struct BackgroundOpacity : PaintProperty { + static float defaultValue() { return 1; } }; +class BackgroundPaintProperties : public PaintProperties< + BackgroundColor, + BackgroundPattern, + BackgroundOpacity +> {}; + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index a2b8d316d6..ce01a12ff2 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -67,13 +67,13 @@ PropertyValue CircleLayer::getDefaultCircleRadius() { } PropertyValue CircleLayer::getCircleRadius(const optional& klass) const { - return impl->paint.circleRadius.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCircleRadius(PropertyValue value, const optional& klass) { if (value == getCircleRadius(klass)) return; - impl->paint.circleRadius.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -82,13 +82,13 @@ PropertyValue CircleLayer::getDefaultCircleColor() { } PropertyValue CircleLayer::getCircleColor(const optional& klass) const { - return impl->paint.circleColor.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCircleColor(PropertyValue value, const optional& klass) { if (value == getCircleColor(klass)) return; - impl->paint.circleColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -97,13 +97,13 @@ PropertyValue CircleLayer::getDefaultCircleBlur() { } PropertyValue CircleLayer::getCircleBlur(const optional& klass) const { - return impl->paint.circleBlur.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCircleBlur(PropertyValue value, const optional& klass) { if (value == getCircleBlur(klass)) return; - impl->paint.circleBlur.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -112,13 +112,13 @@ PropertyValue CircleLayer::getDefaultCircleOpacity() { } PropertyValue CircleLayer::getCircleOpacity(const optional& klass) const { - return impl->paint.circleOpacity.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCircleOpacity(PropertyValue value, const optional& klass) { if (value == getCircleOpacity(klass)) return; - impl->paint.circleOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -127,13 +127,13 @@ PropertyValue> CircleLayer::getDefaultCircleTranslate() { } PropertyValue> CircleLayer::getCircleTranslate(const optional& klass) const { - return impl->paint.circleTranslate.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCircleTranslate(PropertyValue> value, const optional& klass) { if (value == getCircleTranslate(klass)) return; - impl->paint.circleTranslate.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -142,13 +142,13 @@ PropertyValue CircleLayer::getDefaultCircleTranslateAnchor( } PropertyValue CircleLayer::getCircleTranslateAnchor(const optional& klass) const { - return impl->paint.circleTranslateAnchor.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCircleTranslateAnchor(PropertyValue value, const optional& klass) { if (value == getCircleTranslateAnchor(klass)) return; - impl->paint.circleTranslateAnchor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -157,13 +157,13 @@ PropertyValue CircleLayer::getDefaultCirclePitchScale() { } PropertyValue CircleLayer::getCirclePitchScale(const optional& klass) const { - return impl->paint.circlePitchScale.get(klass); + return impl->paint.get(klass); } void CircleLayer::setCirclePitchScale(PropertyValue value, const optional& klass) { if (value == getCirclePitchScale(klass)) return; - impl->paint.circlePitchScale.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index 33699b6665..6599126702 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -12,13 +12,13 @@ void CircleLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool CircleLayer::Impl::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = paint.recalculate(parameters); +bool CircleLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { + paint.evaluate(parameters); - passes = (paint.circleRadius > 0 && paint.circleColor.value.a > 0 && paint.circleOpacity > 0) + passes = (paint.evaluated.get() > 0 && paint.evaluated.get().a > 0 && paint.evaluated.get() > 0) ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr CircleLayer::Impl::createBucket(BucketParameters& parameters) const { @@ -35,8 +35,8 @@ std::unique_ptr CircleLayer::Impl::createBucket(BucketParameters& parame } float CircleLayer::Impl::getQueryRadius() const { - const std::array& translate = paint.circleTranslate; - return paint.circleRadius + util::length(translate[0], translate[1]); + const std::array& translate = paint.evaluated.get(); + return paint.evaluated.get() + util::length(translate[0], translate[1]); } bool CircleLayer::Impl::queryIntersectsGeometry( @@ -46,9 +46,9 @@ bool CircleLayer::Impl::queryIntersectsGeometry( const float pixelsToTileUnits) const { auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.circleTranslate, paint.circleTranslateAnchor, bearing, pixelsToTileUnits); + queryGeometry, paint.evaluated.get(), paint.evaluated.get(), bearing, pixelsToTileUnits); - auto circleRadius = paint.circleRadius * pixelsToTileUnits; + auto circleRadius = paint.evaluated.get() * pixelsToTileUnits; return util::polygonIntersectsBufferedMultiPoint( translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius); diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp index 14baaf84e4..df3b34cc1a 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -13,7 +13,7 @@ public: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; - bool recalculate(const CalculationParameters&) override; + bool evaluate(const PropertyEvaluationParameters&) override; std::unique_ptr createBucket(BucketParameters&) const override; diff --git a/src/mbgl/style/layers/circle_layer_properties.cpp b/src/mbgl/style/layers/circle_layer_properties.cpp index 7243cf87f4..af727fa36f 100644 --- a/src/mbgl/style/layers/circle_layer_properties.cpp +++ b/src/mbgl/style/layers/circle_layer_properties.cpp @@ -5,29 +5,5 @@ namespace mbgl { namespace style { -void CirclePaintProperties::cascade(const CascadeParameters& parameters) { - circleRadius.cascade(parameters); - circleColor.cascade(parameters); - circleBlur.cascade(parameters); - circleOpacity.cascade(parameters); - circleTranslate.cascade(parameters); - circleTranslateAnchor.cascade(parameters); - circlePitchScale.cascade(parameters); -} - -bool CirclePaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= circleRadius.calculate(parameters); - hasTransitions |= circleColor.calculate(parameters); - hasTransitions |= circleBlur.calculate(parameters); - hasTransitions |= circleOpacity.calculate(parameters); - hasTransitions |= circleTranslate.calculate(parameters); - hasTransitions |= circleTranslateAnchor.calculate(parameters); - hasTransitions |= circlePitchScale.calculate(parameters); - - return hasTransitions; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp index 0166bc8be4..b7f279de4b 100644 --- a/src/mbgl/style/layers/circle_layer_properties.hpp +++ b/src/mbgl/style/layers/circle_layer_properties.hpp @@ -9,22 +9,43 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; - -class CirclePaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); - - PaintProperty circleRadius { 5 }; - PaintProperty circleColor { Color::black() }; - PaintProperty circleBlur { 0 }; - PaintProperty circleOpacity { 1 }; - PaintProperty> circleTranslate { {{ 0, 0 }} }; - PaintProperty circleTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty circlePitchScale { CirclePitchScaleType::Map }; +struct CircleRadius : PaintProperty { + static float defaultValue() { return 5; } }; +struct CircleColor : PaintProperty { + static Color defaultValue() { return Color::black(); } +}; + +struct CircleBlur : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct CircleOpacity : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct CircleTranslate : PaintProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct CircleTranslateAnchor : PaintProperty { + static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } +}; + +struct CirclePitchScale : PaintProperty { + static CirclePitchScaleType defaultValue() { return CirclePitchScaleType::Map; } +}; + +class CirclePaintProperties : public PaintProperties< + CircleRadius, + CircleColor, + CircleBlur, + CircleOpacity, + CircleTranslate, + CircleTranslateAnchor, + CirclePitchScale +> {}; + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index 1126d57552..50dcc0dda9 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -62,7 +62,7 @@ void CustomLayer::Impl::render(const TransformState& state) const { renderFn(context, parameters); } -bool CustomLayer::Impl::recalculate(const CalculationParameters&) { +bool CustomLayer::Impl::evaluate(const PropertyEvaluationParameters&) { passes = RenderPass::Translucent; return false; } diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index b5b626ca5e..56e3f3146c 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -29,7 +29,7 @@ private: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) final {} - bool recalculate(const CalculationParameters&) final; + bool evaluate(const PropertyEvaluationParameters&) final; std::unique_ptr createBucket(BucketParameters&) const final; diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index c61de81d1a..3bea9b56b0 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -67,13 +67,13 @@ PropertyValue FillLayer::getDefaultFillAntialias() { } PropertyValue FillLayer::getFillAntialias(const optional& klass) const { - return impl->paint.fillAntialias.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillAntialias(PropertyValue value, const optional& klass) { if (value == getFillAntialias(klass)) return; - impl->paint.fillAntialias.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -82,13 +82,13 @@ PropertyValue FillLayer::getDefaultFillOpacity() { } PropertyValue FillLayer::getFillOpacity(const optional& klass) const { - return impl->paint.fillOpacity.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillOpacity(PropertyValue value, const optional& klass) { if (value == getFillOpacity(klass)) return; - impl->paint.fillOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -97,13 +97,13 @@ PropertyValue FillLayer::getDefaultFillColor() { } PropertyValue FillLayer::getFillColor(const optional& klass) const { - return impl->paint.fillColor.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillColor(PropertyValue value, const optional& klass) { if (value == getFillColor(klass)) return; - impl->paint.fillColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -112,13 +112,13 @@ PropertyValue FillLayer::getDefaultFillOutlineColor() { } PropertyValue FillLayer::getFillOutlineColor(const optional& klass) const { - return impl->paint.fillOutlineColor.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillOutlineColor(PropertyValue value, const optional& klass) { if (value == getFillOutlineColor(klass)) return; - impl->paint.fillOutlineColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -127,13 +127,13 @@ PropertyValue> FillLayer::getDefaultFillTranslate() { } PropertyValue> FillLayer::getFillTranslate(const optional& klass) const { - return impl->paint.fillTranslate.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillTranslate(PropertyValue> value, const optional& klass) { if (value == getFillTranslate(klass)) return; - impl->paint.fillTranslate.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -142,13 +142,13 @@ PropertyValue FillLayer::getDefaultFillTranslateAnchor() { } PropertyValue FillLayer::getFillTranslateAnchor(const optional& klass) const { - return impl->paint.fillTranslateAnchor.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillTranslateAnchor(PropertyValue value, const optional& klass) { if (value == getFillTranslateAnchor(klass)) return; - impl->paint.fillTranslateAnchor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -157,13 +157,13 @@ PropertyValue FillLayer::getDefaultFillPattern() { } PropertyValue FillLayer::getFillPattern(const optional& klass) const { - return impl->paint.fillPattern.get(klass); + return impl->paint.get(klass); } void FillLayer::setFillPattern(PropertyValue value, const optional& klass) { if (value == getFillPattern(klass)) return; - impl->paint.fillPattern.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index fc439f1cd1..6a690ba447 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -12,22 +12,22 @@ void FillLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool FillLayer::Impl::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = paint.recalculate(parameters); +bool FillLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { + paint.evaluate(parameters); passes = RenderPass::None; - if (paint.fillAntialias) { + if (paint.evaluated.get()) { passes |= RenderPass::Translucent; } - if (!paint.fillPattern.value.from.empty() || (paint.fillColor.value.a * paint.fillOpacity) < 1.0f) { + if (!paint.evaluated.get().from.empty() || (paint.evaluated.get().a * paint.evaluated.get()) < 1.0f) { passes |= RenderPass::Translucent; } else { passes |= RenderPass::Opaque; } - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr FillLayer::Impl::createBucket(BucketParameters& parameters) const { @@ -44,7 +44,7 @@ std::unique_ptr FillLayer::Impl::createBucket(BucketParameters& paramete } float FillLayer::Impl::getQueryRadius() const { - const std::array& translate = paint.fillTranslate; + const std::array& translate = paint.evaluated.get(); return util::length(translate[0], translate[1]); } @@ -55,7 +55,7 @@ bool FillLayer::Impl::queryIntersectsGeometry( const float pixelsToTileUnits) const { auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.fillTranslate, paint.fillTranslateAnchor, bearing, pixelsToTileUnits); + queryGeometry, paint.evaluated.get(), paint.evaluated.get(), bearing, pixelsToTileUnits); return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), geometry); } diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp index 54cfb80c86..53276d744a 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -13,7 +13,7 @@ public: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; - bool recalculate(const CalculationParameters&) override; + bool evaluate(const PropertyEvaluationParameters&) override; std::unique_ptr createBucket(BucketParameters&) const override; diff --git a/src/mbgl/style/layers/fill_layer_properties.cpp b/src/mbgl/style/layers/fill_layer_properties.cpp index 9a55cbc145..b07a083950 100644 --- a/src/mbgl/style/layers/fill_layer_properties.cpp +++ b/src/mbgl/style/layers/fill_layer_properties.cpp @@ -5,29 +5,5 @@ namespace mbgl { namespace style { -void FillPaintProperties::cascade(const CascadeParameters& parameters) { - fillAntialias.cascade(parameters); - fillOpacity.cascade(parameters); - fillColor.cascade(parameters); - fillOutlineColor.cascade(parameters); - fillTranslate.cascade(parameters); - fillTranslateAnchor.cascade(parameters); - fillPattern.cascade(parameters); -} - -bool FillPaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= fillAntialias.calculate(parameters); - hasTransitions |= fillOpacity.calculate(parameters); - hasTransitions |= fillColor.calculate(parameters); - hasTransitions |= fillOutlineColor.calculate(parameters); - hasTransitions |= fillTranslate.calculate(parameters); - hasTransitions |= fillTranslateAnchor.calculate(parameters); - hasTransitions |= fillPattern.calculate(parameters); - - return hasTransitions; -} - } // namespace style } // namespace mbgl 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 fillAntialias { true }; - PaintProperty fillOpacity { 1 }; - PaintProperty fillColor { Color::black() }; - PaintProperty fillOutlineColor { {} }; - PaintProperty> fillTranslate { {{ 0, 0 }} }; - PaintProperty fillTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty fillPattern { "" }; +struct FillAntialias : PaintProperty { + static bool defaultValue() { return true; } }; +struct FillOpacity : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct FillColor : PaintProperty { + static Color defaultValue() { return Color::black(); } +}; + +struct FillOutlineColor : PaintProperty { + static Color defaultValue() { return {}; } +}; + +struct FillTranslate : PaintProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct FillTranslateAnchor : PaintProperty { + static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } +}; + +struct FillPattern : CrossFadedPaintProperty { + static std::string defaultValue() { return ""; } +}; + +class FillPaintProperties : public PaintProperties< + FillAntialias, + FillOpacity, + FillColor, + FillOutlineColor, + FillTranslate, + FillTranslateAnchor, + FillPattern +> {}; + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index c2cbc56a09..dcc78bafe5 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -78,17 +78,17 @@ const Filter& <%- camelize(type) %>Layer::getFilter() const { <% for (const property of layoutProperties) { -%> PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::getDefault<%- camelize(property.name) %>() { - return { <%- defaultValue(property) %> }; + return <%- camelize(property.name) %>::defaultValue(); } PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { - return impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.get(); + return impl->layout.unevaluated.get<<%- camelize(property.name) %>>(); } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { if (value == get<%- camelize(property.name) %>()) return; - impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); + impl->layout.unevaluated.get<<%- camelize(property.name) %>>() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>"); } <% } -%> @@ -100,13 +100,13 @@ PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::getDefa } PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(const optional& klass) const { - return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.get(klass); + return impl->paint.get<<%- camelize(property.name) %>>(klass); } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value, const optional& klass) { if (value == get<%- camelize(property.name) %>(klass)) return; - impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value, klass); + impl->paint.set<<%- camelize(property.name) %>>(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } <% } -%> diff --git a/src/mbgl/style/layers/layer_properties.cpp.ejs b/src/mbgl/style/layers/layer_properties.cpp.ejs index b781a4a9d9..3b287decc0 100644 --- a/src/mbgl/style/layers/layer_properties.cpp.ejs +++ b/src/mbgl/style/layers/layer_properties.cpp.ejs @@ -10,29 +10,5 @@ namespace mbgl { namespace style { -<% if (layoutProperties.length) { -%> -void <%- camelize(type) %>LayoutProperties::recalculate(const CalculationParameters& parameters) { -<% for (const property of layoutProperties) { -%> - <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters); -<% } -%> -} - -<% } -%> -void <%- camelize(type) %>PaintProperties::cascade(const CascadeParameters& parameters) { -<% for (const property of paintProperties) { -%> - <%- camelizeWithLeadingLowercase(property.name) %>.cascade(parameters); -<% } -%> -} - -bool <%- camelize(type) %>PaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - -<% for (const property of paintProperties) { -%> - hasTransitions |= <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters); -<% } -%> - - return hasTransitions; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 0c91ecba8c..f490a636f9 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -14,33 +14,35 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; - -<% if (layoutProperties.length) { -%> -class <%- camelize(type) %>LayoutProperties { -public: - void recalculate(const CalculationParameters&); - <% for (const property of layoutProperties) { -%> - LayoutProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; +struct <%- camelize(property.name) %> : LayoutProperty<<%- propertyType(property) %>> { + static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; } +}; + <% } -%> +<% for (const property of paintProperties) { -%> +struct <%- camelize(property.name) %> : <% +if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { +%>CrossFaded<% } -%>PaintProperty<<%- propertyType(property) %>> { + static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; } }; <% } -%> -class <%- camelize(type) %>PaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); +<% if (layoutProperties.length) { -%> +class <%- camelize(type) %>LayoutProperties : public LayoutProperties< +<% for (const property of layoutProperties.slice(0, -1)) { -%> + <%- camelize(property.name) %>, +<% } -%> + <%- camelize(layoutProperties.slice(-1)[0].name) %> +> {}; -<% for (const property of paintProperties) { -%> -<% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> - PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; -<% } else { -%> - PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; <% } -%> +class <%- camelize(type) %>PaintProperties : public PaintProperties< +<% for (const property of paintProperties.slice(0, -1)) { -%> + <%- camelize(property.name) %>, <% } -%> -}; + <%- camelize(paintProperties.slice(-1)[0].name) %> +> {}; } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 49ecf63c18..8c38ef5694 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -60,59 +60,59 @@ const Filter& LineLayer::getFilter() const { // Layout properties PropertyValue LineLayer::getDefaultLineCap() { - return { LineCapType::Butt }; + return LineCap::defaultValue(); } PropertyValue LineLayer::getLineCap() const { - return impl->layout.lineCap.get(); + return impl->layout.unevaluated.get(); } void LineLayer::setLineCap(PropertyValue value) { if (value == getLineCap()) return; - impl->layout.lineCap.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "line-cap"); } PropertyValue LineLayer::getDefaultLineJoin() { - return { LineJoinType::Miter }; + return LineJoin::defaultValue(); } PropertyValue LineLayer::getLineJoin() const { - return impl->layout.lineJoin.get(); + return impl->layout.unevaluated.get(); } void LineLayer::setLineJoin(PropertyValue value) { if (value == getLineJoin()) return; - impl->layout.lineJoin.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "line-join"); } PropertyValue LineLayer::getDefaultLineMiterLimit() { - return { 2 }; + return LineMiterLimit::defaultValue(); } PropertyValue LineLayer::getLineMiterLimit() const { - return impl->layout.lineMiterLimit.get(); + return impl->layout.unevaluated.get(); } void LineLayer::setLineMiterLimit(PropertyValue value) { if (value == getLineMiterLimit()) return; - impl->layout.lineMiterLimit.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit"); } PropertyValue LineLayer::getDefaultLineRoundLimit() { - return { 1 }; + return LineRoundLimit::defaultValue(); } PropertyValue LineLayer::getLineRoundLimit() const { - return impl->layout.lineRoundLimit.get(); + return impl->layout.unevaluated.get(); } void LineLayer::setLineRoundLimit(PropertyValue value) { if (value == getLineRoundLimit()) return; - impl->layout.lineRoundLimit.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "line-round-limit"); } @@ -123,13 +123,13 @@ PropertyValue LineLayer::getDefaultLineOpacity() { } PropertyValue LineLayer::getLineOpacity(const optional& klass) const { - return impl->paint.lineOpacity.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineOpacity(PropertyValue value, const optional& klass) { if (value == getLineOpacity(klass)) return; - impl->paint.lineOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -138,13 +138,13 @@ PropertyValue LineLayer::getDefaultLineColor() { } PropertyValue LineLayer::getLineColor(const optional& klass) const { - return impl->paint.lineColor.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineColor(PropertyValue value, const optional& klass) { if (value == getLineColor(klass)) return; - impl->paint.lineColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -153,13 +153,13 @@ PropertyValue> LineLayer::getDefaultLineTranslate() { } PropertyValue> LineLayer::getLineTranslate(const optional& klass) const { - return impl->paint.lineTranslate.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineTranslate(PropertyValue> value, const optional& klass) { if (value == getLineTranslate(klass)) return; - impl->paint.lineTranslate.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -168,13 +168,13 @@ PropertyValue LineLayer::getDefaultLineTranslateAnchor() { } PropertyValue LineLayer::getLineTranslateAnchor(const optional& klass) const { - return impl->paint.lineTranslateAnchor.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineTranslateAnchor(PropertyValue value, const optional& klass) { if (value == getLineTranslateAnchor(klass)) return; - impl->paint.lineTranslateAnchor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -183,13 +183,13 @@ PropertyValue LineLayer::getDefaultLineWidth() { } PropertyValue LineLayer::getLineWidth(const optional& klass) const { - return impl->paint.lineWidth.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineWidth(PropertyValue value, const optional& klass) { if (value == getLineWidth(klass)) return; - impl->paint.lineWidth.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -198,13 +198,13 @@ PropertyValue LineLayer::getDefaultLineGapWidth() { } PropertyValue LineLayer::getLineGapWidth(const optional& klass) const { - return impl->paint.lineGapWidth.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineGapWidth(PropertyValue value, const optional& klass) { if (value == getLineGapWidth(klass)) return; - impl->paint.lineGapWidth.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -213,13 +213,13 @@ PropertyValue LineLayer::getDefaultLineOffset() { } PropertyValue LineLayer::getLineOffset(const optional& klass) const { - return impl->paint.lineOffset.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineOffset(PropertyValue value, const optional& klass) { if (value == getLineOffset(klass)) return; - impl->paint.lineOffset.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -228,13 +228,13 @@ PropertyValue LineLayer::getDefaultLineBlur() { } PropertyValue LineLayer::getLineBlur(const optional& klass) const { - return impl->paint.lineBlur.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineBlur(PropertyValue value, const optional& klass) { if (value == getLineBlur(klass)) return; - impl->paint.lineBlur.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -243,13 +243,13 @@ PropertyValue> LineLayer::getDefaultLineDasharray() { } PropertyValue> LineLayer::getLineDasharray(const optional& klass) const { - return impl->paint.lineDasharray.get(klass); + return impl->paint.get(klass); } void LineLayer::setLineDasharray(PropertyValue> value, const optional& klass) { if (value == getLineDasharray(klass)) return; - impl->paint.lineDasharray.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -258,13 +258,13 @@ PropertyValue LineLayer::getDefaultLinePattern() { } PropertyValue LineLayer::getLinePattern(const optional& klass) const { - return impl->paint.linePattern.get(klass); + return impl->paint.get(klass); } void LineLayer::setLinePattern(PropertyValue value, const optional& klass) { if (value == getLinePattern(klass)) return; - impl->paint.linePattern.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index c116af5fc2..e6ec21a659 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -12,26 +12,24 @@ void LineLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool LineLayer::Impl::recalculate(const CalculationParameters& parameters) { +bool LineLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { // for scaling dasharrays - CalculationParameters dashArrayParams = parameters; + PropertyEvaluationParameters dashArrayParams = parameters; dashArrayParams.z = std::floor(dashArrayParams.z); - paint.lineWidth.calculate(dashArrayParams); - dashLineWidth = paint.lineWidth; + dashLineWidth = paint.evaluate(dashArrayParams); - bool hasTransitions = paint.recalculate(parameters); + paint.evaluate(parameters); - passes = (paint.lineOpacity > 0 && paint.lineColor.value.a > 0 && paint.lineWidth > 0) + passes = (paint.evaluated.get() > 0 && paint.evaluated.get().a > 0 && paint.evaluated.get() > 0) ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr LineLayer::Impl::createBucket(BucketParameters& parameters) const { auto bucket = std::make_unique(parameters.tileID.overscaleFactor()); - bucket->layout = layout; - bucket->layout.recalculate(CalculationParameters(parameters.tileID.overscaledZ)); + bucket->layout = layout.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ)); auto& name = bucketName(); parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { @@ -44,10 +42,10 @@ std::unique_ptr LineLayer::Impl::createBucket(BucketParameters& paramete } float LineLayer::Impl::getLineWidth() const { - if (paint.lineGapWidth > 0) { - return paint.lineGapWidth + 2 * paint.lineWidth; + if (paint.evaluated.get() > 0) { + return paint.evaluated.get() + 2 * paint.evaluated.get(); } else { - return paint.lineWidth; + return paint.evaluated.get(); } } @@ -82,8 +80,8 @@ optional offsetLine(const GeometryCollection& rings, const d } float LineLayer::Impl::getQueryRadius() const { - const std::array& translate = paint.lineTranslate; - return getLineWidth() / 2.0 + std::abs(paint.lineOffset) + util::length(translate[0], translate[1]); + const std::array& translate = paint.evaluated.get(); + return getLineWidth() / 2.0 + std::abs(paint.evaluated.get()) + util::length(translate[0], translate[1]); } bool LineLayer::Impl::queryIntersectsGeometry( @@ -95,8 +93,8 @@ bool LineLayer::Impl::queryIntersectsGeometry( const float halfWidth = getLineWidth() / 2.0 * pixelsToTileUnits; auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.lineTranslate, paint.lineTranslateAnchor, bearing, pixelsToTileUnits); - auto offsetGeometry = offsetLine(geometry, paint.lineOffset * pixelsToTileUnits); + queryGeometry, paint.evaluated.get(), paint.evaluated.get(), bearing, pixelsToTileUnits); + auto offsetGeometry = offsetLine(geometry, paint.evaluated.get() * pixelsToTileUnits); return util::polygonIntersectsBufferedMultiLine( translatedQueryGeometry.value_or(queryGeometry), diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index c6b4be3bec..3387db07f0 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -13,7 +13,7 @@ public: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; - bool recalculate(const CalculationParameters&) override; + bool evaluate(const PropertyEvaluationParameters&) override; std::unique_ptr createBucket(BucketParameters&) const override; diff --git a/src/mbgl/style/layers/line_layer_properties.cpp b/src/mbgl/style/layers/line_layer_properties.cpp index 2d6092745e..174239bcc8 100644 --- a/src/mbgl/style/layers/line_layer_properties.cpp +++ b/src/mbgl/style/layers/line_layer_properties.cpp @@ -5,42 +5,5 @@ namespace mbgl { namespace style { -void LineLayoutProperties::recalculate(const CalculationParameters& parameters) { - lineCap.calculate(parameters); - lineJoin.calculate(parameters); - lineMiterLimit.calculate(parameters); - lineRoundLimit.calculate(parameters); -} - -void LinePaintProperties::cascade(const CascadeParameters& parameters) { - lineOpacity.cascade(parameters); - lineColor.cascade(parameters); - lineTranslate.cascade(parameters); - lineTranslateAnchor.cascade(parameters); - lineWidth.cascade(parameters); - lineGapWidth.cascade(parameters); - lineOffset.cascade(parameters); - lineBlur.cascade(parameters); - lineDasharray.cascade(parameters); - linePattern.cascade(parameters); -} - -bool LinePaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= lineOpacity.calculate(parameters); - hasTransitions |= lineColor.calculate(parameters); - hasTransitions |= lineTranslate.calculate(parameters); - hasTransitions |= lineTranslateAnchor.calculate(parameters); - hasTransitions |= lineWidth.calculate(parameters); - hasTransitions |= lineGapWidth.calculate(parameters); - hasTransitions |= lineOffset.calculate(parameters); - hasTransitions |= lineBlur.calculate(parameters); - hasTransitions |= lineDasharray.calculate(parameters); - hasTransitions |= linePattern.calculate(parameters); - - return hasTransitions; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index b73e3f2ef2..07458cd634 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -9,35 +9,81 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; - -class LineLayoutProperties { -public: - void recalculate(const CalculationParameters&); - - LayoutProperty lineCap { LineCapType::Butt }; - LayoutProperty lineJoin { LineJoinType::Miter }; - LayoutProperty lineMiterLimit { 2 }; - LayoutProperty lineRoundLimit { 1 }; -}; - -class LinePaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); - - PaintProperty lineOpacity { 1 }; - PaintProperty lineColor { Color::black() }; - PaintProperty> lineTranslate { {{ 0, 0 }} }; - PaintProperty lineTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty lineWidth { 1 }; - PaintProperty lineGapWidth { 0 }; - PaintProperty lineOffset { 0 }; - PaintProperty lineBlur { 0 }; - PaintProperty, CrossFadedPropertyEvaluator> lineDasharray { { } }; - PaintProperty linePattern { "" }; +struct LineCap : LayoutProperty { + static LineCapType defaultValue() { return LineCapType::Butt; } }; +struct LineJoin : LayoutProperty { + static LineJoinType defaultValue() { return LineJoinType::Miter; } +}; + +struct LineMiterLimit : LayoutProperty { + static float defaultValue() { return 2; } +}; + +struct LineRoundLimit : LayoutProperty { + static float defaultValue() { return 1; } +}; + +struct LineOpacity : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct LineColor : PaintProperty { + static Color defaultValue() { return Color::black(); } +}; + +struct LineTranslate : PaintProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct LineTranslateAnchor : PaintProperty { + static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } +}; + +struct LineWidth : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct LineGapWidth : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct LineOffset : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct LineBlur : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct LineDasharray : CrossFadedPaintProperty> { + static std::vector defaultValue() { return { }; } +}; + +struct LinePattern : CrossFadedPaintProperty { + static std::string defaultValue() { return ""; } +}; + +class LineLayoutProperties : public LayoutProperties< + LineCap, + LineJoin, + LineMiterLimit, + LineRoundLimit +> {}; + +class LinePaintProperties : public PaintProperties< + LineOpacity, + LineColor, + LineTranslate, + LineTranslateAnchor, + LineWidth, + LineGapWidth, + LineOffset, + LineBlur, + LineDasharray, + LinePattern +> {}; + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 238bfef6e4..21d72a0fdc 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -49,13 +49,13 @@ PropertyValue RasterLayer::getDefaultRasterOpacity() { } PropertyValue RasterLayer::getRasterOpacity(const optional& klass) const { - return impl->paint.rasterOpacity.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterOpacity(PropertyValue value, const optional& klass) { if (value == getRasterOpacity(klass)) return; - impl->paint.rasterOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -64,13 +64,13 @@ PropertyValue RasterLayer::getDefaultRasterHueRotate() { } PropertyValue RasterLayer::getRasterHueRotate(const optional& klass) const { - return impl->paint.rasterHueRotate.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterHueRotate(PropertyValue value, const optional& klass) { if (value == getRasterHueRotate(klass)) return; - impl->paint.rasterHueRotate.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -79,13 +79,13 @@ PropertyValue RasterLayer::getDefaultRasterBrightnessMin() { } PropertyValue RasterLayer::getRasterBrightnessMin(const optional& klass) const { - return impl->paint.rasterBrightnessMin.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterBrightnessMin(PropertyValue value, const optional& klass) { if (value == getRasterBrightnessMin(klass)) return; - impl->paint.rasterBrightnessMin.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -94,13 +94,13 @@ PropertyValue RasterLayer::getDefaultRasterBrightnessMax() { } PropertyValue RasterLayer::getRasterBrightnessMax(const optional& klass) const { - return impl->paint.rasterBrightnessMax.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterBrightnessMax(PropertyValue value, const optional& klass) { if (value == getRasterBrightnessMax(klass)) return; - impl->paint.rasterBrightnessMax.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -109,13 +109,13 @@ PropertyValue RasterLayer::getDefaultRasterSaturation() { } PropertyValue RasterLayer::getRasterSaturation(const optional& klass) const { - return impl->paint.rasterSaturation.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterSaturation(PropertyValue value, const optional& klass) { if (value == getRasterSaturation(klass)) return; - impl->paint.rasterSaturation.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -124,13 +124,13 @@ PropertyValue RasterLayer::getDefaultRasterContrast() { } PropertyValue RasterLayer::getRasterContrast(const optional& klass) const { - return impl->paint.rasterContrast.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterContrast(PropertyValue value, const optional& klass) { if (value == getRasterContrast(klass)) return; - impl->paint.rasterContrast.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -139,13 +139,13 @@ PropertyValue RasterLayer::getDefaultRasterFadeDuration() { } PropertyValue RasterLayer::getRasterFadeDuration(const optional& klass) const { - return impl->paint.rasterFadeDuration.get(klass); + return impl->paint.get(klass); } void RasterLayer::setRasterFadeDuration(PropertyValue value, const optional& klass) { if (value == getRasterFadeDuration(klass)) return; - impl->paint.rasterFadeDuration.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } diff --git a/src/mbgl/style/layers/raster_layer_impl.cpp b/src/mbgl/style/layers/raster_layer_impl.cpp index 879bfa4559..3be4bb4fbd 100644 --- a/src/mbgl/style/layers/raster_layer_impl.cpp +++ b/src/mbgl/style/layers/raster_layer_impl.cpp @@ -8,12 +8,12 @@ void RasterLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool RasterLayer::Impl::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = paint.recalculate(parameters); +bool RasterLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { + paint.evaluate(parameters); - passes = paint.rasterOpacity > 0 ? RenderPass::Translucent : RenderPass::None; + passes = paint.evaluated.get() > 0 ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr RasterLayer::Impl::createBucket(BucketParameters&) const { diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp index a5b396e2ed..df5d388bdf 100644 --- a/src/mbgl/style/layers/raster_layer_impl.hpp +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -13,7 +13,7 @@ public: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; - bool recalculate(const CalculationParameters&) override; + bool evaluate(const PropertyEvaluationParameters&) override; std::unique_ptr createBucket(BucketParameters&) const override; diff --git a/src/mbgl/style/layers/raster_layer_properties.cpp b/src/mbgl/style/layers/raster_layer_properties.cpp index 68d9d1d35d..303719af40 100644 --- a/src/mbgl/style/layers/raster_layer_properties.cpp +++ b/src/mbgl/style/layers/raster_layer_properties.cpp @@ -5,29 +5,5 @@ namespace mbgl { namespace style { -void RasterPaintProperties::cascade(const CascadeParameters& parameters) { - rasterOpacity.cascade(parameters); - rasterHueRotate.cascade(parameters); - rasterBrightnessMin.cascade(parameters); - rasterBrightnessMax.cascade(parameters); - rasterSaturation.cascade(parameters); - rasterContrast.cascade(parameters); - rasterFadeDuration.cascade(parameters); -} - -bool RasterPaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= rasterOpacity.calculate(parameters); - hasTransitions |= rasterHueRotate.calculate(parameters); - hasTransitions |= rasterBrightnessMin.calculate(parameters); - hasTransitions |= rasterBrightnessMax.calculate(parameters); - hasTransitions |= rasterSaturation.calculate(parameters); - hasTransitions |= rasterContrast.calculate(parameters); - hasTransitions |= rasterFadeDuration.calculate(parameters); - - return hasTransitions; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/raster_layer_properties.hpp b/src/mbgl/style/layers/raster_layer_properties.hpp index ddfb833e12..caa6d0c58d 100644 --- a/src/mbgl/style/layers/raster_layer_properties.hpp +++ b/src/mbgl/style/layers/raster_layer_properties.hpp @@ -9,22 +9,43 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; - -class RasterPaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); - - PaintProperty rasterOpacity { 1 }; - PaintProperty rasterHueRotate { 0 }; - PaintProperty rasterBrightnessMin { 0 }; - PaintProperty rasterBrightnessMax { 1 }; - PaintProperty rasterSaturation { 0 }; - PaintProperty rasterContrast { 0 }; - PaintProperty rasterFadeDuration { 300 }; +struct RasterOpacity : PaintProperty { + static float defaultValue() { return 1; } }; +struct RasterHueRotate : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct RasterBrightnessMin : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct RasterBrightnessMax : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct RasterSaturation : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct RasterContrast : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct RasterFadeDuration : PaintProperty { + static float defaultValue() { return 300; } +}; + +class RasterPaintProperties : public PaintProperties< + RasterOpacity, + RasterHueRotate, + RasterBrightnessMin, + RasterBrightnessMax, + RasterSaturation, + RasterContrast, + RasterFadeDuration +> {}; + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index d49e8d7fe3..61f360ff64 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -60,479 +60,479 @@ const Filter& SymbolLayer::getFilter() const { // Layout properties PropertyValue SymbolLayer::getDefaultSymbolPlacement() { - return { SymbolPlacementType::Point }; + return SymbolPlacement::defaultValue(); } PropertyValue SymbolLayer::getSymbolPlacement() const { - return impl->layout.symbolPlacement.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setSymbolPlacement(PropertyValue value) { if (value == getSymbolPlacement()) return; - impl->layout.symbolPlacement.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-placement"); } PropertyValue SymbolLayer::getDefaultSymbolSpacing() { - return { 250 }; + return SymbolSpacing::defaultValue(); } PropertyValue SymbolLayer::getSymbolSpacing() const { - return impl->layout.symbolSpacing.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setSymbolSpacing(PropertyValue value) { if (value == getSymbolSpacing()) return; - impl->layout.symbolSpacing.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-spacing"); } PropertyValue SymbolLayer::getDefaultSymbolAvoidEdges() { - return { false }; + return SymbolAvoidEdges::defaultValue(); } PropertyValue SymbolLayer::getSymbolAvoidEdges() const { - return impl->layout.symbolAvoidEdges.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setSymbolAvoidEdges(PropertyValue value) { if (value == getSymbolAvoidEdges()) return; - impl->layout.symbolAvoidEdges.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-avoid-edges"); } PropertyValue SymbolLayer::getDefaultIconAllowOverlap() { - return { false }; + return IconAllowOverlap::defaultValue(); } PropertyValue SymbolLayer::getIconAllowOverlap() const { - return impl->layout.iconAllowOverlap.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconAllowOverlap(PropertyValue value) { if (value == getIconAllowOverlap()) return; - impl->layout.iconAllowOverlap.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-allow-overlap"); } PropertyValue SymbolLayer::getDefaultIconIgnorePlacement() { - return { false }; + return IconIgnorePlacement::defaultValue(); } PropertyValue SymbolLayer::getIconIgnorePlacement() const { - return impl->layout.iconIgnorePlacement.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconIgnorePlacement(PropertyValue value) { if (value == getIconIgnorePlacement()) return; - impl->layout.iconIgnorePlacement.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-ignore-placement"); } PropertyValue SymbolLayer::getDefaultIconOptional() { - return { false }; + return IconOptional::defaultValue(); } PropertyValue SymbolLayer::getIconOptional() const { - return impl->layout.iconOptional.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconOptional(PropertyValue value) { if (value == getIconOptional()) return; - impl->layout.iconOptional.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-optional"); } PropertyValue SymbolLayer::getDefaultIconRotationAlignment() { - return { AlignmentType::Auto }; + return IconRotationAlignment::defaultValue(); } PropertyValue SymbolLayer::getIconRotationAlignment() const { - return impl->layout.iconRotationAlignment.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconRotationAlignment(PropertyValue value) { if (value == getIconRotationAlignment()) return; - impl->layout.iconRotationAlignment.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-rotation-alignment"); } PropertyValue SymbolLayer::getDefaultIconSize() { - return { 1 }; + return IconSize::defaultValue(); } PropertyValue SymbolLayer::getIconSize() const { - return impl->layout.iconSize.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconSize(PropertyValue value) { if (value == getIconSize()) return; - impl->layout.iconSize.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-size"); } PropertyValue SymbolLayer::getDefaultIconTextFit() { - return { IconTextFitType::None }; + return IconTextFit::defaultValue(); } PropertyValue SymbolLayer::getIconTextFit() const { - return impl->layout.iconTextFit.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconTextFit(PropertyValue value) { if (value == getIconTextFit()) return; - impl->layout.iconTextFit.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit"); } PropertyValue> SymbolLayer::getDefaultIconTextFitPadding() { - return { {{ 0, 0, 0, 0 }} }; + return IconTextFitPadding::defaultValue(); } PropertyValue> SymbolLayer::getIconTextFitPadding() const { - return impl->layout.iconTextFitPadding.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconTextFitPadding(PropertyValue> value) { if (value == getIconTextFitPadding()) return; - impl->layout.iconTextFitPadding.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit-padding"); } PropertyValue SymbolLayer::getDefaultIconImage() { - return { "" }; + return IconImage::defaultValue(); } PropertyValue SymbolLayer::getIconImage() const { - return impl->layout.iconImage.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconImage(PropertyValue value) { if (value == getIconImage()) return; - impl->layout.iconImage.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-image"); } PropertyValue SymbolLayer::getDefaultIconRotate() { - return { 0 }; + return IconRotate::defaultValue(); } PropertyValue SymbolLayer::getIconRotate() const { - return impl->layout.iconRotate.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconRotate(PropertyValue value) { if (value == getIconRotate()) return; - impl->layout.iconRotate.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-rotate"); } PropertyValue SymbolLayer::getDefaultIconPadding() { - return { 2 }; + return IconPadding::defaultValue(); } PropertyValue SymbolLayer::getIconPadding() const { - return impl->layout.iconPadding.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconPadding(PropertyValue value) { if (value == getIconPadding()) return; - impl->layout.iconPadding.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-padding"); } PropertyValue SymbolLayer::getDefaultIconKeepUpright() { - return { false }; + return IconKeepUpright::defaultValue(); } PropertyValue SymbolLayer::getIconKeepUpright() const { - return impl->layout.iconKeepUpright.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconKeepUpright(PropertyValue value) { if (value == getIconKeepUpright()) return; - impl->layout.iconKeepUpright.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-keep-upright"); } PropertyValue> SymbolLayer::getDefaultIconOffset() { - return { {{ 0, 0 }} }; + return IconOffset::defaultValue(); } PropertyValue> SymbolLayer::getIconOffset() const { - return impl->layout.iconOffset.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setIconOffset(PropertyValue> value) { if (value == getIconOffset()) return; - impl->layout.iconOffset.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "icon-offset"); } PropertyValue SymbolLayer::getDefaultTextPitchAlignment() { - return { AlignmentType::Auto }; + return TextPitchAlignment::defaultValue(); } PropertyValue SymbolLayer::getTextPitchAlignment() const { - return impl->layout.textPitchAlignment.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextPitchAlignment(PropertyValue value) { if (value == getTextPitchAlignment()) return; - impl->layout.textPitchAlignment.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-pitch-alignment"); } PropertyValue SymbolLayer::getDefaultTextRotationAlignment() { - return { AlignmentType::Auto }; + return TextRotationAlignment::defaultValue(); } PropertyValue SymbolLayer::getTextRotationAlignment() const { - return impl->layout.textRotationAlignment.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextRotationAlignment(PropertyValue value) { if (value == getTextRotationAlignment()) return; - impl->layout.textRotationAlignment.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotation-alignment"); } PropertyValue SymbolLayer::getDefaultTextField() { - return { "" }; + return TextField::defaultValue(); } PropertyValue SymbolLayer::getTextField() const { - return impl->layout.textField.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextField(PropertyValue value) { if (value == getTextField()) return; - impl->layout.textField.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-field"); } PropertyValue> SymbolLayer::getDefaultTextFont() { - return { { "Open Sans Regular", "Arial Unicode MS Regular" } }; + return TextFont::defaultValue(); } PropertyValue> SymbolLayer::getTextFont() const { - return impl->layout.textFont.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextFont(PropertyValue> value) { if (value == getTextFont()) return; - impl->layout.textFont.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-font"); } PropertyValue SymbolLayer::getDefaultTextSize() { - return { 16 }; + return TextSize::defaultValue(); } PropertyValue SymbolLayer::getTextSize() const { - return impl->layout.textSize.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextSize(PropertyValue value) { if (value == getTextSize()) return; - impl->layout.textSize.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-size"); } PropertyValue SymbolLayer::getDefaultTextMaxWidth() { - return { 10 }; + return TextMaxWidth::defaultValue(); } PropertyValue SymbolLayer::getTextMaxWidth() const { - return impl->layout.textMaxWidth.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextMaxWidth(PropertyValue value) { if (value == getTextMaxWidth()) return; - impl->layout.textMaxWidth.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-width"); } PropertyValue SymbolLayer::getDefaultTextLineHeight() { - return { 1.2 }; + return TextLineHeight::defaultValue(); } PropertyValue SymbolLayer::getTextLineHeight() const { - return impl->layout.textLineHeight.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextLineHeight(PropertyValue value) { if (value == getTextLineHeight()) return; - impl->layout.textLineHeight.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-line-height"); } PropertyValue SymbolLayer::getDefaultTextLetterSpacing() { - return { 0 }; + return TextLetterSpacing::defaultValue(); } PropertyValue SymbolLayer::getTextLetterSpacing() const { - return impl->layout.textLetterSpacing.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextLetterSpacing(PropertyValue value) { if (value == getTextLetterSpacing()) return; - impl->layout.textLetterSpacing.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-letter-spacing"); } PropertyValue SymbolLayer::getDefaultTextJustify() { - return { TextJustifyType::Center }; + return TextJustify::defaultValue(); } PropertyValue SymbolLayer::getTextJustify() const { - return impl->layout.textJustify.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextJustify(PropertyValue value) { if (value == getTextJustify()) return; - impl->layout.textJustify.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-justify"); } PropertyValue SymbolLayer::getDefaultTextAnchor() { - return { TextAnchorType::Center }; + return TextAnchor::defaultValue(); } PropertyValue SymbolLayer::getTextAnchor() const { - return impl->layout.textAnchor.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextAnchor(PropertyValue value) { if (value == getTextAnchor()) return; - impl->layout.textAnchor.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-anchor"); } PropertyValue SymbolLayer::getDefaultTextMaxAngle() { - return { 45 }; + return TextMaxAngle::defaultValue(); } PropertyValue SymbolLayer::getTextMaxAngle() const { - return impl->layout.textMaxAngle.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextMaxAngle(PropertyValue value) { if (value == getTextMaxAngle()) return; - impl->layout.textMaxAngle.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-angle"); } PropertyValue SymbolLayer::getDefaultTextRotate() { - return { 0 }; + return TextRotate::defaultValue(); } PropertyValue SymbolLayer::getTextRotate() const { - return impl->layout.textRotate.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextRotate(PropertyValue value) { if (value == getTextRotate()) return; - impl->layout.textRotate.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotate"); } PropertyValue SymbolLayer::getDefaultTextPadding() { - return { 2 }; + return TextPadding::defaultValue(); } PropertyValue SymbolLayer::getTextPadding() const { - return impl->layout.textPadding.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextPadding(PropertyValue value) { if (value == getTextPadding()) return; - impl->layout.textPadding.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-padding"); } PropertyValue SymbolLayer::getDefaultTextKeepUpright() { - return { true }; + return TextKeepUpright::defaultValue(); } PropertyValue SymbolLayer::getTextKeepUpright() const { - return impl->layout.textKeepUpright.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextKeepUpright(PropertyValue value) { if (value == getTextKeepUpright()) return; - impl->layout.textKeepUpright.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-keep-upright"); } PropertyValue SymbolLayer::getDefaultTextTransform() { - return { TextTransformType::None }; + return TextTransform::defaultValue(); } PropertyValue SymbolLayer::getTextTransform() const { - return impl->layout.textTransform.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextTransform(PropertyValue value) { if (value == getTextTransform()) return; - impl->layout.textTransform.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-transform"); } PropertyValue> SymbolLayer::getDefaultTextOffset() { - return { {{ 0, 0 }} }; + return TextOffset::defaultValue(); } PropertyValue> SymbolLayer::getTextOffset() const { - return impl->layout.textOffset.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextOffset(PropertyValue> value) { if (value == getTextOffset()) return; - impl->layout.textOffset.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-offset"); } PropertyValue SymbolLayer::getDefaultTextAllowOverlap() { - return { false }; + return TextAllowOverlap::defaultValue(); } PropertyValue SymbolLayer::getTextAllowOverlap() const { - return impl->layout.textAllowOverlap.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextAllowOverlap(PropertyValue value) { if (value == getTextAllowOverlap()) return; - impl->layout.textAllowOverlap.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-allow-overlap"); } PropertyValue SymbolLayer::getDefaultTextIgnorePlacement() { - return { false }; + return TextIgnorePlacement::defaultValue(); } PropertyValue SymbolLayer::getTextIgnorePlacement() const { - return impl->layout.textIgnorePlacement.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextIgnorePlacement(PropertyValue value) { if (value == getTextIgnorePlacement()) return; - impl->layout.textIgnorePlacement.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-ignore-placement"); } PropertyValue SymbolLayer::getDefaultTextOptional() { - return { false }; + return TextOptional::defaultValue(); } PropertyValue SymbolLayer::getTextOptional() const { - return impl->layout.textOptional.get(); + return impl->layout.unevaluated.get(); } void SymbolLayer::setTextOptional(PropertyValue value) { if (value == getTextOptional()) return; - impl->layout.textOptional.set(value); + impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-optional"); } @@ -543,13 +543,13 @@ PropertyValue SymbolLayer::getDefaultIconOpacity() { } PropertyValue SymbolLayer::getIconOpacity(const optional& klass) const { - return impl->paint.iconOpacity.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconOpacity(PropertyValue value, const optional& klass) { if (value == getIconOpacity(klass)) return; - impl->paint.iconOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -558,13 +558,13 @@ PropertyValue SymbolLayer::getDefaultIconColor() { } PropertyValue SymbolLayer::getIconColor(const optional& klass) const { - return impl->paint.iconColor.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconColor(PropertyValue value, const optional& klass) { if (value == getIconColor(klass)) return; - impl->paint.iconColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -573,13 +573,13 @@ PropertyValue SymbolLayer::getDefaultIconHaloColor() { } PropertyValue SymbolLayer::getIconHaloColor(const optional& klass) const { - return impl->paint.iconHaloColor.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconHaloColor(PropertyValue value, const optional& klass) { if (value == getIconHaloColor(klass)) return; - impl->paint.iconHaloColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -588,13 +588,13 @@ PropertyValue SymbolLayer::getDefaultIconHaloWidth() { } PropertyValue SymbolLayer::getIconHaloWidth(const optional& klass) const { - return impl->paint.iconHaloWidth.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconHaloWidth(PropertyValue value, const optional& klass) { if (value == getIconHaloWidth(klass)) return; - impl->paint.iconHaloWidth.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -603,13 +603,13 @@ PropertyValue SymbolLayer::getDefaultIconHaloBlur() { } PropertyValue SymbolLayer::getIconHaloBlur(const optional& klass) const { - return impl->paint.iconHaloBlur.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconHaloBlur(PropertyValue value, const optional& klass) { if (value == getIconHaloBlur(klass)) return; - impl->paint.iconHaloBlur.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -618,13 +618,13 @@ PropertyValue> SymbolLayer::getDefaultIconTranslate() { } PropertyValue> SymbolLayer::getIconTranslate(const optional& klass) const { - return impl->paint.iconTranslate.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconTranslate(PropertyValue> value, const optional& klass) { if (value == getIconTranslate(klass)) return; - impl->paint.iconTranslate.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -633,13 +633,13 @@ PropertyValue SymbolLayer::getDefaultIconTranslateAnchor() } PropertyValue SymbolLayer::getIconTranslateAnchor(const optional& klass) const { - return impl->paint.iconTranslateAnchor.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setIconTranslateAnchor(PropertyValue value, const optional& klass) { if (value == getIconTranslateAnchor(klass)) return; - impl->paint.iconTranslateAnchor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -648,13 +648,13 @@ PropertyValue SymbolLayer::getDefaultTextOpacity() { } PropertyValue SymbolLayer::getTextOpacity(const optional& klass) const { - return impl->paint.textOpacity.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextOpacity(PropertyValue value, const optional& klass) { if (value == getTextOpacity(klass)) return; - impl->paint.textOpacity.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -663,13 +663,13 @@ PropertyValue SymbolLayer::getDefaultTextColor() { } PropertyValue SymbolLayer::getTextColor(const optional& klass) const { - return impl->paint.textColor.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextColor(PropertyValue value, const optional& klass) { if (value == getTextColor(klass)) return; - impl->paint.textColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -678,13 +678,13 @@ PropertyValue SymbolLayer::getDefaultTextHaloColor() { } PropertyValue SymbolLayer::getTextHaloColor(const optional& klass) const { - return impl->paint.textHaloColor.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextHaloColor(PropertyValue value, const optional& klass) { if (value == getTextHaloColor(klass)) return; - impl->paint.textHaloColor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -693,13 +693,13 @@ PropertyValue SymbolLayer::getDefaultTextHaloWidth() { } PropertyValue SymbolLayer::getTextHaloWidth(const optional& klass) const { - return impl->paint.textHaloWidth.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextHaloWidth(PropertyValue value, const optional& klass) { if (value == getTextHaloWidth(klass)) return; - impl->paint.textHaloWidth.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -708,13 +708,13 @@ PropertyValue SymbolLayer::getDefaultTextHaloBlur() { } PropertyValue SymbolLayer::getTextHaloBlur(const optional& klass) const { - return impl->paint.textHaloBlur.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextHaloBlur(PropertyValue value, const optional& klass) { if (value == getTextHaloBlur(klass)) return; - impl->paint.textHaloBlur.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -723,13 +723,13 @@ PropertyValue> SymbolLayer::getDefaultTextTranslate() { } PropertyValue> SymbolLayer::getTextTranslate(const optional& klass) const { - return impl->paint.textTranslate.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextTranslate(PropertyValue> value, const optional& klass) { if (value == getTextTranslate(klass)) return; - impl->paint.textTranslate.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } @@ -738,13 +738,13 @@ PropertyValue SymbolLayer::getDefaultTextTranslateAnchor() } PropertyValue SymbolLayer::getTextTranslateAnchor(const optional& klass) const { - return impl->paint.textTranslateAnchor.get(klass); + return impl->paint.get(klass); } void SymbolLayer::setTextTranslateAnchor(PropertyValue value, const optional& klass) { if (value == getTextTranslateAnchor(klass)) return; - impl->paint.textTranslateAnchor.set(value, klass); + impl->paint.set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 0ac9ff832d..957bc1993e 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -10,20 +10,18 @@ void SymbolLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool SymbolLayer::Impl::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = paint.recalculate(parameters); +bool SymbolLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { + paint.evaluate(parameters); // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: - layout.iconSize.calculate(parameters); - layout.textSize.calculate(parameters); - iconSize = layout.iconSize; - textSize = layout.textSize; + iconSize = layout.evaluate(parameters); + textSize = layout.evaluate(parameters); - passes = ((paint.iconOpacity > 0 && (paint.iconColor.value.a > 0 || paint.iconHaloColor.value.a > 0) && iconSize > 0) - || (paint.textOpacity > 0 && (paint.textColor.value.a > 0 || paint.textHaloColor.value.a > 0) && textSize > 0)) + passes = ((paint.evaluated.get() > 0 && (paint.evaluated.get().a > 0 || paint.evaluated.get().a > 0) && iconSize > 0) + || (paint.evaluated.get() > 0 && (paint.evaluated.get().a > 0 || paint.evaluated.get().a > 0) && textSize > 0)) ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr SymbolLayer::Impl::createBucket(BucketParameters&) const { @@ -32,37 +30,34 @@ std::unique_ptr SymbolLayer::Impl::createBucket(BucketParameters&) const } std::unique_ptr SymbolLayer::Impl::createLayout(BucketParameters& parameters) const { - SymbolLayoutProperties layoutProperties = layout; + PropertyEvaluationParameters p(parameters.tileID.overscaledZ); + SymbolLayoutProperties::Evaluated evaluated = layout.evaluate(p); - CalculationParameters p(parameters.tileID.overscaledZ); - layoutProperties.recalculate(p); - - if (layoutProperties.iconRotationAlignment.value == AlignmentType::Auto) { - if (layoutProperties.symbolPlacement.value == SymbolPlacementType::Line) { - layoutProperties.iconRotationAlignment.value = AlignmentType::Map; + if (evaluated.get() == AlignmentType::Auto) { + if (evaluated.get() == SymbolPlacementType::Line) { + evaluated.get() = AlignmentType::Map; } else { - layoutProperties.iconRotationAlignment.value = AlignmentType::Viewport; + evaluated.get() = AlignmentType::Viewport; } } - if (layoutProperties.textRotationAlignment.value == AlignmentType::Auto) { - if (layoutProperties.symbolPlacement.value == SymbolPlacementType::Line) { - layoutProperties.textRotationAlignment.value = AlignmentType::Map; + if (evaluated.get() == AlignmentType::Auto) { + if (evaluated.get() == SymbolPlacementType::Line) { + evaluated.get() = AlignmentType::Map; } else { - layoutProperties.textRotationAlignment.value = AlignmentType::Viewport; + evaluated.get() = AlignmentType::Viewport; } } // If unspecified `text-pitch-alignment` inherits `text-rotation-alignment` - if (layoutProperties.textPitchAlignment.value == AlignmentType::Auto) { - layoutProperties.textPitchAlignment.value = layoutProperties.textRotationAlignment.value; + if (evaluated.get() == AlignmentType::Auto) { + evaluated.get() = evaluated.get(); } - layoutProperties.textSize.calculate(CalculationParameters(18)); - float textMaxSize = layoutProperties.textSize; + float textMaxSize = layout.evaluate(PropertyEvaluationParameters(18)); - layoutProperties.iconSize.calculate(CalculationParameters(p.z + 1)); - layoutProperties.textSize.calculate(CalculationParameters(p.z + 1)); + evaluated.get() = layout.evaluate(PropertyEvaluationParameters(p.z + 1)); + evaluated.get() = layout.evaluate(PropertyEvaluationParameters(p.z + 1)); return std::make_unique(id, parameters.layer.getName(), @@ -71,40 +66,40 @@ std::unique_ptr SymbolLayer::Impl::createLayout(BucketParameters& parameters.mode, parameters.layer, filter, - layoutProperties, + evaluated, textMaxSize, *spriteAtlas); } -SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties& layout_) const { +SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { return SymbolPropertyValues { - layout_.iconRotationAlignment.value, // icon-pitch-alignment is not yet implemented; inherit the rotation alignment - layout_.iconRotationAlignment.value, - layout_.iconSize.value, - paint.iconOpacity.value, - paint.iconColor.value, - paint.iconHaloColor.value, - paint.iconHaloWidth.value, - paint.iconHaloBlur.value, - paint.iconTranslate.value, - paint.iconTranslateAnchor.value, + layout_.get(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment + layout_.get(), + layout_.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), iconSize, 1.0f }; } -SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties& layout_) const { +SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { return SymbolPropertyValues { - layout_.textPitchAlignment.value, - layout_.textRotationAlignment.value, - layout_.textSize.value, - paint.textOpacity.value, - paint.textColor.value, - paint.textHaloColor.value, - paint.textHaloWidth.value, - paint.textHaloBlur.value, - paint.textTranslate.value, - paint.textTranslateAnchor.value, + layout_.get(), + layout_.get(), + layout_.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), textSize, 24.0f }; diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index b760538f86..46ed75b231 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -47,13 +47,13 @@ public: std::unique_ptr cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; - bool recalculate(const CalculationParameters&) override; + bool evaluate(const PropertyEvaluationParameters&) override; std::unique_ptr createBucket(BucketParameters&) const override; std::unique_ptr createLayout(BucketParameters&) const; - SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties&) const; - SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties&) const; + SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::Evaluated&) const; + SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::Evaluated&) const; SymbolLayoutProperties layout; SymbolPaintProperties paint; diff --git a/src/mbgl/style/layers/symbol_layer_properties.cpp b/src/mbgl/style/layers/symbol_layer_properties.cpp index 59a73d3d59..5a1ce713ba 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.cpp +++ b/src/mbgl/style/layers/symbol_layer_properties.cpp @@ -5,80 +5,5 @@ namespace mbgl { namespace style { -void SymbolLayoutProperties::recalculate(const CalculationParameters& parameters) { - symbolPlacement.calculate(parameters); - symbolSpacing.calculate(parameters); - symbolAvoidEdges.calculate(parameters); - iconAllowOverlap.calculate(parameters); - iconIgnorePlacement.calculate(parameters); - iconOptional.calculate(parameters); - iconRotationAlignment.calculate(parameters); - iconSize.calculate(parameters); - iconTextFit.calculate(parameters); - iconTextFitPadding.calculate(parameters); - iconImage.calculate(parameters); - iconRotate.calculate(parameters); - iconPadding.calculate(parameters); - iconKeepUpright.calculate(parameters); - iconOffset.calculate(parameters); - textPitchAlignment.calculate(parameters); - textRotationAlignment.calculate(parameters); - textField.calculate(parameters); - textFont.calculate(parameters); - textSize.calculate(parameters); - textMaxWidth.calculate(parameters); - textLineHeight.calculate(parameters); - textLetterSpacing.calculate(parameters); - textJustify.calculate(parameters); - textAnchor.calculate(parameters); - textMaxAngle.calculate(parameters); - textRotate.calculate(parameters); - textPadding.calculate(parameters); - textKeepUpright.calculate(parameters); - textTransform.calculate(parameters); - textOffset.calculate(parameters); - textAllowOverlap.calculate(parameters); - textIgnorePlacement.calculate(parameters); - textOptional.calculate(parameters); -} - -void SymbolPaintProperties::cascade(const CascadeParameters& parameters) { - iconOpacity.cascade(parameters); - iconColor.cascade(parameters); - iconHaloColor.cascade(parameters); - iconHaloWidth.cascade(parameters); - iconHaloBlur.cascade(parameters); - iconTranslate.cascade(parameters); - iconTranslateAnchor.cascade(parameters); - textOpacity.cascade(parameters); - textColor.cascade(parameters); - textHaloColor.cascade(parameters); - textHaloWidth.cascade(parameters); - textHaloBlur.cascade(parameters); - textTranslate.cascade(parameters); - textTranslateAnchor.cascade(parameters); -} - -bool SymbolPaintProperties::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= iconOpacity.calculate(parameters); - hasTransitions |= iconColor.calculate(parameters); - hasTransitions |= iconHaloColor.calculate(parameters); - hasTransitions |= iconHaloWidth.calculate(parameters); - hasTransitions |= iconHaloBlur.calculate(parameters); - hasTransitions |= iconTranslate.calculate(parameters); - hasTransitions |= iconTranslateAnchor.calculate(parameters); - hasTransitions |= textOpacity.calculate(parameters); - hasTransitions |= textColor.calculate(parameters); - hasTransitions |= textHaloColor.calculate(parameters); - hasTransitions |= textHaloWidth.calculate(parameters); - hasTransitions |= textHaloBlur.calculate(parameters); - hasTransitions |= textTranslate.calculate(parameters); - hasTransitions |= textTranslateAnchor.calculate(parameters); - - return hasTransitions; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index fefa0ae05e..8b72c4347a 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -9,69 +9,251 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; - -class SymbolLayoutProperties { -public: - void recalculate(const CalculationParameters&); - - LayoutProperty symbolPlacement { SymbolPlacementType::Point }; - LayoutProperty symbolSpacing { 250 }; - LayoutProperty symbolAvoidEdges { false }; - LayoutProperty iconAllowOverlap { false }; - LayoutProperty iconIgnorePlacement { false }; - LayoutProperty iconOptional { false }; - LayoutProperty iconRotationAlignment { AlignmentType::Auto }; - LayoutProperty iconSize { 1 }; - LayoutProperty iconTextFit { IconTextFitType::None }; - LayoutProperty> iconTextFitPadding { {{ 0, 0, 0, 0 }} }; - LayoutProperty iconImage { "" }; - LayoutProperty iconRotate { 0 }; - LayoutProperty iconPadding { 2 }; - LayoutProperty iconKeepUpright { false }; - LayoutProperty> iconOffset { {{ 0, 0 }} }; - LayoutProperty textPitchAlignment { AlignmentType::Auto }; - LayoutProperty textRotationAlignment { AlignmentType::Auto }; - LayoutProperty textField { "" }; - LayoutProperty> textFont { { "Open Sans Regular", "Arial Unicode MS Regular" } }; - LayoutProperty textSize { 16 }; - LayoutProperty textMaxWidth { 10 }; - LayoutProperty textLineHeight { 1.2 }; - LayoutProperty textLetterSpacing { 0 }; - LayoutProperty textJustify { TextJustifyType::Center }; - LayoutProperty textAnchor { TextAnchorType::Center }; - LayoutProperty textMaxAngle { 45 }; - LayoutProperty textRotate { 0 }; - LayoutProperty textPadding { 2 }; - LayoutProperty textKeepUpright { true }; - LayoutProperty textTransform { TextTransformType::None }; - LayoutProperty> textOffset { {{ 0, 0 }} }; - LayoutProperty textAllowOverlap { false }; - LayoutProperty textIgnorePlacement { false }; - LayoutProperty textOptional { false }; -}; - -class SymbolPaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); - - PaintProperty iconOpacity { 1 }; - PaintProperty iconColor { Color::black() }; - PaintProperty iconHaloColor { {} }; - PaintProperty iconHaloWidth { 0 }; - PaintProperty iconHaloBlur { 0 }; - PaintProperty> iconTranslate { {{ 0, 0 }} }; - PaintProperty iconTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty textOpacity { 1 }; - PaintProperty textColor { Color::black() }; - PaintProperty textHaloColor { {} }; - PaintProperty textHaloWidth { 0 }; - PaintProperty textHaloBlur { 0 }; - PaintProperty> textTranslate { {{ 0, 0 }} }; - PaintProperty textTranslateAnchor { TranslateAnchorType::Map }; +struct SymbolPlacement : LayoutProperty { + static SymbolPlacementType defaultValue() { return SymbolPlacementType::Point; } }; +struct SymbolSpacing : LayoutProperty { + static float defaultValue() { return 250; } +}; + +struct SymbolAvoidEdges : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct IconAllowOverlap : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct IconIgnorePlacement : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct IconOptional : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct IconRotationAlignment : LayoutProperty { + static AlignmentType defaultValue() { return AlignmentType::Auto; } +}; + +struct IconSize : LayoutProperty { + static float defaultValue() { return 1; } +}; + +struct IconTextFit : LayoutProperty { + static IconTextFitType defaultValue() { return IconTextFitType::None; } +}; + +struct IconTextFitPadding : LayoutProperty> { + static std::array defaultValue() { return {{ 0, 0, 0, 0 }}; } +}; + +struct IconImage : LayoutProperty { + static std::string defaultValue() { return ""; } +}; + +struct IconRotate : LayoutProperty { + static float defaultValue() { return 0; } +}; + +struct IconPadding : LayoutProperty { + static float defaultValue() { return 2; } +}; + +struct IconKeepUpright : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct IconOffset : LayoutProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct TextPitchAlignment : LayoutProperty { + static AlignmentType defaultValue() { return AlignmentType::Auto; } +}; + +struct TextRotationAlignment : LayoutProperty { + static AlignmentType defaultValue() { return AlignmentType::Auto; } +}; + +struct TextField : LayoutProperty { + static std::string defaultValue() { return ""; } +}; + +struct TextFont : LayoutProperty> { + static std::vector defaultValue() { return { "Open Sans Regular", "Arial Unicode MS Regular" }; } +}; + +struct TextSize : LayoutProperty { + static float defaultValue() { return 16; } +}; + +struct TextMaxWidth : LayoutProperty { + static float defaultValue() { return 10; } +}; + +struct TextLineHeight : LayoutProperty { + static float defaultValue() { return 1.2; } +}; + +struct TextLetterSpacing : LayoutProperty { + static float defaultValue() { return 0; } +}; + +struct TextJustify : LayoutProperty { + static TextJustifyType defaultValue() { return TextJustifyType::Center; } +}; + +struct TextAnchor : LayoutProperty { + static TextAnchorType defaultValue() { return TextAnchorType::Center; } +}; + +struct TextMaxAngle : LayoutProperty { + static float defaultValue() { return 45; } +}; + +struct TextRotate : LayoutProperty { + static float defaultValue() { return 0; } +}; + +struct TextPadding : LayoutProperty { + static float defaultValue() { return 2; } +}; + +struct TextKeepUpright : LayoutProperty { + static bool defaultValue() { return true; } +}; + +struct TextTransform : LayoutProperty { + static TextTransformType defaultValue() { return TextTransformType::None; } +}; + +struct TextOffset : LayoutProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct TextAllowOverlap : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct TextIgnorePlacement : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct TextOptional : LayoutProperty { + static bool defaultValue() { return false; } +}; + +struct IconOpacity : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct IconColor : PaintProperty { + static Color defaultValue() { return Color::black(); } +}; + +struct IconHaloColor : PaintProperty { + static Color defaultValue() { return {}; } +}; + +struct IconHaloWidth : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct IconHaloBlur : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct IconTranslate : PaintProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct IconTranslateAnchor : PaintProperty { + static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } +}; + +struct TextOpacity : PaintProperty { + static float defaultValue() { return 1; } +}; + +struct TextColor : PaintProperty { + static Color defaultValue() { return Color::black(); } +}; + +struct TextHaloColor : PaintProperty { + static Color defaultValue() { return {}; } +}; + +struct TextHaloWidth : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct TextHaloBlur : PaintProperty { + static float defaultValue() { return 0; } +}; + +struct TextTranslate : PaintProperty> { + static std::array defaultValue() { return {{ 0, 0 }}; } +}; + +struct TextTranslateAnchor : PaintProperty { + static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } +}; + +class SymbolLayoutProperties : public LayoutProperties< + SymbolPlacement, + SymbolSpacing, + SymbolAvoidEdges, + IconAllowOverlap, + IconIgnorePlacement, + IconOptional, + IconRotationAlignment, + IconSize, + IconTextFit, + IconTextFitPadding, + IconImage, + IconRotate, + IconPadding, + IconKeepUpright, + IconOffset, + TextPitchAlignment, + TextRotationAlignment, + TextField, + TextFont, + TextSize, + TextMaxWidth, + TextLineHeight, + TextLetterSpacing, + TextJustify, + TextAnchor, + TextMaxAngle, + TextRotate, + TextPadding, + TextKeepUpright, + TextTransform, + TextOffset, + TextAllowOverlap, + TextIgnorePlacement, + TextOptional +> {}; + +class SymbolPaintProperties : public PaintProperties< + IconOpacity, + IconColor, + IconHaloColor, + IconHaloWidth, + IconHaloBlur, + IconTranslate, + IconTranslateAnchor, + TextOpacity, + TextColor, + TextHaloColor, + TextHaloWidth, + TextHaloBlur, + TextTranslate, + TextTranslateAnchor +> {}; + } // namespace style } // namespace mbgl -- cgit v1.2.1