From a43940afb2208c61b487bfd8729bbde1bd674794 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 13:15:44 -0700 Subject: [core] Runtime style layer API --- include/mbgl/layer/background_layer.hpp | 39 +++++++ include/mbgl/layer/circle_layer.hpp | 54 ++++++++++ include/mbgl/layer/custom_layer.hpp | 30 ++++++ include/mbgl/layer/fill_layer.hpp | 57 +++++++++++ include/mbgl/layer/line_layer.hpp | 82 +++++++++++++++ include/mbgl/layer/raster_layer.hpp | 56 ++++++++++ include/mbgl/layer/symbol_layer.hpp | 175 ++++++++++++++++++++++++++++++++ include/mbgl/style/layer.hpp | 78 ++++++++++++++ include/mbgl/style/types.hpp | 21 ++++ 9 files changed, 592 insertions(+) create mode 100644 include/mbgl/layer/background_layer.hpp create mode 100644 include/mbgl/layer/circle_layer.hpp create mode 100644 include/mbgl/layer/custom_layer.hpp create mode 100644 include/mbgl/layer/fill_layer.hpp create mode 100644 include/mbgl/layer/line_layer.hpp create mode 100644 include/mbgl/layer/raster_layer.hpp create mode 100644 include/mbgl/layer/symbol_layer.hpp create mode 100644 include/mbgl/style/layer.hpp (limited to 'include') 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 + +namespace mbgl { + +class BackgroundLayer : public Layer { +public: + BackgroundLayer(const std::string& layerID); + ~BackgroundLayer() final; + + // Paint properties + + Function getBackgroundColor() const; + void setBackgroundColor(Function); + + Function getBackgroundPattern() const; + void setBackgroundPattern(Function); + + Function getBackgroundOpacity() const; + void setBackgroundOpacity(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + BackgroundLayer(const Impl&); + BackgroundLayer(const BackgroundLayer&) = delete; +}; + +template <> +inline bool Layer::is() 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 + +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 getCircleRadius() const; + void setCircleRadius(Function); + + Function getCircleColor() const; + void setCircleColor(Function); + + Function getCircleBlur() const; + void setCircleBlur(Function); + + Function getCircleOpacity() const; + void setCircleOpacity(Function); + + Function> getCircleTranslate() const; + void setCircleTranslate(Function>); + + Function getCircleTranslateAnchor() const; + void setCircleTranslateAnchor(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + CircleLayer(const Impl&); + CircleLayer(const CircleLayer&) = delete; +}; + +template <> +inline bool Layer::is() 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 + +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() 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 + +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 getFillAntialias() const; + void setFillAntialias(Function); + + Function getFillOpacity() const; + void setFillOpacity(Function); + + Function getFillColor() const; + void setFillColor(Function); + + Function getFillOutlineColor() const; + void setFillOutlineColor(Function); + + Function> getFillTranslate() const; + void setFillTranslate(Function>); + + Function getFillTranslateAnchor() const; + void setFillTranslateAnchor(Function); + + Function getFillPattern() const; + void setFillPattern(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + FillLayer(const Impl&); + FillLayer(const FillLayer&) = delete; +}; + +template <> +inline bool Layer::is() 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 + +#include + +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 getLineCap() const; + void setLineCap(Function); + + Function getLineJoin() const; + void setLineJoin(Function); + + Function getLineMiterLimit() const; + void setLineMiterLimit(Function); + + Function getLineRoundLimit() const; + void setLineRoundLimit(Function); + + // Paint properties + + Function getLineOpacity() const; + void setLineOpacity(Function); + + Function getLineColor() const; + void setLineColor(Function); + + Function> getLineTranslate() const; + void setLineTranslate(Function>); + + Function getLineTranslateAnchor() const; + void setLineTranslateAnchor(Function); + + Function getLineWidth() const; + void setLineWidth(Function); + + Function getLineGapWidth() const; + void setLineGapWidth(Function); + + Function getLineOffset() const; + void setLineOffset(Function); + + Function getLineBlur() const; + void setLineBlur(Function); + + Function> getLineDasharray() const; + void setLineDasharray(Function>); + + Function getLinePattern() const; + void setLinePattern(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + LineLayer(const Impl&); + LineLayer(const LineLayer&) = delete; +}; + +template <> +inline bool Layer::is() 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 + +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 getRasterOpacity() const; + void setRasterOpacity(Function); + + Function getRasterHueRotate() const; + void setRasterHueRotate(Function); + + Function getRasterBrightnessMin() const; + void setRasterBrightnessMin(Function); + + Function getRasterBrightnessMax() const; + void setRasterBrightnessMax(Function); + + Function getRasterSaturation() const; + void setRasterSaturation(Function); + + Function getRasterContrast() const; + void setRasterContrast(Function); + + Function getRasterFadeDuration() const; + void setRasterFadeDuration(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + RasterLayer(const Impl&); + RasterLayer(const RasterLayer&) = delete; +}; + +template <> +inline bool Layer::is() 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 + +#include + +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 getSymbolPlacement() const; + void setSymbolPlacement(Function); + + Function getSymbolSpacing() const; + void setSymbolSpacing(Function); + + Function getSymbolAvoidEdges() const; + void setSymbolAvoidEdges(Function); + + Function getIconAllowOverlap() const; + void setIconAllowOverlap(Function); + + Function getIconIgnorePlacement() const; + void setIconIgnorePlacement(Function); + + Function getIconOptional() const; + void setIconOptional(Function); + + Function getIconRotationAlignment() const; + void setIconRotationAlignment(Function); + + Function getIconSize() const; + void setIconSize(Function); + + Function getIconImage() const; + void setIconImage(Function); + + Function getIconRotate() const; + void setIconRotate(Function); + + Function getIconPadding() const; + void setIconPadding(Function); + + Function getIconKeepUpright() const; + void setIconKeepUpright(Function); + + Function> getIconOffset() const; + void setIconOffset(Function>); + + Function getTextRotationAlignment() const; + void setTextRotationAlignment(Function); + + Function getTextField() const; + void setTextField(Function); + + Function> getTextFont() const; + void setTextFont(Function>); + + Function getTextSize() const; + void setTextSize(Function); + + Function getTextMaxWidth() const; + void setTextMaxWidth(Function); + + Function getTextLineHeight() const; + void setTextLineHeight(Function); + + Function getTextLetterSpacing() const; + void setTextLetterSpacing(Function); + + Function getTextJustify() const; + void setTextJustify(Function); + + Function getTextAnchor() const; + void setTextAnchor(Function); + + Function getTextMaxAngle() const; + void setTextMaxAngle(Function); + + Function getTextRotate() const; + void setTextRotate(Function); + + Function getTextPadding() const; + void setTextPadding(Function); + + Function getTextKeepUpright() const; + void setTextKeepUpright(Function); + + Function getTextTransform() const; + void setTextTransform(Function); + + Function> getTextOffset() const; + void setTextOffset(Function>); + + Function getTextAllowOverlap() const; + void setTextAllowOverlap(Function); + + Function getTextIgnorePlacement() const; + void setTextIgnorePlacement(Function); + + Function getTextOptional() const; + void setTextOptional(Function); + + // Paint properties + + Function getIconOpacity() const; + void setIconOpacity(Function); + + Function getIconColor() const; + void setIconColor(Function); + + Function getIconHaloColor() const; + void setIconHaloColor(Function); + + Function getIconHaloWidth() const; + void setIconHaloWidth(Function); + + Function getIconHaloBlur() const; + void setIconHaloBlur(Function); + + Function> getIconTranslate() const; + void setIconTranslate(Function>); + + Function getIconTranslateAnchor() const; + void setIconTranslateAnchor(Function); + + Function getTextOpacity() const; + void setTextOpacity(Function); + + Function getTextColor() const; + void setTextColor(Function); + + Function getTextHaloColor() const; + void setTextHaloColor(Function); + + Function getTextHaloWidth() const; + void setTextHaloWidth(Function); + + Function getTextHaloBlur() const; + void setTextHaloBlur(Function); + + Function> getTextTranslate() const; + void setTextTranslate(Function>); + + Function getTextTranslateAnchor() const; + void setTextTranslateAnchor(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + SymbolLayer(const Impl&); + SymbolLayer(const SymbolLayer&) = delete; +}; + +template <> +inline bool Layer::is() 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 +#include + +#include + +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("my-circle-layer"); + */ +class Layer : public mbgl::util::noncopyable { +public: + virtual ~Layer(); + + // Check whether this layer is of the given subtype. + template + bool is() const; + + // Dynamically cast this layer to the given subtype. + template + T* as() { + return is() ? reinterpret_cast(this) : nullptr; + } + + template + const T* as() const { + return is() ? reinterpret_cast(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 copy(const std::string& id, + const std::string& ref) const; + + // Private implementation + class Impl; + const std::unique_ptr baseImpl; + +protected: + enum class Type { + Fill, + Line, + Circle, + Symbol, + Raster, + Background, + Custom, + }; + + const Type type; + Layer(Type, std::unique_ptr); +}; + +} // 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 #include #include +#include namespace mbgl { @@ -20,6 +21,26 @@ struct FontStackHash { std::size_t operator()(const FontStack&) const; }; +template +class Function { +public: + using Stop = std::pair; + using Stops = std::vector; + + 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>& getStops() const { return stops; } + +private: + float base = 1; + std::vector> stops; +}; + // ------------------------------------------------------------------------------------------------- enum class SourceType : uint8_t { -- cgit v1.2.1