only animate when we need to fade the text
This commit is contained in:
@@ -20,6 +20,8 @@ public:
|
||||
// Record frame history that will be used to calculate fading params
|
||||
void record(float zoom);
|
||||
|
||||
bool needsAnimation(float duration) const;
|
||||
|
||||
public:
|
||||
std::deque<FrameSnapshot> history;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
void prepareClippingMask();
|
||||
void drawClippingMask(const mat4& matrix, uint8_t clip_id, bool opaque = true);
|
||||
void finishClippingMask();
|
||||
|
||||
bool needsAnimation() const;
|
||||
private:
|
||||
void setupShaders();
|
||||
void renderRaster(const std::shared_ptr<TileData>& tile);
|
||||
|
||||
@@ -483,5 +483,5 @@ bool Map::render() {
|
||||
|
||||
painter.renderMatte();
|
||||
|
||||
return changed || transform.needsAnimation();
|
||||
return changed || transform.needsAnimation() || painter.needsAnimation();
|
||||
}
|
||||
|
||||
@@ -14,3 +14,34 @@ void FrameHistory::record(float zoom) {
|
||||
history.emplace_back(FrameSnapshot{static_cast<float>(platform::time() * 1000), zoom});
|
||||
}
|
||||
}
|
||||
|
||||
bool FrameHistory::needsAnimation(const float duration) const {
|
||||
if (!history.size()) return true;
|
||||
|
||||
// If we have a value that is older than duration and whose z value is the
|
||||
// same as the most current z value, and if all values inbetween have the
|
||||
// same z value, we don't need animation, otherwise we probably do.
|
||||
const FrameSnapshot &pivot = history.back();
|
||||
|
||||
int i = -1;
|
||||
while (history.size() > i + 1 &&
|
||||
history[i + 1].time + duration < pivot.time) {
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
// There is no frame that is older than the duration time, so we need to
|
||||
// check all frames.
|
||||
i = 0;
|
||||
}
|
||||
|
||||
// Make sure that all subsequent snapshots have the same zoom as the last
|
||||
// pivot element.
|
||||
for (; history.size() > i; i++) {
|
||||
if (history[i].z != pivot.z) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -29,6 +29,10 @@ Painter::Painter(Transform& transform, Settings& settings, Style& style, GlyphAt
|
||||
glyphAtlas(glyphAtlas) {
|
||||
}
|
||||
|
||||
bool Painter::needsAnimation() const {
|
||||
return frameHistory.needsAnimation(300);
|
||||
}
|
||||
|
||||
void Painter::setup() {
|
||||
setupShaders();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user