[core] Push layouts and paints to subclasses
This commit is contained in:
@@ -26,11 +26,13 @@ void ShapeAnnotationImpl::updateStyle(Style& style) {
|
||||
if (style.getLayer(layerID))
|
||||
return;
|
||||
|
||||
std::unique_ptr<StyleLayer> layer;
|
||||
std::string beforeLayerID = AnnotationManager::PointLayerID;
|
||||
|
||||
if (shape.properties.is<LinePaintProperties>()) {
|
||||
layer = createLineLayer();
|
||||
type = ProjectedFeatureType::LineString;
|
||||
|
||||
std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>();
|
||||
layer->type = StyleLayerType::Line;
|
||||
|
||||
layer->layout.set(PropertyKey::LineJoin, Function<JoinType>(JoinType::Round));
|
||||
|
||||
const LinePaintProperties& properties = shape.properties.get<LinePaintProperties>();
|
||||
ClassProperties paintProperties;
|
||||
@@ -39,8 +41,17 @@ void ShapeAnnotationImpl::updateStyle(Style& style) {
|
||||
paintProperties.set(PropertyKey::LineColor, Function<Color>(properties.color));
|
||||
layer->paints.paints.emplace(ClassID::Default, std::move(paintProperties));
|
||||
|
||||
layer->id = layerID;
|
||||
layer->source = AnnotationManager::SourceID;
|
||||
layer->sourceLayer = layer->id;
|
||||
|
||||
style.addLayer(std::move(layer), AnnotationManager::PointLayerID);
|
||||
|
||||
} else if (shape.properties.is<FillPaintProperties>()) {
|
||||
layer = createFillLayer();
|
||||
type = ProjectedFeatureType::Polygon;
|
||||
|
||||
std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>();
|
||||
layer->type = StyleLayerType::Fill;
|
||||
|
||||
const FillPaintProperties& properties = shape.properties.get<FillPaintProperties>();
|
||||
ClassProperties paintProperties;
|
||||
@@ -49,49 +60,28 @@ void ShapeAnnotationImpl::updateStyle(Style& style) {
|
||||
paintProperties.set(PropertyKey::FillOutlineColor, Function<Color>(properties.stroke_color));
|
||||
layer->paints.paints.emplace(ClassID::Default, std::move(paintProperties));
|
||||
|
||||
} else {
|
||||
beforeLayerID = shape.properties.get<std::string>();
|
||||
layer->id = layerID;
|
||||
layer->source = AnnotationManager::SourceID;
|
||||
layer->sourceLayer = layer->id;
|
||||
|
||||
const StyleLayer* sourceLayer = style.getLayer(beforeLayerID);
|
||||
style.addLayer(std::move(layer), AnnotationManager::PointLayerID);
|
||||
|
||||
} else {
|
||||
const StyleLayer* sourceLayer = style.getLayer(shape.properties.get<std::string>());
|
||||
if (!sourceLayer) return;
|
||||
|
||||
switch (sourceLayer->type) {
|
||||
case StyleLayerType::Line:
|
||||
layer = createLineLayer();
|
||||
break;
|
||||
std::unique_ptr<StyleLayer> layer = sourceLayer->clone();
|
||||
|
||||
case StyleLayerType::Fill:
|
||||
layer = createFillLayer();
|
||||
break;
|
||||
type = layer->type == StyleLayerType::Line
|
||||
? ProjectedFeatureType::LineString
|
||||
: ProjectedFeatureType::Polygon;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
layer->id = layerID;
|
||||
layer->source = AnnotationManager::SourceID;
|
||||
layer->sourceLayer = layer->id;
|
||||
|
||||
layer->paints.paints = sourceLayer->paints.paints;
|
||||
layer->layout = sourceLayer->layout;
|
||||
style.addLayer(std::move(layer), sourceLayer->id);
|
||||
}
|
||||
|
||||
layer->id = layerID;
|
||||
layer->source = AnnotationManager::SourceID;
|
||||
layer->sourceLayer = layer->id;
|
||||
|
||||
style.addLayer(std::move(layer), beforeLayerID);
|
||||
}
|
||||
|
||||
std::unique_ptr<StyleLayer> ShapeAnnotationImpl::createLineLayer() {
|
||||
type = ProjectedFeatureType::LineString;
|
||||
std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>();
|
||||
layer->type = StyleLayerType::Line;
|
||||
layer->layout.set(PropertyKey::LineJoin, Function<JoinType>(JoinType::Round));
|
||||
return std::move(layer);
|
||||
}
|
||||
|
||||
std::unique_ptr<StyleLayer> ShapeAnnotationImpl::createFillLayer() {
|
||||
type = ProjectedFeatureType::Polygon;
|
||||
std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>();
|
||||
layer->type = StyleLayerType::Fill;
|
||||
return std::move(layer);
|
||||
}
|
||||
|
||||
void ShapeAnnotationImpl::updateTile(const TileID& tileID, AnnotationTile& tile) {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Style;
|
||||
class StyleLayer;
|
||||
class AnnotationTile;
|
||||
|
||||
class ShapeAnnotationImpl {
|
||||
@@ -32,9 +31,6 @@ public:
|
||||
const ShapeAnnotation shape;
|
||||
|
||||
private:
|
||||
std::unique_ptr<StyleLayer> createLineLayer();
|
||||
std::unique_ptr<StyleLayer> createFillLayer();
|
||||
|
||||
const uint8_t maxZoom;
|
||||
mapbox::util::geojsonvt::ProjectedFeatureType type;
|
||||
std::unique_ptr<mapbox::util::geojsonvt::GeoJSONVT> shapeTiler;
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
#include <mbgl/layer/background_layer.hpp>
|
||||
#include <mbgl/style/property_parsing.hpp>
|
||||
#include <mbgl/renderer/bucket.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void BackgroundLayer::parsePaints(const JSVal& layer) {
|
||||
paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
|
||||
parseProperty<Function<float>>("background-opacity", PropertyKey::BackgroundOpacity, paint, value);
|
||||
@@ -11,6 +20,14 @@ void BackgroundLayer::parsePaints(const JSVal& layer) {
|
||||
});
|
||||
}
|
||||
|
||||
void BackgroundLayer::cascade(const StyleCascadeParameters& parameters) {
|
||||
paints.cascade(parameters);
|
||||
}
|
||||
|
||||
bool BackgroundLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
void BackgroundLayer::recalculate(const StyleCalculationParameters& parameters) {
|
||||
paints.removeExpiredTransitions(parameters.now);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ namespace mbgl {
|
||||
|
||||
class BackgroundLayer : public StyleLayer {
|
||||
public:
|
||||
std::unique_ptr<StyleLayer> clone() const override;
|
||||
|
||||
void parseLayout(const JSVal&) override {};
|
||||
void parsePaints(const JSVal&) override;
|
||||
|
||||
void cascade(const StyleCascadeParameters&) override;
|
||||
void recalculate(const StyleCalculationParameters&) override;
|
||||
|
||||
std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;
|
||||
|
||||
bool hasTransitions() const override;
|
||||
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
BackgroundPaintProperties properties;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void CircleLayer::parsePaints(const JSVal& layer) {
|
||||
paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
|
||||
parseProperty<Function<float>>("circle-radius", PropertyKey::CircleRadius, paint, value);
|
||||
@@ -16,6 +24,14 @@ void CircleLayer::parsePaints(const JSVal& layer) {
|
||||
});
|
||||
}
|
||||
|
||||
void CircleLayer::cascade(const StyleCascadeParameters& parameters) {
|
||||
paints.cascade(parameters);
|
||||
}
|
||||
|
||||
bool CircleLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
void CircleLayer::recalculate(const StyleCalculationParameters& parameters) {
|
||||
paints.removeExpiredTransitions(parameters.now);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ namespace mbgl {
|
||||
|
||||
class CircleLayer : public StyleLayer {
|
||||
public:
|
||||
std::unique_ptr<StyleLayer> clone() const override;
|
||||
|
||||
void parseLayout(const JSVal&) override {};
|
||||
void parsePaints(const JSVal&) override;
|
||||
|
||||
void cascade(const StyleCascadeParameters&) override;
|
||||
void recalculate(const StyleCalculationParameters&) override;
|
||||
|
||||
std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;
|
||||
|
||||
bool hasTransitions() const override;
|
||||
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
CirclePaintProperties properties;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void FillLayer::parsePaints(const JSVal& layer) {
|
||||
paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
|
||||
parseProperty<Function<bool>>("fill-antialias", PropertyKey::FillAntialias, paint, value);
|
||||
@@ -21,6 +29,14 @@ void FillLayer::parsePaints(const JSVal& layer) {
|
||||
});
|
||||
}
|
||||
|
||||
void FillLayer::cascade(const StyleCascadeParameters& parameters) {
|
||||
paints.cascade(parameters);
|
||||
}
|
||||
|
||||
bool FillLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
void FillLayer::recalculate(const StyleCalculationParameters& parameters) {
|
||||
paints.removeExpiredTransitions(parameters.now);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ namespace mbgl {
|
||||
|
||||
class FillLayer : public StyleLayer {
|
||||
public:
|
||||
std::unique_ptr<StyleLayer> clone() const override;
|
||||
|
||||
void parseLayout(const JSVal&) override {};
|
||||
void parsePaints(const JSVal&) override;
|
||||
|
||||
void cascade(const StyleCascadeParameters&) override;
|
||||
void recalculate(const StyleCalculationParameters&) override;
|
||||
|
||||
std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;
|
||||
|
||||
bool hasTransitions() const override;
|
||||
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
FillPaintProperties properties;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
std::unique_ptr<StyleLayer> LineLayer::clone() const {
|
||||
std::unique_ptr<LineLayer> result = std::make_unique<LineLayer>();
|
||||
result->copy(*this);
|
||||
result->layout = layout;
|
||||
result->paints.paints = paints.paints;
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
void LineLayer::parseLayout(const JSVal& value) {
|
||||
parseProperty<Function<CapType>>("line-cap", PropertyKey::LineCap, layout, value);
|
||||
parseProperty<Function<JoinType>>("line-join", PropertyKey::LineJoin, layout, value);
|
||||
@@ -33,6 +41,14 @@ void LineLayer::parsePaints(const JSVal& layer) {
|
||||
});
|
||||
}
|
||||
|
||||
void LineLayer::cascade(const StyleCascadeParameters& parameters) {
|
||||
paints.cascade(parameters);
|
||||
}
|
||||
|
||||
bool LineLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
void LineLayer::recalculate(const StyleCalculationParameters& parameters) {
|
||||
paints.removeExpiredTransitions(parameters.now);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ namespace mbgl {
|
||||
|
||||
class LineLayer : public StyleLayer {
|
||||
public:
|
||||
std::unique_ptr<StyleLayer> clone() const override;
|
||||
|
||||
void parseLayout(const JSVal&) override;
|
||||
void parsePaints(const JSVal&) override;
|
||||
|
||||
void cascade(const StyleCascadeParameters&) override;
|
||||
void recalculate(const StyleCalculationParameters&) override;
|
||||
|
||||
std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;
|
||||
|
||||
bool hasTransitions() const override;
|
||||
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
LinePaintProperties properties;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void RasterLayer::parsePaints(const JSVal& layer) {
|
||||
paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
|
||||
parseProperty<Function<float>>("raster-opacity", PropertyKey::RasterOpacity, paint, value);
|
||||
@@ -22,6 +30,14 @@ void RasterLayer::parsePaints(const JSVal& layer) {
|
||||
});
|
||||
}
|
||||
|
||||
void RasterLayer::cascade(const StyleCascadeParameters& parameters) {
|
||||
paints.cascade(parameters);
|
||||
}
|
||||
|
||||
bool RasterLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
void RasterLayer::recalculate(const StyleCalculationParameters& parameters) {
|
||||
paints.removeExpiredTransitions(parameters.now);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ namespace mbgl {
|
||||
|
||||
class RasterLayer : public StyleLayer {
|
||||
public:
|
||||
std::unique_ptr<StyleLayer> clone() const override;
|
||||
|
||||
void parseLayout(const JSVal&) override {};
|
||||
void parsePaints(const JSVal&) override;
|
||||
|
||||
void cascade(const StyleCascadeParameters&) override;
|
||||
void recalculate(const StyleCalculationParameters&) override;
|
||||
|
||||
std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;
|
||||
|
||||
bool hasTransitions() const override;
|
||||
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
RasterPaintProperties properties;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,14 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
std::unique_ptr<StyleLayer> SymbolLayer::clone() const {
|
||||
std::unique_ptr<SymbolLayer> result = std::make_unique<SymbolLayer>();
|
||||
result->copy(*this);
|
||||
result->layout = layout;
|
||||
result->paints.paints = paints.paints;
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
void SymbolLayer::parseLayout(const JSVal& value) {
|
||||
parseProperty<Function<PlacementType>>("symbol-placement", PropertyKey::SymbolPlacement, layout, value);
|
||||
parseProperty<Function<float>>("symbol-spacing", PropertyKey::SymbolSpacing, layout, value);
|
||||
@@ -77,6 +85,14 @@ void SymbolLayer::parsePaints(const JSVal& layer) {
|
||||
});
|
||||
}
|
||||
|
||||
void SymbolLayer::cascade(const StyleCascadeParameters& parameters) {
|
||||
paints.cascade(parameters);
|
||||
}
|
||||
|
||||
bool SymbolLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
void SymbolLayer::recalculate(const StyleCalculationParameters& parameters) {
|
||||
paints.removeExpiredTransitions(parameters.now);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ namespace mbgl {
|
||||
|
||||
class SymbolLayer : public StyleLayer {
|
||||
public:
|
||||
std::unique_ptr<StyleLayer> clone() const override;
|
||||
|
||||
void parseLayout(const JSVal&) override;
|
||||
void parsePaints(const JSVal&) override;
|
||||
|
||||
void cascade(const StyleCascadeParameters&) override;
|
||||
void recalculate(const StyleCalculationParameters&) override;
|
||||
|
||||
std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;
|
||||
|
||||
bool hasTransitions() const override;
|
||||
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
SymbolPaintProperties properties;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
#include <mbgl/style/property_transition.hpp>
|
||||
#include <mbgl/style/property_fallback.hpp>
|
||||
#include <mbgl/style/class_properties.hpp>
|
||||
#include <mbgl/style/style_cascade_parameters.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
void PaintPropertiesMap::parseEach(const JSVal& layer, std::function<void (ClassProperties &, const JSVal &)> parsePaint) {
|
||||
paints.clear();
|
||||
|
||||
rapidjson::Value::ConstMemberIterator itr = layer.MemberBegin();
|
||||
for (; itr != layer.MemberEnd(); ++itr) {
|
||||
const std::string name { itr->name.GetString(), itr->name.GetStringLength() };
|
||||
@@ -17,26 +20,24 @@ void PaintPropertiesMap::parseEach(const JSVal& layer, std::function<void (Class
|
||||
}
|
||||
}
|
||||
|
||||
void PaintPropertiesMap::cascade(const std::vector<std::string>& classes,
|
||||
const TimePoint& now,
|
||||
const PropertyTransition& defaultTransition) {
|
||||
void PaintPropertiesMap::cascade(const StyleCascadeParameters& parameters) {
|
||||
// Stores all keys that we have already added transitions for.
|
||||
std::set<PropertyKey> alreadyApplied;
|
||||
|
||||
// We only apply the default style values if there are no classes set.
|
||||
if (classes.empty()) {
|
||||
cascadeClass(ClassID::Default, alreadyApplied, now, defaultTransition);
|
||||
if (parameters.classes.empty()) {
|
||||
cascadeClass(ClassID::Default, alreadyApplied, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reverse iterate through all class names and apply them last to first.
|
||||
for (auto it = classes.rbegin(); it != classes.rend(); ++it) {
|
||||
for (auto it = parameters.classes.rbegin(); it != parameters.classes.rend(); ++it) {
|
||||
// From here on, we're only dealing with IDs to avoid comparing strings all the time.
|
||||
cascadeClass(ClassDictionary::Get().lookup(*it), alreadyApplied, now, defaultTransition);
|
||||
cascadeClass(ClassDictionary::Get().lookup(*it), alreadyApplied, parameters);
|
||||
}
|
||||
|
||||
// As the last class, apply the default class.
|
||||
cascadeClass(ClassID::Default, alreadyApplied, now, defaultTransition);
|
||||
cascadeClass(ClassID::Default, alreadyApplied, parameters);
|
||||
|
||||
// Make sure that we also transition to the fallback value for keys that aren't changed by
|
||||
// any applied classes.
|
||||
@@ -56,8 +57,8 @@ void PaintPropertiesMap::cascade(const std::vector<std::string>& classes,
|
||||
|
||||
// This property key hasn't been set by a previous class, so we need to add a transition
|
||||
// to the fallback value for that key.
|
||||
const TimePoint begin = now + *defaultTransition.delay;
|
||||
const TimePoint end = begin + *defaultTransition.duration;
|
||||
const TimePoint begin = parameters.now + *parameters.defaultTransition.delay;
|
||||
const TimePoint end = begin + *parameters.defaultTransition.duration;
|
||||
const PropertyValue &value = PropertyFallbackValue::Get(key);
|
||||
appliedProperties.add(ClassID::Fallback, begin, end, value);
|
||||
}
|
||||
@@ -65,8 +66,7 @@ void PaintPropertiesMap::cascade(const std::vector<std::string>& classes,
|
||||
|
||||
void PaintPropertiesMap::cascadeClass(const ClassID classID,
|
||||
std::set<PropertyKey>& alreadyApplied,
|
||||
const TimePoint& now,
|
||||
const PropertyTransition& defaultTransition) {
|
||||
const StyleCascadeParameters& parameters) {
|
||||
auto styleIt = paints.find(classID);
|
||||
if (styleIt == paints.end()) {
|
||||
// There is no class in this layer with this class_name.
|
||||
@@ -92,9 +92,9 @@ void PaintPropertiesMap::cascadeClass(const ClassID classID,
|
||||
AppliedClassPropertyValues &appliedProperties = appliedStyle[key];
|
||||
if (appliedProperties.mostRecent() != classID) {
|
||||
PropertyTransition transition = classProperties.getTransition(key);
|
||||
Duration delay = transition.delay ? *transition.delay : *defaultTransition.delay;
|
||||
Duration duration = transition.duration ? *transition.duration : *defaultTransition.duration;
|
||||
const TimePoint begin = now + delay;
|
||||
Duration delay = transition.delay ? *transition.delay : *parameters.defaultTransition.delay;
|
||||
Duration duration = transition.duration ? *transition.duration : *parameters.defaultTransition.duration;
|
||||
const TimePoint begin = parameters.now + delay;
|
||||
const TimePoint end = begin + duration;
|
||||
const PropertyValue &value = propertyPair.second;
|
||||
appliedProperties.add(classID, begin, end, value);
|
||||
|
||||
@@ -18,14 +18,13 @@ namespace mbgl {
|
||||
|
||||
class ClassProperties;
|
||||
class PropertyTransition;
|
||||
class StyleCascadeParameters;
|
||||
|
||||
using JSVal = rapidjson::Value;
|
||||
|
||||
class PaintPropertiesMap {
|
||||
public:
|
||||
void cascade(const std::vector<std::string>& classNames,
|
||||
const TimePoint& now,
|
||||
const PropertyTransition& defaultTransition);
|
||||
void cascade(const StyleCascadeParameters&);
|
||||
|
||||
bool hasTransitions() const;
|
||||
void removeExpiredTransitions(const TimePoint& now);
|
||||
@@ -81,8 +80,7 @@ private:
|
||||
// Applies all properties from a class, if they haven't been applied already.
|
||||
void cascadeClass(const ClassID,
|
||||
std::set<PropertyKey>&,
|
||||
const TimePoint&,
|
||||
const PropertyTransition&);
|
||||
const StyleCascadeParameters&);
|
||||
|
||||
// For every property, stores a list of applied property values, with
|
||||
// optional transition times.
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/style/property_transition.hpp>
|
||||
#include <mbgl/style/style_cascade_parameters.hpp>
|
||||
#include <mbgl/style/style_calculation_parameters.hpp>
|
||||
#include <mbgl/geometry/glyph_atlas.hpp>
|
||||
#include <mbgl/geometry/sprite_atlas.hpp>
|
||||
#include <mbgl/geometry/line_atlas.hpp>
|
||||
@@ -119,10 +121,13 @@ void Style::update(const TransformState& transform,
|
||||
}
|
||||
|
||||
void Style::cascade() {
|
||||
StyleCascadeParameters parameters(data.getClasses(),
|
||||
data.getAnimationTime(),
|
||||
PropertyTransition { data.getDefaultTransitionDuration(),
|
||||
data.getDefaultTransitionDelay() });
|
||||
|
||||
for (const auto& layer : layers) {
|
||||
layer->cascade(data.getClasses(),
|
||||
data.getAnimationTime(),
|
||||
PropertyTransition { data.getDefaultTransitionDuration(), data.getDefaultTransitionDelay() });
|
||||
layer->cascade(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
src/mbgl/style/style_cascade_parameters.hpp
Normal file
28
src/mbgl/style/style_cascade_parameters.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef STYLE_CASCADE_PARAMETERS
|
||||
#define STYLE_CASCADE_PARAMETERS
|
||||
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class PropertyTransition;
|
||||
|
||||
class StyleCascadeParameters {
|
||||
public:
|
||||
StyleCascadeParameters(const std::vector<std::string>& classes_,
|
||||
const TimePoint& now_,
|
||||
const PropertyTransition& defaultTransition_)
|
||||
: classes(classes_),
|
||||
now(now_),
|
||||
defaultTransition(defaultTransition_) {}
|
||||
|
||||
std::vector<std::string> classes;
|
||||
TimePoint now;
|
||||
PropertyTransition defaultTransition;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -31,18 +31,18 @@ const std::string& StyleLayer::bucketName() const {
|
||||
return ref.empty() ? id : ref;
|
||||
}
|
||||
|
||||
void StyleLayer::cascade(const std::vector<std::string>& classes,
|
||||
const TimePoint& now,
|
||||
const PropertyTransition& defaultTransition) {
|
||||
paints.cascade(classes, now, defaultTransition);
|
||||
}
|
||||
|
||||
bool StyleLayer::hasTransitions() const {
|
||||
return paints.hasTransitions();
|
||||
}
|
||||
|
||||
bool StyleLayer::hasRenderPass(RenderPass pass) const {
|
||||
return bool(passes & pass);
|
||||
}
|
||||
|
||||
void StyleLayer::copy(const StyleLayer& src) {
|
||||
type = src.type;
|
||||
source = src.source;
|
||||
sourceLayer = src.sourceLayer;
|
||||
filter = src.filter;
|
||||
minZoom = src.minZoom;
|
||||
maxZoom = src.maxZoom;
|
||||
visibility = src.visibility;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,32 +3,26 @@
|
||||
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/style/filter_expression.hpp>
|
||||
#include <mbgl/style/class_properties.hpp>
|
||||
#include <mbgl/style/paint_properties_map.hpp>
|
||||
|
||||
#include <mbgl/renderer/render_pass.hpp>
|
||||
#include <mbgl/map/tile_data.hpp>
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class StyleCascadeParameters;
|
||||
class StyleCalculationParameters;
|
||||
class StyleBucketParameters;
|
||||
class PropertyTransition;
|
||||
class Bucket;
|
||||
|
||||
using JSVal = rapidjson::Value;
|
||||
|
||||
class StyleLayer : public util::noncopyable {
|
||||
public:
|
||||
static std::unique_ptr<StyleLayer> create(StyleLayerType);
|
||||
virtual std::unique_ptr<StyleLayer> clone() const = 0;
|
||||
|
||||
virtual ~StyleLayer() = default;
|
||||
|
||||
@@ -39,9 +33,7 @@ public:
|
||||
const std::string& bucketName() const;
|
||||
|
||||
// Partially evaluate paint properties based on a set of classes.
|
||||
void cascade(const std::vector<std::string>& classNames,
|
||||
const TimePoint& now,
|
||||
const PropertyTransition& defaultTransition);
|
||||
virtual void cascade(const StyleCascadeParameters&) = 0;
|
||||
|
||||
// Fully evaluate cascaded paint properties based on a zoom level.
|
||||
virtual void recalculate(const StyleCalculationParameters&) = 0;
|
||||
@@ -49,7 +41,7 @@ public:
|
||||
virtual std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const = 0;
|
||||
|
||||
// Checks whether this layer has any active paint properties with transitions.
|
||||
bool hasTransitions() const;
|
||||
virtual bool hasTransitions() const = 0;
|
||||
|
||||
// Checks whether this layer needs to be rendered in the given render pass.
|
||||
bool hasRenderPass(RenderPass) const;
|
||||
@@ -64,13 +56,13 @@ public:
|
||||
float minZoom = -std::numeric_limits<float>::infinity();
|
||||
float maxZoom = std::numeric_limits<float>::infinity();
|
||||
VisibilityType visibility = VisibilityType::Visible;
|
||||
ClassProperties layout;
|
||||
PaintPropertiesMap paints;
|
||||
|
||||
protected:
|
||||
// Stores what render passes this layer is currently enabled for. This depends on the
|
||||
// evaluated StyleProperties object and is updated accordingly.
|
||||
RenderPass passes = RenderPass::None;
|
||||
|
||||
void copy(const StyleLayer& source);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -184,16 +184,9 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, util::pt
|
||||
return;
|
||||
}
|
||||
|
||||
layer = StyleLayer::create(reference->type);
|
||||
layer = reference->clone();
|
||||
layer->id = id;
|
||||
layer->type = reference->type;
|
||||
layer->source = reference->source;
|
||||
layer->sourceLayer = reference->sourceLayer;
|
||||
layer->filter = reference->filter;
|
||||
layer->minZoom = reference->minZoom;
|
||||
layer->maxZoom = reference->maxZoom;
|
||||
layer->visibility = reference->visibility;
|
||||
layer->layout = reference->layout;
|
||||
layer->ref = ref;
|
||||
|
||||
} else {
|
||||
// Otherwise, parse the source/source-layer/filter/render keys to form the bucket.
|
||||
|
||||
Reference in New Issue
Block a user