diff options
Diffstat (limited to 'src/mbgl/style/layers/background_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/background_layer.cpp | 126 |
1 files changed, 82 insertions, 44 deletions
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index b4ffea138b..d4ead18816 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -2,39 +2,65 @@ #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> -#include <mbgl/style/conversion/stringify.hpp> +#include <mbgl/style/layer_observer.hpp> namespace mbgl { namespace style { BackgroundLayer::BackgroundLayer(const std::string& layerID) - : Layer(LayerType::Background, std::make_unique<Impl>()) - , impl(static_cast<Impl*>(baseImpl.get())) { - impl->id = layerID; + : Layer(makeMutable<Impl>(LayerType::Background, layerID, std::string())) { } -BackgroundLayer::BackgroundLayer(const Impl& other) - : Layer(LayerType::Background, std::make_unique<Impl>(other)) - , impl(static_cast<Impl*>(baseImpl.get())) { +BackgroundLayer::BackgroundLayer(Immutable<Impl> impl_) + : Layer(std::move(impl_)) { } BackgroundLayer::~BackgroundLayer() = default; -std::unique_ptr<Layer> BackgroundLayer::Impl::clone() const { - return std::make_unique<BackgroundLayer>(*this); +const BackgroundLayer::Impl& BackgroundLayer::impl() const { + return static_cast<const Impl&>(*baseImpl); } -std::unique_ptr<Layer> BackgroundLayer::Impl::cloneRef(const std::string& id_) const { - auto result = std::make_unique<BackgroundLayer>(*this); - result->impl->id = id_; - result->impl->cascading = BackgroundPaintProperties::Cascading(); - return std::move(result); +Mutable<BackgroundLayer::Impl> BackgroundLayer::mutableImpl() const { + return makeMutable<Impl>(impl()); +} + +std::unique_ptr<Layer> BackgroundLayer::cloneRef(const std::string& id_) const { + auto impl_ = mutableImpl(); + impl_->id = id_; + impl_->paint = BackgroundPaintProperties::Transitionable(); + return std::make_unique<BackgroundLayer>(std::move(impl_)); } void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const { } +// Visibility + +void BackgroundLayer::setVisibility(VisibilityType value) { + if (value == getVisibility()) + return; + auto impl_ = mutableImpl(); + impl_->visibility = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} + +// Zoom range + +void BackgroundLayer::setMinZoom(float minZoom) { + auto impl_ = mutableImpl(); + impl_->minZoom = minZoom; + baseImpl = std::move(impl_); +} + +void BackgroundLayer::setMaxZoom(float maxZoom) { + auto impl_ = mutableImpl(); + impl_->maxZoom = maxZoom; + baseImpl = std::move(impl_); +} + // Layout properties @@ -44,69 +70,81 @@ PropertyValue<Color> BackgroundLayer::getDefaultBackgroundColor() { return { Color::black() }; } -PropertyValue<Color> BackgroundLayer::getBackgroundColor(const optional<std::string>& klass) const { - return impl->cascading.template get<BackgroundColor>().get(klass); +PropertyValue<Color> BackgroundLayer::getBackgroundColor() const { + return impl().paint.template get<BackgroundColor>().value; } -void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value, const optional<std::string>& klass) { - if (value == getBackgroundColor(klass)) +void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value) { + if (value == getBackgroundColor()) return; - impl->cascading.template get<BackgroundColor>().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->paint.template get<BackgroundColor>().value = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); } -void BackgroundLayer::setBackgroundColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->cascading.template get<BackgroundColor>().setTransition(value, klass); +void BackgroundLayer::setBackgroundColorTransition(const TransitionOptions& options) { + auto impl_ = mutableImpl(); + impl_->paint.template get<BackgroundColor>().options = options; + baseImpl = std::move(impl_); } -TransitionOptions BackgroundLayer::getBackgroundColorTransition(const optional<std::string>& klass) const { - return impl->cascading.template get<BackgroundColor>().getTransition(klass); +TransitionOptions BackgroundLayer::getBackgroundColorTransition() const { + return impl().paint.template get<BackgroundColor>().options; } PropertyValue<std::string> BackgroundLayer::getDefaultBackgroundPattern() { return { "" }; } -PropertyValue<std::string> BackgroundLayer::getBackgroundPattern(const optional<std::string>& klass) const { - return impl->cascading.template get<BackgroundPattern>().get(klass); +PropertyValue<std::string> BackgroundLayer::getBackgroundPattern() const { + return impl().paint.template get<BackgroundPattern>().value; } -void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value, const optional<std::string>& klass) { - if (value == getBackgroundPattern(klass)) +void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value) { + if (value == getBackgroundPattern()) return; - impl->cascading.template get<BackgroundPattern>().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->paint.template get<BackgroundPattern>().value = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); } -void BackgroundLayer::setBackgroundPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->cascading.template get<BackgroundPattern>().setTransition(value, klass); +void BackgroundLayer::setBackgroundPatternTransition(const TransitionOptions& options) { + auto impl_ = mutableImpl(); + impl_->paint.template get<BackgroundPattern>().options = options; + baseImpl = std::move(impl_); } -TransitionOptions BackgroundLayer::getBackgroundPatternTransition(const optional<std::string>& klass) const { - return impl->cascading.template get<BackgroundPattern>().getTransition(klass); +TransitionOptions BackgroundLayer::getBackgroundPatternTransition() const { + return impl().paint.template get<BackgroundPattern>().options; } PropertyValue<float> BackgroundLayer::getDefaultBackgroundOpacity() { return { 1 }; } -PropertyValue<float> BackgroundLayer::getBackgroundOpacity(const optional<std::string>& klass) const { - return impl->cascading.template get<BackgroundOpacity>().get(klass); +PropertyValue<float> BackgroundLayer::getBackgroundOpacity() const { + return impl().paint.template get<BackgroundOpacity>().value; } -void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value, const optional<std::string>& klass) { - if (value == getBackgroundOpacity(klass)) +void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value) { + if (value == getBackgroundOpacity()) return; - impl->cascading.template get<BackgroundOpacity>().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->paint.template get<BackgroundOpacity>().value = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); } -void BackgroundLayer::setBackgroundOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->cascading.template get<BackgroundOpacity>().setTransition(value, klass); +void BackgroundLayer::setBackgroundOpacityTransition(const TransitionOptions& options) { + auto impl_ = mutableImpl(); + impl_->paint.template get<BackgroundOpacity>().options = options; + baseImpl = std::move(impl_); } -TransitionOptions BackgroundLayer::getBackgroundOpacityTransition(const optional<std::string>& klass) const { - return impl->cascading.template get<BackgroundOpacity>().getTransition(klass); +TransitionOptions BackgroundLayer::getBackgroundOpacityTransition() const { + return impl().paint.template get<BackgroundOpacity>().options; } } // namespace style |