diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-25 13:15:44 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-02 14:51:39 -0700 |
commit | a43940afb2208c61b487bfd8729bbde1bd674794 (patch) | |
tree | 53d192ea899be1d88f99aeef3d1b3255f9cb5104 /include | |
parent | 27baa34d44f0006c05ba7c417bf11e184b0bd22b (diff) | |
download | qtlocation-mapboxgl-a43940afb2208c61b487bfd8729bbde1bd674794.tar.gz |
[core] Runtime style layer API
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/layer/background_layer.hpp | 39 | ||||
-rw-r--r-- | include/mbgl/layer/circle_layer.hpp | 54 | ||||
-rw-r--r-- | include/mbgl/layer/custom_layer.hpp | 30 | ||||
-rw-r--r-- | include/mbgl/layer/fill_layer.hpp | 57 | ||||
-rw-r--r-- | include/mbgl/layer/line_layer.hpp | 82 | ||||
-rw-r--r-- | include/mbgl/layer/raster_layer.hpp | 56 | ||||
-rw-r--r-- | include/mbgl/layer/symbol_layer.hpp | 175 | ||||
-rw-r--r-- | include/mbgl/style/layer.hpp | 78 | ||||
-rw-r--r-- | include/mbgl/style/types.hpp | 21 |
9 files changed, 592 insertions, 0 deletions
diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/layer/background_layer.hpp new file mode 100644 index 0000000000..79f24990e6 --- /dev/null +++ b/include/mbgl/layer/background_layer.hpp @@ -0,0 +1,39 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> + +namespace mbgl { + +class BackgroundLayer : public Layer { +public: + BackgroundLayer(const std::string& layerID); + ~BackgroundLayer() final; + + // Paint properties + + Function<Color> getBackgroundColor() const; + void setBackgroundColor(Function<Color>); + + Function<std::string> getBackgroundPattern() const; + void setBackgroundPattern(Function<std::string>); + + Function<float> getBackgroundOpacity() const; + void setBackgroundOpacity(Function<float>); + + // Private implementation + + class Impl; + Impl* const impl; + + BackgroundLayer(const Impl&); + BackgroundLayer(const BackgroundLayer&) = delete; +}; + +template <> +inline bool Layer::is<BackgroundLayer>() const { + return type == Type::Background; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/layer/circle_layer.hpp new file mode 100644 index 0000000000..14b9da895f --- /dev/null +++ b/include/mbgl/layer/circle_layer.hpp @@ -0,0 +1,54 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> + +namespace mbgl { + +class CircleLayer : public Layer { +public: + CircleLayer(const std::string& layerID); + ~CircleLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Paint properties + + Function<float> getCircleRadius() const; + void setCircleRadius(Function<float>); + + Function<Color> getCircleColor() const; + void setCircleColor(Function<Color>); + + Function<float> getCircleBlur() const; + void setCircleBlur(Function<float>); + + Function<float> getCircleOpacity() const; + void setCircleOpacity(Function<float>); + + Function<std::array<float, 2>> getCircleTranslate() const; + void setCircleTranslate(Function<std::array<float, 2>>); + + Function<TranslateAnchorType> getCircleTranslateAnchor() const; + void setCircleTranslateAnchor(Function<TranslateAnchorType>); + + // Private implementation + + class Impl; + Impl* const impl; + + CircleLayer(const Impl&); + CircleLayer(const CircleLayer&) = delete; +}; + +template <> +inline bool Layer::is<CircleLayer>() const { + return type == Type::Circle; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/custom_layer.hpp b/include/mbgl/layer/custom_layer.hpp new file mode 100644 index 0000000000..81e91ddf50 --- /dev/null +++ b/include/mbgl/layer/custom_layer.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <mbgl/style/layer.hpp> + +namespace mbgl { + +class CustomLayer : public Layer { +public: + CustomLayer(const std::string& id, + CustomLayerInitializeFunction, + CustomLayerRenderFunction, + CustomLayerDeinitializeFunction, + void* context); + ~CustomLayer() final; + + // Private implementation + + class Impl; + Impl* impl; + + CustomLayer(const Impl&); + CustomLayer(const CustomLayer&) = delete; +}; + +template <> +inline bool Layer::is<CustomLayer>() const { + return type == Type::Custom; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/layer/fill_layer.hpp new file mode 100644 index 0000000000..dc0752f9e2 --- /dev/null +++ b/include/mbgl/layer/fill_layer.hpp @@ -0,0 +1,57 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> + +namespace mbgl { + +class FillLayer : public Layer { +public: + FillLayer(const std::string& layerID); + ~FillLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Paint properties + + Function<bool> getFillAntialias() const; + void setFillAntialias(Function<bool>); + + Function<float> getFillOpacity() const; + void setFillOpacity(Function<float>); + + Function<Color> getFillColor() const; + void setFillColor(Function<Color>); + + Function<Color> getFillOutlineColor() const; + void setFillOutlineColor(Function<Color>); + + Function<std::array<float, 2>> getFillTranslate() const; + void setFillTranslate(Function<std::array<float, 2>>); + + Function<TranslateAnchorType> getFillTranslateAnchor() const; + void setFillTranslateAnchor(Function<TranslateAnchorType>); + + Function<std::string> getFillPattern() const; + void setFillPattern(Function<std::string>); + + // Private implementation + + class Impl; + Impl* const impl; + + FillLayer(const Impl&); + FillLayer(const FillLayer&) = delete; +}; + +template <> +inline bool Layer::is<FillLayer>() const { + return type == Type::Fill; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/layer/line_layer.hpp new file mode 100644 index 0000000000..0f898d3c69 --- /dev/null +++ b/include/mbgl/layer/line_layer.hpp @@ -0,0 +1,82 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> + +#include <vector> + +namespace mbgl { + +class LineLayer : public Layer { +public: + LineLayer(const std::string& layerID); + ~LineLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Layout properties + + Function<LineCapType> getLineCap() const; + void setLineCap(Function<LineCapType>); + + Function<LineJoinType> getLineJoin() const; + void setLineJoin(Function<LineJoinType>); + + Function<float> getLineMiterLimit() const; + void setLineMiterLimit(Function<float>); + + Function<float> getLineRoundLimit() const; + void setLineRoundLimit(Function<float>); + + // Paint properties + + Function<float> getLineOpacity() const; + void setLineOpacity(Function<float>); + + Function<Color> getLineColor() const; + void setLineColor(Function<Color>); + + Function<std::array<float, 2>> getLineTranslate() const; + void setLineTranslate(Function<std::array<float, 2>>); + + Function<TranslateAnchorType> getLineTranslateAnchor() const; + void setLineTranslateAnchor(Function<TranslateAnchorType>); + + Function<float> getLineWidth() const; + void setLineWidth(Function<float>); + + Function<float> getLineGapWidth() const; + void setLineGapWidth(Function<float>); + + Function<float> getLineOffset() const; + void setLineOffset(Function<float>); + + Function<float> getLineBlur() const; + void setLineBlur(Function<float>); + + Function<std::vector<float>> getLineDasharray() const; + void setLineDasharray(Function<std::vector<float>>); + + Function<std::string> getLinePattern() const; + void setLinePattern(Function<std::string>); + + // Private implementation + + class Impl; + Impl* const impl; + + LineLayer(const Impl&); + LineLayer(const LineLayer&) = delete; +}; + +template <> +inline bool Layer::is<LineLayer>() const { + return type == Type::Line; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/layer/raster_layer.hpp new file mode 100644 index 0000000000..9dc27a274a --- /dev/null +++ b/include/mbgl/layer/raster_layer.hpp @@ -0,0 +1,56 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> + +namespace mbgl { + +class RasterLayer : public Layer { +public: + RasterLayer(const std::string& layerID); + ~RasterLayer() final; + + // Source + + void setSource(const std::string& sourceID); + const std::string& getSourceID() const; + + // Paint properties + + Function<float> getRasterOpacity() const; + void setRasterOpacity(Function<float>); + + Function<float> getRasterHueRotate() const; + void setRasterHueRotate(Function<float>); + + Function<float> getRasterBrightnessMin() const; + void setRasterBrightnessMin(Function<float>); + + Function<float> getRasterBrightnessMax() const; + void setRasterBrightnessMax(Function<float>); + + Function<float> getRasterSaturation() const; + void setRasterSaturation(Function<float>); + + Function<float> getRasterContrast() const; + void setRasterContrast(Function<float>); + + Function<float> getRasterFadeDuration() const; + void setRasterFadeDuration(Function<float>); + + // Private implementation + + class Impl; + Impl* const impl; + + RasterLayer(const Impl&); + RasterLayer(const RasterLayer&) = delete; +}; + +template <> +inline bool Layer::is<RasterLayer>() const { + return type == Type::Raster; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/layer/symbol_layer.hpp new file mode 100644 index 0000000000..f9b2956390 --- /dev/null +++ b/include/mbgl/layer/symbol_layer.hpp @@ -0,0 +1,175 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> + +#include <vector> + +namespace mbgl { + +class SymbolLayer : public Layer { +public: + SymbolLayer(const std::string& layerID); + ~SymbolLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Layout properties + + Function<SymbolPlacementType> getSymbolPlacement() const; + void setSymbolPlacement(Function<SymbolPlacementType>); + + Function<float> getSymbolSpacing() const; + void setSymbolSpacing(Function<float>); + + Function<bool> getSymbolAvoidEdges() const; + void setSymbolAvoidEdges(Function<bool>); + + Function<bool> getIconAllowOverlap() const; + void setIconAllowOverlap(Function<bool>); + + Function<bool> getIconIgnorePlacement() const; + void setIconIgnorePlacement(Function<bool>); + + Function<bool> getIconOptional() const; + void setIconOptional(Function<bool>); + + Function<RotationAlignmentType> getIconRotationAlignment() const; + void setIconRotationAlignment(Function<RotationAlignmentType>); + + Function<float> getIconSize() const; + void setIconSize(Function<float>); + + Function<std::string> getIconImage() const; + void setIconImage(Function<std::string>); + + Function<float> getIconRotate() const; + void setIconRotate(Function<float>); + + Function<float> getIconPadding() const; + void setIconPadding(Function<float>); + + Function<bool> getIconKeepUpright() const; + void setIconKeepUpright(Function<bool>); + + Function<std::array<float, 2>> getIconOffset() const; + void setIconOffset(Function<std::array<float, 2>>); + + Function<RotationAlignmentType> getTextRotationAlignment() const; + void setTextRotationAlignment(Function<RotationAlignmentType>); + + Function<std::string> getTextField() const; + void setTextField(Function<std::string>); + + Function<std::vector<std::string>> getTextFont() const; + void setTextFont(Function<std::vector<std::string>>); + + Function<float> getTextSize() const; + void setTextSize(Function<float>); + + Function<float> getTextMaxWidth() const; + void setTextMaxWidth(Function<float>); + + Function<float> getTextLineHeight() const; + void setTextLineHeight(Function<float>); + + Function<float> getTextLetterSpacing() const; + void setTextLetterSpacing(Function<float>); + + Function<TextJustifyType> getTextJustify() const; + void setTextJustify(Function<TextJustifyType>); + + Function<TextAnchorType> getTextAnchor() const; + void setTextAnchor(Function<TextAnchorType>); + + Function<float> getTextMaxAngle() const; + void setTextMaxAngle(Function<float>); + + Function<float> getTextRotate() const; + void setTextRotate(Function<float>); + + Function<float> getTextPadding() const; + void setTextPadding(Function<float>); + + Function<bool> getTextKeepUpright() const; + void setTextKeepUpright(Function<bool>); + + Function<TextTransformType> getTextTransform() const; + void setTextTransform(Function<TextTransformType>); + + Function<std::array<float, 2>> getTextOffset() const; + void setTextOffset(Function<std::array<float, 2>>); + + Function<bool> getTextAllowOverlap() const; + void setTextAllowOverlap(Function<bool>); + + Function<bool> getTextIgnorePlacement() const; + void setTextIgnorePlacement(Function<bool>); + + Function<bool> getTextOptional() const; + void setTextOptional(Function<bool>); + + // Paint properties + + Function<float> getIconOpacity() const; + void setIconOpacity(Function<float>); + + Function<Color> getIconColor() const; + void setIconColor(Function<Color>); + + Function<Color> getIconHaloColor() const; + void setIconHaloColor(Function<Color>); + + Function<float> getIconHaloWidth() const; + void setIconHaloWidth(Function<float>); + + Function<float> getIconHaloBlur() const; + void setIconHaloBlur(Function<float>); + + Function<std::array<float, 2>> getIconTranslate() const; + void setIconTranslate(Function<std::array<float, 2>>); + + Function<TranslateAnchorType> getIconTranslateAnchor() const; + void setIconTranslateAnchor(Function<TranslateAnchorType>); + + Function<float> getTextOpacity() const; + void setTextOpacity(Function<float>); + + Function<Color> getTextColor() const; + void setTextColor(Function<Color>); + + Function<Color> getTextHaloColor() const; + void setTextHaloColor(Function<Color>); + + Function<float> getTextHaloWidth() const; + void setTextHaloWidth(Function<float>); + + Function<float> getTextHaloBlur() const; + void setTextHaloBlur(Function<float>); + + Function<std::array<float, 2>> getTextTranslate() const; + void setTextTranslate(Function<std::array<float, 2>>); + + Function<TranslateAnchorType> getTextTranslateAnchor() const; + void setTextTranslateAnchor(Function<TranslateAnchorType>); + + // Private implementation + + class Impl; + Impl* const impl; + + SymbolLayer(const Impl&); + SymbolLayer(const SymbolLayer&) = delete; +}; + +template <> +inline bool Layer::is<SymbolLayer>() const { + return type == Type::Symbol; +} + +} // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp new file mode 100644 index 0000000000..e6c33a9784 --- /dev/null +++ b/include/mbgl/style/layer.hpp @@ -0,0 +1,78 @@ +#ifndef MBGL_LAYER +#define MBGL_LAYER + +#include <mbgl/util/noncopyable.hpp> +#include <mbgl/style/types.hpp> + +#include <memory> + +namespace mbgl { + +/** + * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style + * Specification. + * + * `Layer` is an abstract base class; concrete derived classes are provided for each layer type. `Layer` contains + * functionality that is common to all layer types: + * + * * Runtime type information: type predicates and casting + * * Accessors for properties common to all layer types: ID, visibility, etc. + * * Cloning and copying + * + * All other functionality lives in the derived classes. To instantiate a layer, create an instance of the desired + * type, passing the ID: + * + * auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer"); + */ +class Layer : public mbgl::util::noncopyable { +public: + virtual ~Layer(); + + // Check whether this layer is of the given subtype. + template <class T> + bool is() const; + + // Dynamically cast this layer to the given subtype. + template <class T> + T* as() { + return is<T>() ? reinterpret_cast<T*>(this) : nullptr; + } + + template <class T> + const T* as() const { + return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; + } + + const std::string& getID() const; + + // Visibility + VisibilityType getVisibility() const; + void setVisibility(VisibilityType); + + // Create a new layer with the specified `id` and `ref`. All other properties + // are copied from this layer. + std::unique_ptr<Layer> copy(const std::string& id, + const std::string& ref) const; + + // Private implementation + class Impl; + const std::unique_ptr<Impl> baseImpl; + +protected: + enum class Type { + Fill, + Line, + Circle, + Symbol, + Raster, + Background, + Custom, + }; + + const Type type; + Layer(Type, std::unique_ptr<Impl>); +}; + +} // namespace mbgl + +#endif diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 9b03ab8a2d..a852a09a14 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -5,6 +5,7 @@ #include <string> #include <array> #include <vector> +#include <utility> namespace mbgl { @@ -20,6 +21,26 @@ struct FontStackHash { std::size_t operator()(const FontStack&) const; }; +template <typename T> +class Function { +public: + using Stop = std::pair<float, T>; + using Stops = std::vector<Stop>; + + Function(const T& constant) + : stops({{ 0, constant }}) {} + + explicit Function(const Stops& stops_, float base_) + : base(base_), stops(stops_) {} + + float getBase() const { return base; } + const std::vector<std::pair<float, T>>& getStops() const { return stops; } + +private: + float base = 1; + std::vector<std::pair<float, T>> stops; +}; + // ------------------------------------------------------------------------------------------------- enum class SourceType : uint8_t { |