summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-11-13 17:42:11 -0800
committerChris Loer <chris.loer@gmail.com>2017-11-13 17:42:11 -0800
commitc1223b68763d421ee38975c40ba623e6177761cd (patch)
tree22ae6dcf926d672e1474213bea661172df6658b8
parentd6d469aff8a00e86c45c963b44ef1a20051fd67a (diff)
downloadqtlocation-mapboxgl-upstream/viewport-collision-no-fade-line-labels.tar.gz
Extend "fade in immediately" for line labels to labels that were previously outside the range of the CollisionIndex.upstream/viewport-collision-no-fade-line-labels
Otherwise there's a weird mix on panning of some labels fading in vs. some popping in.
-rw-r--r--src/mbgl/text/collision_index.cpp11
-rw-r--r--src/mbgl/text/collision_index.hpp6
-rw-r--r--src/mbgl/text/placement.cpp21
-rw-r--r--src/mbgl/text/placement.hpp10
4 files changed, 30 insertions, 18 deletions
diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp
index 17663363b6..7cfa39099e 100644
--- a/src/mbgl/text/collision_index.cpp
+++ b/src/mbgl/text/collision_index.cpp
@@ -73,7 +73,8 @@ std::pair<bool,bool> CollisionIndex::placeFeature(CollisionFeature& feature,
const float fontSize,
const bool allowOverlap,
const bool pitchWithMap,
- const bool collisionDebug) {
+ const bool collisionDebug,
+ bool& outsideGrid) {
if (!feature.alongLine) {
CollisionBox& box = feature.boxes.front();
const auto projectedPoint = projectAndGetPerspectiveRatio(posMatrix, box.anchor);
@@ -82,6 +83,8 @@ std::pair<bool,bool> CollisionIndex::placeFeature(CollisionFeature& feature,
box.py1 = box.y1 / tileToViewport + projectedPoint.first.y;
box.px2 = box.x2 / tileToViewport + projectedPoint.first.x;
box.py2 = box.y2 / tileToViewport + projectedPoint.first.y;
+
+ outsideGrid &= !isInsideGrid(box);
if (!isInsideGrid(box) ||
(!allowOverlap && collisionGrid.hitTest({{ box.px1, box.py1 }, { box.px2, box.py2 }}))) {
@@ -90,7 +93,7 @@ std::pair<bool,bool> CollisionIndex::placeFeature(CollisionFeature& feature,
return {true, isOffscreen(box)};
} else {
- return placeLineFeature(feature, posMatrix, labelPlaneMatrix, textPixelRatio, symbol, scale, fontSize, allowOverlap, pitchWithMap, collisionDebug);
+ return placeLineFeature(feature, posMatrix, labelPlaneMatrix, textPixelRatio, symbol, scale, fontSize, allowOverlap, pitchWithMap, collisionDebug, outsideGrid);
}
}
@@ -103,7 +106,8 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
const float fontSize,
const bool allowOverlap,
const bool pitchWithMap,
- const bool collisionDebug) {
+ const bool collisionDebug,
+ bool& outsideGrid) {
const auto tileUnitAnchorPoint = symbol.anchorPoint;
const auto projectedAnchor = projectAnchor(posMatrix, tileUnitAnchorPoint);
@@ -213,6 +217,7 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
}
}
+ outsideGrid &= !inGrid;
return {!collisionDetected && firstAndLastGlyph && inGrid, entirelyOffscreen};
}
diff --git a/src/mbgl/text/collision_index.hpp b/src/mbgl/text/collision_index.hpp
index 8653c1d76c..2521dac1f6 100644
--- a/src/mbgl/text/collision_index.hpp
+++ b/src/mbgl/text/collision_index.hpp
@@ -26,7 +26,8 @@ public:
const float fontSize,
const bool allowOverlap,
const bool pitchWithMap,
- const bool collisionDebug);
+ const bool collisionDebug,
+ bool& outsideGrid);
void insertFeature(CollisionFeature& feature, bool ignorePlacement);
@@ -46,7 +47,8 @@ private:
const float fontSize,
const bool allowOverlap,
const bool pitchWithMap,
- const bool collisionDebug);
+ const bool collisionDebug,
+ bool& outsideGrid);
float approximateTileDistance(const TileDistance& tileDistance, const float lastSegmentAngle, const float pixelsToTileUnits, const float cameraToAnchorDistance, const bool pitchWithMap);
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 112d641be0..4652654148 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -22,9 +22,11 @@ bool OpacityState::isHidden() const {
return opacity == 0 && !placed;
}
-JointOpacityState::JointOpacityState(bool placedIcon, bool placedText, bool skipFadeIn) :
+JointOpacityState::JointOpacityState(bool placedIcon, bool placedText, bool skipFadeIn, bool outsideGrid_) :
icon(OpacityState(placedIcon, skipFadeIn)),
- text(OpacityState(placedText, skipFadeIn)) {}
+ text(OpacityState(placedText, skipFadeIn)),
+ outsideGrid(outsideGrid_)
+{}
JointOpacityState::JointOpacityState(const JointOpacityState& prevOpacityState, float increment, bool placedIcon, bool placedText) :
icon(OpacityState(prevOpacityState.icon, increment, placedIcon)),
@@ -105,6 +107,7 @@ void Placement::placeLayerBucket(
bool placeIcon = false;
bool offscreen = true;
bool lineLabel = false;
+ bool outsideGrid = true;
if (symbolInstance.placedTextIndex) {
PlacedSymbol& placedSymbol = bucket.text.placedSymbols.at(*symbolInstance.placedTextIndex);
@@ -115,7 +118,7 @@ void Placement::placeLayerBucket(
placedSymbol, scale, fontSize,
bucket.layout.get<TextAllowOverlap>(),
bucket.layout.get<TextPitchAlignment>() == style::AlignmentType::Map,
- showCollisionBoxes);
+ showCollisionBoxes, outsideGrid);
placeText = placed.first;
offscreen &= placed.second;
lineLabel = symbolInstance.textCollisionFeature.alongLine;
@@ -130,7 +133,7 @@ void Placement::placeLayerBucket(
placedSymbol, scale, fontSize,
bucket.layout.get<IconAllowOverlap>(),
bucket.layout.get<IconPitchAlignment>() == style::AlignmentType::Map,
- showCollisionBoxes);
+ showCollisionBoxes, outsideGrid);
placeIcon = placed.first;
offscreen &= placed.second;
}
@@ -154,7 +157,7 @@ void Placement::placeLayerBucket(
assert(symbolInstance.crossTileID != 0);
- placements.emplace(symbolInstance.crossTileID, JointPlacement(placeText, placeIcon, offscreen, lineLabel));
+ placements.emplace(symbolInstance.crossTileID, JointPlacement(placeText, placeIcon, offscreen, lineLabel, outsideGrid));
seenCrossTileIDs.insert(symbolInstance.crossTileID);
}
}
@@ -172,13 +175,13 @@ bool Placement::commit(const Placement& prevPlacement, TimePoint now) {
// add the opacities from the current placement, and copy their current values from the previous placement
for (auto& jointPlacement : placements) {
auto prevOpacity = prevPlacement.opacities.find(jointPlacement.first);
- if (prevOpacity != prevPlacement.opacities.end()) {
+ if (prevOpacity != prevPlacement.opacities.end() && !prevOpacity->second.outsideGrid) {
opacities.emplace(jointPlacement.first, JointOpacityState(prevOpacity->second, increment, jointPlacement.second.icon, jointPlacement.second.text));
placementChanged = placementChanged ||
jointPlacement.second.icon != prevOpacity->second.icon.placed ||
jointPlacement.second.text != prevOpacity->second.text.placed;
} else {
- opacities.emplace(jointPlacement.first, JointOpacityState(jointPlacement.second.icon, jointPlacement.second.text, jointPlacement.second.offscreen || jointPlacement.second.lineLabel));
+ opacities.emplace(jointPlacement.first, JointOpacityState(jointPlacement.second.icon, jointPlacement.second.text, jointPlacement.second.offscreen || jointPlacement.second.lineLabel, jointPlacement.second.outsideGrid));
placementChanged = placementChanged || jointPlacement.second.icon || jointPlacement.second.text;
}
}
@@ -220,7 +223,7 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket, std::set<uint32_t>&
for (SymbolInstance& symbolInstance : bucket.symbolInstances) {
auto opacityState = seenCrossTileIDs.count(symbolInstance.crossTileID) == 0 ?
getOpacity(symbolInstance.crossTileID) :
- JointOpacityState(false, false, false);
+ JointOpacityState(false, false, false, false);
seenCrossTileIDs.insert(symbolInstance.crossTileID);
@@ -282,7 +285,7 @@ JointOpacityState Placement::getOpacity(uint32_t crossTileSymbolID) const {
if (it != opacities.end()) {
return it->second;
} else {
- return JointOpacityState(false, false, false);
+ return JointOpacityState(false, false, false, false);
}
}
diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp
index 68de16a358..8b3cbda86d 100644
--- a/src/mbgl/text/placement.hpp
+++ b/src/mbgl/text/placement.hpp
@@ -14,7 +14,7 @@ class SymbolBucket;
class OpacityState {
public:
- OpacityState(bool placed, bool offscreen);
+ OpacityState(bool placed, bool skipFadeIn);
OpacityState(const OpacityState& prevOpacityState, float increment, bool placed);
bool isHidden() const;
float opacity;
@@ -23,17 +23,18 @@ public:
class JointOpacityState {
public:
- JointOpacityState(bool placedIcon, bool placedText, bool offscreen);
+ JointOpacityState(bool placedIcon, bool placedText, bool skipFadeIn, bool outsideGrid);
JointOpacityState(const JointOpacityState& prevOpacityState, float increment, bool placedIcon, bool placedText);
bool isHidden() const;
OpacityState icon;
OpacityState text;
+ bool outsideGrid;
};
class JointPlacement {
public:
- JointPlacement(bool text_, bool icon_, bool offscreen_, bool lineLabel_)
- : text(text_), icon(icon_), offscreen(offscreen_), lineLabel(lineLabel_)
+ JointPlacement(bool text_, bool icon_, bool offscreen_, bool lineLabel_, bool outsideGrid_)
+ : text(text_), icon(icon_), offscreen(offscreen_), lineLabel(lineLabel_), outsideGrid(outsideGrid_)
{}
const bool text;
@@ -44,6 +45,7 @@ public:
// visible right away.
const bool offscreen;
const bool lineLabel;
+ const bool outsideGrid;
};
class Placement {