diff options
Diffstat (limited to 'include')
19 files changed, 143 insertions, 55 deletions
diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp index 8b0c3026a8..6cb26e6a82 100644 --- a/include/mbgl/annotation/annotation.hpp +++ b/include/mbgl/annotation/annotation.hpp @@ -1,9 +1,8 @@ #pragma once -#include <mbgl/style/types.hpp> - #include <mbgl/util/geometry.hpp> #include <mbgl/util/variant.hpp> +#include <mbgl/util/color.hpp> #include <cstdint> #include <vector> diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index aadfdf9ada..b44b53ff99 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -9,7 +9,7 @@ #include <mbgl/util/feature.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/annotation/annotation.hpp> -#include <mbgl/style/property_transition.hpp> +#include <mbgl/style/transition_options.hpp> #include <cstdint> #include <string> @@ -22,10 +22,13 @@ namespace mbgl { class FileSource; class View; class SpriteImage; -class Layer; struct CameraOptions; struct AnimationOptions; +namespace style { +class Layer; +} + class Map : private util::noncopyable { public: explicit Map(View&, FileSource&, @@ -47,9 +50,9 @@ public: void update(Update update); // Styling - void addClass(const std::string&, const PropertyTransition& = {}); - void removeClass(const std::string&, const PropertyTransition& = {}); - void setClasses(const std::vector<std::string>&, const PropertyTransition& = {}); + void addClass(const std::string&, const style::TransitionOptions& = {}); + void removeClass(const std::string&, const style::TransitionOptions& = {}); + void setClasses(const std::vector<std::string>&, const style::TransitionOptions& = {}); bool hasClass(const std::string&) const; std::vector<std::string> getClasses() const; @@ -146,7 +149,7 @@ public: AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&); - void addLayer(std::unique_ptr<Layer>, const optional<std::string>& beforeLayerID = {}); + void addLayer(std::unique_ptr<style::Layer>, const optional<std::string>& beforeLayerID = {}); void removeLayer(const std::string& layerID); // Feature queries diff --git a/include/mbgl/storage/offline.hpp b/include/mbgl/storage/offline.hpp index e0c5ba6247..990c8470bb 100644 --- a/include/mbgl/storage/offline.hpp +++ b/include/mbgl/storage/offline.hpp @@ -12,7 +12,7 @@ namespace mbgl { class TileID; -class SourceInfo; +class Tileset; /* * An offline region defined by a style URL, geographic bounding box, zoom range, and @@ -30,7 +30,7 @@ public: OfflineTilePyramidRegionDefinition(const std::string&, const LatLngBounds&, double, double, float); /* Private */ - std::vector<CanonicalTileID> tileCover(SourceType, uint16_t tileSize, const SourceInfo&) const; + std::vector<CanonicalTileID> tileCover(SourceType, uint16_t tileSize, const Tileset&) const; const std::string styleURL; const LatLngBounds bounds; diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp index 62ee549663..a75de380a1 100644 --- a/include/mbgl/storage/resource.hpp +++ b/include/mbgl/storage/resource.hpp @@ -2,7 +2,7 @@ #include <mbgl/storage/response.hpp> #include <mbgl/util/optional.hpp> -#include <mbgl/style/types.hpp> +#include <mbgl/util/font_stack.hpp> #include <string> diff --git a/include/mbgl/style/filter.hpp b/include/mbgl/style/filter.hpp index 6ad6969fbf..9cf84f5e1d 100644 --- a/include/mbgl/style/filter.hpp +++ b/include/mbgl/style/filter.hpp @@ -7,6 +7,7 @@ #include <vector> namespace mbgl { +namespace style { typedef variant< class NullFilter, @@ -100,4 +101,5 @@ public: std::string key; }; +} // namespace style } // namespace mbgl diff --git a/include/mbgl/style/function.hpp b/include/mbgl/style/function.hpp new file mode 100644 index 0000000000..da2659c76a --- /dev/null +++ b/include/mbgl/style/function.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include <vector> +#include <utility> + +namespace mbgl { +namespace style { + +template <typename T> +class Function { +public: + using Stop = std::pair<float, T>; + using Stops = std::vector<Stop>; + + 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; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 4a40cc0cff..1f4a6fdf35 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -1,5 +1,4 @@ -#ifndef MBGL_LAYER -#define MBGL_LAYER +#pragma once #include <mbgl/util/noncopyable.hpp> #include <mbgl/style/types.hpp> @@ -7,6 +6,7 @@ #include <memory> namespace mbgl { +namespace style { /** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style @@ -79,6 +79,5 @@ protected: Layer(Type, std::unique_ptr<Impl>); }; +} // namespace style } // namespace mbgl - -#endif diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index bba16d3839..2eb84ee499 100644 --- a/include/mbgl/layer/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -6,7 +6,10 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/util/color.hpp> + namespace mbgl { +namespace style { class BackgroundLayer : public Layer { public: @@ -38,4 +41,5 @@ inline bool Layer::is<BackgroundLayer>() const { return type == Type::Background; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 81f84d36a8..10d281b6ac 100644 --- a/include/mbgl/layer/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -6,7 +6,10 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/util/color.hpp> + namespace mbgl { +namespace style { class CircleLayer : public Layer { public: @@ -56,4 +59,5 @@ inline bool Layer::is<CircleLayer>() const { return type == Type::Circle; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 9782d9593f..d3867e2c4f 100644 --- a/include/mbgl/layer/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -3,6 +3,7 @@ #include <mbgl/style/layer.hpp> namespace mbgl { +namespace style { /** * Initialize any GL state needed by the custom layer. This method is called once, from the @@ -66,4 +67,5 @@ inline bool Layer::is<CustomLayer>() const { return type == Type::Custom; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 10cf4f3bbd..a14bf4a390 100644 --- a/include/mbgl/layer/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -6,7 +6,10 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/util/color.hpp> + namespace mbgl { +namespace style { class FillLayer : public Layer { public: @@ -59,4 +62,5 @@ inline bool Layer::is<FillLayer>() const { return type == Type::Fill; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index aeec363281..fb9e37811a 100644 --- a/include/mbgl/layer/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -6,9 +6,12 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/util/color.hpp> + #include <vector> namespace mbgl { +namespace style { class LineLayer : public Layer { public: @@ -84,4 +87,5 @@ inline bool Layer::is<LineLayer>() const { return type == Type::Line; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index 7dc2532a2f..6d0c7dd91c 100644 --- a/include/mbgl/layer/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -6,7 +6,10 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/util/color.hpp> + namespace mbgl { +namespace style { class RasterLayer : public Layer { public: @@ -55,4 +58,5 @@ inline bool Layer::is<RasterLayer>() const { return type == Type::Raster; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 006506b3d8..3806310c95 100644 --- a/include/mbgl/layer/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -6,9 +6,12 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/util/color.hpp> + #include <vector> namespace mbgl { +namespace style { class SymbolLayer : public Layer { public: @@ -177,4 +180,5 @@ inline bool Layer::is<SymbolLayer>() const { return type == Type::Symbol; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp new file mode 100644 index 0000000000..d8f83a0fb3 --- /dev/null +++ b/include/mbgl/style/property_value.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include <mbgl/util/variant.hpp> +#include <mbgl/style/function.hpp> + +namespace mbgl { +namespace style { + +class Undefined {}; + +template <class T> +class PropertyValue { +private: + using Value = variant<Undefined, T, Function<T>>; + Value value; + +public: + PropertyValue() : value() {} + PropertyValue( T constant) : value(constant) {} + PropertyValue(Function<T> function) : value(function) {} + + bool isUndefined() const { return value.which() == 0; } + bool isConstant() const { return value.which() == 1; } + bool isFunction() const { return value.which() == 2; } + + const T & asConstant() const { return value.template get< T >(); } + const Function<T>& asFunction() const { return value.template get<Function<T>>(); } + + explicit operator bool() const { return !isUndefined(); }; + + template <typename Visitor> + static auto visit(const PropertyValue<T>& value, Visitor&& visitor) { + return Value::visit(value.value, visitor); + } +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/property_transition.hpp b/include/mbgl/style/transition_options.hpp index b9a301feea..87faff21f8 100644 --- a/include/mbgl/style/property_transition.hpp +++ b/include/mbgl/style/transition_options.hpp @@ -4,14 +4,16 @@ #include <mbgl/util/optional.hpp> namespace mbgl { +namespace style { -class PropertyTransition { +class TransitionOptions { public: - PropertyTransition(const optional<Duration>& duration_ = {}, const optional<Duration>& delay_ = {}) + TransitionOptions(const optional<Duration>& duration_ = {}, const optional<Duration>& delay_ = {}) : duration(duration_), delay(delay_) {} optional<Duration> duration; optional<Duration> delay; }; +} // namespace style } // namespace mbgl diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 56f3570357..27b524a800 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -2,44 +2,9 @@ #include <mbgl/util/enum.hpp> -#include <string> -#include <array> -#include <vector> -#include <utility> - namespace mbgl { -// Stores a premultiplied color, with all four channels ranging from 0..1 -using Color = std::array<float, 4>; - -// An array of font names -using FontStack = std::vector<std::string>; - -std::string fontStackToString(const FontStack&); - -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>; - - 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; -}; - -// ------------------------------------------------------------------------------------------------- - +// TODO: should be in public source.hpp header and style namespace enum class SourceType : uint8_t { Vector, Raster, @@ -56,7 +21,7 @@ MBGL_DEFINE_ENUM_CLASS(SourceTypeClass, SourceType, { { SourceType::Annotations, "annotations" }, }); -// ------------------------------------------------------------------------------------------------- +namespace style { enum class VisibilityType : bool { Visible, @@ -122,5 +87,5 @@ enum class TextTransformType : uint8_t { Lowercase, }; +} // namespace style } // namespace mbgl - diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp new file mode 100644 index 0000000000..d7fe61c640 --- /dev/null +++ b/include/mbgl/util/color.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include <array> + +namespace mbgl { + +// Stores a premultiplied color, with all four channels ranging from 0..1 +using Color = std::array<float, 4>; + +} // namespace mbgl diff --git a/include/mbgl/util/font_stack.hpp b/include/mbgl/util/font_stack.hpp new file mode 100644 index 0000000000..d0b431e9ea --- /dev/null +++ b/include/mbgl/util/font_stack.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include <string> +#include <vector> + +namespace mbgl { + +// An array of font names +using FontStack = std::vector<std::string>; + +std::string fontStackToString(const FontStack&); + +struct FontStackHash { + std::size_t operator()(const FontStack&) const; +}; + +} // namespace mbgl |