summaryrefslogtreecommitdiff
path: root/include/llmr/style
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-06-27 16:59:42 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-06-27 16:59:42 +0200
commit0e9e2972755b05ddc3e7ab073bb4f9c10377d83c (patch)
tree1b6a79ba94b36e0f48f47f26975f6acf0b73cb19 /include/llmr/style
parentd75f0075f3356f8c0b8616ae93a9973d01cfbcfd (diff)
downloadqtlocation-mapboxgl-0e9e2972755b05ddc3e7ab073bb4f9c10377d83c.tar.gz
more refactoring and fallback values
Diffstat (limited to 'include/llmr/style')
-rw-r--r--include/llmr/style/applied_class_properties.hpp41
-rw-r--r--include/llmr/style/class_properties.hpp79
-rw-r--r--include/llmr/style/property_fallback.hpp29
-rw-r--r--include/llmr/style/property_key.hpp61
-rw-r--r--include/llmr/style/property_value.hpp21
-rw-r--r--include/llmr/style/style_parser.hpp4
6 files changed, 161 insertions, 74 deletions
diff --git a/include/llmr/style/applied_class_properties.hpp b/include/llmr/style/applied_class_properties.hpp
new file mode 100644
index 0000000000..f90102200f
--- /dev/null
+++ b/include/llmr/style/applied_class_properties.hpp
@@ -0,0 +1,41 @@
+#ifndef LLMR_STYLE_APPLIED_CLASS_PROPERTIES
+#define LLMR_STYLE_APPLIED_CLASS_PROPERTIES
+
+#include <llmr/style/property_value.hpp>
+#include <llmr/style/class_dictionary.hpp>
+#include <llmr/util/time.hpp>
+
+#include <list>
+
+namespace llmr {
+
+class AppliedClassProperty {
+public:
+ AppliedClassProperty(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value);
+
+public:
+ ClassID name;
+ timestamp begin;
+ timestamp end;
+ PropertyValue value;
+};
+
+
+class AppliedClassProperties {
+public:
+ std::list<AppliedClassProperty> properties;
+
+public:
+ // Returns thie ID of the most recent
+ ClassID mostRecent() const {
+ return properties.size() ? properties.back().name : ClassID::Fallback;
+ }
+
+ void add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value) {
+ properties.emplace_back(class_id, begin, end, value);
+ }
+};
+
+}
+
+#endif
diff --git a/include/llmr/style/class_properties.hpp b/include/llmr/style/class_properties.hpp
index f355ede22f..79b16e51a7 100644
--- a/include/llmr/style/class_properties.hpp
+++ b/include/llmr/style/class_properties.hpp
@@ -1,78 +1,13 @@
#ifndef LLMR_STYLE_CLASS_PROPERTIES
#define LLMR_STYLE_CLASS_PROPERTIES
-#include <llmr/util/variant.hpp>
-#include <llmr/style/function_properties.hpp>
-#include <llmr/style/types.hpp>
-
+#include <llmr/style/property_key.hpp>
+#include <llmr/style/property_value.hpp>
#include <map>
namespace llmr {
-enum class ClassPropertyKey {
- FillEnabled,
- FillAntialias,
- FillOpacity,
- FillColor,
- FillOutlineColor,
- FillTranslate, // for transitions only
- FillTranslateX,
- FillTranslateY,
- FillTranslateAnchor,
- FillImage,
-
- LineEnabled,
- LineOpacity,
- LineColor,
- LineTranslate, // for transitions only
- LineTranslateX,
- LineTranslateY,
- LineTranslateAnchor,
- LineWidth,
- LineOffset,
- LineBlur,
- LineDashArray, // for transitions only
- LineDashLand,
- LineDashGap,
- LineImage,
-
- IconEnabled,
- IconOpacity,
- IconRotate,
- IconRotateAnchor,
-
- TextEnabled,
- TextOpacity,
- TextSize,
- TextColor,
- TextHaloColor,
- TextHaloWidth,
- TextHaloBlur,
-
- CompositeEnabled,
- CompositeOpacity,
-
- RasterSpin,
- RasterBrightnessLow,
- RasterBrightnessHigh,
- RasterSaturation,
- RasterContrast,
- RasterFade,
-
- BackgroundColor
-};
-
-typedef util::variant<
- FunctionProperty,
- TranslateAnchorType,
- RotateAnchorType,
- Color,
- std::string,
- bool
-> ClassPropertyValue;
-
-
struct ClassPropertyTransition {
uint16_t duration = 0;
uint16_t delay = 0;
@@ -93,7 +28,7 @@ public:
transitions.emplace(::std::forward<Args>(args)...);
}
- inline const ClassPropertyTransition &getTransition(ClassPropertyKey key, const ClassPropertyTransition &defaultTransition) const {
+ inline const ClassPropertyTransition &getTransition(PropertyKey key, const ClassPropertyTransition &defaultTransition) const {
auto it = transitions.find(key);
if (it == transitions.end()) {
return defaultTransition;
@@ -103,16 +38,16 @@ public:
}
// Route-through iterable interface so that you can iterate on the object as is.
- inline std::map<ClassPropertyKey, ClassPropertyValue>::const_iterator begin() const {
+ inline std::map<PropertyKey, PropertyValue>::const_iterator begin() const {
return properties.begin();
}
- inline std::map<ClassPropertyKey, ClassPropertyValue>::const_iterator end() const {
+ inline std::map<PropertyKey, PropertyValue>::const_iterator end() const {
return properties.end();
}
public:
- std::map<ClassPropertyKey, ClassPropertyValue> properties;
- std::map<ClassPropertyKey, ClassPropertyTransition> transitions;
+ std::map<PropertyKey, PropertyValue> properties;
+ std::map<PropertyKey, ClassPropertyTransition> transitions;
};
}
diff --git a/include/llmr/style/property_fallback.hpp b/include/llmr/style/property_fallback.hpp
new file mode 100644
index 0000000000..eb6bb15c9c
--- /dev/null
+++ b/include/llmr/style/property_fallback.hpp
@@ -0,0 +1,29 @@
+#ifndef LLMR_STYLE_PROPERTY_FALLBACK
+#define LLMR_STYLE_PROPERTY_FALLBACK
+
+#include <llmr/style/property_key.hpp>
+#include <llmr/style/property_value.hpp>
+
+#include <map>
+
+namespace llmr {
+
+class PropertyFallbackValue {
+public:
+ static const PropertyValue &Get(PropertyKey key) {
+ auto it = properties.find(key);
+ if (it != properties.end()) {
+ return it->second;
+ } else {
+ return defaultProperty;
+ }
+ }
+
+private:
+ static const std::map<PropertyKey, PropertyValue> properties;
+ static const PropertyValue defaultProperty;
+};
+
+}
+
+#endif
diff --git a/include/llmr/style/property_key.hpp b/include/llmr/style/property_key.hpp
new file mode 100644
index 0000000000..e355872394
--- /dev/null
+++ b/include/llmr/style/property_key.hpp
@@ -0,0 +1,61 @@
+#ifndef LLMR_STYLE_PROPERTY_KEY
+#define LLMR_STYLE_PROPERTY_KEY
+
+namespace llmr {
+
+enum class PropertyKey {
+ FillEnabled,
+ FillAntialias,
+ FillOpacity,
+ FillColor,
+ FillOutlineColor,
+ FillTranslate, // for transitions only
+ FillTranslateX,
+ FillTranslateY,
+ FillTranslateAnchor,
+ FillImage,
+
+ LineEnabled,
+ LineOpacity,
+ LineColor,
+ LineTranslate, // for transitions only
+ LineTranslateX,
+ LineTranslateY,
+ LineTranslateAnchor,
+ LineWidth,
+ LineOffset,
+ LineBlur,
+ LineDashArray, // for transitions only
+ LineDashLand,
+ LineDashGap,
+ LineImage,
+
+ IconEnabled,
+ IconOpacity,
+ IconRotate,
+ IconRotateAnchor,
+
+ TextEnabled,
+ TextOpacity,
+ TextSize,
+ TextColor,
+ TextHaloColor,
+ TextHaloWidth,
+ TextHaloBlur,
+
+ CompositeEnabled,
+ CompositeOpacity,
+
+ RasterSpin,
+ RasterBrightnessLow,
+ RasterBrightnessHigh,
+ RasterSaturation,
+ RasterContrast,
+ RasterFade,
+
+ BackgroundColor
+};
+
+}
+
+#endif
diff --git a/include/llmr/style/property_value.hpp b/include/llmr/style/property_value.hpp
new file mode 100644
index 0000000000..9772258da8
--- /dev/null
+++ b/include/llmr/style/property_value.hpp
@@ -0,0 +1,21 @@
+#ifndef LLMR_STYLE_PROPERTY_VALUE
+#define LLMR_STYLE_PROPERTY_VALUE
+
+#include <llmr/util/variant.hpp>
+#include <llmr/style/function_properties.hpp>
+#include <llmr/style/types.hpp>
+
+namespace llmr {
+
+typedef util::variant<
+ FunctionProperty,
+ TranslateAnchorType,
+ RotateAnchorType,
+ Color,
+ std::string,
+ bool
+> PropertyValue;
+
+}
+
+#endif
diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp
index 8d78653694..52866f7713 100644
--- a/include/llmr/style/style_parser.hpp
+++ b/include/llmr/style/style_parser.hpp
@@ -52,9 +52,9 @@ private:
// Parses optional properties into style class properties.
template <typename T>
- bool parseStyleProperty(const char *property_name, ClassPropertyKey key, ClassProperties &klass, JSVal value);
+ bool parseStyleProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value);
template <typename T>
- bool parseStyleProperty(const char *property_name, const std::vector<ClassPropertyKey> &keys, ClassProperties &klass, JSVal value);
+ bool parseStyleProperty(const char *property_name, const std::vector<PropertyKey> &keys, ClassProperties &klass, JSVal value);
FilterExpression parseFilter(JSVal, FilterExpression::Operator op);