From 5ac1e328ee029dd7b76187fff3f8be57e8cd7742 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 30 Oct 2016 11:06:59 -0700 Subject: [PATCH] [core] Properties refactor --- cmake/core-files.cmake | 4 +- include/mbgl/style/property_value.hpp | 6 +- include/mbgl/style/transition_options.hpp | 14 +- src/mbgl/layout/symbol_instance.cpp | 2 +- src/mbgl/layout/symbol_instance.hpp | 7 +- src/mbgl/layout/symbol_layout.cpp | 100 +++--- src/mbgl/layout/symbol_layout.hpp | 4 +- src/mbgl/programs/line_program.cpp | 40 +-- src/mbgl/programs/line_program.hpp | 11 +- src/mbgl/renderer/line_bucket.cpp | 10 +- src/mbgl/renderer/line_bucket.hpp | 2 +- src/mbgl/renderer/painter_background.cpp | 18 +- src/mbgl/renderer/painter_circle.cpp | 18 +- src/mbgl/renderer/painter_fill.cpp | 38 +-- src/mbgl/renderer/painter_line.cpp | 16 +- src/mbgl/renderer/painter_raster.cpp | 14 +- src/mbgl/renderer/painter_symbol.cpp | 4 +- src/mbgl/renderer/symbol_bucket.cpp | 2 +- src/mbgl/renderer/symbol_bucket.hpp | 4 +- src/mbgl/style/class_dictionary.hpp | 1 - src/mbgl/style/layer_impl.hpp | 4 +- src/mbgl/style/layers/background_layer.cpp | 12 +- .../style/layers/background_layer_impl.cpp | 8 +- .../style/layers/background_layer_impl.hpp | 2 +- .../layers/background_layer_properties.cpp | 16 - .../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 +- .../style/layers/circle_layer_properties.cpp | 24 -- .../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 +- .../style/layers/fill_layer_properties.cpp | 24 -- .../style/layers/fill_layer_properties.hpp | 51 ++- src/mbgl/style/layers/layer.cpp.ejs | 10 +- .../style/layers/layer_properties.cpp.ejs | 24 -- .../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 +- .../style/layers/line_layer_properties.cpp | 37 --- .../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 +- .../style/layers/raster_layer_properties.cpp | 24 -- .../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 +- .../style/layers/symbol_layer_properties.cpp | 75 ----- .../style/layers/symbol_layer_properties.hpp | 306 ++++++++++++++---- src/mbgl/style/layout_property.hpp | 67 ++-- src/mbgl/style/paint_property.hpp | 221 ++++++++----- ...hpp => property_evaluation_parameters.hpp} | 6 +- src/mbgl/style/property_evaluator.cpp | 2 +- src/mbgl/style/property_evaluator.hpp | 10 +- src/mbgl/style/style.cpp | 13 +- src/mbgl/text/quads.cpp | 30 +- src/mbgl/text/quads.hpp | 9 +- src/mbgl/text/shaping.cpp | 8 +- src/mbgl/text/shaping.hpp | 7 +- src/mbgl/util/indexed_tuple.hpp | 51 +++ test/style/functions.test.cpp | 6 +- test/text/quads.test.cpp | 96 +++--- 69 files changed, 1256 insertions(+), 1058 deletions(-) rename src/mbgl/style/{calculation_parameters.hpp => property_evaluation_parameters.hpp} (82%) create mode 100644 src/mbgl/util/indexed_tuple.hpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 3fd52d99887..cf224ad9ffa 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -236,7 +236,6 @@ set(MBGL_CORE_FILES include/mbgl/style/types.hpp src/mbgl/style/bucket_parameters.cpp src/mbgl/style/bucket_parameters.hpp - src/mbgl/style/calculation_parameters.hpp src/mbgl/style/cascade_parameters.hpp src/mbgl/style/class_dictionary.cpp src/mbgl/style/class_dictionary.hpp @@ -249,6 +248,7 @@ set(MBGL_CORE_FILES src/mbgl/style/paint_property.hpp src/mbgl/style/parser.cpp src/mbgl/style/parser.hpp + src/mbgl/style/property_evaluation_parameters.hpp src/mbgl/style/property_evaluator.cpp src/mbgl/style/property_evaluator.hpp src/mbgl/style/property_parsing.cpp @@ -440,6 +440,8 @@ set(MBGL_CORE_FILES src/mbgl/util/http_header.hpp src/mbgl/util/http_timeout.cpp src/mbgl/util/http_timeout.hpp + src/mbgl/util/ignore.hpp + src/mbgl/util/indexed_tuple.hpp src/mbgl/util/interpolate.hpp src/mbgl/util/intersection_tests.cpp src/mbgl/util/intersection_tests.hpp diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index d7e160fdca3..859b683d5ed 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -33,9 +33,9 @@ class PropertyValue { explicit operator bool() const { return !isUndefined(); }; - template - static auto visit(const PropertyValue& value, Visitor&& visitor) { - return Value::visit(value.value, visitor); + template + auto evaluate(const Evaluator& evaluator) const { + return Value::visit(value, evaluator); } }; diff --git a/include/mbgl/style/transition_options.hpp b/include/mbgl/style/transition_options.hpp index d7a6633f0c8..d0cfefbf5db 100644 --- a/include/mbgl/style/transition_options.hpp +++ b/include/mbgl/style/transition_options.hpp @@ -6,9 +6,21 @@ namespace mbgl { namespace style { -struct TransitionOptions { +class TransitionOptions { +public: optional duration = {}; optional delay = {}; + + TransitionOptions defaults(const TransitionOptions& defaults) const { + return { + duration ? duration : defaults.duration, + delay ? delay : defaults.delay + }; + } + + explicit operator bool() const { + return duration || delay; + } }; } // namespace style diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp index 64b913200e4..fafcc7c15d1 100644 --- a/src/mbgl/layout/symbol_instance.cpp +++ b/src/mbgl/layout/symbol_instance.cpp @@ -7,7 +7,7 @@ using namespace style; SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line, const Shaping& shapedText, const PositionedIcon& shapedIcon, - const SymbolLayoutProperties& layout, const bool addToBuffers, const uint32_t index_, + const SymbolLayoutProperties::Evaluated& layout, const bool addToBuffers, const uint32_t index_, const float textBoxScale, const float textPadding, const SymbolPlacementType textPlacement, const float iconBoxScale, const float iconPadding, const SymbolPlacementType iconPlacement, const GlyphPositions& face, const IndexedSubfeature& indexedFeature) : diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp index 3087bf09f9a..508c11a3940 100644 --- a/src/mbgl/layout/symbol_instance.hpp +++ b/src/mbgl/layout/symbol_instance.hpp @@ -2,21 +2,18 @@ #include #include +#include namespace mbgl { struct Anchor; class IndexedSubfeature; -namespace style { -class SymbolLayoutProperties; -} // namespace style - class SymbolInstance { public: explicit SymbolInstance(Anchor& anchor, const GeometryCoordinates& line, const Shaping& shapedText, const PositionedIcon& shapedIcon, - const style::SymbolLayoutProperties&, const bool inside, const uint32_t index, + const style::SymbolLayoutProperties::Evaluated&, const bool inside, const uint32_t index, const float textBoxScale, const float textPadding, style::SymbolPlacementType textPlacement, const float iconBoxScale, const float iconPadding, style::SymbolPlacementType iconPlacement, const GlyphPositions& face, const IndexedSubfeature& indexedfeature); diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 932745aa57c..37742a0d3f0 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -31,7 +31,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_, const MapMode mode_, const GeometryTileLayer& layer, const style::Filter& filter, - style::SymbolLayoutProperties layout_, + style::SymbolLayoutProperties::Evaluated layout_, float textMaxSize_, SpriteAtlas& spriteAtlas_) : bucketName(std::move(bucketName_)), @@ -45,8 +45,8 @@ SymbolLayout::SymbolLayout(std::string bucketName_, tileSize(util::tileSize * overscaling_), tilePixelRatio(float(util::EXTENT) / tileSize) { - const bool hasText = !layout.textField.value.empty() && !layout.textFont.value.empty(); - const bool hasIcon = !layout.iconImage.value.empty(); + const bool hasText = !layout.get().empty() && !layout.get().empty(); + const bool hasIcon = !layout.get().empty(); if (!hasText && !hasIcon) { return; @@ -82,11 +82,11 @@ SymbolLayout::SymbolLayout(std::string bucketName_, }; if (hasText) { - std::string u8string = util::replaceTokens(layout.textField, getValue); + std::string u8string = util::replaceTokens(layout.get(), getValue); - if (layout.textTransform == TextTransformType::Uppercase) { + if (layout.get() == TextTransformType::Uppercase) { u8string = platform::uppercase(u8string); - } else if (layout.textTransform == TextTransformType::Lowercase) { + } else if (layout.get() == TextTransformType::Lowercase) { u8string = platform::lowercase(u8string); } @@ -99,7 +99,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_, } if (hasIcon) { - ft.icon = util::replaceTokens(layout.iconImage, getValue); + ft.icon = util::replaceTokens(layout.get(), getValue); } if (ft.text || ft.icon) { @@ -117,7 +117,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_, } } - if (layout.symbolPlacement == SymbolPlacementType::Line) { + if (layout.get() == SymbolPlacementType::Line) { util::mergeLines(features); } } @@ -127,11 +127,11 @@ bool SymbolLayout::hasSymbolInstances() const { } bool SymbolLayout::canPrepare(GlyphAtlas& glyphAtlas) { - if (!layout.textField.value.empty() && !layout.textFont.value.empty() && !glyphAtlas.hasGlyphRanges(layout.textFont, ranges)) { + if (!layout.get().empty() && !layout.get().empty() && !glyphAtlas.hasGlyphRanges(layout.get(), ranges)) { return false; } - if (!layout.iconImage.value.empty() && !spriteAtlas.isLoaded()) { + if (!layout.get().empty() && !spriteAtlas.isLoaded()) { return false; } @@ -143,7 +143,7 @@ void SymbolLayout::prepare(uintptr_t tileUID, float horizontalAlign = 0.5; float verticalAlign = 0.5; - switch (layout.textAnchor) { + switch (layout.get()) { case TextAnchorType::Top: case TextAnchorType::Bottom: case TextAnchorType::Center: @@ -160,7 +160,7 @@ void SymbolLayout::prepare(uintptr_t tileUID, break; } - switch (layout.textAnchor) { + switch (layout.get()) { case TextAnchorType::Left: case TextAnchorType::Right: case TextAnchorType::Center: @@ -177,11 +177,11 @@ void SymbolLayout::prepare(uintptr_t tileUID, break; } - const float justify = layout.textJustify == TextJustifyType::Right ? 1 : - layout.textJustify == TextJustifyType::Left ? 0 : + const float justify = layout.get() == TextJustifyType::Right ? 1 : + layout.get() == TextJustifyType::Left ? 0 : 0.5; - auto glyphSet = glyphAtlas.getGlyphSet(layout.textFont); + auto glyphSet = glyphAtlas.getGlyphSet(layout.get()); for (const auto& feature : features) { if (feature.geometry.empty()) continue; @@ -194,18 +194,18 @@ void SymbolLayout::prepare(uintptr_t tileUID, if (feature.text) { shapedText = glyphSet->getShaping( /* string */ *feature.text, - /* maxWidth: ems */ layout.symbolPlacement != SymbolPlacementType::Line ? - layout.textMaxWidth * 24 : 0, - /* lineHeight: ems */ layout.textLineHeight * 24, + /* maxWidth: ems */ layout.get() != SymbolPlacementType::Line ? + layout.get() * 24 : 0, + /* lineHeight: ems */ layout.get() * 24, /* horizontalAlign */ horizontalAlign, /* verticalAlign */ verticalAlign, /* justify */ justify, - /* spacing: ems */ layout.textLetterSpacing * 24, - /* translate */ Point(layout.textOffset.value[0], layout.textOffset.value[1])); + /* spacing: ems */ layout.get() * 24, + /* translate */ Point(layout.get()[0], layout.get()[1])); // Add the glyphs we need for this label to the glyph atlas. if (shapedText) { - glyphAtlas.addGlyphs(tileUID, *feature.text, layout.textFont, **glyphSet, face); + glyphAtlas.addGlyphs(tileUID, *feature.text, layout.get(), **glyphSet, face); } } @@ -220,7 +220,7 @@ void SymbolLayout::prepare(uintptr_t tileUID, } if ((*image).relativePixelRatio != 1.0f) { iconsNeedLinear = true; - } else if (layout.iconRotate != 0) { + } else if (layout.get() != 0) { iconsNeedLinear = true; } } @@ -242,24 +242,24 @@ void SymbolLayout::addFeature(const GeometryCollection &lines, const float minScale = 0.5f; const float glyphSize = 24.0f; - const float fontScale = layout.textSize / glyphSize; + const float fontScale = layout.get() / glyphSize; const float textBoxScale = tilePixelRatio * fontScale; const float textMaxBoxScale = tilePixelRatio * textMaxSize / glyphSize; - const float iconBoxScale = tilePixelRatio * layout.iconSize; - const float symbolSpacing = tilePixelRatio * layout.symbolSpacing; - const bool avoidEdges = layout.symbolAvoidEdges && layout.symbolPlacement != SymbolPlacementType::Line; - const float textPadding = layout.textPadding * tilePixelRatio; - const float iconPadding = layout.iconPadding * tilePixelRatio; - const float textMaxAngle = layout.textMaxAngle * util::DEG2RAD; - const SymbolPlacementType textPlacement = layout.textRotationAlignment != AlignmentType::Map + const float iconBoxScale = tilePixelRatio * layout.get(); + const float symbolSpacing = tilePixelRatio * layout.get(); + const bool avoidEdges = layout.get() && layout.get() != SymbolPlacementType::Line; + const float textPadding = layout.get() * tilePixelRatio; + const float iconPadding = layout.get() * tilePixelRatio; + const float textMaxAngle = layout.get() * util::DEG2RAD; + const SymbolPlacementType textPlacement = layout.get() != AlignmentType::Map ? SymbolPlacementType::Point - : layout.symbolPlacement; - const SymbolPlacementType iconPlacement = layout.iconRotationAlignment != AlignmentType::Map + : layout.get(); + const SymbolPlacementType iconPlacement = layout.get() != AlignmentType::Map ? SymbolPlacementType::Point - : layout.symbolPlacement; - const bool mayOverlap = layout.textAllowOverlap || layout.iconAllowOverlap || - layout.textIgnorePlacement || layout.iconIgnorePlacement; - const bool isLine = layout.symbolPlacement == SymbolPlacementType::Line; + : layout.get(); + const bool mayOverlap = layout.get() || layout.get() || + layout.get() || layout.get(); + const bool isLine = layout.get() == SymbolPlacementType::Line; const float textRepeatDistance = symbolSpacing / 2; auto& clippedLines = isLine ? @@ -330,15 +330,15 @@ std::unique_ptr SymbolLayout::place(CollisionTile& collisionTile) // Calculate which labels can be shown and when they can be shown and // create the bufers used for rendering. - const SymbolPlacementType textPlacement = layout.textRotationAlignment != AlignmentType::Map + const SymbolPlacementType textPlacement = layout.get() != AlignmentType::Map ? SymbolPlacementType::Point - : layout.symbolPlacement; - const SymbolPlacementType iconPlacement = layout.iconRotationAlignment != AlignmentType::Map + : layout.get(); + const SymbolPlacementType iconPlacement = layout.get() != AlignmentType::Map ? SymbolPlacementType::Point - : layout.symbolPlacement; + : layout.get(); - const bool mayOverlap = layout.textAllowOverlap || layout.iconAllowOverlap || - layout.textIgnorePlacement || layout.iconIgnorePlacement; + const bool mayOverlap = layout.get() || layout.get() || + layout.get() || layout.get(); // Sort symbols by their y position on the canvas so that they lower symbols // are drawn on top of higher symbols. @@ -362,18 +362,18 @@ std::unique_ptr SymbolLayout::place(CollisionTile& collisionTile) const bool hasText = symbolInstance.hasText; const bool hasIcon = symbolInstance.hasIcon; - const bool iconWithoutText = layout.textOptional || !hasText; - const bool textWithoutIcon = layout.iconOptional || !hasIcon; + const bool iconWithoutText = layout.get() || !hasText; + const bool textWithoutIcon = layout.get() || !hasIcon; // Calculate the scales at which the text and icon can be placed without collision. float glyphScale = hasText ? collisionTile.placeFeature(symbolInstance.textCollisionFeature, - layout.textAllowOverlap, layout.symbolAvoidEdges) : + layout.get(), layout.get()) : collisionTile.minScale; float iconScale = hasIcon ? collisionTile.placeFeature(symbolInstance.iconCollisionFeature, - layout.iconAllowOverlap, layout.symbolAvoidEdges) : + layout.get(), layout.get()) : collisionTile.minScale; @@ -391,20 +391,20 @@ std::unique_ptr SymbolLayout::place(CollisionTile& collisionTile) // Insert final placement into collision tree and add glyphs/icons to buffers if (hasText) { - collisionTile.insertFeature(symbolInstance.textCollisionFeature, glyphScale, layout.textIgnorePlacement); + collisionTile.insertFeature(symbolInstance.textCollisionFeature, glyphScale, layout.get()); if (glyphScale < collisionTile.maxScale) { addSymbols( bucket->text, symbolInstance.glyphQuads, glyphScale, - layout.textKeepUpright, textPlacement, collisionTile.config.angle); + layout.get(), textPlacement, collisionTile.config.angle); } } if (hasIcon) { - collisionTile.insertFeature(symbolInstance.iconCollisionFeature, iconScale, layout.iconIgnorePlacement); + collisionTile.insertFeature(symbolInstance.iconCollisionFeature, iconScale, layout.get()); if (iconScale < collisionTile.maxScale) { addSymbols( bucket->icon, symbolInstance.iconQuads, iconScale, - layout.iconKeepUpright, iconPlacement, collisionTile.config.angle); + layout.get(), iconPlacement, collisionTile.config.angle); } } } diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index 54acf84aaf5..b496740787b 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -33,7 +33,7 @@ class SymbolLayout { const MapMode, const GeometryTileLayer&, const style::Filter&, - style::SymbolLayoutProperties, + style::SymbolLayoutProperties::Evaluated, float textMaxSize, SpriteAtlas&); @@ -77,7 +77,7 @@ class SymbolLayout { const float overscaling; const float zoom; const MapMode mode; - const style::SymbolLayoutProperties layout; + const style::SymbolLayoutProperties::Evaluated layout; const float textMaxSize; SpriteAtlas& spriteAtlas; diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index 8e7dd77c79f..cbf2d899bd0 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -8,10 +8,12 @@ namespace mbgl { +using namespace style; + static_assert(sizeof(LineAttributes::Vertex) == 8, "expected LineVertex size"); template -Values makeValues(const style::LinePaintProperties& properties, +Values makeValues(const LinePaintProperties::Evaluated& properties, float pixelRatio, const RenderTile& tile, const TransformState& state, @@ -31,14 +33,14 @@ Values makeValues(const style::LinePaintProperties& properties, float x = state.getSize().height / 2.0f * std::tan(state.getPitch()); return Values { - tile.translatedMatrix(properties.lineTranslate.value, - properties.lineTranslateAnchor.value, + tile.translatedMatrix(properties.get(), + properties.get(), state), - properties.lineOpacity.value, - properties.lineWidth.value / 2, - properties.lineGapWidth.value / 2, - properties.lineBlur.value + antialiasing, - -properties.lineOffset.value, + properties.get(), + properties.get() / 2, + properties.get() / 2, + properties.get() + antialiasing, + -properties.get(), antialiasing / 2, antialiasingMatrix, 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()), @@ -48,7 +50,7 @@ Values makeValues(const style::LinePaintProperties& properties, } LineProgram::UniformValues -LineProgram::uniformValues(const style::LinePaintProperties& properties, +LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties, float pixelRatio, const RenderTile& tile, const TransformState& state) { @@ -57,12 +59,12 @@ LineProgram::uniformValues(const style::LinePaintProperties& properties, pixelRatio, tile, state, - properties.lineColor.value + properties.get() ); } LineSDFProgram::UniformValues -LineSDFProgram::uniformValues(const style::LinePaintProperties& properties, +LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties, float pixelRatio, const RenderTile& tile, const TransformState& state, @@ -70,8 +72,8 @@ LineSDFProgram::uniformValues(const style::LinePaintProperties& properties, const LinePatternPos& posB, float dashLineWidth, float atlasWidth) { - const float widthA = posA.width * properties.lineDasharray.value.fromScale * dashLineWidth; - const float widthB = posB.width * properties.lineDasharray.value.toScale * dashLineWidth; + const float widthA = posA.width * properties.get().fromScale * dashLineWidth; + const float widthB = posB.width * properties.get().toScale * dashLineWidth; std::array scaleA {{ 1.0f / tile.id.pixelsToTileUnits(widthA, state.getIntegerZoom()), @@ -88,31 +90,31 @@ LineSDFProgram::uniformValues(const style::LinePaintProperties& properties, pixelRatio, tile, state, - properties.lineColor.value, + properties.get(), scaleA, scaleB, posA.y, posB.y, - properties.lineDasharray.value.t, + properties.get().t, atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f, 0 ); } LinePatternProgram::UniformValues -LinePatternProgram::uniformValues(const style::LinePaintProperties& properties, +LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properties, float pixelRatio, const RenderTile& tile, const TransformState& state, const SpriteAtlasPosition& posA, const SpriteAtlasPosition& posB) { std::array sizeA {{ - tile.id.pixelsToTileUnits(posA.size[0] * properties.linePattern.value.fromScale, state.getIntegerZoom()), + tile.id.pixelsToTileUnits(posA.size[0] * properties.get().fromScale, state.getIntegerZoom()), posA.size[1] }}; std::array sizeB {{ - tile.id.pixelsToTileUnits(posB.size[0] * properties.linePattern.value.toScale, state.getIntegerZoom()), + tile.id.pixelsToTileUnits(posB.size[0] * properties.get().toScale, state.getIntegerZoom()), posB.size[1] }}; @@ -127,7 +129,7 @@ LinePatternProgram::uniformValues(const style::LinePaintProperties& properties, posB.br, sizeA, sizeB, - properties.linePattern.value.t, + properties.get().t, 0 ); } diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index 07ae35b8edc..c629a281e11 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -6,16 +6,13 @@ #include #include #include +#include #include #include namespace mbgl { -namespace style { -class LinePaintProperties; -} // namespace style - class RenderTile; class TransformState; class LinePatternPos; @@ -106,7 +103,7 @@ class LineProgram : public Program< public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties&, + static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&, float pixelRatio, const RenderTile&, const TransformState&); @@ -139,7 +136,7 @@ class LinePatternProgram : public Program< public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties&, + static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&, float pixelRatio, const RenderTile&, const TransformState&, @@ -174,7 +171,7 @@ class LineSDFProgram : public Program< public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties&, + static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&, float pixelRatio, const RenderTile&, const TransformState&, diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 554fef5ca75..007060bd1bc 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -64,7 +64,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) { return; } - const float miterLimit = layout.lineJoin == LineJoinType::Bevel ? 1.05f : float(layout.lineMiterLimit); + const float miterLimit = layout.get() == LineJoinType::Bevel ? 1.05f : float(layout.get()); const double sharpCornerOffset = SHARP_CORNER_OFFSET * (float(util::EXTENT) / (util::tileSize * overscaling)); @@ -77,8 +77,8 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) { return; } - const LineCapType beginCap = layout.lineCap; - const LineCapType endCap = closed ? LineCapType::Butt : LineCapType(layout.lineCap); + const LineCapType beginCap = layout.get(); + const LineCapType endCap = closed ? LineCapType::Butt : LineCapType(layout.get()); double distance = 0; bool startOfLine = true; @@ -171,12 +171,12 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) { // The join if a middle vertex, otherwise the cap const bool middleVertex = prevCoordinate && nextCoordinate; - LineJoinType currentJoin = layout.lineJoin; + LineJoinType currentJoin = layout.get(); const LineCapType currentCap = nextCoordinate ? beginCap : endCap; if (middleVertex) { if (currentJoin == LineJoinType::Round) { - if (miterLength < layout.lineRoundLimit) { + if (miterLength < layout.get()) { currentJoin = LineJoinType::Miter; } else if (miterLength <= 2) { currentJoin = LineJoinType::FakeRound; diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 9903ca1842b..1c8509ec75c 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -24,7 +24,7 @@ class LineBucket : public Bucket { void addGeometry(const GeometryCollection&); void addGeometry(const GeometryCoordinates& line); - style::LineLayoutProperties layout; + style::LineLayoutProperties::Evaluated layout; gl::VertexVector vertices; gl::IndexVector triangles; diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index adb0bd17110..0f1fc70da3a 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -14,13 +14,13 @@ using namespace style; void Painter::renderBackground(PaintParameters& parameters, const BackgroundLayer& layer) { // Note that for bottommost layers without a pattern, the background color is drawn with // glClear rather than this method. - const BackgroundPaintProperties& properties = layer.impl->paint; + const BackgroundPaintProperties::Evaluated& properties = layer.impl->paint.evaluated; - if (!properties.backgroundPattern.value.to.empty()) { + if (!properties.get().to.empty()) { optional imagePosA = spriteAtlas->getPosition( - properties.backgroundPattern.value.from, SpritePatternMode::Repeating); + properties.get().from, SpritePatternMode::Repeating); optional imagePosB = spriteAtlas->getPosition( - properties.backgroundPattern.value.to, SpritePatternMode::Repeating); + properties.get().to, SpritePatternMode::Repeating); if (!imagePosA || !imagePosB) return; @@ -36,11 +36,11 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye colorModeForRenderPass(), FillPatternUniforms::values( matrixForTile(tileID), - properties.backgroundOpacity.value, + properties.get(), context.viewport.getCurrentValue().size, *imagePosA, *imagePosB, - properties.backgroundPattern.value, + properties.get(), tileID, state ), @@ -57,9 +57,9 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye colorModeForRenderPass(), FillUniforms::values( matrixForTile(tileID), - properties.backgroundOpacity.value, - properties.backgroundColor.value, - properties.backgroundColor.value, + properties.get(), + properties.get(), + properties.get(), context.viewport.getCurrentValue().size ), tileTriangleVertexBuffer diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index ea4ea5964d7..07524119aaf 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -20,7 +20,7 @@ void Painter::renderCircle(PaintParameters& parameters, return; } - const CirclePaintProperties& properties = layer.impl->paint; + const CirclePaintProperties::Evaluated& properties = layer.impl->paint.evaluated; parameters.programs.circle.draw( context, @@ -31,15 +31,15 @@ void Painter::renderCircle(PaintParameters& parameters, : gl::StencilMode::disabled(), colorModeForRenderPass(), CircleProgram::UniformValues( - tile.translatedMatrix(properties.circleTranslate.value, - properties.circleTranslateAnchor.value, + tile.translatedMatrix(properties.get(), + properties.get(), state), - properties.circleOpacity.value, - properties.circleColor.value, - properties.circleRadius.value, - properties.circleBlur.value, - properties.circlePitchScale.value == CirclePitchScaleType::Map, - properties.circlePitchScale.value == CirclePitchScaleType::Map + properties.get(), + properties.get(), + properties.get(), + properties.get(), + properties.get() == CirclePitchScaleType::Map, + properties.get() == CirclePitchScaleType::Map ? std::array {{ pixelsToGLUnits[0] * state.getAltitude(), pixelsToGLUnits[1] * state.getAltitude() diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 8a166f23776..9856d49746c 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -17,17 +17,17 @@ void Painter::renderFill(PaintParameters& parameters, FillBucket& bucket, const FillLayer& layer, const RenderTile& tile) { - const FillPaintProperties& properties = layer.impl->paint; + const FillPaintProperties::Evaluated& properties = layer.impl->paint.evaluated; - if (!properties.fillPattern.value.from.empty()) { + if (!properties.get().from.empty()) { if (pass != RenderPass::Translucent) { return; } optional imagePosA = spriteAtlas->getPosition( - properties.fillPattern.value.from, SpritePatternMode::Repeating); + properties.get().from, SpritePatternMode::Repeating); optional imagePosB = spriteAtlas->getPosition( - properties.fillPattern.value.to, SpritePatternMode::Repeating); + properties.get().to, SpritePatternMode::Repeating); if (!imagePosA || !imagePosB) { return; @@ -48,14 +48,14 @@ void Painter::renderFill(PaintParameters& parameters, stencilModeForClipping(tile.clip), colorModeForRenderPass(), FillPatternUniforms::values( - tile.translatedMatrix(properties.fillTranslate.value, - properties.fillTranslateAnchor.value, + tile.translatedMatrix(properties.get(), + properties.get(), state), - properties.fillOpacity.value, + properties.get(), context.viewport.getCurrentValue().size, *imagePosA, *imagePosB, - properties.fillPattern.value, + properties.get(), tile.id, state ), @@ -72,7 +72,7 @@ void Painter::renderFill(PaintParameters& parameters, *bucket.triangleIndexBuffer, bucket.triangleSegments); - if (!properties.fillAntialias.value || !properties.fillOutlineColor.isUndefined()) { + if (!properties.get() || !layer.impl->paint.unevaluated.get().isUndefined()) { return; } @@ -97,11 +97,11 @@ void Painter::renderFill(PaintParameters& parameters, stencilModeForClipping(tile.clip), colorModeForRenderPass(), FillUniforms::values( - tile.translatedMatrix(properties.fillTranslate.value, - properties.fillTranslateAnchor.value, + tile.translatedMatrix(properties.get(), + properties.get(), state), - properties.fillOpacity.value, - properties.fillColor.value, + properties.get(), + properties.get(), outlineColor, context.viewport.getCurrentValue().size ), @@ -111,10 +111,10 @@ void Painter::renderFill(PaintParameters& parameters, ); }; - if (properties.fillAntialias.value && !properties.fillOutlineColor.isUndefined() && pass == RenderPass::Translucent) { + if (properties.get() && !layer.impl->paint.unevaluated.get().isUndefined() && pass == RenderPass::Translucent) { draw(2, parameters.programs.fillOutline, - properties.fillOutlineColor.value, + properties.get(), gl::Lines { 2.0f }, *bucket.vertexBuffer, *bucket.lineIndexBuffer, @@ -123,20 +123,20 @@ void Painter::renderFill(PaintParameters& parameters, // Only draw the fill when it's opaque and we're drawing opaque fragments, // or when it's translucent and we're drawing translucent fragments. - if ((properties.fillColor.value.a >= 1.0f && properties.fillOpacity.value >= 1.0f) == (pass == RenderPass::Opaque)) { + if ((properties.get().a >= 1.0f && properties.get() >= 1.0f) == (pass == RenderPass::Opaque)) { draw(1, parameters.programs.fill, - properties.fillOutlineColor.value, + properties.get(), gl::Triangles(), *bucket.vertexBuffer, *bucket.triangleIndexBuffer, bucket.triangleSegments); } - if (properties.fillAntialias.value && properties.fillOutlineColor.isUndefined() && pass == RenderPass::Translucent) { + if (properties.get() && layer.impl->paint.unevaluated.get().isUndefined() && pass == RenderPass::Translucent) { draw(2, parameters.programs.fillOutline, - properties.fillColor.value, + properties.get(), gl::Lines { 2.0f }, *bucket.vertexBuffer, *bucket.lineIndexBuffer, diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index a495edc428a..0b25bfe7e77 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -21,7 +21,7 @@ void Painter::renderLine(PaintParameters& parameters, return; } - const auto& properties = layer.impl->paint; + const LinePaintProperties::Evaluated& properties = layer.impl->paint.evaluated; auto draw = [&] (auto& program, auto&& uniformValues) { program.draw( @@ -37,11 +37,11 @@ void Painter::renderLine(PaintParameters& parameters, ); }; - if (!properties.lineDasharray.value.from.empty()) { - const LinePatternCap cap = bucket.layout.lineCap == LineCapType::Round + if (!properties.get().from.empty()) { + const LinePatternCap cap = bucket.layout.get() == LineCapType::Round ? LinePatternCap::Round : LinePatternCap::Square; - LinePatternPos posA = lineAtlas->getDashPosition(properties.lineDasharray.value.from, cap); - LinePatternPos posB = lineAtlas->getDashPosition(properties.lineDasharray.value.to, cap); + LinePatternPos posA = lineAtlas->getDashPosition(properties.get().from, cap); + LinePatternPos posB = lineAtlas->getDashPosition(properties.get().to, cap); lineAtlas->bind(context, 0); @@ -56,11 +56,11 @@ void Painter::renderLine(PaintParameters& parameters, layer.impl->dashLineWidth, lineAtlas->getSize().width)); - } else if (!properties.linePattern.value.from.empty()) { + } else if (!properties.get().from.empty()) { optional posA = spriteAtlas->getPosition( - properties.linePattern.value.from, SpritePatternMode::Repeating); + properties.get().from, SpritePatternMode::Repeating); optional posB = spriteAtlas->getPosition( - properties.linePattern.value.to, SpritePatternMode::Repeating); + properties.get().to, SpritePatternMode::Repeating); if (!posA || !posB) return; diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index ff4fac49a92..6b2eae6e415 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -48,7 +48,7 @@ void Painter::renderRaster(PaintParameters& parameters, if (!bucket.hasData()) return; - const RasterPaintProperties& properties = layer.impl->paint; + const RasterPaintProperties::Evaluated& properties = layer.impl->paint.evaluated; assert(bucket.texture); context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear); @@ -64,13 +64,13 @@ void Painter::renderRaster(PaintParameters& parameters, tile.matrix, 0, 1, - properties.rasterOpacity.value, + properties.get(), 0, - properties.rasterBrightnessMin.value, - properties.rasterBrightnessMax.value, - saturationFactor(properties.rasterSaturation.value), - contrastFactor(properties.rasterContrast.value), - spinWeights(properties.rasterHueRotate.value), + properties.get(), + properties.get(), + saturationFactor(properties.get()), + contrastFactor(properties.get()), + spinWeights(properties.get()), 1.0f, 1.0f, std::array {{ 0.0f, 0.0f }} diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 7813d96b9f3..af64dc9b221 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -43,8 +43,8 @@ void Painter::renderSymbol(PaintParameters& parameters, // tile edges the icons are included in both tiles and clipped when drawing. // // TODO remove the `true ||` when #1673 is implemented - const bool drawAcrossEdges = (frame.mapMode == MapMode::Continuous) && (true || !(layout.textAllowOverlap || layout.iconAllowOverlap || - layout.textIgnorePlacement || layout.iconIgnorePlacement)); + const bool drawAcrossEdges = (frame.mapMode == MapMode::Continuous) && (true || !(layout.get() || layout.get() || + layout.get() || layout.get())); program.draw( context, diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 7fb34739678..b0de857f0bb 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -7,7 +7,7 @@ namespace mbgl { using namespace style; SymbolBucket::SymbolBucket(const MapMode mode_, - style::SymbolLayoutProperties layout_, + style::SymbolLayoutProperties::Evaluated layout_, bool sdfIcons_, bool iconsNeedLinear_) : mode(mode_), diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index f1fc3d324e1..0d5d1e7a1c6 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -17,7 +17,7 @@ namespace mbgl { class SymbolBucket : public Bucket { public: SymbolBucket(const MapMode, - style::SymbolLayoutProperties, + style::SymbolLayoutProperties::Evaluated, bool sdfIcons, bool iconsNeedLinear); @@ -29,7 +29,7 @@ class SymbolBucket : public Bucket { bool hasCollisionBoxData() const; const MapMode mode; - const style::SymbolLayoutProperties layout; + const style::SymbolLayoutProperties::Evaluated layout; const bool sdfIcons; const bool iconsNeedLinear; diff --git a/src/mbgl/style/class_dictionary.hpp b/src/mbgl/style/class_dictionary.hpp index e609fb5303b..37eb488240c 100644 --- a/src/mbgl/style/class_dictionary.hpp +++ b/src/mbgl/style/class_dictionary.hpp @@ -9,7 +9,6 @@ namespace mbgl { namespace style { enum class ClassID : uint32_t { - Fallback = 0, // These values are from the fallback properties Default = 1, // These values are from the default style for a layer Named = 2 // These values (and all subsequent IDs) are from a named style from the layer }; diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 4bf2956a6db..38ac32e1deb 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -19,7 +19,7 @@ class Bucket; namespace style { class CascadeParameters; -class CalculationParameters; +class PropertyEvaluationParameters; class BucketParameters; /** @@ -57,7 +57,7 @@ class Layer::Impl { // Fully evaluate cascaded paint properties based on a zoom level. // Returns true if any paint properties have active transitions. - virtual bool recalculate(const CalculationParameters&) = 0; + virtual bool evaluate(const PropertyEvaluationParameters&) = 0; virtual std::unique_ptr createBucket(BucketParameters&) const = 0; diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 5e5faf37e6a..a54115d1a7a 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 ea389b828e2..9a7db9416eb 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 abbb740f427..6ede1b7d975 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -13,7 +13,7 @@ class BackgroundLayer::Impl : public Layer::Impl { 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 558093a2555..ba3e638977a 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 78a35a4f0cc..792bf3de949 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 a2b8d316d61..ce01a12ff20 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 33699b6665e..6599126702f 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 14baaf84e41..df3b34cc1af 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -13,7 +13,7 @@ class CircleLayer::Impl : public Layer::Impl { 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 7243cf87f43..af727fa36f5 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 0166bc8be45..b7f279de4bd 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 124d6b0ce96..0a0a5160869 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -60,7 +60,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 ffa892ddf81..5128e6087b9 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -28,7 +28,7 @@ class CustomLayer::Impl : public Layer::Impl { 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 c61de81d1a6..3bea9b56b09 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 fc439f1cd14..6a690ba447a 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 54cfb80c86d..53276d744a1 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -13,7 +13,7 @@ class FillLayer::Impl : public Layer::Impl { 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 9a55cbc1452..b07a083950a 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 d12eb8d6f4b..b2d926c31e9 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 237a68aadf0..8121a1af06d 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); } <% } -%> @@ -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 b781a4a9d95..3b287decc08 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 0c91ecba8c9..f490a636f9f 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 100ee7247f0..c76bc027ecf 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); } 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); } 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); } 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); } @@ -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 c116af5fc2f..e6ec21a6598 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 c6b4be3bec1..3387db07f06 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -13,7 +13,7 @@ class LineLayer::Impl : public Layer::Impl { 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 2d6092745eb..174239bcc8d 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 b73e3f2ef2f..07458cd6344 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 238bfef6e4b..21d72a0fdc0 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 879bfa45594..3be4bb4fbd2 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 a5b396e2ed2..df5d388bdfd 100644 --- a/src/mbgl/style/layers/raster_layer_impl.hpp +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -13,7 +13,7 @@ class RasterLayer::Impl : public Layer::Impl { 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 68d9d1d35df..303719af405 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 ddfb833e128..caa6d0c58d0 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 6b4d7400da0..14df9267f62 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } @@ -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 0ac9ff832d4..957bc1993ea 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 b760538f862..46ed75b2317 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -47,13 +47,13 @@ class SymbolLayer::Impl : public Layer::Impl { 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 59a73d3d59d..5a1ce713ba4 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 fefa0ae05e9..8b72c4347a9 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 diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index db1a1ebf28f..37ebd31dd61 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -1,44 +1,57 @@ #pragma once -#include -#include #include - -#include +#include +#include namespace mbgl { namespace style { -template +class PropertyEvaluationParameters; + +template class LayoutProperty { public: - explicit LayoutProperty(T v) - : value(std::move(v)), - defaultValue(value) {} - - const PropertyValue& get() const { - return currentValue; - } + using EvaluatorType = PropertyEvaluator; + using UnevaluatedType = PropertyValue; + using EvaluatedType = T; +}; - void set(const PropertyValue& value_) { - currentValue = value_; +template +class LayoutProperties { +public: + using Properties = TypeList; + using EvaluatedTypes = TypeList; + using UnevaluatedTypes = TypeList; + + template + using Tuple = IndexedTuple; + + class Evaluated : public Tuple { + public: + using Tuple::Tuple; + }; + + class Unevaluated : public Tuple { + public: + using Tuple::Tuple; + }; + + template + auto evaluate(const PropertyEvaluationParameters& parameters) const { + using Evaluator = typename P::EvaluatorType; + return unevaluated.template get

() + .evaluate(Evaluator(parameters, P::defaultValue())); } - void calculate(const CalculationParameters& parameters) { - if (currentValue) { - PropertyEvaluator evaluator(parameters, defaultValue); - value = PropertyValue::visit(currentValue, evaluator); - } + Evaluated evaluate(const PropertyEvaluationParameters& parameters) const { + return Evaluated { + evaluate(parameters)... + }; } - // TODO: remove / privatize - operator T() const { return value; } - T value; - -private: - T defaultValue; - PropertyValue currentValue; + Unevaluated unevaluated; }; } // namespace style -} // namespace mbgl +} // namespace mgbl diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 4a620706ec9..e8f6336d283 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -1,14 +1,14 @@ #pragma once #include -#include #include #include #include -#include +#include #include #include -#include +#include +#include #include #include @@ -16,29 +16,59 @@ namespace mbgl { namespace style { -template class Evaluator = PropertyEvaluator> -class PaintProperty { +template +class UnevaluatedPaintProperty { public: - using Result = typename Evaluator::ResultType; + using Result = typename Evaluator::ResultType; + + UnevaluatedPaintProperty() = default; + + UnevaluatedPaintProperty(PropertyValue value_, + UnevaluatedPaintProperty prior_, + TransitionOptions transition, + TimePoint now) + : begin(now + transition.delay.value_or(Duration::zero())), + end(begin + transition.duration.value_or(Duration::zero())), + value(std::move(value_)) { + if (transition) { + prior = { std::move(prior_) }; + } + } - explicit PaintProperty(T defaultValue_) - : defaultValue(defaultValue_) { - values.emplace(ClassID::Fallback, defaultValue_); + Result evaluate(const PropertyEvaluationParameters& parameters, T defaultValue) { + Result finalValue = value.evaluate(Evaluator(parameters, defaultValue)); + if (!prior) { + // No prior value. + return finalValue; + } else if (parameters.now >= end) { + // Transition from prior value is now complete. + prior = {}; + return finalValue; + } else { + // Interpolate between recursively-calculated prior value and final. + float t = std::chrono::duration(parameters.now - begin) / (end - begin); + return util::interpolate(prior->get().evaluate(parameters, defaultValue), finalValue, util::DEFAULT_TRANSITION_EASE.solve(t, 0.001)); + } } - PaintProperty(const PaintProperty& other) - : defaultValue(other.defaultValue), - values(other.values), - transitions(other.transitions) { + bool hasTransition() const { + return bool(prior); } - PaintProperty& operator=(const PaintProperty& other) { - defaultValue = other.defaultValue; - values = other.values; - transitions = other.transitions; - return *this; + bool isUndefined() const { + return value.isUndefined(); } +private: + optional>> prior; + TimePoint begin; + TimePoint end; + PropertyValue value; +}; + +template +class CascadingPaintProperty { +public: bool isUndefined() const { return values.find(ClassID::Default) == values.end(); } @@ -57,83 +87,116 @@ class PaintProperty { transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition; } - void cascade(const CascadeParameters& params) { - const bool overrideTransition = !params.transition.delay && !params.transition.duration; - Duration delay = params.transition.delay.value_or(Duration::zero()); - Duration duration = params.transition.duration.value_or(Duration::zero()); + template + UnevaluatedPaintProperty cascade(const CascadeParameters& params, UnevaluatedPaintProperty prior) const { + TransitionOptions transition; + PropertyValue value; for (const auto classID : params.classes) { - if (values.find(classID) == values.end()) - continue; - - if (overrideTransition && transitions.find(classID) != transitions.end()) { - const TransitionOptions& transition = transitions[classID]; - if (transition.delay) delay = *transition.delay; - if (transition.duration) duration = *transition.duration; + if (transitions.find(classID) != transitions.end()) { + transition = transitions.at(classID).defaults(transition); } - cascaded = std::make_unique(std::move(cascaded), - params.now + delay, - params.now + delay + duration, - values.at(classID)); - - break; + if (values.find(classID) != values.end()) { + value = values.at(classID); + } } - assert(cascaded); - } - - bool calculate(const CalculationParameters& parameters) { - assert(cascaded); - Evaluator evaluator(parameters, defaultValue); - value = cascaded->calculate(evaluator, parameters.now); - return cascaded->prior.operator bool(); + return UnevaluatedPaintProperty(std::move(value), + std::move(prior), + transition.defaults(params.transition), + params.now); } - // TODO: remove / privatize - operator T() const { return value; } - Result value; - private: - T defaultValue; std::unordered_map> values; std::unordered_map transitions; +}; - struct CascadedValue { - CascadedValue(std::unique_ptr prior_, - TimePoint begin_, - TimePoint end_, - PropertyValue value_) - : prior(std::move(prior_)), - begin(std::move(begin_)), - end(std::move(end_)), - value(std::move(value_)) { - } +template +class PaintProperty { +public: + using ValueType = PropertyValue; + using CascadingType = CascadingPaintProperty; + using EvaluatorType = PropertyEvaluator; + using UnevaluatedType = UnevaluatedPaintProperty; + using EvaluatedType = T; +}; - Result calculate(const Evaluator& evaluator, const TimePoint& now) { - Result finalValue = PropertyValue::visit(value, evaluator); - if (!prior) { - // No prior value. - return finalValue; - } else if (now >= end) { - // Transition from prior value is now complete. - prior.reset(); - return finalValue; - } else { - // Interpolate between recursively-calculated prior value and final. - float t = std::chrono::duration(now - begin) / (end - begin); - return util::interpolate(prior->calculate(evaluator, now), finalValue, util::DEFAULT_TRANSITION_EASE.solve(t, 0.001)); - } - } +template +class CrossFadedPaintProperty { +public: + using ValueType = PropertyValue; + using CascadingType = CascadingPaintProperty; + using EvaluatorType = CrossFadedPropertyEvaluator; + using UnevaluatedType = UnevaluatedPaintProperty; + using EvaluatedType = Faded; +}; - std::unique_ptr prior; - TimePoint begin; - TimePoint end; - PropertyValue value; +template +class PaintProperties { +public: + using Properties = TypeList; + using EvaluatedTypes = TypeList; + using UnevaluatedTypes = TypeList; + using CascadingTypes = TypeList; + + template + using Tuple = IndexedTuple; + + class Evaluated : public Tuple { + public: + using Tuple::Tuple; }; - std::unique_ptr cascaded; + class Unevaluated : public Tuple { + public: + using Tuple::Tuple; + }; + + class Cascading : public Tuple { + public: + using Tuple::Tuple; + }; + + template + auto get(const optional& klass) const { + return cascading.template get

().get(klass); + } + + template + void set(const typename P::ValueType& value, const optional& klass) { + cascading.template get

().set(value, klass); + } + + void cascade(const CascadeParameters& parameters) { + unevaluated = Unevaluated { + cascading.template get().cascade(parameters, + std::move(unevaluated.template get()))... + }; + } + + template + auto evaluate(const PropertyEvaluationParameters& parameters) { + return unevaluated.template get

().evaluate(parameters, P::defaultValue()); + } + + void evaluate(const PropertyEvaluationParameters& parameters) { + evaluated = Evaluated { + evaluate(parameters)... + }; + } + + bool hasTransition() const { + bool result = false; + ignore({ result |= unevaluated.template get().hasTransition()... }); + return result; + } + + Cascading cascading; + Unevaluated unevaluated; + Evaluated evaluated; }; } // namespace style -} // namespace mbgl +} // namespace mgbl diff --git a/src/mbgl/style/calculation_parameters.hpp b/src/mbgl/style/property_evaluation_parameters.hpp similarity index 82% rename from src/mbgl/style/calculation_parameters.hpp rename to src/mbgl/style/property_evaluation_parameters.hpp index e1f059c5248..2591fc07a18 100644 --- a/src/mbgl/style/calculation_parameters.hpp +++ b/src/mbgl/style/property_evaluation_parameters.hpp @@ -6,12 +6,12 @@ namespace mbgl { namespace style { -class CalculationParameters { +class PropertyEvaluationParameters { public: - explicit CalculationParameters(float z_) + explicit PropertyEvaluationParameters(float z_) : z(z_) {} - CalculationParameters(float z_, + PropertyEvaluationParameters(float z_, TimePoint now_, ZoomHistory zoomHistory_, Duration defaultFadeDuration_) diff --git a/src/mbgl/style/property_evaluator.cpp b/src/mbgl/style/property_evaluator.cpp index abb3681efaf..c19f7221004 100644 --- a/src/mbgl/style/property_evaluator.cpp +++ b/src/mbgl/style/property_evaluator.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/mbgl/style/property_evaluator.hpp b/src/mbgl/style/property_evaluator.hpp index 3f657fe3f4a..c93a11a4e13 100644 --- a/src/mbgl/style/property_evaluator.hpp +++ b/src/mbgl/style/property_evaluator.hpp @@ -6,14 +6,14 @@ namespace mbgl { namespace style { -class CalculationParameters; +class PropertyEvaluationParameters; template class PropertyEvaluator { public: using ResultType = T; - PropertyEvaluator(const CalculationParameters& parameters_, T defaultValue_) + PropertyEvaluator(const PropertyEvaluationParameters& parameters_, T defaultValue_) : parameters(parameters_), defaultValue(std::move(defaultValue_)) {} @@ -22,7 +22,7 @@ class PropertyEvaluator { T operator()(const Function&) const; private: - const CalculationParameters& parameters; + const PropertyEvaluationParameters& parameters; T defaultValue; }; @@ -41,7 +41,7 @@ class CrossFadedPropertyEvaluator { public: using ResultType = Faded; - CrossFadedPropertyEvaluator(const CalculationParameters& parameters_, T defaultValue_) + CrossFadedPropertyEvaluator(const PropertyEvaluationParameters& parameters_, T defaultValue_) : parameters(parameters_), defaultValue(std::move(defaultValue_)) {} @@ -52,7 +52,7 @@ class CrossFadedPropertyEvaluator { private: Faded calculate(const T& min, const T& mid, const T& max) const; - const CalculationParameters& parameters; + const PropertyEvaluationParameters& parameters; T defaultValue; }; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 3c2b97b65d2..e6cd3d41e71 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -240,7 +240,6 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) { classIDs.push_back(ClassDictionary::Get().lookup(className)); } classIDs.push_back(ClassID::Default); - classIDs.push_back(ClassID::Fallback); const CascadeParameters parameters { classIDs, @@ -262,7 +261,7 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { zoomHistory.update(z, timePoint); - const CalculationParameters parameters { + const PropertyEvaluationParameters parameters { z, mode == MapMode::Continuous ? timePoint : Clock::time_point::max(), zoomHistory, @@ -271,7 +270,7 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { hasPendingTransitions = false; for (const auto& layer : layers) { - const bool hasTransitions = layer->baseImpl->recalculate(parameters); + const bool hasTransitions = layer->baseImpl->evaluate(parameters); // Disable this layer if it doesn't need to be rendered. const bool needsRendering = layer->baseImpl->needsRendering(zoomHistory.lastZoom); @@ -348,10 +347,10 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions) const { result.order.emplace_back(*layer); continue; } - const BackgroundPaintProperties& paint = background->impl->paint; - if (layer.get() == layers[0].get() && paint.backgroundPattern.value.from.empty()) { + const BackgroundPaintProperties::Evaluated& paint = background->impl->paint.evaluated; + if (layer.get() == layers[0].get() && paint.get().from.empty()) { // This is a solid background. We can use glClear(). - result.backgroundColor = paint.backgroundColor * paint.backgroundOpacity; + result.backgroundColor = paint.get() * paint.get(); } else { // This is a textured background, or not the bottommost layer. We need to render it with a quad. result.order.emplace_back(*layer); diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 3f142cd9086..1a05e6f94f2 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -14,7 +14,7 @@ using namespace style; const float globalMinScale = 0.5f; // underscale by 1 zoom level SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, - const GeometryCoordinates& line, const SymbolLayoutProperties& layout, + const GeometryCoordinates& line, const SymbolLayoutProperties::Evaluated& layout, const style::SymbolPlacementType placement, const Shaping& shapedText) { auto image = *(shapedIcon.image); @@ -29,24 +29,24 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, Point br; Point bl; - if (layout.iconTextFit != IconTextFitType::None && shapedText) { + if (layout.get() != IconTextFitType::None && shapedText) { auto iconWidth = right - left; auto iconHeight = bottom - top; - auto size = layout.textSize / 24.0f; + auto size = layout.get() / 24.0f; auto textLeft = shapedText.left * size; auto textRight = shapedText.right * size; auto textTop = shapedText.top * size; auto textBottom = shapedText.bottom * size; auto textWidth = textRight - textLeft; auto textHeight = textBottom - textTop;; - auto padT = layout.iconTextFitPadding.value[0]; - auto padR = layout.iconTextFitPadding.value[1]; - auto padB = layout.iconTextFitPadding.value[2]; - auto padL = layout.iconTextFitPadding.value[3]; - auto offsetY = layout.iconTextFit == IconTextFitType::Width ? (textHeight - iconHeight) * 0.5 : 0; - auto offsetX = layout.iconTextFit == IconTextFitType::Height ? (textWidth - iconWidth) * 0.5 : 0; - auto width = layout.iconTextFit == IconTextFitType::Width || layout.iconTextFit == IconTextFitType::Both ? textWidth : iconWidth; - auto height = layout.iconTextFit == IconTextFitType::Height || layout.iconTextFit == IconTextFitType::Both ? textHeight : iconHeight; + auto padT = layout.get()[0]; + auto padR = layout.get()[1]; + auto padB = layout.get()[2]; + auto padL = layout.get()[3]; + auto offsetY = layout.get() == IconTextFitType::Width ? (textHeight - iconHeight) * 0.5 : 0; + auto offsetX = layout.get() == IconTextFitType::Height ? (textWidth - iconWidth) * 0.5 : 0; + auto width = layout.get() == IconTextFitType::Width || layout.get() == IconTextFitType::Both ? textWidth : iconWidth; + auto height = layout.get() == IconTextFitType::Height || layout.get() == IconTextFitType::Both ? textHeight : iconHeight; left = textLeft + offsetX - padL; top = textTop + offsetY - padT; right = textLeft + offsetX + padR + width; @@ -62,7 +62,7 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, bl = {left, bottom}; } - float angle = layout.iconRotate * util::DEG2RAD; + float angle = layout.get() * util::DEG2RAD; if (placement == style::SymbolPlacementType::Line) { assert(static_cast(anchor.segment) < line.size()); const GeometryCoordinate &prev= line[anchor.segment]; @@ -165,11 +165,11 @@ void getSegmentGlyphs(std::back_insert_iterator glyphs, Anchor & } SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, - const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout, + const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties::Evaluated& layout, const style::SymbolPlacementType placement, const GlyphPositions& face) { - const float textRotate = layout.textRotate * util::DEG2RAD; - const bool keepUpright = layout.textKeepUpright; + const float textRotate = layout.get() * util::DEG2RAD; + const bool keepUpright = layout.get(); SymbolQuads quads; diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp index d4edbf94933..75fb53aaded 100644 --- a/src/mbgl/text/quads.hpp +++ b/src/mbgl/text/quads.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -11,10 +12,6 @@ namespace mbgl { struct Anchor; class PositionedIcon; -namespace style { -class SymbolLayoutProperties; -} // namespace style - struct SymbolQuad { explicit SymbolQuad(Point tl_, Point tr_, Point bl_, Point br_, Rect tex_, float anchorAngle_, float glyphAngle_, Point anchorPoint_, @@ -40,11 +37,11 @@ struct SymbolQuad { typedef std::vector SymbolQuads; SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, - const GeometryCoordinates& line, const style::SymbolLayoutProperties&, + const GeometryCoordinates& line, const style::SymbolLayoutProperties::Evaluated&, style::SymbolPlacementType placement, const Shaping& shapedText); SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, - const float boxScale, const GeometryCoordinates& line, const style::SymbolLayoutProperties&, + const float boxScale, const GeometryCoordinates& line, const style::SymbolLayoutProperties::Evaluated&, style::SymbolPlacementType placement, const GlyphPositions& face); } // namespace mbgl diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 1091cd6e941..062066aaf4f 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -3,9 +3,11 @@ namespace mbgl { -PositionedIcon shapeIcon(const SpriteAtlasElement& image, const style::SymbolLayoutProperties& layout) { - float dx = layout.iconOffset.value[0]; - float dy = layout.iconOffset.value[1]; +using namespace style; + +PositionedIcon shapeIcon(const SpriteAtlasElement& image, const SymbolLayoutProperties::Evaluated& layout) { + float dx = layout.get()[0]; + float dy = layout.get()[1]; float x1 = dx - image.spriteImage->getWidth() / 2.0f; float x2 = x1 + image.spriteImage->getWidth(); float y1 = dy - image.spriteImage->getHeight() / 2.0f; diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp index d7c64e88b44..30375179b6b 100644 --- a/src/mbgl/text/shaping.hpp +++ b/src/mbgl/text/shaping.hpp @@ -3,16 +3,13 @@ #include #include #include +#include #include namespace mbgl { class SpriteAtlasElement; -namespace style { -class SymbolLayoutProperties; -} // namespace style - class PositionedIcon { public: explicit PositionedIcon() {} @@ -29,6 +26,6 @@ class PositionedIcon { explicit operator bool() const { return image && (*image).pos.hasArea(); } }; -PositionedIcon shapeIcon(const SpriteAtlasElement& image, const style::SymbolLayoutProperties&); +PositionedIcon shapeIcon(const SpriteAtlasElement& image, const style::SymbolLayoutProperties::Evaluated&); } // namespace mbgl diff --git a/src/mbgl/util/indexed_tuple.hpp b/src/mbgl/util/indexed_tuple.hpp new file mode 100644 index 00000000000..aca06b9db11 --- /dev/null +++ b/src/mbgl/util/indexed_tuple.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +#include + +namespace mbgl { + +namespace detail { + +template +struct TypeIndex; + +template +struct TypeIndex : std::integral_constant {}; + +template +struct TypeIndex : std::integral_constant::value> {}; + +} // namespace detail + +template class TypeList {}; + +template class IndexedTuple; + +// A tuple of Ts, where individual members can be accessed via `t.get()` for I ∈ Is. +// +// See https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md +// for motivation. +// +template +class IndexedTuple, TypeList> : public std::tuple { +public: + static_assert(sizeof...(Is) == sizeof...(Ts), "IndexedTuple size mismatch"); + + using std::tuple::tuple; + + template + static constexpr std::size_t Index = detail::TypeIndex::value; + + template + auto& get() { + return std::get>(*this); + } + + template + const auto& get() const { + return std::get>(*this); + } +}; + +} // namespace mgbl diff --git a/test/style/functions.test.cpp b/test/style/functions.test.cpp index 9577bcc6336..8ca2f951e72 100644 --- a/test/style/functions.test.cpp +++ b/test/style/functions.test.cpp @@ -2,16 +2,16 @@ #include #include -#include +#include using namespace mbgl; using namespace mbgl::style; float evaluate(PropertyValue value, float zoom) { - return PropertyValue::visit(value, PropertyEvaluator(CalculationParameters(zoom), 0)); + return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), 0)); } std::string evaluate(PropertyValue value, float zoom) { - return PropertyValue::visit(value, PropertyEvaluator(CalculationParameters(zoom), "")); + return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), "")); } TEST(Function, Constant) { diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp index 421d2f362d8..c20218a82ff 100644 --- a/test/text/quads.test.cpp +++ b/test/text/quads.test.cpp @@ -10,7 +10,7 @@ using namespace mbgl; using namespace mbgl::style; TEST(getIconQuads, normal) { - SymbolLayoutProperties layout; + SymbolLayoutProperties::Evaluated layout; Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0); SpriteAtlasElement image = { Rect( 0, 0, 15, 11 ), @@ -58,7 +58,7 @@ TEST(getIconQuads, style) { // none { - SymbolLayoutProperties layout; + SymbolLayoutProperties::Evaluated layout; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -80,9 +80,9 @@ TEST(getIconQuads, style) { // width { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(24.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Width); + SymbolLayoutProperties::Evaluated layout; + layout.get() = 24.0f; + layout.get() = IconTextFitType::Width; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -98,9 +98,9 @@ TEST(getIconQuads, style) { // width x textSize { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Width); + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Width; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -116,13 +116,13 @@ TEST(getIconQuads, style) { // width x textSize + padding { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Width); - layout.iconTextFitPadding.value[0] = 5.0f; - layout.iconTextFitPadding.value[1] = 10.0f; - layout.iconTextFitPadding.value[2] = 5.0f; - layout.iconTextFitPadding.value[3] = 10.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Width; + layout.get()[0] = 5.0f; + layout.get()[1] = 10.0f; + layout.get()[2] = 5.0f; + layout.get()[3] = 10.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -138,9 +138,9 @@ TEST(getIconQuads, style) { // height { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(24.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Height); + SymbolLayoutProperties::Evaluated layout; + layout.get() = 24.0f; + layout.get() = IconTextFitType::Height; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -156,9 +156,9 @@ TEST(getIconQuads, style) { // height x textSize { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Height); + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Height; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -174,13 +174,13 @@ TEST(getIconQuads, style) { // height x textSize + padding { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Height); - layout.iconTextFitPadding.value[0] = 5.0f; - layout.iconTextFitPadding.value[1] = 10.0f; - layout.iconTextFitPadding.value[2] = 5.0f; - layout.iconTextFitPadding.value[3] = 10.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Height; + layout.get()[0] = 5.0f; + layout.get()[1] = 10.0f; + layout.get()[2] = 5.0f; + layout.get()[3] = 10.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -196,9 +196,9 @@ TEST(getIconQuads, style) { // both { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(24.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Both); + SymbolLayoutProperties::Evaluated layout; + layout.get() = 24.0f; + layout.get() = IconTextFitType::Both; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -214,9 +214,9 @@ TEST(getIconQuads, style) { // both x textSize { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Both); + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Both; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -232,13 +232,13 @@ TEST(getIconQuads, style) { // both x textSize + padding { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Both); - layout.iconTextFitPadding.value[0] = 5.0f; - layout.iconTextFitPadding.value[1] = 10.0f; - layout.iconTextFitPadding.value[2] = 5.0f; - layout.iconTextFitPadding.value[3] = 10.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Both; + layout.get()[0] = 5.0f; + layout.get()[1] = 10.0f; + layout.get()[2] = 5.0f; + layout.get()[3] = 10.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText); @@ -254,13 +254,13 @@ TEST(getIconQuads, style) { // both x textSize + padding t/r/b/l { - SymbolLayoutProperties layout; - layout.textSize = LayoutProperty(12.0f); - layout.iconTextFit = LayoutProperty(IconTextFitType::Both); - layout.iconTextFitPadding.value[0] = 0.0f; - layout.iconTextFitPadding.value[1] = 5.0f; - layout.iconTextFitPadding.value[2] = 10.0f; - layout.iconTextFitPadding.value[3] = 15.0f; + SymbolLayoutProperties::Evaluated layout; + layout.get() = 12.0f; + layout.get() = IconTextFitType::Both; + layout.get()[0] = 0.0f; + layout.get()[1] = 5.0f; + layout.get()[2] = 10.0f; + layout.get()[3] = 15.0f; SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);