Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Properties refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Nov 4, 2016
1 parent f41e21d commit c87d461
Show file tree
Hide file tree
Showing 68 changed files with 1,204 additions and 1,058 deletions.
4 changes: 3 additions & 1 deletion cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class PropertyValue {

explicit operator bool() const { return !isUndefined(); };

template <typename Visitor>
static auto visit(const PropertyValue<T>& value, Visitor&& visitor) {
return Value::visit(value.value, visitor);
template <typename Evaluator>
auto evaluate(const Evaluator& evaluator) const {
return Value::visit(value, evaluator);
}
};

Expand Down
14 changes: 13 additions & 1 deletion include/mbgl/style/transition_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@
namespace mbgl {
namespace style {

struct TransitionOptions {
class TransitionOptions {
public:
optional<Duration> duration = {};
optional<Duration> 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
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/layout/symbol_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
7 changes: 2 additions & 5 deletions src/mbgl/layout/symbol_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

#include <mbgl/text/quads.hpp>
#include <mbgl/text/collision_feature.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>

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);
Expand Down
100 changes: 50 additions & 50 deletions src/mbgl/layout/symbol_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)),
Expand All @@ -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<TextField>().empty() && !layout.get<TextFont>().empty();
const bool hasIcon = !layout.get<IconImage>().empty();

if (!hasText && !hasIcon) {
return;
Expand Down Expand Up @@ -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<TextField>(), getValue);

if (layout.textTransform == TextTransformType::Uppercase) {
if (layout.get<TextTransform>() == TextTransformType::Uppercase) {
u8string = platform::uppercase(u8string);
} else if (layout.textTransform == TextTransformType::Lowercase) {
} else if (layout.get<TextTransform>() == TextTransformType::Lowercase) {
u8string = platform::lowercase(u8string);
}

Expand All @@ -99,7 +99,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_,
}

if (hasIcon) {
ft.icon = util::replaceTokens(layout.iconImage, getValue);
ft.icon = util::replaceTokens(layout.get<IconImage>(), getValue);
}

if (ft.text || ft.icon) {
Expand All @@ -117,7 +117,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_,
}
}

if (layout.symbolPlacement == SymbolPlacementType::Line) {
if (layout.get<SymbolPlacement>() == SymbolPlacementType::Line) {
util::mergeLines(features);
}
}
Expand All @@ -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<TextField>().empty() && !layout.get<TextFont>().empty() && !glyphAtlas.hasGlyphRanges(layout.get<TextFont>(), ranges)) {
return false;
}

if (!layout.iconImage.value.empty() && !spriteAtlas.isLoaded()) {
if (!layout.get<IconImage>().empty() && !spriteAtlas.isLoaded()) {
return false;
}

Expand All @@ -143,7 +143,7 @@ void SymbolLayout::prepare(uintptr_t tileUID,
float horizontalAlign = 0.5;
float verticalAlign = 0.5;

switch (layout.textAnchor) {
switch (layout.get<TextAnchor>()) {
case TextAnchorType::Top:
case TextAnchorType::Bottom:
case TextAnchorType::Center:
Expand All @@ -160,7 +160,7 @@ void SymbolLayout::prepare(uintptr_t tileUID,
break;
}

switch (layout.textAnchor) {
switch (layout.get<TextAnchor>()) {
case TextAnchorType::Left:
case TextAnchorType::Right:
case TextAnchorType::Center:
Expand All @@ -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<TextJustify>() == TextJustifyType::Right ? 1 :
layout.get<TextJustify>() == TextJustifyType::Left ? 0 :
0.5;

auto glyphSet = glyphAtlas.getGlyphSet(layout.textFont);
auto glyphSet = glyphAtlas.getGlyphSet(layout.get<TextFont>());

for (const auto& feature : features) {
if (feature.geometry.empty()) continue;
Expand All @@ -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<SymbolPlacement>() != SymbolPlacementType::Line ?
layout.get<TextMaxWidth>() * 24 : 0,
/* lineHeight: ems */ layout.get<TextLineHeight>() * 24,
/* horizontalAlign */ horizontalAlign,
/* verticalAlign */ verticalAlign,
/* justify */ justify,
/* spacing: ems */ layout.textLetterSpacing * 24,
/* translate */ Point<float>(layout.textOffset.value[0], layout.textOffset.value[1]));
/* spacing: ems */ layout.get<TextLetterSpacing>() * 24,
/* translate */ Point<float>(layout.get<TextOffset>()[0], layout.get<TextOffset>()[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<TextFont>(), **glyphSet, face);
}
}

Expand All @@ -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<IconRotate>() != 0) {
iconsNeedLinear = true;
}
}
Expand All @@ -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<TextSize>() / 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<IconSize>();
const float symbolSpacing = tilePixelRatio * layout.get<SymbolSpacing>();
const bool avoidEdges = layout.get<SymbolAvoidEdges>() && layout.get<SymbolPlacement>() != SymbolPlacementType::Line;
const float textPadding = layout.get<TextPadding>() * tilePixelRatio;
const float iconPadding = layout.get<IconPadding>() * tilePixelRatio;
const float textMaxAngle = layout.get<TextMaxAngle>() * util::DEG2RAD;
const SymbolPlacementType textPlacement = layout.get<TextRotationAlignment>() != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
const SymbolPlacementType iconPlacement = layout.iconRotationAlignment != AlignmentType::Map
: layout.get<SymbolPlacement>();
const SymbolPlacementType iconPlacement = layout.get<IconRotationAlignment>() != 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<SymbolPlacement>();
const bool mayOverlap = layout.get<TextAllowOverlap>() || layout.get<IconAllowOverlap>() ||
layout.get<TextIgnorePlacement>() || layout.get<IconIgnorePlacement>();
const bool isLine = layout.get<SymbolPlacement>() == SymbolPlacementType::Line;
const float textRepeatDistance = symbolSpacing / 2;

auto& clippedLines = isLine ?
Expand Down Expand Up @@ -330,15 +330,15 @@ std::unique_ptr<SymbolBucket> 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<TextRotationAlignment>() != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
const SymbolPlacementType iconPlacement = layout.iconRotationAlignment != AlignmentType::Map
: layout.get<SymbolPlacement>();
const SymbolPlacementType iconPlacement = layout.get<IconRotationAlignment>() != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
: layout.get<SymbolPlacement>();

const bool mayOverlap = layout.textAllowOverlap || layout.iconAllowOverlap ||
layout.textIgnorePlacement || layout.iconIgnorePlacement;
const bool mayOverlap = layout.get<TextAllowOverlap>() || layout.get<IconAllowOverlap>() ||
layout.get<TextIgnorePlacement>() || layout.get<IconIgnorePlacement>();

// Sort symbols by their y position on the canvas so that they lower symbols
// are drawn on top of higher symbols.
Expand All @@ -362,18 +362,18 @@ std::unique_ptr<SymbolBucket> 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<TextOptional>() || !hasText;
const bool textWithoutIcon = layout.get<IconOptional>() || !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<TextAllowOverlap>(), layout.get<SymbolAvoidEdges>()) :
collisionTile.minScale;
float iconScale = hasIcon ?
collisionTile.placeFeature(symbolInstance.iconCollisionFeature,
layout.iconAllowOverlap, layout.symbolAvoidEdges) :
layout.get<IconAllowOverlap>(), layout.get<SymbolAvoidEdges>()) :
collisionTile.minScale;


Expand All @@ -391,20 +391,20 @@ std::unique_ptr<SymbolBucket> 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<TextIgnorePlacement>());
if (glyphScale < collisionTile.maxScale) {
addSymbols(
bucket->text, symbolInstance.glyphQuads, glyphScale,
layout.textKeepUpright, textPlacement, collisionTile.config.angle);
layout.get<TextKeepUpright>(), textPlacement, collisionTile.config.angle);
}
}

if (hasIcon) {
collisionTile.insertFeature(symbolInstance.iconCollisionFeature, iconScale, layout.iconIgnorePlacement);
collisionTile.insertFeature(symbolInstance.iconCollisionFeature, iconScale, layout.get<IconIgnorePlacement>());
if (iconScale < collisionTile.maxScale) {
addSymbols(
bucket->icon, symbolInstance.iconQuads, iconScale,
layout.iconKeepUpright, iconPlacement, collisionTile.config.angle);
layout.get<IconKeepUpright>(), iconPlacement, collisionTile.config.angle);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/layout/symbol_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SymbolLayout {
const MapMode,
const GeometryTileLayer&,
const style::Filter&,
style::SymbolLayoutProperties,
style::SymbolLayoutProperties::Evaluated,
float textMaxSize,
SpriteAtlas&);

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit c87d461

Please sign in to comment.