[core] Use PropertyValue<T> for Annotation line/fill
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
#include <mbgl/util/color.hpp>
|
||||
#include <mbgl/style/property_value.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@@ -28,17 +29,17 @@ using ShapeAnnotationGeometry = variant<
|
||||
class LineAnnotation {
|
||||
public:
|
||||
ShapeAnnotationGeometry geometry;
|
||||
float opacity = 1;
|
||||
float width = 1;
|
||||
Color color = Color::black();
|
||||
style::PropertyValue<float> opacity { 1.0f };
|
||||
style::PropertyValue<float> width { 1.0f };
|
||||
style::PropertyValue<Color> color { Color::black() };
|
||||
};
|
||||
|
||||
class FillAnnotation {
|
||||
public:
|
||||
ShapeAnnotationGeometry geometry;
|
||||
float opacity = 1;
|
||||
Color color = Color::black();
|
||||
Color outlineColor = { 0, 0, 0, -1 };
|
||||
style::PropertyValue<float> opacity { 1.0f };
|
||||
style::PropertyValue<Color> color { Color::black() };
|
||||
style::PropertyValue<Color> outlineColor {};
|
||||
};
|
||||
|
||||
// An annotation whose type and properties are sourced from a style layer.
|
||||
|
||||
@@ -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<GLfloat>(frame.framebufferSize);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
PaintProperty<bool> fillAntialias { true };
|
||||
PaintProperty<float> fillOpacity { 1 };
|
||||
PaintProperty<Color> fillColor { { 0, 0, 0, 1 } };
|
||||
PaintProperty<Color> fillOutlineColor { { 0, 0, 0, -1 } };
|
||||
PaintProperty<Color> fillOutlineColor { {} };
|
||||
PaintProperty<std::array<float, 2>> fillTranslate { {{ 0, 0 }} };
|
||||
PaintProperty<TranslateAnchorType> fillTranslateAnchor { TranslateAnchorType::Map };
|
||||
PaintProperty<std::string, CrossFadedPropertyEvaluator> fillPattern { "" };
|
||||
|
||||
@@ -39,8 +39,12 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool isUndefined() const {
|
||||
return values.find(ClassID::Default) == values.end();
|
||||
}
|
||||
|
||||
const PropertyValue<T>& get() const {
|
||||
return values.at(ClassID::Default);
|
||||
return isUndefined() ? values.at(ClassID::Fallback) : values.at(ClassID::Default);
|
||||
}
|
||||
|
||||
void set(const PropertyValue<T>& value_, const optional<std::string>& klass) {
|
||||
|
||||
@@ -53,8 +53,8 @@ TEST(Annotations, LineAnnotation) {
|
||||
|
||||
LineString<double> 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<double> 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<double> 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<double> 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);
|
||||
|
||||
Reference in New Issue
Block a user