From c670b08ecb431b1bfd02da748de3d9fa16a757ec Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 12 Jul 2016 16:16:21 +0300 Subject: [PATCH] [core] Use PropertyValue for Annotation line/fill --- include/mbgl/annotation/annotation.hpp | 13 +++++++------ src/mbgl/renderer/painter_fill.cpp | 7 ++----- src/mbgl/style/layers/fill_layer_properties.hpp | 2 +- src/mbgl/style/paint_property.hpp | 6 +++++- test/api/annotations.cpp | 12 ++++++------ 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp index e8ac9a2fb..a72c65b8c 100644 --- a/include/mbgl/annotation/annotation.hpp +++ b/include/mbgl/annotation/annotation.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -28,17 +29,17 @@ using ShapeAnnotationGeometry = variant< class LineAnnotation { public: ShapeAnnotationGeometry geometry; - float opacity = 1; - float width = 1; - Color color = Color::black(); + style::PropertyValue opacity { 1.0f }; + style::PropertyValue width { 1.0f }; + style::PropertyValue color { Color::black() }; }; class FillAnnotation { public: ShapeAnnotationGeometry geometry; - float opacity = 1; - Color color = Color::black(); - Color outlineColor = { 0, 0, 0, -1 }; + style::PropertyValue opacity { 1.0f }; + style::PropertyValue color { Color::black() }; + style::PropertyValue outlineColor {}; }; // An annotation whose type and properties are sourced from a style layer. diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 3c0eb515a..9af2af9d1 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -24,11 +24,8 @@ void Painter::renderFill(PaintParameters& parameters, Color fillColor = properties.fillColor; float opacity = properties.fillOpacity; - Color strokeColor = properties.fillOutlineColor; - bool isOutlineColorDefined = strokeColor.a >= 0; - if (!isOutlineColorDefined) { - strokeColor = fillColor; - } + const bool isOutlineColorDefined = !properties.fillOutlineColor.isUndefined(); + Color strokeColor = isOutlineColorDefined? properties.fillOutlineColor : fillColor; auto worldSize = util::convert(frame.framebufferSize); diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp index 82981a9b6..225fec4f4 100644 --- a/src/mbgl/style/layers/fill_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_layer_properties.hpp @@ -20,7 +20,7 @@ public: PaintProperty fillAntialias { true }; PaintProperty fillOpacity { 1 }; PaintProperty fillColor { { 0, 0, 0, 1 } }; - PaintProperty fillOutlineColor { { 0, 0, 0, -1 } }; + PaintProperty fillOutlineColor { {} }; PaintProperty> fillTranslate { {{ 0, 0 }} }; PaintProperty fillTranslateAnchor { TranslateAnchorType::Map }; PaintProperty fillPattern { "" }; diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index b982fe76e..332ec051d 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -39,8 +39,12 @@ public: return *this; } + bool isUndefined() const { + return values.find(ClassID::Default) == values.end(); + } + const PropertyValue& get() const { - return values.at(ClassID::Default); + return isUndefined() ? values.at(ClassID::Fallback) : values.at(ClassID::Default); } void set(const PropertyValue& value_, const optional& klass) { diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp index 05d1f28fc..253e6995f 100644 --- a/test/api/annotations.cpp +++ b/test/api/annotations.cpp @@ -53,8 +53,8 @@ TEST(Annotations, LineAnnotation) { LineString line = {{ { 0, 0 }, { 45, 45 }, { 30, 0 } }}; LineAnnotation annotation { line }; - annotation.color = { 255, 0, 0, 1 }; - annotation.width = 5; + annotation.color = { { 255, 0, 0, 1 } }; + annotation.width = { 5 }; test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); test.map.addAnnotation(annotation); @@ -69,7 +69,7 @@ TEST(Annotations, FillAnnotation) { Polygon polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }}; FillAnnotation annotation { polygon }; - annotation.color = { 255, 0, 0, 1 }; + annotation.color = { { 255, 0, 0, 1 } }; test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); test.map.addAnnotation(annotation); @@ -110,7 +110,7 @@ TEST(Annotations, NonImmediateAdd) { Polygon polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }}; FillAnnotation annotation { polygon }; - annotation.color = { 255, 0, 0, 1 }; + annotation.color = { { 255, 0, 0, 1 } }; test.map.addAnnotation(annotation); test.checkRendering("non_immediate_add"); @@ -162,8 +162,8 @@ TEST(Annotations, RemoveShape) { LineString line = {{ { 0, 0 }, { 45, 45 } }}; LineAnnotation annotation { line }; - annotation.color = { 255, 0, 0, 1 }; - annotation.width = 5; + annotation.color = { { 255, 0, 0, 1 } }; + annotation.width = { 5 }; test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); AnnotationID shape = test.map.addAnnotation(annotation);