diff options
Diffstat (limited to 'src/mbgl/style/layers/background_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/background_layer.cpp | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 7a186a3354..9187784452 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -1,5 +1,3 @@ -// clang-format off - // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. #include <mbgl/style/layers/background_layer.hpp> @@ -148,28 +146,37 @@ TransitionOptions BackgroundLayer::getBackgroundPatternTransition() const { using namespace conversion; +namespace { + +enum class Property : uint8_t { + BackgroundColor, + BackgroundOpacity, + BackgroundPattern, + BackgroundColorTransition, + BackgroundOpacityTransition, + BackgroundPatternTransition, +}; + +template <typename T> +constexpr uint8_t toUint8(T t) noexcept { + return uint8_t(mbgl::underlying_type(t)); +} + +MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>( + {{"background-color", toUint8(Property::BackgroundColor)}, + {"background-opacity", toUint8(Property::BackgroundOpacity)}, + {"background-pattern", toUint8(Property::BackgroundPattern)}, + {"background-color-transition", toUint8(Property::BackgroundColorTransition)}, + {"background-opacity-transition", toUint8(Property::BackgroundOpacityTransition)}, + {"background-pattern-transition", toUint8(Property::BackgroundPatternTransition)}}); + +constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::BackgroundPatternTransition); +} // namespace + optional<Error> BackgroundLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - BackgroundColor, - BackgroundOpacity, - BackgroundPattern, - BackgroundColorTransition, - BackgroundOpacityTransition, - BackgroundPatternTransition, - }; - - MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({ - { "background-color", mbgl::underlying_type(Property::BackgroundColor) }, - { "background-opacity", mbgl::underlying_type(Property::BackgroundOpacity) }, - { "background-pattern", mbgl::underlying_type(Property::BackgroundPattern) }, - { "background-color-transition", mbgl::underlying_type(Property::BackgroundColorTransition) }, - { "background-opacity-transition", mbgl::underlying_type(Property::BackgroundOpacityTransition) }, - { "background-pattern-transition", mbgl::underlying_type(Property::BackgroundPatternTransition) } - }); - - const auto it = properties.find(name.c_str()); - if (it == properties.end()) { - return Error { "layer doesn't support this property" }; + const auto it = layerProperties.find(name.c_str()); + if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + return Error{"layer doesn't support this property"}; } auto property = static_cast<Property>(it->second); @@ -217,24 +224,46 @@ optional<Error> BackgroundLayer::setPaintProperty(const std::string& name, const if (!transition) { return error; } - + if (property == Property::BackgroundColorTransition) { setBackgroundColorTransition(*transition); return nullopt; } - + if (property == Property::BackgroundOpacityTransition) { setBackgroundOpacityTransition(*transition); return nullopt; } - + if (property == Property::BackgroundPatternTransition) { setBackgroundPatternTransition(*transition); return nullopt; } - - return Error { "layer doesn't support this property" }; + return Error{"layer doesn't support this property"}; +} + +StyleProperty BackgroundLayer::getProperty(const std::string& name) const { + const auto it = layerProperties.find(name.c_str()); + if (it == layerProperties.end()) { + return {}; + } + + switch (static_cast<Property>(it->second)) { + case Property::BackgroundColor: + return makeStyleProperty(getBackgroundColor()); + case Property::BackgroundOpacity: + return makeStyleProperty(getBackgroundOpacity()); + case Property::BackgroundPattern: + return makeStyleProperty(getBackgroundPattern()); + case Property::BackgroundColorTransition: + return makeStyleProperty(getBackgroundColorTransition()); + case Property::BackgroundOpacityTransition: + return makeStyleProperty(getBackgroundOpacityTransition()); + case Property::BackgroundPatternTransition: + return makeStyleProperty(getBackgroundPatternTransition()); + } + return {}; } optional<Error> BackgroundLayer::setLayoutProperty(const std::string& name, const Convertible& value) { @@ -251,5 +280,3 @@ Mutable<Layer::Impl> BackgroundLayer::mutableBaseImpl() const { } // namespace style } // namespace mbgl - -// clang-format on |