summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-10-03 17:00:28 -0700
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-11-21 16:43:20 +0200
commit594d2074a3849d141219c04cdde739f86e7256b3 (patch)
tree0c7c0c5bd549b47e3b0c248d8412fa9c79c9504c /src/mbgl/text
parent5fb0b0c1bc2dbde473742ab281706abff2b24217 (diff)
downloadqtlocation-mapboxgl-594d2074a3849d141219c04cdde739f86e7256b3.tar.gz
[core] Let placement transitions use the transition duration, if set, and allow disabling them entirely
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/placement.cpp21
-rw-r--r--src/mbgl/text/placement.hpp5
2 files changed, 17 insertions, 9 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 367e421412..3b2cf20b7e 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -55,10 +55,11 @@ const CollisionGroups::CollisionGroup& CollisionGroups::get(const std::string& s
}
}
-Placement::Placement(const TransformState& state_, MapMode mapMode_, const bool crossSourceCollisions)
+Placement::Placement(const TransformState& state_, MapMode mapMode_, style::TransitionOptions transitionOptions_, const bool crossSourceCollisions)
: collisionIndex(state_)
, state(state_)
, mapMode(mapMode_)
+ , transitionOptions(transitionOptions_)
, collisionGroups(crossSourceCollisions)
{}
@@ -244,8 +245,8 @@ void Placement::commit(const Placement& prevPlacement, TimePoint now) {
bool placementChanged = false;
- float increment = mapMode == MapMode::Continuous ?
- std::chrono::duration<float>(commitTime - prevPlacement.commitTime) / Duration(std::chrono::milliseconds(300)) :
+ float increment = mapMode == MapMode::Continuous && transitionOptions.enablePlacementTransitions ?
+ std::chrono::duration<float>(commitTime - prevPlacement.commitTime) / transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) :
1.0;
// add the opacities from the current placement, and copy their current values from the previous placement
@@ -404,23 +405,27 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket, std::set<uint32_t>&
}
float Placement::symbolFadeChange(TimePoint now) const {
- if (mapMode == MapMode::Continuous) {
- return std::chrono::duration<float>(now - commitTime) / Duration(std::chrono::milliseconds(300));
+ if (mapMode == MapMode::Continuous && transitionOptions.enablePlacementTransitions) {
+ return std::chrono::duration<float>(now - commitTime) / transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION);
} else {
return 1.0;
}
}
bool Placement::hasTransitions(TimePoint now) const {
- if (mapMode == MapMode::Continuous) {
- return stale || std::chrono::duration<float>(now - fadeStartTime) < Duration(std::chrono::milliseconds(300));
+ if (mapMode == MapMode::Continuous && transitionOptions.enablePlacementTransitions) {
+ return stale || std::chrono::duration<float>(now - fadeStartTime) < transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION);
} else {
return false;
}
}
bool Placement::stillRecent(TimePoint now) const {
- return mapMode == MapMode::Continuous && commitTime + Duration(std::chrono::milliseconds(300)) > now;
+ // Even if transitionOptions.duration is set to a value < 300ms, we still wait for this default transition duration
+ // before attempting another placement operation.
+ return mapMode == MapMode::Continuous &&
+ transitionOptions.enablePlacementTransitions &&
+ commitTime + std::max(util::DEFAULT_TRANSITION_DURATION, transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION)) > now;
}
void Placement::setStale() {
diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp
index f34a8a25c2..cc23110e54 100644
--- a/src/mbgl/text/placement.hpp
+++ b/src/mbgl/text/placement.hpp
@@ -5,6 +5,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/text/collision_index.hpp>
#include <mbgl/layout/symbol_projection.hpp>
+#include <mbgl/style/transition_options.hpp>
#include <unordered_set>
namespace mbgl {
@@ -79,7 +80,7 @@ private:
class Placement {
public:
- Placement(const TransformState&, MapMode mapMode, const bool crossSourceCollisions);
+ Placement(const TransformState&, MapMode, style::TransitionOptions, const bool crossSourceCollisions);
void placeLayer(const RenderLayerSymbolInterface&, const mat4&, bool showCollisionBoxes);
void commit(const Placement& prevPlacement, TimePoint);
void updateLayerOpacities(const RenderLayerSymbolInterface&);
@@ -113,6 +114,8 @@ private:
TransformState state;
MapMode mapMode;
+ style::TransitionOptions transitionOptions;
+
TimePoint fadeStartTime;
TimePoint commitTime;