summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-02-04 15:30:51 -0800
committerAnsis Brammanis <brammanis@gmail.com>2015-02-04 18:46:47 -0800
commitf07de8dd23779319909f20f9da384eaf46aa4ca3 (patch)
tree0d17118533e81bb8443b09e691c541e69733ac1d /src
parenta49737e542dc518076add81fca7d02c0a9449ae7 (diff)
downloadqtlocation-mapboxgl-f07de8dd23779319909f20f9da384eaf46aa4ca3.tar.gz
make pattern and dasharray properties use duration
from "*-transition" properties
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/piecewisefunction_properties.cpp4
-rw-r--r--src/mbgl/style/piecewisefunction_properties.hpp2
-rw-r--r--src/mbgl/style/style_parser.cpp76
-rw-r--r--src/mbgl/style/style_parser.hpp8
4 files changed, 59 insertions, 31 deletions
diff --git a/src/mbgl/style/piecewisefunction_properties.cpp b/src/mbgl/style/piecewisefunction_properties.cpp
index 86d02e7b12..72ed0b8f73 100644
--- a/src/mbgl/style/piecewisefunction_properties.cpp
+++ b/src/mbgl/style/piecewisefunction_properties.cpp
@@ -6,7 +6,7 @@
namespace mbgl {
template <typename T>
-uint32_t getBiggestStopLessThan(std::vector<std::pair<float, T>> stops, float z) {
+size_t getBiggestStopLessThan(std::vector<std::pair<float, T>> stops, float z) {
for (uint32_t i = 0; i < stops.size(); i++) {
if (stops[i].first > z) {
return i == 0 ? i : i - 1;
@@ -23,7 +23,7 @@ T PiecewiseConstantFunction<T>::evaluate(float z, const ZoomHistory &zh) const {
float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f);
float fromScale = 1.0f;
float toScale = 1.0f;
- uint32_t from, to;
+ size_t from, to;
if (z > zh.lastIntegerZoom) {
result.t = fraction + (1.0f - fraction) * t;
diff --git a/src/mbgl/style/piecewisefunction_properties.hpp b/src/mbgl/style/piecewisefunction_properties.hpp
index 769020002e..0440655ba5 100644
--- a/src/mbgl/style/piecewisefunction_properties.hpp
+++ b/src/mbgl/style/piecewisefunction_properties.hpp
@@ -10,7 +10,7 @@ namespace mbgl {
template <typename T>
struct PiecewiseConstantFunction {
inline PiecewiseConstantFunction(const std::vector<std::pair<float, T>> &values_, std::chrono::duration<float> duration_) : values(values_), duration(duration_) {}
- inline PiecewiseConstantFunction(T &value) : values({{ 0, value }}), duration(std::chrono::milliseconds(300)) {}
+ inline PiecewiseConstantFunction(T &value, std::chrono::duration<float> duration_) : values({{ 0, value }}), duration(duration_) {}
inline PiecewiseConstantFunction() : values(), duration(std::chrono::milliseconds(300)) {}
T evaluate(float z, const ZoomHistory &zoomHistory) const;
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index a334cecc05..89a266a18a 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -268,13 +268,13 @@ Faded<std::vector<float>> StyleParser::parseFunctionArgument(JSVal value) {
template <>
Faded<std::string> StyleParser::parseFunctionArgument(JSVal value) {
JSVal rvalue = replaceConstant(value);
+ Faded<std::string> parsed;
if (rvalue.IsString()) {
- Faded<std::string> parsed;
parsed.to = { value.GetString(), value.GetStringLength() };
return parsed;
} else {
Log::Warning(Event::ParseStyle, "function argument must be a string");
- return {};
+ return parsed;
}
}
@@ -308,7 +308,7 @@ std::tuple<bool, std::vector<std::pair<float, T>>> StyleParser::parseStops(JSVal
return std::tuple<bool, std::vector<std::pair<float, T>>> { false, {}};
}
}
- return { true, stops };
+ return std::tuple<bool, std::vector<std::pair<float, T>>>(true, stops);
}
template <typename T> inline float defaultBaseValue() { return 1.75; }
@@ -341,26 +341,13 @@ std::tuple<bool, Function<T>> StyleParser::parseFunction(JSVal value) {
return std::tuple<bool, Function<T>> { true, StopsFunction<T>(std::get<1>(stops), base) };
}
-template <typename T> inline std::chrono::duration<float> defaultDurationValue() { return std::chrono::milliseconds(300); }
-
template <typename T>
-std::tuple<bool, PiecewiseConstantFunction<T>> StyleParser::parsePiecewiseConstantFunction(JSVal value) {
+std::tuple<bool, PiecewiseConstantFunction<T>> StyleParser::parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration) {
if (!value.HasMember("stops")) {
Log::Warning(Event::ParseStyle, "function must specify a function type");
return std::tuple<bool, PiecewiseConstantFunction<T>> { false, {} };
}
- std::chrono::duration<float> duration = defaultDurationValue<T>();
-
- if (value.HasMember("duration")) {
- JSVal value_duration = value["duration"];
- if (value_duration.IsNumber()) {
- duration = std::chrono::milliseconds(value_duration.GetUint());
- } else {
- Log::Warning(Event::ParseStyle, "duration must be numeric");
- }
- }
-
auto stops = parseStops<T>(value["stops"]);
if (!std::get<0>(stops)) {
@@ -379,6 +366,15 @@ bool StyleParser::setProperty(JSVal value, const char *property_name, PropertyKe
return std::get<0>(res);
}
+template <typename T>
+bool StyleParser::setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass, JSVal transition) {
+ auto res = parseProperty<T>(value, property_name, transition);
+ if (std::get<0>(res)) {
+ klass.set(key, std::get<1>(res));
+ }
+ return std::get<0>(res);
+}
+
template<typename T>
void StyleParser::parseVisibility(StyleBucket &bucket, JSVal value) {
if (!value.HasMember("visibility")) {
@@ -400,6 +396,21 @@ bool StyleParser::parseOptionalProperty(const char *property_name, PropertyKey k
}
}
+template<typename T>
+bool StyleParser::parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value, const char *transition_name) {
+ if (!value.HasMember(property_name)) {
+ return false;
+ } else {
+ if (value.HasMember(transition_name)) {
+ return setProperty<T>(replaceConstant(value[property_name]), property_name, key, klass, value[transition_name]);
+ } else {
+ JSVal val(rapidjson::kObjectType);
+ return setProperty<T>(replaceConstant(value[property_name]), property_name, key, klass, val);
+ }
+ }
+}
+
+
template<> std::tuple<bool, std::string> StyleParser::parseProperty(JSVal value, const char *property_name) {
if (!value.IsString()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
@@ -554,27 +565,38 @@ template<> std::tuple<bool, Function<Color>> StyleParser::parseProperty(JSVal va
}
}
-template<> std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>> StyleParser::parseProperty(JSVal value, const char *property_name) {
+template<> std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>> StyleParser::parseProperty(JSVal value, const char *property_name, JSVal transition) {
+ std::chrono::steady_clock::duration duration = std::chrono::milliseconds(300);
+ if (transition.HasMember("duration")) {
+ duration = std::chrono::milliseconds(transition["duration"].GetUint());
+ }
+
if (value.IsObject()) {
- return parsePiecewiseConstantFunction<Faded<std::vector<float>>>(value);
+ return parsePiecewiseConstantFunction<Faded<std::vector<float>>>(value, duration);
} else if (value.IsArray()) {
Faded<std::vector<float>> parsed;
std::tuple<bool, std::vector<float>> floatarray = parseFloatArray(value);
parsed.to = std::get<1>(floatarray);
- return std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>> { std::get<0>(floatarray), parsed };
+ return std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>> { std::get<0>(floatarray), { parsed, duration } };
} else {
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers, or a number array function", property_name);
return std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>> { false, {} };
}
}
-template<> std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> StyleParser::parseProperty(JSVal value, const char *property_name) {
+template<> std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> StyleParser::parseProperty(JSVal value, const char *property_name, JSVal transition) {
+
+ std::chrono::steady_clock::duration duration = std::chrono::milliseconds(300);
+ if (transition.HasMember("duration")) {
+ duration = std::chrono::milliseconds(transition["duration"].GetUint());
+ }
+
if (value.IsObject()) {
- return parsePiecewiseConstantFunction<Faded<std::string>>(value);
+ return parsePiecewiseConstantFunction<Faded<std::string>>(value, duration);
} else if (value.IsString()) {
Faded<std::string> parsed;
parsed.to = { value.GetString(), value.GetStringLength() };
- return std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> { true, parsed };
+ return std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> { true, { parsed, duration } };
} else {
Log::Warning(Event::ParseStyle, "value of '%s' must be string or a string function", property_name);
return std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> { false, {} };
@@ -724,7 +746,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
parseOptionalProperty<Function<float>>("fill-translate", { Key::FillTranslateX, Key::FillTranslateY }, klass, value);
parseOptionalProperty<PropertyTransition>("fill-translate-transition", Key::FillTranslate, klass, value);
parseOptionalProperty<TranslateAnchorType>("fill-translate-anchor", Key::FillTranslateAnchor, klass, value);
- parseOptionalProperty<PiecewiseConstantFunction<Faded<std::string>>>("fill-image", Key::FillImage, klass, value);
+ parseOptionalProperty<PiecewiseConstantFunction<Faded<std::string>>>("fill-image", Key::FillImage, klass, value, "fill-image-transition");
parseOptionalProperty<Function<float>>("line-opacity", Key::LineOpacity, klass, value);
parseOptionalProperty<PropertyTransition>("line-opacity-transition", Key::LineOpacity, klass, value);
@@ -739,8 +761,8 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
parseOptionalProperty<PropertyTransition>("line-gap-width-transition", Key::LineGapWidth, klass, value);
parseOptionalProperty<Function<float>>("line-blur", Key::LineBlur, klass, value);
parseOptionalProperty<PropertyTransition>("line-blur-transition", Key::LineBlur, klass, value);
- parseOptionalProperty<PiecewiseConstantFunction<Faded<std::vector<float>>>>("line-dasharray", Key::LineDashArray, klass, value);
- parseOptionalProperty<PiecewiseConstantFunction<Faded<std::string>>>("line-image", Key::LineImage, klass, value);
+ parseOptionalProperty<PiecewiseConstantFunction<Faded<std::vector<float>>>>("line-dasharray", Key::LineDashArray, klass, value, "line-dasharray-transition");
+ parseOptionalProperty<PiecewiseConstantFunction<Faded<std::string>>>("line-image", Key::LineImage, klass, value, "line-image-transition");
parseOptionalProperty<Function<float>>("icon-opacity", Key::IconOpacity, klass, value);
parseOptionalProperty<PropertyTransition>("icon-opacity-transition", Key::IconOpacity, klass, value);
@@ -790,7 +812,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
parseOptionalProperty<Function<float>>("background-opacity", Key::BackgroundOpacity, klass, value);
parseOptionalProperty<Function<Color>>("background-color", Key::BackgroundColor, klass, value);
- parseOptionalProperty<PiecewiseConstantFunction<Faded<std::string>>>("background-image", Key::BackgroundImage, klass, value);
+ parseOptionalProperty<PiecewiseConstantFunction<Faded<std::string>>>("background-image", Key::BackgroundImage, klass, value, "background-image-transition");
}
void StyleParser::parseLayout(JSVal value, util::ptr<StyleBucket> &bucket) {
diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp
index fd26dc8648..d25c705792 100644
--- a/src/mbgl/style/style_parser.hpp
+++ b/src/mbgl/style/style_parser.hpp
@@ -69,17 +69,23 @@ private:
template <typename T>
bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value);
template <typename T>
+ bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value, const char *transition_name);
+ template <typename T>
bool parseOptionalProperty(const char *property_name, const std::vector<PropertyKey> &keys, ClassProperties &klass, JSVal value);
template <typename T>
bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass);
+ template <typename T>
+ bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass, JSVal transition);
template <typename T>
std::tuple<bool, T> parseProperty(JSVal value, const char *property_name);
+ template <typename T>
+ std::tuple<bool, T> parseProperty(JSVal value, const char *property_name, JSVal transition);
template <typename T>
std::tuple<bool, Function<T>> parseFunction(JSVal value);
template <typename T>
- std::tuple<bool, PiecewiseConstantFunction<T>> parsePiecewiseConstantFunction(JSVal value);
+ std::tuple<bool, PiecewiseConstantFunction<T>> parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration);
template <typename T>
T parseFunctionArgument(JSVal value);
template <typename T>