[core] Eliminate use of ClassProperties for layout

This commit is contained in:
John Firebaugh
2015-10-26 10:14:24 -07:00
parent 728a9858ea
commit a562567589
33 changed files with 237 additions and 323 deletions

View File

@@ -7,7 +7,6 @@ namespace mbgl {
std::unique_ptr<StyleLayer> BackgroundLayer::clone() const {
std::unique_ptr<BackgroundLayer> result = std::make_unique<BackgroundLayer>();
result->copy(*this);
result->layout = layout;
result->paints.paints = paints.paints;
return std::move(result);
}

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/paint_properties_map.hpp>
#include <mbgl/style/class_properties.hpp>
namespace mbgl {
@@ -22,7 +21,6 @@ public:
bool hasTransitions() const override;
ClassProperties layout;
PaintPropertiesMap paints;
BackgroundPaintProperties properties;

View File

@@ -8,7 +8,6 @@ namespace mbgl {
std::unique_ptr<StyleLayer> CircleLayer::clone() const {
std::unique_ptr<CircleLayer> result = std::make_unique<CircleLayer>();
result->copy(*this);
result->layout = layout;
result->paints.paints = paints.paints;
return std::move(result);
}

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/paint_properties_map.hpp>
#include <mbgl/style/class_properties.hpp>
namespace mbgl {
@@ -22,7 +21,6 @@ public:
bool hasTransitions() const override;
ClassProperties layout;
PaintPropertiesMap paints;
CirclePaintProperties properties;

View File

@@ -8,7 +8,6 @@ namespace mbgl {
std::unique_ptr<StyleLayer> FillLayer::clone() const {
std::unique_ptr<FillLayer> result = std::make_unique<FillLayer>();
result->copy(*this);
result->layout = layout;
result->paints.paints = paints.paints;
return std::move(result);
}

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/paint_properties_map.hpp>
#include <mbgl/style/class_properties.hpp>
namespace mbgl {
@@ -22,7 +21,6 @@ public:
bool hasTransitions() const override;
ClassProperties layout;
PaintPropertiesMap paints;
FillPaintProperties properties;

View File

@@ -15,10 +15,10 @@ std::unique_ptr<StyleLayer> LineLayer::clone() const {
}
void LineLayer::parseLayout(const JSVal& value) {
parseProperty<Function<CapType>>("line-cap", PropertyKey::LineCap, layout, value);
parseProperty<Function<JoinType>>("line-join", PropertyKey::LineJoin, layout, value);
parseProperty<Function<float>>("line-miter-limit", PropertyKey::LineMiterLimit, layout, value);
parseProperty<Function<float>>("line-round-limit", PropertyKey::LineRoundLimit, layout, value);
layout.cap.parse("line-cap", value);
layout.join.parse("line-join", value);
layout.miterLimit.parse("line-miter-limit", value);
layout.roundLimit.parse("line-round-limit", value);
}
void LineLayer::parsePaints(const JSVal& layer) {
@@ -73,12 +73,13 @@ void LineLayer::recalculate(const StyleCalculationParameters& parameters) {
std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<LineBucket>();
const float z = parameters.tileID.z;
bucket->layout = layout;
layout.calculate(PropertyKey::LineCap, bucket->layout.cap, z);
layout.calculate(PropertyKey::LineJoin, bucket->layout.join, z);
layout.calculate(PropertyKey::LineMiterLimit, bucket->layout.miter_limit, z);
layout.calculate(PropertyKey::LineRoundLimit, bucket->layout.round_limit, z);
StyleCalculationParameters p(parameters.tileID.z);
bucket->layout.cap.calculate(p);
bucket->layout.join.calculate(p);
bucket->layout.miterLimit.calculate(p);
bucket->layout.roundLimit.calculate(p);
parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());

View File

@@ -4,10 +4,18 @@
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/paint_properties_map.hpp>
#include <mbgl/style/class_properties.hpp>
#include <mbgl/style/layout_property.hpp>
namespace mbgl {
class LineLayoutProperties {
public:
LayoutProperty<CapType> cap = CapType::Butt;
LayoutProperty<JoinType> join = JoinType::Miter;
LayoutProperty<float> miterLimit = 2.0f;
LayoutProperty<float> roundLimit = 1.0f;
};
class LineLayer : public StyleLayer {
public:
std::unique_ptr<StyleLayer> clone() const override;
@@ -22,7 +30,7 @@ public:
bool hasTransitions() const override;
ClassProperties layout;
LineLayoutProperties layout;
PaintPropertiesMap paints;
LinePaintProperties properties;

View File

@@ -7,7 +7,6 @@ namespace mbgl {
std::unique_ptr<StyleLayer> RasterLayer::clone() const {
std::unique_ptr<RasterLayer> result = std::make_unique<RasterLayer>();
result->copy(*this);
result->layout = layout;
result->paints.paints = paints.paints;
return std::move(result);
}

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/paint_properties_map.hpp>
#include <mbgl/style/class_properties.hpp>
namespace mbgl {
@@ -22,7 +21,6 @@ public:
bool hasTransitions() const override;
ClassProperties layout;
PaintPropertiesMap paints;
RasterPaintProperties properties;

View File

@@ -16,45 +16,45 @@ std::unique_ptr<StyleLayer> SymbolLayer::clone() const {
}
void SymbolLayer::parseLayout(const JSVal& value) {
parseProperty<Function<PlacementType>>("symbol-placement", PropertyKey::SymbolPlacement, layout, value);
parseProperty<Function<float>>("symbol-spacing", PropertyKey::SymbolSpacing, layout, value);
parseProperty<Function<bool>>("symbol-avoid-edges", PropertyKey::SymbolAvoidEdges, layout, value);
parseProperty<Function<bool>>("icon-allow-overlap", PropertyKey::IconAllowOverlap, layout, value);
parseProperty<Function<bool>>("icon-ignore-placement", PropertyKey::IconIgnorePlacement, layout, value);
parseProperty<Function<bool>>("icon-optional", PropertyKey::IconOptional, layout, value);
parseProperty<Function<RotationAlignmentType>>("icon-rotation-alignment", PropertyKey::IconRotationAlignment, layout, value);
parseProperty<Function<float>>("icon-size", PropertyKey::IconSize, layout, value);
parseProperty<Function<std::string>>("icon-image", PropertyKey::IconImage, layout, value);
parseProperty<Function<float>>("icon-rotate", PropertyKey::IconRotate, layout, value);
parseProperty<Function<float>>("icon-padding", PropertyKey::IconPadding, layout, value);
parseProperty<Function<bool>>("icon-keep-upright", PropertyKey::IconKeepUpright, layout, value);
parseProperty<Function<std::array<float, 2>>>("icon-offset", PropertyKey::IconOffset, layout, value);
parseProperty<Function<RotationAlignmentType>>("text-rotation-alignment", PropertyKey::TextRotationAlignment, layout, value);
parseProperty<Function<std::string>>("text-field", PropertyKey::TextField, layout, value);
parseProperty<Function<std::string>>("text-font", PropertyKey::TextFont, layout, value);
parseProperty<Function<float>>("text-size", PropertyKey::TextSize, layout, value);
parseProperty<Function<float>>("text-max-width", PropertyKey::TextMaxWidth, layout, value);
parseProperty<Function<float>>("text-line-height", PropertyKey::TextLineHeight, layout, value);
parseProperty<Function<float>>("text-letter-spacing", PropertyKey::TextLetterSpacing, layout, value);
parseProperty<Function<TextJustifyType>>("text-justify", PropertyKey::TextJustify, layout, value);
parseProperty<Function<TextAnchorType>>("text-anchor", PropertyKey::TextAnchor, layout, value);
parseProperty<Function<float>>("text-max-angle", PropertyKey::TextMaxAngle, layout, value);
parseProperty<Function<float>>("text-rotate", PropertyKey::TextRotate, layout, value);
parseProperty<Function<float>>("text-padding", PropertyKey::TextPadding, layout, value);
parseProperty<Function<bool>>("text-keep-upright", PropertyKey::TextKeepUpright, layout, value);
parseProperty<Function<TextTransformType>>("text-transform", PropertyKey::TextTransform, layout, value);
parseProperty<Function<std::array<float, 2>>>("text-offset", PropertyKey::TextOffset, layout, value);
parseProperty<Function<bool>>("text-allow-overlap", PropertyKey::TextAllowOverlap, layout, value);
parseProperty<Function<bool>>("text-ignore-placement", PropertyKey::TextIgnorePlacement, layout, value);
parseProperty<Function<bool>>("text-optional", PropertyKey::TextOptional, layout, value);
layout.placement.parse("symbol-placement", value);
layout.spacing.parse("symbol-spacing", value);
layout.avoidEdges.parse("symbol-avoid-edges", value);
layout.icon.allowOverlap.parse("icon-allow-overlap", value);
layout.icon.ignorePlacement.parse("icon-ignore-placement", value);
layout.icon.optional.parse("icon-optional", value);
layout.icon.rotationAlignment.parse("icon-rotation-alignment", value);
layout.icon.size.parse("icon-size", value);
layout.icon.image.parse("icon-image", value);
layout.icon.rotate.parse("icon-rotate", value);
layout.icon.padding.parse("icon-padding", value);
layout.icon.keepUpright.parse("icon-keep-upright", value);
layout.icon.offset.parse("icon-offset", value);
layout.text.rotationAlignment.parse("text-rotation-alignment", value);
layout.text.field.parse("text-field", value);
layout.text.font.parse("text-font", value);
layout.text.size.parse("text-size", value);
layout.text.maxWidth.parse("text-max-width", value);
layout.text.lineHeight.parse("text-line-height", value);
layout.text.letterSpacing.parse("text-letter-spacing", value);
layout.text.justify.parse("text-justify", value);
layout.text.anchor.parse("text-anchor", value);
layout.text.maxAngle.parse("text-max-angle", value);
layout.text.rotate.parse("text-rotate", value);
layout.text.padding.parse("text-padding", value);
layout.text.keepUpright.parse("text-keep-upright", value);
layout.text.transform.parse("text-transform", value);
layout.text.offset.parse("text-offset", value);
layout.text.allowOverlap.parse("text-allow-overlap", value);
layout.text.ignorePlacement.parse("text-ignore-placement", value);
layout.text.optional.parse("text-optional", value);
}
void SymbolLayer::parsePaints(const JSVal& layer) {
paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
parseProperty<Function<float>>("icon-opacity", PropertyKey::IconOpacity, paint, value);
parseProperty<PropertyTransition>("icon-opacity-transition", PropertyKey::IconOpacity, paint, value);
parseProperty<Function<float>>("icon-size", PropertyKey::IconSize, paint, value);
parseProperty<PropertyTransition>("icon-size-transition", PropertyKey::IconSize, paint, value);
parseProperty<Function<Color>>("icon-color", PropertyKey::IconColor, paint, value);
parseProperty<PropertyTransition>("icon-color-transition", PropertyKey::IconColor, paint, value);
parseProperty<Function<Color>>("icon-halo-color", PropertyKey::IconHaloColor, paint, value);
@@ -69,8 +69,6 @@ void SymbolLayer::parsePaints(const JSVal& layer) {
parseProperty<Function<float>>("text-opacity", PropertyKey::TextOpacity, paint, value);
parseProperty<PropertyTransition>("text-opacity-transition", PropertyKey::TextOpacity, paint, value);
parseProperty<Function<float>>("text-size", PropertyKey::TextSize, paint, value);
parseProperty<PropertyTransition>("text-size-transition", PropertyKey::TextSize, paint, value);
parseProperty<Function<Color>>("text-color", PropertyKey::TextColor, paint, value);
parseProperty<PropertyTransition>("text-color-transition", PropertyKey::TextColor, paint, value);
parseProperty<Function<Color>>("text-halo-color", PropertyKey::TextHaloColor, paint, value);
@@ -113,64 +111,63 @@ void SymbolLayer::recalculate(const StyleCalculationParameters& parameters) {
paints.calculate(PropertyKey::TextTranslateAnchor, properties.text.translate_anchor, parameters);
// text-size and icon-size are layout properties but they also need to be evaluated as paint properties:
auto it = layout.properties.find(PropertyKey::IconSize);
if (it != layout.properties.end()) {
const PropertyEvaluator<float> evaluator(parameters);
properties.icon.size = mapbox::util::apply_visitor(evaluator, it->second);
}
it = layout.properties.find(PropertyKey::TextSize);
if (it != layout.properties.end()) {
const PropertyEvaluator<float> evaluator(parameters);
properties.text.size = mapbox::util::apply_visitor(evaluator, it->second);
}
layout.icon.size.calculate(parameters);
layout.text.size.calculate(parameters);
properties.icon.size = layout.icon.size;
properties.text.size = layout.text.size;
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}
std::unique_ptr<Bucket> SymbolLayer::createBucket(StyleBucketParameters& parameters) const {
const float z = parameters.tileID.z;
auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling, z);
auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling,
parameters.tileID.z);
layout.calculate(PropertyKey::SymbolPlacement, bucket->layout.placement, z);
if (bucket->layout.placement == PlacementType::Line) {
bucket->layout.icon.rotation_alignment = RotationAlignmentType::Map;
bucket->layout.text.rotation_alignment = RotationAlignmentType::Map;
bucket->layout = layout;
StyleCalculationParameters p(parameters.tileID.z);
bucket->layout.placement.calculate(p);
if (bucket->layout.placement.value == PlacementType::Line) {
bucket->layout.icon.rotationAlignment = RotationAlignmentType::Map;
bucket->layout.text.rotationAlignment = RotationAlignmentType::Map;
};
layout.calculate(PropertyKey::SymbolSpacing, bucket->layout.spacing, z);
layout.calculate(PropertyKey::SymbolAvoidEdges, bucket->layout.avoid_edges, z);
bucket->layout.spacing.calculate(p);
bucket->layout.avoidEdges.calculate(p);
layout.calculate(PropertyKey::IconAllowOverlap, bucket->layout.icon.allow_overlap, z);
layout.calculate(PropertyKey::IconIgnorePlacement, bucket->layout.icon.ignore_placement, z);
layout.calculate(PropertyKey::IconOptional, bucket->layout.icon.optional, z);
layout.calculate(PropertyKey::IconRotationAlignment, bucket->layout.icon.rotation_alignment, z);
layout.calculate(PropertyKey::IconImage, bucket->layout.icon.image, z);
layout.calculate(PropertyKey::IconPadding, bucket->layout.icon.padding, z);
layout.calculate(PropertyKey::IconRotate, bucket->layout.icon.rotate, z);
layout.calculate(PropertyKey::IconKeepUpright, bucket->layout.icon.keep_upright, z);
layout.calculate(PropertyKey::IconOffset, bucket->layout.icon.offset, z);
bucket->layout.icon.allowOverlap.calculate(p);
bucket->layout.icon.ignorePlacement.calculate(p);
bucket->layout.icon.optional.calculate(p);
bucket->layout.icon.rotationAlignment.calculate(p);
bucket->layout.icon.image.calculate(p);
bucket->layout.icon.padding.calculate(p);
bucket->layout.icon.rotate.calculate(p);
bucket->layout.icon.keepUpright.calculate(p);
bucket->layout.icon.offset.calculate(p);
layout.calculate(PropertyKey::TextRotationAlignment, bucket->layout.text.rotation_alignment, z);
layout.calculate(PropertyKey::TextField, bucket->layout.text.field, z);
layout.calculate(PropertyKey::TextFont, bucket->layout.text.font, z);
layout.calculate(PropertyKey::TextMaxWidth, bucket->layout.text.max_width, z);
layout.calculate(PropertyKey::TextLineHeight, bucket->layout.text.line_height, z);
layout.calculate(PropertyKey::TextLetterSpacing, bucket->layout.text.letter_spacing, z);
layout.calculate(PropertyKey::TextMaxAngle, bucket->layout.text.max_angle, z);
layout.calculate(PropertyKey::TextRotate, bucket->layout.text.rotate, z);
layout.calculate(PropertyKey::TextPadding, bucket->layout.text.padding, z);
layout.calculate(PropertyKey::TextIgnorePlacement, bucket->layout.text.ignore_placement, z);
layout.calculate(PropertyKey::TextOptional, bucket->layout.text.optional, z);
layout.calculate(PropertyKey::TextJustify, bucket->layout.text.justify, z);
layout.calculate(PropertyKey::TextAnchor, bucket->layout.text.anchor, z);
layout.calculate(PropertyKey::TextKeepUpright, bucket->layout.text.keep_upright, z);
layout.calculate(PropertyKey::TextTransform, bucket->layout.text.transform, z);
layout.calculate(PropertyKey::TextOffset, bucket->layout.text.offset, z);
layout.calculate(PropertyKey::TextAllowOverlap, bucket->layout.text.allow_overlap, z);
bucket->layout.text.rotationAlignment.calculate(p);
bucket->layout.text.field.calculate(p);
bucket->layout.text.font.calculate(p);
bucket->layout.text.maxWidth.calculate(p);
bucket->layout.text.lineHeight.calculate(p);
bucket->layout.text.letterSpacing.calculate(p);
bucket->layout.text.maxAngle.calculate(p);
bucket->layout.text.rotate.calculate(p);
bucket->layout.text.padding.calculate(p);
bucket->layout.text.ignorePlacement.calculate(p);
bucket->layout.text.optional.calculate(p);
bucket->layout.text.justify.calculate(p);
bucket->layout.text.anchor.calculate(p);
bucket->layout.text.keepUpright.calculate(p);
bucket->layout.text.transform.calculate(p);
bucket->layout.text.offset.calculate(p);
bucket->layout.text.allowOverlap.calculate(p);
layout.calculate(PropertyKey::IconSize, bucket->layout.icon.size, z + 1);
layout.calculate(PropertyKey::IconSize, bucket->layout.icon.max_size, 18);
layout.calculate(PropertyKey::TextSize, bucket->layout.text.size, z + 1);
layout.calculate(PropertyKey::TextSize, bucket->layout.text.max_size, 18);
bucket->layout.icon.size.calculate(StyleCalculationParameters(18));
bucket->layout.text.size.calculate(StyleCalculationParameters(18));
bucket->layout.iconMaxSize = bucket->layout.icon.size;
bucket->layout.textMaxSize = bucket->layout.text.size;
bucket->layout.icon.size.calculate(StyleCalculationParameters(p.z + 1));
bucket->layout.text.size.calculate(StyleCalculationParameters(p.z + 1));
bucket->parseFeatures(parameters.layer, filter);

View File

@@ -4,10 +4,57 @@
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_properties.hpp>
#include <mbgl/style/paint_properties_map.hpp>
#include <mbgl/style/class_properties.hpp>
#include <mbgl/style/layout_property.hpp>
namespace mbgl {
class SymbolLayoutProperties {
public:
LayoutProperty<PlacementType> placement = PlacementType::Point;
LayoutProperty<float> spacing = 250.0f;
LayoutProperty<bool> avoidEdges = false;
class IconProperties {
public:
LayoutProperty<bool> allowOverlap = false;
LayoutProperty<bool> ignorePlacement = false;
LayoutProperty<bool> optional = false;
LayoutProperty<RotationAlignmentType> rotationAlignment = RotationAlignmentType::Viewport;
LayoutProperty<float> size = 1.0f;
LayoutProperty<std::string> image = { "" };
LayoutProperty<float> rotate = 0.0f;
LayoutProperty<float> padding = 2.0f;
LayoutProperty<bool> keepUpright = false;
LayoutProperty<std::array<float, 2>> offset = { {{ 0, 0 }} };
} icon;
class TextProperties {
public:
LayoutProperty<RotationAlignmentType> rotationAlignment = RotationAlignmentType::Viewport;
LayoutProperty<std::string> field = { "" };
LayoutProperty<std::string> font = { "Open Sans Regular, Arial Unicode MS Regular" };
LayoutProperty<float> size = 16.0f;
LayoutProperty<float> maxWidth = 15.0f /* em */;
LayoutProperty<float> lineHeight = 1.2f /* em */;
LayoutProperty<float> letterSpacing = 0.0f /* em */;
LayoutProperty<TextJustifyType> justify = TextJustifyType::Center;
LayoutProperty<TextAnchorType> anchor = TextAnchorType::Center;
LayoutProperty<float> maxAngle = 45.0f /* degrees */;
LayoutProperty<float> rotate = 0.0f;
LayoutProperty<float> padding = 2.0f;
LayoutProperty<bool> keepUpright = true;
LayoutProperty<TextTransformType> transform = TextTransformType::None;
LayoutProperty<std::array<float, 2>> offset = { {{ 0, 0 }} };
LayoutProperty<bool> allowOverlap = false;
LayoutProperty<bool> ignorePlacement = false;
LayoutProperty<bool> optional = false;
} text;
// Special case.
float iconMaxSize = 1.0f;
float textMaxSize = 16.0f;
};
class SymbolLayer : public StyleLayer {
public:
std::unique_ptr<StyleLayer> clone() const override;
@@ -22,7 +69,7 @@ public:
bool hasTransitions() const override;
ClassProperties layout;
SymbolLayoutProperties layout;
PaintPropertiesMap paints;
SymbolPaintProperties properties;