[core] generated accessor methods on light
This commit is contained in:
committed by
Ivo van Dongen
parent
20810f988a
commit
feae5e22ee
@@ -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
|
||||
|
||||
@@ -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 {};
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
class RenderLight;
|
||||
|
||||
namespace style {
|
||||
|
||||
template <class T>
|
||||
class LightProperty {
|
||||
class Light {
|
||||
public:
|
||||
using Type = T;
|
||||
using ValueType = PropertyValue<T>;
|
||||
|
||||
PropertyValue<T> value;
|
||||
TransitionOptions transition;
|
||||
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;
|
||||
};
|
||||
|
||||
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>;
|
||||
class Light : public IndexedTuple<LightProperties, LightProperties> {};
|
||||
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
|
||||
35
include/mbgl/style/light.hpp.ejs
Normal file
35
include/mbgl/style/light.hpp.ejs
Normal file
@@ -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
|
||||
@@ -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}));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -69,8 +69,6 @@ public:
|
||||
using TransitioningLight = Transitioning<style::LightProperties>;
|
||||
using EvaluatedLight = Evaluated<style::LightProperties>;
|
||||
|
||||
class Painter;
|
||||
|
||||
class RenderLight {
|
||||
public:
|
||||
RenderLight(const style::Light);
|
||||
|
||||
115
src/mbgl/style/light.cpp
Normal file
115
src/mbgl/style/light.cpp
Normal file
@@ -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
|
||||
42
src/mbgl/style/light.cpp.ejs
Normal file
42
src/mbgl/style/light.cpp.ejs
Normal file
@@ -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
|
||||
51
src/mbgl/style/light_properties.hpp
Normal file
51
src/mbgl/style/light_properties.hpp
Normal file
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user