diff --git a/include/llmr/style/style_layer.hpp b/include/llmr/style/style_layer.hpp index 36dba1e30..5d8215cf0 100644 --- a/include/llmr/style/style_layer.hpp +++ b/include/llmr/style/style_layer.hpp @@ -36,7 +36,7 @@ public: // Updates the StyleProperties information in this layer by evaluating all // pending transitions and applied classes in order. - void updateProperties(float z, timestamp t); + void updateProperties(float z, timestamp now); // Sets the list of classes and creates transitions to the currently applied values. void setClasses(const std::vector &class_names, timestamp now, @@ -51,11 +51,11 @@ private: // Sets the properties of this object by evaluating all pending transitions and // aplied classes in order. - template void applyStyleProperties(float z, timestamp t); - template void applyStyleProperty(PropertyKey key, T &, float z, timestamp t); + template void applyStyleProperties(float z, timestamp now); + template void applyStyleProperty(PropertyKey key, T &, float z, timestamp now); // Removes all expired style transitions. - void cleanupAppliedStyleProperties(timestamp t); + void cleanupAppliedStyleProperties(timestamp now); public: // The name of this layer. diff --git a/src/style/style.cpp b/src/style/style.cpp index 9edec3438..2fc9ef001 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -39,13 +39,13 @@ void Style::updateSources(const std::shared_ptr &group) { } } -void Style::updateProperties(float z, timestamp t) { +void Style::updateProperties(float z, timestamp now) { uv::writelock lock(mtx); updateSources(); if (layers) { - layers->updateProperties(z, t); + layers->updateProperties(z, now); } // Apply transitions after the first time. diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 54baac4be..e47ec6c43 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -96,68 +96,6 @@ void StyleLayer::applyClassProperties(const ClassID class_id, } } -//void applyStyleProperties(StyleProperties &style, const ClassProperties &properties, float z) { -// if (style.is()) { -// FillProperties &fill = style.get(); -// applyStyleProperty(properties, PropertyKey::FillEnabled, fill.enabled, z); -// applyStyleProperty(properties, PropertyKey::FillAntialias, fill.antialias, z); -// applyStyleProperty(properties, PropertyKey::FillOpacity, fill.opacity, z); -// applyStyleProperty(properties, PropertyKey::FillColor, fill.fill_color); -// applyStyleProperty(properties, PropertyKey::FillOutlineColor, fill.stroke_color); -// applyStyleProperty(properties, PropertyKey::FillTranslateX, fill.translate[0], z); -// applyStyleProperty(properties, PropertyKey::FillTranslateY, fill.translate[1], z); -// applyStyleProperty(properties, PropertyKey::FillTranslateAnchor, fill.translateAnchor); -// applyStyleProperty(properties, PropertyKey::FillImage, fill.image); -// } else if (style.is()) { -// LineProperties &line = style.get(); -// applyStyleProperty(properties, PropertyKey::LineEnabled, line.enabled, z); -// applyStyleProperty(properties, PropertyKey::LineOpacity, line.opacity, z); -// applyStyleProperty(properties, PropertyKey::LineColor, line.color); -// applyStyleProperty(properties, PropertyKey::LineTranslateX, line.translate[0], z); -// applyStyleProperty(properties, PropertyKey::LineTranslateY, line.translate[1], z); -// applyStyleProperty(properties, PropertyKey::LineTranslateAnchor, line.translateAnchor); -// applyStyleProperty(properties, PropertyKey::LineWidth, line.width, z); -// applyStyleProperty(properties, PropertyKey::LineOffset, line.offset, z); -// applyStyleProperty(properties, PropertyKey::LineBlur, line.blur, z); -// applyStyleProperty(properties, PropertyKey::LineDashLand, line.dash_array[0], z); -// applyStyleProperty(properties, PropertyKey::LineDashGap, line.dash_array[1], z); -// applyStyleProperty(properties, PropertyKey::LineImage, line.image); -// } else if (style.is()) { -// IconProperties &icon = style.get(); -// applyStyleProperty(properties, PropertyKey::IconEnabled, icon.enabled, z); -// applyStyleProperty(properties, PropertyKey::IconOpacity, icon.opacity, z); -// applyStyleProperty(properties, PropertyKey::IconRotate, icon.rotate, z); -// applyStyleProperty(properties, PropertyKey::IconRotateAnchor, icon.rotate_anchor); -// } else if (style.is()) { -// TextProperties &text = style.get(); -// applyStyleProperty(properties, PropertyKey::TextEnabled, text.enabled, z); -// applyStyleProperty(properties, PropertyKey::TextOpacity, text.opacity, z); -// applyStyleProperty(properties, PropertyKey::TextSize, text.size, z); -// applyStyleProperty(properties, PropertyKey::TextColor, text.color); -// applyStyleProperty(properties, PropertyKey::TextHaloColor, text.halo_color); -// applyStyleProperty(properties, PropertyKey::TextHaloWidth, text.halo_width, z); -// applyStyleProperty(properties, PropertyKey::TextHaloBlur, text.halo_blur, z); -// } else if (style.is()) { -// CompositeProperties &composite = style.get(); -// applyStyleProperty(properties, PropertyKey::CompositeEnabled, composite.enabled, z); -// applyStyleProperty(properties, PropertyKey::CompositeOpacity, composite.opacity, z); -// } else if (style.is()) { -// RasterProperties &raster = style.get(); -// applyStyleProperty(properties, PropertyKey::RasterEnabled, raster.enabled, z); -// applyStyleProperty(properties, PropertyKey::RasterOpacity, raster.opacity, z); -// applyStyleProperty(properties, PropertyKey::RasterSpin, raster.spin, z); -// applyStyleProperty(properties, PropertyKey::RasterBrightnessLow, raster.brightness[0], z); -// applyStyleProperty(properties, PropertyKey::RasterBrightnessHigh, raster.brightness[1], z); -// applyStyleProperty(properties, PropertyKey::RasterSaturation, raster.saturation, z); -// applyStyleProperty(properties, PropertyKey::RasterContrast, raster.contrast, z); -// applyStyleProperty(properties, PropertyKey::RasterFade, raster.fade, z); -// } else if (style.is()) { -// BackgroundProperties &background = style.get(); -// applyStyleProperty(properties, PropertyKey::BackgroundColor, background.color); -// } -//} -// - template struct PropertyEvaluator { typedef T result_type; @@ -201,19 +139,19 @@ inline T interpolate(const T a, const T b, const float t) { } template -void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const timestamp t) { +void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const timestamp now) { auto it = appliedStyle.find(key); if (it != appliedStyle.end()) { AppliedClassProperties &applied = it->second; // Iterate through all properties that we need to apply in order. const PropertyEvaluator evaluator(z); for (AppliedClassProperty &property : applied.properties) { - if (t >= property.end) { + if (now >= property.end) { // We overwrite the current property with the new value. target = util::apply_visitor(evaluator, property.value); - } else if (t >= property.begin) { + } else if (now >= property.begin) { // We overwrite the current property partially with the new value. - float progress = float(t - property.begin) / float(property.end - property.begin); + float progress = float(now - property.begin) / float(property.end - property.begin); target = interpolate(target, util::apply_visitor(evaluator, property.value), progress); } else { // Do not apply this property because its transition hasn't begun yet. @@ -229,41 +167,93 @@ void StyleLayer::applyStyleProperties(float, timestamp) { } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp t) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { properties.set(); FillProperties &fill = properties.get(); - applyStyleProperty(PropertyKey::FillEnabled, fill.enabled, z, t); - applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, t); - applyStyleProperty(PropertyKey::FillOpacity, fill.opacity, z, t); - applyStyleProperty(PropertyKey::FillColor, fill.fill_color, z, t); - applyStyleProperty(PropertyKey::FillOutlineColor, fill.stroke_color, z, t); - applyStyleProperty(PropertyKey::FillTranslateX, fill.translate[0], z, t); - applyStyleProperty(PropertyKey::FillTranslateY, fill.translate[1], z, t); - applyStyleProperty(PropertyKey::FillTranslateAnchor, fill.translateAnchor, z, t); - applyStyleProperty(PropertyKey::FillImage, fill.image, z, t); + applyStyleProperty(PropertyKey::FillEnabled, fill.enabled, z, now); + applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, now); + applyStyleProperty(PropertyKey::FillOpacity, fill.opacity, z, now); + applyStyleProperty(PropertyKey::FillColor, fill.fill_color, z, now); + applyStyleProperty(PropertyKey::FillOutlineColor, fill.stroke_color, z, now); + applyStyleProperty(PropertyKey::FillTranslateX, fill.translate[0], z, now); + applyStyleProperty(PropertyKey::FillTranslateY, fill.translate[1], z, now); + applyStyleProperty(PropertyKey::FillTranslateAnchor, fill.translateAnchor, z, now); + applyStyleProperty(PropertyKey::FillImage, fill.image, z, now); } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp t) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { properties.set(); LineProperties &line = properties.get(); - applyStyleProperty(PropertyKey::LineEnabled, line.enabled, z, t); - applyStyleProperty(PropertyKey::LineOpacity, line.opacity, z, t); - applyStyleProperty(PropertyKey::LineColor, line.color, z, t); - applyStyleProperty(PropertyKey::LineTranslateX, line.translate[0], z, t); - applyStyleProperty(PropertyKey::LineTranslateY, line.translate[1], z, t); - applyStyleProperty(PropertyKey::LineTranslateAnchor, line.translateAnchor, z, t); - applyStyleProperty(PropertyKey::LineWidth, line.width, z, t); - applyStyleProperty(PropertyKey::LineOffset, line.offset, z, t); - applyStyleProperty(PropertyKey::LineBlur, line.blur, z, t); - applyStyleProperty(PropertyKey::LineDashLand, line.dash_array[0], z, t); - applyStyleProperty(PropertyKey::LineDashGap, line.dash_array[1], z, t); - applyStyleProperty(PropertyKey::LineImage, line.image, z, t); + applyStyleProperty(PropertyKey::LineEnabled, line.enabled, z, now); + applyStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now); + applyStyleProperty(PropertyKey::LineColor, line.color, z, now); + applyStyleProperty(PropertyKey::LineTranslateX, line.translate[0], z, now); + applyStyleProperty(PropertyKey::LineTranslateY, line.translate[1], z, now); + applyStyleProperty(PropertyKey::LineTranslateAnchor, line.translateAnchor, z, now); + applyStyleProperty(PropertyKey::LineWidth, line.width, z, now); + applyStyleProperty(PropertyKey::LineOffset, line.offset, z, now); + applyStyleProperty(PropertyKey::LineBlur, line.blur, z, now); + applyStyleProperty(PropertyKey::LineDashLand, line.dash_array[0], z, now); + applyStyleProperty(PropertyKey::LineDashGap, line.dash_array[1], z, now); + applyStyleProperty(PropertyKey::LineImage, line.image, z, now); } -void StyleLayer::updateProperties(float z, const timestamp t) { +template <> +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { + properties.set(); + IconProperties &icon = properties.get(); + applyStyleProperty(PropertyKey::IconEnabled, icon.enabled, z, now); + applyStyleProperty(PropertyKey::IconOpacity, icon.opacity, z, now); + applyStyleProperty(PropertyKey::IconRotate, icon.rotate, z, now); + applyStyleProperty(PropertyKey::IconRotateAnchor, icon.rotate_anchor, z, now); +} + +template <> +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { + properties.set(); + TextProperties &text = properties.get(); + applyStyleProperty(PropertyKey::TextEnabled, text.enabled, z, now); + applyStyleProperty(PropertyKey::TextOpacity, text.opacity, z, now); + applyStyleProperty(PropertyKey::TextSize, text.size, z, now); + applyStyleProperty(PropertyKey::TextColor, text.color, z, now); + applyStyleProperty(PropertyKey::TextHaloColor, text.halo_color, z, now); + applyStyleProperty(PropertyKey::TextHaloWidth, text.halo_width, z, now); + applyStyleProperty(PropertyKey::TextHaloBlur, text.halo_blur, z, now); +} + +template <> +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { + properties.set(); + CompositeProperties &composite = properties.get(); + applyStyleProperty(PropertyKey::CompositeEnabled, composite.enabled, z, now); + applyStyleProperty(PropertyKey::CompositeOpacity, composite.opacity, z, now); +} + +template <> +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { + properties.set(); + RasterProperties &raster = properties.get(); + applyStyleProperty(PropertyKey::RasterEnabled, raster.enabled, z, now); + applyStyleProperty(PropertyKey::RasterOpacity, raster.opacity, z, now); + applyStyleProperty(PropertyKey::RasterSpin, raster.spin, z, now); + applyStyleProperty(PropertyKey::RasterBrightnessLow, raster.brightness[0], z, now); + applyStyleProperty(PropertyKey::RasterBrightnessHigh, raster.brightness[1], z, now); + applyStyleProperty(PropertyKey::RasterSaturation, raster.saturation, z, now); + applyStyleProperty(PropertyKey::RasterContrast, raster.contrast, z, now); + applyStyleProperty(PropertyKey::RasterFade, raster.fade, z, now); +} + +template <> +void StyleLayer::applyStyleProperties(const float z, const timestamp now) { + properties.set(); + BackgroundProperties &background = properties.get(); + applyStyleProperty(PropertyKey::BackgroundColor, background.color, z, now); +} + +void StyleLayer::updateProperties(float z, const timestamp now) { if (layers) { - layers->updateProperties(z, t); + layers->updateProperties(z, now); } // Accomodate for different tile size. @@ -271,21 +261,21 @@ void StyleLayer::updateProperties(float z, const timestamp t) { z += std::log(bucket->source->tile_size / 256.0f) / M_LN2; } - cleanupAppliedStyleProperties(t); + cleanupAppliedStyleProperties(now); if (layers) { - applyStyleProperties(z, t); + applyStyleProperties(z, now); } else if (bucket) { switch (bucket->type) { - case BucketType::Fill: applyStyleProperties(z, t); break; - case BucketType::Line: applyStyleProperties(z, t); break; - case BucketType::Icon: applyStyleProperties(z, t); break; - case BucketType::Text: applyStyleProperties(z, t); break; - case BucketType::Raster: applyStyleProperties(z, t); break; + case BucketType::Fill: applyStyleProperties(z, now); break; + case BucketType::Line: applyStyleProperties(z, now); break; + case BucketType::Icon: applyStyleProperties(z, now); break; + case BucketType::Text: applyStyleProperties(z, now); break; + case BucketType::Raster: applyStyleProperties(z, now); break; default: properties.set(); break; } } else { - return applyStyleProperties(z, t); + return applyStyleProperties(z, now); } }