summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-05-04 17:26:42 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-05-08 19:39:55 +0300
commitfeae5e22ee4910a1508f2120c8131b2f8531bae8 (patch)
treeb5ca0ba87b42bcc732070485b5ccea2c3f832840
parent20810f988a735e0d43f9abff9260ea0784cd218c (diff)
downloadqtlocation-mapboxgl-feae5e22ee4910a1508f2120c8131b2f8531bae8.tar.gz
[core] generated accessor methods on light
-rw-r--r--cmake/core-files.cmake5
-rw-r--r--include/mbgl/style/conversion/light.hpp16
-rw-r--r--include/mbgl/style/light.hpp72
-rw-r--r--include/mbgl/style/light.hpp.ejs35
-rw-r--r--scripts/generate-style-code.js23
-rw-r--r--src/mbgl/renderer/render_light.cpp2
-rw-r--r--src/mbgl/renderer/render_light.hpp2
-rw-r--r--src/mbgl/style/light.cpp115
-rw-r--r--src/mbgl/style/light.cpp.ejs42
-rw-r--r--src/mbgl/style/light_properties.hpp51
-rw-r--r--test/style/conversion/light.test.cpp38
11 files changed, 332 insertions, 69 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake
index 80e9f16156..e9d7442e5d 100644
--- a/cmake/core-files.cmake
+++ b/cmake/core-files.cmake
@@ -327,6 +327,11 @@ set(MBGL_CORE_FILES
src/mbgl/style/layer_impl.hpp
src/mbgl/style/layer_observer.hpp
src/mbgl/style/layout_property.hpp
+ src/mbgl/style/light.cpp
+ src/mbgl/style/light_impl.cpp
+ src/mbgl/style/light_impl.hpp
+ src/mbgl/style/light_observer.hpp
+ src/mbgl/style/light_properties.hpp
src/mbgl/style/observer.hpp
src/mbgl/style/paint_property.hpp
src/mbgl/style/parser.cpp
diff --git a/include/mbgl/style/conversion/light.hpp b/include/mbgl/style/conversion/light.hpp
index 631ed04ccb..30bb906037 100644
--- a/include/mbgl/style/conversion/light.hpp
+++ b/include/mbgl/style/conversion/light.hpp
@@ -28,7 +28,7 @@ public:
convert<PropertyValue<LightAnchorType>>(*anchor, error);
if (convertedAnchor) {
- light.get<LightAnchor>().value = *convertedAnchor;
+ light.setAnchor(*convertedAnchor);
} else {
return {};
}
@@ -39,7 +39,7 @@ public:
optional<TransitionOptions> transition =
convert<TransitionOptions>(*anchorTransition, error);
if (transition) {
- light.get<LightAnchor>().transition = *transition;
+ light.setAnchorTransition(*transition);
} else {
return {};
}
@@ -51,7 +51,7 @@ public:
convert<PropertyValue<Color>>(*color, error);
if (convertedColor) {
- light.get<LightColor>().value = *convertedColor;
+ light.setColor(*convertedColor);
} else {
return {};
}
@@ -62,7 +62,7 @@ public:
optional<TransitionOptions> transition =
convert<TransitionOptions>(*colorTransition, error);
if (transition) {
- light.get<LightColor>().transition = *transition;
+ light.setColorTransition(*transition);
} else {
return {};
}
@@ -74,7 +74,7 @@ public:
convert<PropertyValue<Position>>(*position, error);
if (convertedPosition) {
- light.get<LightPosition>().value = *convertedPosition;
+ light.setPosition(*convertedPosition);
} else {
return {};
}
@@ -85,7 +85,7 @@ public:
optional<TransitionOptions> transition =
convert<TransitionOptions>(*positionTransition, error);
if (transition) {
- light.get<LightPosition>().transition = *transition;
+ light.setPositionTransition(*transition);
} else {
return {};
}
@@ -97,7 +97,7 @@ public:
convert<PropertyValue<float>>(*intensity, error);
if (convertedIntensity) {
- light.get<LightIntensity>().value = *convertedIntensity;
+ light.setIntensity(*convertedIntensity);
} else {
return {};
}
@@ -108,7 +108,7 @@ public:
optional<TransitionOptions> transition =
convert<TransitionOptions>(*intensityTransition, error);
if (transition) {
- light.get<LightIntensity>().transition = *transition;
+ light.setIntensityTransition(*transition);
} else {
return {};
}
diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp
index bec8e6ddeb..7942d0d237 100644
--- a/include/mbgl/style/light.hpp
+++ b/include/mbgl/style/light.hpp
@@ -1,52 +1,48 @@
-#pragma once
+// This file is generated. Do not edit.
+#pragma once
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
-#include <mbgl/style/position.hpp>
-#include <mbgl/util/color.hpp>
-#include <mbgl/util/indexed_tuple.hpp>
namespace mbgl {
-namespace style {
-template <class T>
-class LightProperty {
-public:
- using Type = T;
- using ValueType = PropertyValue<T>;
+class RenderLight;
- PropertyValue<T> value;
- TransitionOptions transition;
-};
-
-struct LightAnchor : LightProperty<LightAnchorType> {
- static LightAnchorType defaultValue() {
- return LightAnchorType::Viewport;
- }
-};
-
-struct LightPosition : LightProperty<Position> {
- static Position defaultValue() {
- std::array<float, 3> default_ = { { 1.15, 210, 30 } };
- return Position{ { default_ } };
- }
-};
+namespace style {
-struct LightColor : LightProperty<Color> {
- static Color defaultValue() {
- return Color::white();
- }
-};
+class Light {
+public:
-struct LightIntensity : LightProperty<float> {
- static float defaultValue() {
- return 0.5;
- }
+ static LightAnchorType getDefaultAnchor();
+ PropertyValue<LightAnchorType> getAnchor() const;
+ void setAnchor(PropertyValue<LightAnchorType>);
+ void setAnchorTransition(const TransitionOptions&);
+ TransitionOptions getAnchorTransition() const;
+
+ static Position getDefaultPosition();
+ PropertyValue<Position> getPosition() const;
+ void setPosition(PropertyValue<Position>);
+ void setPositionTransition(const TransitionOptions&);
+ TransitionOptions getPositionTransition() const;
+
+ static Color getDefaultColor();
+ PropertyValue<Color> getColor() const;
+ void setColor(PropertyValue<Color>);
+ void setColorTransition(const TransitionOptions&);
+ TransitionOptions getColorTransition() const;
+
+ static float getDefaultIntensity();
+ PropertyValue<float> getIntensity() const;
+ void setIntensity(PropertyValue<float>);
+ void setIntensityTransition(const TransitionOptions&);
+ TransitionOptions getIntensityTransition() const;
+
+private:
+ IndexedTuple<LightProperties, LightProperties> properties;
+
+ friend class mbgl::RenderLight;
};
-using LightProperties = TypeList<LightAnchor, LightPosition, LightColor, LightIntensity>;
-class Light : public IndexedTuple<LightProperties, LightProperties> {};
-
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/light.hpp.ejs b/include/mbgl/style/light.hpp.ejs
new file mode 100644
index 0000000000..40f85b66b5
--- /dev/null
+++ b/include/mbgl/style/light.hpp.ejs
@@ -0,0 +1,35 @@
+<%
+ const properties = locals.properties;
+-%>
+// This file is generated. Do not edit.
+
+#pragma once
+#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/transition_options.hpp>
+#include <mbgl/style/types.hpp>
+
+namespace mbgl {
+
+class RenderLight;
+
+namespace style {
+
+class Light {
+public:
+
+<% for (const property of properties) { -%>
+ static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>();
+ <%- propertyValueType(property) %> get<%- camelize(property.name) %>() const;
+ void set<%- camelize(property.name) %>(<%- propertyValueType(property) %>);
+ void set<%- camelize(property.name) %>Transition(const TransitionOptions&);
+ TransitionOptions get<%- camelize(property.name) %>Transition() const;
+
+<% } -%>
+private:
+ IndexedTuple<LightProperties, LightProperties> properties;
+
+ friend class mbgl::RenderLight;
+};
+
+} // namespace style
+} // namespace mbgl
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index 9629c8fe45..c169c4ecd5 100644
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -18,6 +18,10 @@ global.isDataDriven = function (property) {
return property['property-function'] === true;
};
+global.isLightProperty = function (property) {
+ return property['light-property'] === true;
+};
+
global.evaluatedType = function (property) {
if (/-translate-anchor$/.test(property.name)) {
return 'TranslateAnchorType';
@@ -25,6 +29,9 @@ global.evaluatedType = function (property) {
if (/-(rotation|pitch|illumination)-alignment$/.test(property.name)) {
return 'AlignmentType';
}
+ if (/position/.test(property.name)) {
+ return 'Position';
+ }
switch (property.type) {
case 'boolean':
return 'bool';
@@ -33,7 +40,7 @@ global.evaluatedType = function (property) {
case 'string':
return 'std::string';
case 'enum':
- return `${camelize(property.name)}Type`;
+ return (isLightProperty(property) ? 'Light' : '') + `${camelize(property.name)}Type`;
case 'color':
return `Color`;
case 'array':
@@ -177,3 +184,17 @@ for (const layer of layers) {
const propertySettersHpp = ejs.compile(fs.readFileSync('include/mbgl/style/conversion/make_property_setters.hpp.ejs', 'utf8'), {strict: true});
writeIfModified('include/mbgl/style/conversion/make_property_setters.hpp', propertySettersHpp({layers: layers}));
+
+// Light
+const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => {
+ var property = spec[`light`][name];
+ property.name = name;
+ property['light-property'] = true;
+ memo.push(property);
+ return memo;
+}, []);
+
+const lightHpp = ejs.compile(fs.readFileSync('include/mbgl/style/light.hpp.ejs', 'utf8'), {strict: true});
+const lightCpp = ejs.compile(fs.readFileSync('src/mbgl/style/light.cpp.ejs', 'utf8'), {strict: true});
+writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties}));
+writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}));
diff --git a/src/mbgl/renderer/render_light.cpp b/src/mbgl/renderer/render_light.cpp
index 6f154de2e2..faf89bf9e2 100644
--- a/src/mbgl/renderer/render_light.cpp
+++ b/src/mbgl/renderer/render_light.cpp
@@ -7,7 +7,7 @@ RenderLight::RenderLight(const style::Light light_)
}
void RenderLight::transition(const CascadeParameters& parameters) {
- transitioning = TransitioningLight(light, std::move(transitioning), parameters);
+ transitioning = TransitioningLight(light.properties, std::move(transitioning), parameters);
}
void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) {
diff --git a/src/mbgl/renderer/render_light.hpp b/src/mbgl/renderer/render_light.hpp
index e609550445..1a813ab1f8 100644
--- a/src/mbgl/renderer/render_light.hpp
+++ b/src/mbgl/renderer/render_light.hpp
@@ -69,8 +69,6 @@ public:
using TransitioningLight = Transitioning<style::LightProperties>;
using EvaluatedLight = Evaluated<style::LightProperties>;
-class Painter;
-
class RenderLight {
public:
RenderLight(const style::Light);
diff --git a/src/mbgl/style/light.cpp b/src/mbgl/style/light.cpp
new file mode 100644
index 0000000000..0a9cbbee9a
--- /dev/null
+++ b/src/mbgl/style/light.cpp
@@ -0,0 +1,115 @@
+// This file is generated. Do not edit.
+
+#include <mbgl/style/light.hpp>
+#include <mbgl/style/light_impl.hpp>
+#include <mbgl/style/light_properties.hpp>
+
+namespace mbgl {
+namespace style {
+
+LightAnchorType Light::getDefaultAnchor() {
+ return LightAnchor::defaultValue();
+}
+
+PropertyValue<LightAnchorType> Light::getAnchor() const {
+ return properties.get<LightAnchor>().value;
+}
+
+void Light::setAnchor(PropertyValue<LightAnchorType> property) {
+ properties.get<LightAnchor>().value = property;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+void Light::setAnchorTransition(const TransitionOptions& transition) {
+ properties.get<LightAnchor>().transition = transition;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+TransitionOptions Light::getAnchorTransition() const {
+ return properties.get<LightAnchor>().transition;
+}
+
+Position Light::getDefaultPosition() {
+ return LightPosition::defaultValue();
+}
+
+PropertyValue<Position> Light::getPosition() const {
+ return properties.get<LightPosition>().value;
+}
+
+void Light::setPosition(PropertyValue<Position> property) {
+ properties.get<LightPosition>().value = property;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+void Light::setPositionTransition(const TransitionOptions& transition) {
+ properties.get<LightPosition>().transition = transition;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+TransitionOptions Light::getPositionTransition() const {
+ return properties.get<LightPosition>().transition;
+}
+
+Color Light::getDefaultColor() {
+ return LightColor::defaultValue();
+}
+
+PropertyValue<Color> Light::getColor() const {
+ return properties.get<LightColor>().value;
+}
+
+void Light::setColor(PropertyValue<Color> property) {
+ properties.get<LightColor>().value = property;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+void Light::setColorTransition(const TransitionOptions& transition) {
+ properties.get<LightColor>().transition = transition;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+TransitionOptions Light::getColorTransition() const {
+ return properties.get<LightColor>().transition;
+}
+
+float Light::getDefaultIntensity() {
+ return LightIntensity::defaultValue();
+}
+
+PropertyValue<float> Light::getIntensity() const {
+ return properties.get<LightIntensity>().value;
+}
+
+void Light::setIntensity(PropertyValue<float> property) {
+ properties.get<LightIntensity>().value = property;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+void Light::setIntensityTransition(const TransitionOptions& transition) {
+ properties.get<LightIntensity>().transition = transition;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+TransitionOptions Light::getIntensityTransition() const {
+ return properties.get<LightIntensity>().transition;
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/light.cpp.ejs b/src/mbgl/style/light.cpp.ejs
new file mode 100644
index 0000000000..7d2e0ecc1e
--- /dev/null
+++ b/src/mbgl/style/light.cpp.ejs
@@ -0,0 +1,42 @@
+<%
+ const properties = locals.properties;
+-%>
+// This file is generated. Do not edit.
+
+#include <mbgl/style/light.hpp>
+#include <mbgl/style/light_impl.hpp>
+#include <mbgl/style/light_properties.hpp>
+
+namespace mbgl {
+namespace style {
+
+<% for (const property of properties) { -%>
+<%- evaluatedType(property) %> Light::getDefault<%- camelize(property.name) %>() {
+ return Light<%- camelize(property.name) %>::defaultValue();
+}
+
+<%- propertyValueType(property) %> Light::get<%- camelize(property.name) %>() const {
+ return properties.get<Light<%- camelize(property.name) %>>().value;
+}
+
+void Light::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> property) {
+ properties.get<Light<%- camelize(property.name) %>>().value = property;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+void Light::set<%- camelize(property.name) %>Transition(const TransitionOptions& transition) {
+ properties.get<Light<%- camelize(property.name) %>>().transition = transition;
+ if (observer) {
+ observer->onLightChanged(*this);
+ }
+}
+
+TransitionOptions Light::get<%- camelize(property.name) %>Transition() const {
+ return properties.get<Light<%- camelize(property.name) %>>().transition;
+}
+
+<% } -%>
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/light_properties.hpp b/src/mbgl/style/light_properties.hpp
new file mode 100644
index 0000000000..9f6088a633
--- /dev/null
+++ b/src/mbgl/style/light_properties.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/transition_options.hpp>
+#include <mbgl/style/types.hpp>
+#include <mbgl/style/position.hpp>
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/indexed_tuple.hpp>
+
+namespace mbgl {
+namespace style {
+
+template <class T>
+class LightProperty {
+public:
+ using Type = T;
+ using ValueType = PropertyValue<T>;
+
+ PropertyValue<T> value;
+ TransitionOptions transition;
+};
+
+struct LightAnchor : LightProperty<LightAnchorType> {
+ static LightAnchorType defaultValue() {
+ return LightAnchorType::Viewport;
+ }
+};
+
+struct LightPosition : LightProperty<Position> {
+ static Position defaultValue() {
+ std::array<float, 3> default_ = { { 1.15, 210, 30 } };
+ return Position{ { default_ } };
+ }
+};
+
+struct LightColor : LightProperty<Color> {
+ static Color defaultValue() {
+ return Color::white();
+ }
+};
+
+struct LightIntensity : LightProperty<float> {
+ static float defaultValue() {
+ return 0.5;
+ }
+};
+
+using LightProperties = TypeList<LightAnchor, LightPosition, LightColor, LightIntensity>;
+
+} // namespace style
+} // namespace mbgl
diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp
index da0fd3054a..a2185906d6 100644
--- a/test/style/conversion/light.test.cpp
+++ b/test/style/conversion/light.test.cpp
@@ -33,35 +33,35 @@ TEST(StyleConversion, Light) {
auto light = parseLight("{\"color\":{\"stops\":[[14,\"blue\"],[16,\"red\"]]},\"intensity\":0.3,\"position\":[3,90,90]}");
ASSERT_TRUE((bool) light);
- ASSERT_TRUE(light->get<LightAnchor>().value.isUndefined());
- ASSERT_FALSE(light->get<LightAnchor>().value.isConstant());
- ASSERT_FALSE(light->get<LightAnchor>().value.isCameraFunction());
+ ASSERT_TRUE(light->getAnchor().isUndefined());
+ ASSERT_FALSE(light->getAnchor().isConstant());
+ ASSERT_FALSE(light->getAnchor().isCameraFunction());
- ASSERT_FALSE(light->get<LightIntensity>().value.isUndefined());
- ASSERT_TRUE(light->get<LightIntensity>().value.isConstant());
- ASSERT_EQ(light->get<LightIntensity>().value.asConstant(), 0.3f);
- ASSERT_FALSE(light->get<LightAnchor>().value.isCameraFunction());
+ ASSERT_FALSE(light->getIntensity().isUndefined());
+ ASSERT_TRUE(light->getIntensity().isConstant());
+ ASSERT_EQ(light->getIntensity().asConstant(), 0.3f);
+ ASSERT_FALSE(light->getAnchor().isCameraFunction());
- ASSERT_FALSE(light->get<LightColor>().value.isUndefined());
- ASSERT_FALSE(light->get<LightColor>().value.isConstant());
- ASSERT_TRUE(light->get<LightColor>().value.isCameraFunction());
+ ASSERT_FALSE(light->getColor().isUndefined());
+ ASSERT_FALSE(light->getColor().isConstant());
+ ASSERT_TRUE(light->getColor().isCameraFunction());
- ASSERT_FALSE(light->get<LightPosition>().value.isUndefined());
- ASSERT_TRUE(light->get<LightPosition>().value.isConstant());
+ ASSERT_FALSE(light->getPosition().isUndefined());
+ ASSERT_TRUE(light->getPosition().isConstant());
std::array<float, 3> expected{{ 3, 90, 90 }};
- ASSERT_EQ(light->get<LightPosition>().value.asConstant(), mbgl::style::Position({ expected }));
- ASSERT_FALSE(light->get<LightPosition>().value.isCameraFunction());
+ ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({ expected }));
+ ASSERT_FALSE(light->getPosition().isCameraFunction());
}
{
auto light = parseLight("{\"color\":\"blue\",\"intensity\":0.3,\"color-transition\":{\"duration\":1000}}");
ASSERT_TRUE((bool) light);
- ASSERT_FALSE(light->get<LightColor>().value.isUndefined());
- ASSERT_TRUE(light->get<LightColor>().value.isConstant());
- ASSERT_FALSE(light->get<LightColor>().value.isCameraFunction());
- ASSERT_EQ(light->get<LightColor>().transition.duration, mbgl::Duration(mbgl::Milliseconds(1000)));
- ASSERT_FALSE((bool) light->get<LightColor>().transition.delay);
+ ASSERT_FALSE(light->getColor().isUndefined());
+ ASSERT_TRUE(light->getColor().isConstant());
+ ASSERT_FALSE(light->getColor().isCameraFunction());
+ ASSERT_EQ(light->getColorTransition().duration, mbgl::Duration(mbgl::Milliseconds(1000)));
+ ASSERT_FALSE((bool) light->getColorTransition().delay);
}
{