From fa3a41136ca6345f34b53a1f211926cc1bd8649c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 29 Jul 2014 18:27:59 +0200 Subject: merge text and icon buckets/styles (we're not yet placing together!) --- include/mbgl/style/property_key.hpp | 2 + include/mbgl/style/style_bucket.hpp | 56 +++----- include/mbgl/style/style_parser.hpp | 4 +- include/mbgl/style/style_properties.hpp | 32 +---- include/mbgl/style/types.hpp | 219 ++++++++++++++++---------------- 5 files changed, 134 insertions(+), 179 deletions(-) (limited to 'include/mbgl/style') diff --git a/include/mbgl/style/property_key.hpp b/include/mbgl/style/property_key.hpp index d5553ebf0d..68dc709597 100644 --- a/include/mbgl/style/property_key.hpp +++ b/include/mbgl/style/property_key.hpp @@ -35,6 +35,7 @@ enum class PropertyKey { IconHaloColor, IconHaloWidth, IconHaloBlur, + IconTranslate, // for transitions only IconTranslateX, IconTranslateY, IconTranslateAnchor, @@ -45,6 +46,7 @@ enum class PropertyKey { TextHaloColor, TextHaloWidth, TextHaloBlur, + TextTranslate, // for transitions only TextTranslateX, TextTranslateY, TextTranslateAnchor, diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp index 6948a96158..af76650e56 100644 --- a/include/mbgl/style/style_bucket.hpp +++ b/include/mbgl/style/style_bucket.hpp @@ -18,52 +18,27 @@ class Source; class StyleBucketFill { public: - WindingType winding = WindingType::Default; + WindingType winding = WindingType::NonZero; }; class StyleBucketLine { public: - CapType cap = CapType::Default; - JoinType join = JoinType::Default; + CapType cap = CapType::Butt; + JoinType join = JoinType::Miter; float miter_limit = 2.0f; float round_limit = 1.0f; }; -class StyleBucketIcon { +class StyleBucketSymbol { public: - uint16_t size = 16; - vec2 translate {0, 0}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Default; - std::string icon; - float spacing = 0.0f; - float padding = 2.0f; -}; - -class StyleBucketText { -public: - std::string field; - TextPathType path = TextPathType::Default; - TextTransformType transform = TextTransformType::Default; - std::string font; - float max_size = 16.0f; - float max_width = 15.0f * 24; - float line_height = 1.2f * 24; - float letter_spacing = 0.0f; - float alignment = 0.5f; - float vertical_alignment = 0.5; - vec2 translate {0, 0}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Default; - float max_angle_delta = 45.0f; - float min_distance = 250.0f; - float rotate = 0.0f; // what is this? - float padding = 2.0f; - float slant = 0.0f; - bool always_visible = false; -}; - -class StyleBucketSymbol : util::noncopyable { -public: - PlacementType placement = PlacementType::Default; + // Make movable only. + inline StyleBucketSymbol() = default; + inline StyleBucketSymbol(StyleBucketSymbol &&) = default; + inline StyleBucketSymbol& operator=(StyleBucketSymbol &&) = default; + inline StyleBucketSymbol(const StyleBucketSymbol &) = delete; + inline StyleBucketSymbol& operator=(const StyleBucketSymbol &) = delete; + + PlacementType placement = PlacementType::Point; float min_distance = 250.0f; struct { @@ -76,6 +51,7 @@ public: float padding = 2.0f; bool keep_upright = false; vec2 offset = {0, 0}; + TranslateAnchorType translate_anchor = TranslateAnchorType::Map; } icon; struct { @@ -96,6 +72,7 @@ public: bool keep_upright = true; TextTransformType transform = TextTransformType::None; vec2 offset = {0, 0}; + TranslateAnchorType translate_anchor = TranslateAnchorType::Map; bool allow_overlap = false; bool ignore_placement = false; bool optional = false; @@ -106,9 +83,8 @@ class StyleBucketRaster { public: }; -typedef util::variant StyleBucketRender; +typedef util::variant StyleBucketRender; class StyleBucket { diff --git a/include/mbgl/style/style_parser.hpp b/include/mbgl/style/style_parser.hpp index 431e3af8db..8b8dc74f21 100644 --- a/include/mbgl/style/style_parser.hpp +++ b/include/mbgl/style/style_parser.hpp @@ -62,8 +62,8 @@ private: // Parses optional properties into a render bucket. template bool parseRenderProperty(JSVal value, T &target, const char *name); - template - bool parseRenderProperty(JSVal value, T &target, const char *name, Parser &parser); + template + bool parseRenderProperty(JSVal value, T &target, const char *name); // Parses optional properties into style class properties. template diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp index 9575347be3..35ea97781b 100644 --- a/include/mbgl/style/style_properties.hpp +++ b/include/mbgl/style/style_properties.hpp @@ -19,7 +19,7 @@ struct FillProperties { Color fill_color = {{ 0, 0, 0, 1 }}; Color stroke_color = {{ 0, 0, 0, -1 }}; std::array translate = {{ 0, 0 }}; - TranslateAnchorType translateAnchor = TranslateAnchorType::Default; + TranslateAnchorType translateAnchor = TranslateAnchorType::Map; std::string image; inline bool isVisible() const { @@ -32,7 +32,7 @@ struct LineProperties { float opacity = 1.0f; Color color = {{ 0, 0, 0, 1 }}; std::array translate = {{ 0, 0 }}; - TranslateAnchorType translateAnchor = TranslateAnchorType::Default; + TranslateAnchorType translateAnchor = TranslateAnchorType::Map; float width = 1; float offset = 0; float blur = 0; @@ -44,31 +44,6 @@ struct LineProperties { } }; -struct IconProperties { - inline IconProperties() {} - float opacity = 1.0f; - float rotate = 0.0f; - RotateAnchorType rotate_anchor = RotateAnchorType::Default; - - inline bool isVisible() const { - return opacity > 0; - } -}; - -struct TextProperties { - inline TextProperties() {} - float opacity = 1.0f; - float size = 12.0f; - Color color = {{ 0, 0, 0, 1 }}; - Color halo_color = {{ 1, 1, 1, 0.75 }}; - float halo_width = 0.25f; - float halo_blur = 1.0f; - - inline bool isVisible() const { - return opacity > 0 && (color[3] > 0 || halo_color[3] > 0) && size > 0; - } -}; - struct SymbolProperties { inline SymbolProperties() {} @@ -133,8 +108,7 @@ struct BackgroundProperties { typedef util::variant< FillProperties, LineProperties, - IconProperties, - TextProperties, + SymbolProperties, CompositeProperties, RasterProperties, BackgroundProperties, diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 70090a7e36..55b7685fd3 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -11,12 +11,13 @@ namespace mbgl { // Stores a premultiplied color, with all four channels ranging from 0..1 typedef std::array Color; +// ------------------------------------------------------------------------------------------------- + enum class StyleLayerType : uint8_t { Unknown, Fill, Line, - Icon, - Text, + Symbol, Raster, Composite, Background @@ -26,170 +27,172 @@ MBGL_DEFINE_ENUM_CLASS(StyleLayerTypeClass, StyleLayerType, { { StyleLayerType::Unknown, "unknown" }, { StyleLayerType::Fill, "fill" }, { StyleLayerType::Line, "line" }, - { StyleLayerType::Icon, "icon" }, - { StyleLayerType::Text, "text" }, + { StyleLayerType::Symbol, "symbol" }, { StyleLayerType::Raster, "raster" }, { StyleLayerType::Composite, "composite" }, { StyleLayerType::Background, "background" }, { StyleLayerType(-1), "unknown" }, }); +// ------------------------------------------------------------------------------------------------- -enum class WindingType : uint8_t { +enum class SourceType : uint8_t { + Vector, + Raster, + GeoJSON, + Video +}; + +MBGL_DEFINE_ENUM_CLASS(SourceTypeClass, SourceType, { + { SourceType::Vector, "vector" }, + { SourceType::Raster, "raster" }, + { SourceType::GeoJSON, "geojson" }, + { SourceType::Video, "video" }, +}); + +// ------------------------------------------------------------------------------------------------- + +enum class WindingType : bool { EvenOdd, NonZero, - Default = NonZero }; +MBGL_DEFINE_ENUM_CLASS(WindingTypeClass, WindingType, { + { WindingType::EvenOdd, "even-odd" }, + { WindingType::NonZero, "non-zero" }, +}); + +// ------------------------------------------------------------------------------------------------- + enum class CapType : uint8_t { Round, Butt, Square, - Default = Butt }; +MBGL_DEFINE_ENUM_CLASS(CapTypeClass, CapType, { + { CapType::Round, "round" }, + { CapType::Butt, "butt" }, + { CapType::Square, "square" }, +}); + +// ------------------------------------------------------------------------------------------------- + enum class JoinType : uint8_t { Miter, Bevel, - Round, - Default = Miter + Round }; -enum class TextPathType : uint8_t { - Horizontal, - Curve, - Default = Horizontal -}; +MBGL_DEFINE_ENUM_CLASS(JoinTypeClass, JoinType, { + { JoinType::Miter, "miter" }, + { JoinType::Bevel, "bevel" }, + { JoinType::Round, "round" }, +}); -enum class PlacementType : bool { - Point, - Line, - Default = Point -}; +// ------------------------------------------------------------------------------------------------- -enum class TextTransformType : uint8_t { - None, - Uppercase, - Lowercase, - Default = None +enum class TranslateAnchorType : bool { + Map, + Viewport }; -enum class TranslateAnchorType : uint8_t { +MBGL_DEFINE_ENUM_CLASS(TranslateAnchorTypeClass, TranslateAnchorType, { + { TranslateAnchorType::Map, "map" }, + { TranslateAnchorType::Viewport, "viewport" }, +}); + +// ------------------------------------------------------------------------------------------------- + +enum class RotateAnchorType : bool { Map, Viewport, - Default = Map }; -enum class RotateAnchorType : uint8_t { - Map, - Viewport, - Default = Viewport +MBGL_DEFINE_ENUM_CLASS(RotateAnchorTypeClass, RotateAnchorType, { + { RotateAnchorType::Map, "map" }, + { RotateAnchorType::Viewport, "viewport" }, +}); + +// ------------------------------------------------------------------------------------------------- + +enum class PlacementType : bool { + Point, + Line, }; +MBGL_DEFINE_ENUM_CLASS(PlacementTypeClass, PlacementType, { + { PlacementType::Point, "point" }, + { PlacementType::Line, "line" }, +}); + +// ------------------------------------------------------------------------------------------------- + enum class RotationAlignmentType : bool { Map, Viewport, - Default = Viewport }; +MBGL_DEFINE_ENUM_CLASS(RotationAlignmentTypeClass, RotationAlignmentType, { + { RotationAlignmentType::Map, "map" }, + { RotationAlignmentType::Viewport, "viewport" }, +}); + +// ------------------------------------------------------------------------------------------------- + enum class TextJustifyType : uint8_t { Center, Left, - Right, - Default = Center + Right }; +MBGL_DEFINE_ENUM_CLASS(TextJustifyTypeClass, TextJustifyType, { + { TextJustifyType::Center, "center" }, + { TextJustifyType::Left, "left" }, + { TextJustifyType::Right, "right" }, +}); + +// ------------------------------------------------------------------------------------------------- + enum class TextHorizontalAlignType : uint8_t { Left, Center, Right, - Default = Center }; +MBGL_DEFINE_ENUM_CLASS(TextHorizontalAlignTypeClass, TextHorizontalAlignType, { + { TextHorizontalAlignType::Left, "left" }, + { TextHorizontalAlignType::Center, "center" }, + { TextHorizontalAlignType::Right, "right" }, +}); + +// ------------------------------------------------------------------------------------------------- + enum class TextVerticalAlignType : uint8_t { Top, Center, Bottom, - Default = Center -}; - -enum class SourceType : uint8_t { - Vector, - Raster, - GeoJSON, - Video, - Default = Vector }; -inline WindingType parseWindingType(const std::string &type) { - if (type == "even-odd") return WindingType::EvenOdd; - if (type == "non-zero") return WindingType::NonZero; - return WindingType::Default; -} - -inline CapType parseCapType(const std::string &cap) { - if (cap == "round") return CapType::Round; - if (cap == "butt") return CapType::Butt; - if (cap == "square") return CapType::Square; - return CapType::Default; -} - -inline JoinType parseJoinType(const std::string &join) { - if (join == "miter") return JoinType::Miter; - if (join == "bevel") return JoinType::Bevel; - if (join == "round") return JoinType::Round; - return JoinType::Default; -} - -inline TextPathType parseTextPathType(const std::string &path) { - if (path == "horizontal") return TextPathType::Horizontal; - if (path == "curve") return TextPathType::Curve; - return TextPathType::Default; -} +MBGL_DEFINE_ENUM_CLASS(TextVerticalAlignTypeClass, TextVerticalAlignType, { + { TextVerticalAlignType::Top, "top" }, + { TextVerticalAlignType::Center, "center" }, + { TextVerticalAlignType::Bottom, "bottom" }, +}); -inline PlacementType parsePlacementType(const std::string &path) { - if (path == "point") return PlacementType::Point; - if (path == "line") return PlacementType::Line; - return PlacementType::Default; -} +// ------------------------------------------------------------------------------------------------- -inline TextTransformType parseTextTransformType(const std::string& transform) { - if (transform == "uppercase") return TextTransformType::Uppercase; - if (transform == "lowercase") return TextTransformType::Lowercase; - return TextTransformType::Default; +enum class TextTransformType : uint8_t { + None, + Uppercase, + Lowercase, }; -inline TranslateAnchorType parseTranslateAnchorType(const std::string &anchor) { - if (anchor == "map") return TranslateAnchorType::Map; - if (anchor == "viewport") return TranslateAnchorType::Viewport; - return TranslateAnchorType::Default; -} - -inline RotateAnchorType parseRotateAnchorType(const std::string &anchor) { - if (anchor == "map") return RotateAnchorType::Map; - if (anchor == "viewport") return RotateAnchorType::Viewport; - return RotateAnchorType::Default; -} - -inline float parseAlignmentType(const std::string &alignment) { - if (alignment == "right") return 1.0f; - if (alignment == "left") return 0.0f; - return 0.5f; -} - -inline float parseVerticalAlignmentType(const std::string &alignment) { - if (alignment == "bottom") return 1.0f; - if (alignment == "top") return 0.0f; - return 0.5f; -} - -inline SourceType parseSourceType(const std::string &source) { - if (source == "vector") return SourceType::Vector; - if (source == "raster") return SourceType::Raster; - if (source == "geojson") return SourceType::GeoJSON; - if (source == "video") return SourceType::Video; - return SourceType::Default; -} +MBGL_DEFINE_ENUM_CLASS(TextTransformTypeClass, TextTransformType, { + { TextTransformType::None, "none" }, + { TextTransformType::Uppercase, "uppercase" }, + { TextTransformType::Lowercase, "lowercase" }, +}); } -- cgit v1.2.1