rename animation => transition
This commit is contained in:
@@ -48,8 +48,8 @@ public:
|
||||
void resize(uint16_t width, uint16_t height, float ratio = 1);
|
||||
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height);
|
||||
|
||||
// Animations
|
||||
void cancelAnimations();
|
||||
// Transition
|
||||
void cancelTransitions();
|
||||
|
||||
// Position
|
||||
void moveBy(double dx, double dy, double duration = 0);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LLMR_MAP_TRANSFORM
|
||||
#define LLMR_MAP_TRANSFORM
|
||||
|
||||
#include <llmr/util/animation.hpp>
|
||||
#include <llmr/util/transition.hpp>
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/util/uv.hpp>
|
||||
|
||||
@@ -48,10 +48,10 @@ public:
|
||||
void startScaling();
|
||||
void stopScaling();
|
||||
|
||||
// Animations
|
||||
bool needsAnimation() const;
|
||||
void updateAnimations(time now);
|
||||
void cancelAnimations();
|
||||
// Transitions
|
||||
bool needsTransition() const;
|
||||
void updateTransitions(time now);
|
||||
void cancelTransitions();
|
||||
|
||||
// Transform state
|
||||
const TransformState currentState() const;
|
||||
@@ -76,7 +76,7 @@ private:
|
||||
// you render a new frame.
|
||||
TransformState current;
|
||||
|
||||
// This reflects the final position of the transform, after all possible animations took place.
|
||||
// This reflects the final position of the transform, after all possible transition took place.
|
||||
TransformState final;
|
||||
|
||||
// Limit the amount of zooming possible on the map.
|
||||
@@ -87,10 +87,10 @@ private:
|
||||
// cache values for spherical mercator math
|
||||
double zc, Bc, Cc;
|
||||
|
||||
std::forward_list<std::shared_ptr<util::animation>> animations;
|
||||
std::shared_ptr<util::animation> scale_timeout;
|
||||
std::shared_ptr<util::animation> rotate_timeout;
|
||||
std::shared_ptr<util::animation> pan_timeout;
|
||||
std::forward_list<std::shared_ptr<util::transition>> transitions;
|
||||
std::shared_ptr<util::transition> scale_timeout;
|
||||
std::shared_ptr<util::transition> rotate_timeout;
|
||||
std::shared_ptr<util::transition> pan_timeout;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LLMR_UTIL_RASTER
|
||||
#define LLMR_UTIL_RASTER
|
||||
|
||||
#include <llmr/util/animation.hpp>
|
||||
#include <llmr/util/transition.hpp>
|
||||
#include <llmr/util/texturepool.hpp>
|
||||
|
||||
#include <string>
|
||||
@@ -29,10 +29,10 @@ public:
|
||||
// loaded status
|
||||
bool isLoaded() const;
|
||||
|
||||
// animations
|
||||
void beginFadeInAnimation();
|
||||
bool needsAnimation() const;
|
||||
void updateAnimations(time now);
|
||||
// transitions
|
||||
void beginFadeInTransition();
|
||||
bool needsTransition() const;
|
||||
void updateTransitions(time now);
|
||||
|
||||
inline void setData(const std::string &img) { data = img; }
|
||||
|
||||
@@ -71,8 +71,8 @@ private:
|
||||
// the raw pixels
|
||||
char *img = nullptr;
|
||||
|
||||
// fade in animation
|
||||
std::shared_ptr<util::animation> fade_animation = nullptr;
|
||||
// fade in transition
|
||||
std::shared_ptr<util::transition> fade_transition = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef LLMR_UTIL_ANIMATION
|
||||
#define LLMR_UTIL_ANIMATION
|
||||
#ifndef LLMR_UTIL_TRANSITION
|
||||
#define LLMR_UTIL_TRANSITION
|
||||
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/util/time.hpp>
|
||||
@@ -7,14 +7,14 @@
|
||||
namespace llmr {
|
||||
namespace util {
|
||||
|
||||
class animation : private noncopyable {
|
||||
class transition : private noncopyable {
|
||||
public:
|
||||
enum state {
|
||||
running,
|
||||
complete
|
||||
};
|
||||
|
||||
inline animation(time start, time duration)
|
||||
inline transition(time start, time duration)
|
||||
: start(start),
|
||||
duration(duration) {}
|
||||
|
||||
@@ -23,20 +23,20 @@ public:
|
||||
}
|
||||
|
||||
virtual state update(time now) const = 0;
|
||||
virtual ~animation();
|
||||
virtual ~transition();
|
||||
|
||||
protected:
|
||||
const time start, duration;
|
||||
};
|
||||
|
||||
class ease_animation : public animation {
|
||||
class ease_transition : public transition {
|
||||
public:
|
||||
// Disable automatic casts.
|
||||
template <typename T1, typename T2>
|
||||
inline ease_animation(double from, double to, double& value, T1 start, T2 duration) = delete;
|
||||
inline ease_transition(double from, double to, double& value, T1 start, T2 duration) = delete;
|
||||
|
||||
// Actual constructor.
|
||||
ease_animation(double from, double to, double& value, time start, time duration);
|
||||
ease_transition(double from, double to, double& value, time start, time duration);
|
||||
state update(time now) const;
|
||||
|
||||
private:
|
||||
@@ -45,7 +45,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class timeout : public animation {
|
||||
class timeout : public transition {
|
||||
public:
|
||||
// Disable automatic casts.
|
||||
template <typename T1, typename T2>
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
// Actual constructor.
|
||||
timeout(T final_value, T& value, time start, time duration)
|
||||
: animation(start, duration),
|
||||
: transition(start, duration),
|
||||
final_value(final_value),
|
||||
value(value) {}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <llmr/platform/platform.hpp>
|
||||
#include <llmr/style/resources.hpp>
|
||||
#include <llmr/style/sprite.hpp>
|
||||
#include <llmr/util/animation.hpp>
|
||||
#include <llmr/util/transition.hpp>
|
||||
#include <llmr/util/time.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -179,10 +179,10 @@ void Map::resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Animations
|
||||
#pragma mark - Transitions
|
||||
|
||||
void Map::cancelAnimations() {
|
||||
transform.cancelAnimations();
|
||||
void Map::cancelTransitions() {
|
||||
transform.cancelTransitions();
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -348,11 +348,10 @@ void Map::updateTiles() {
|
||||
void Map::prepare() {
|
||||
view.make_active();
|
||||
|
||||
// Update animations
|
||||
// Update transitions
|
||||
animationTime = util::now();
|
||||
bool animating = transform.needsAnimation();
|
||||
if (animating) {
|
||||
transform.updateAnimations(animationTime);
|
||||
if (transform.needsTransition()) {
|
||||
transform.updateTransitions(animationTime);
|
||||
}
|
||||
|
||||
state = transform.currentState();
|
||||
@@ -403,7 +402,7 @@ void Map::render() {
|
||||
painter.renderMatte();
|
||||
|
||||
// Schedule another rerender when we definitely need a next frame.
|
||||
if (transform.needsAnimation()) {
|
||||
if (transform.needsTransition()) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +55,10 @@ void Source::render(time animationTime) {
|
||||
std::shared_ptr<Raster> raster = tile.data->raster;
|
||||
if (raster && !raster->textured) {
|
||||
raster->setTexturepool(&texturepool);
|
||||
raster->beginFadeInAnimation();
|
||||
raster->beginFadeInTransition();
|
||||
}
|
||||
if (raster && raster->needsAnimation()) {
|
||||
raster->updateAnimations(animationTime);
|
||||
if (raster && raster->needsTransition()) {
|
||||
raster->updateTransitions(animationTime);
|
||||
}
|
||||
}
|
||||
painter.render(tile);
|
||||
|
||||
@@ -56,12 +56,12 @@ void Transform::_moveBy(const double dx, const double dy, const time duration) {
|
||||
current.x = final.x;
|
||||
current.y = final.y;
|
||||
} else {
|
||||
// Use a common start time for all of the animations to avoid divergent animations.
|
||||
// Use a common start time for all of the transitions to avoid divergent transitions.
|
||||
time start = util::now();
|
||||
animations.emplace_front(
|
||||
std::make_shared<util::ease_animation>(current.x, final.x, current.x, start, duration));
|
||||
animations.emplace_front(
|
||||
std::make_shared<util::ease_animation>(current.y, final.y, current.y, start, duration));
|
||||
transitions.emplace_front(
|
||||
std::make_shared<util::ease_transition>(current.x, final.x, current.x, start, duration));
|
||||
transitions.emplace_front(
|
||||
std::make_shared<util::ease_transition>(current.y, final.y, current.y, start, duration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ void Transform::startPanning() {
|
||||
current.panning = true;
|
||||
time start = util::now();
|
||||
pan_timeout = std::make_shared<util::timeout<bool>>(false, current.panning, start, 200_milliseconds);
|
||||
animations.emplace_front(pan_timeout);
|
||||
transitions.emplace_front(pan_timeout);
|
||||
}
|
||||
|
||||
void Transform::stopPanning() {
|
||||
@@ -128,7 +128,7 @@ void Transform::stopPanning() {
|
||||
void Transform::_clearPanning() {
|
||||
current.panning = false;
|
||||
if (pan_timeout) {
|
||||
animations.remove(pan_timeout);
|
||||
transitions.remove(pan_timeout);
|
||||
pan_timeout.reset();
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ void Transform::startScaling() {
|
||||
current.scaling = true;
|
||||
time start = util::now();
|
||||
scale_timeout = std::make_shared<util::timeout<bool>>(false, current.scaling, start, 200_milliseconds);
|
||||
animations.emplace_front(scale_timeout);
|
||||
transitions.emplace_front(scale_timeout);
|
||||
}
|
||||
|
||||
void Transform::stopScaling() {
|
||||
@@ -197,7 +197,7 @@ void Transform::_clearScaling() {
|
||||
|
||||
current.scaling = false;
|
||||
if (scale_timeout) {
|
||||
animations.remove(scale_timeout);
|
||||
transitions.remove(scale_timeout);
|
||||
scale_timeout.reset();
|
||||
}
|
||||
}
|
||||
@@ -248,14 +248,14 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
|
||||
current.x = final.x;
|
||||
current.y = final.y;
|
||||
} else {
|
||||
// Use a common start time for all of the animations to avoid divergent animations.
|
||||
// Use a common start time for all of the transitions to avoid divergent transitions.
|
||||
time start = util::now();
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(
|
||||
transitions.emplace_front(std::make_shared<util::ease_transition>(
|
||||
current.scale, final.scale, current.scale, start, duration));
|
||||
animations.emplace_front(
|
||||
std::make_shared<util::ease_animation>(current.x, final.x, current.x, start, duration));
|
||||
animations.emplace_front(
|
||||
std::make_shared<util::ease_animation>(current.y, final.y, current.y, start, duration));
|
||||
transitions.emplace_front(
|
||||
std::make_shared<util::ease_transition>(current.x, final.x, current.x, start, duration));
|
||||
transitions.emplace_front(
|
||||
std::make_shared<util::ease_transition>(current.y, final.y, current.y, start, duration));
|
||||
}
|
||||
|
||||
const double s = final.scale * util::tileSize;
|
||||
@@ -335,7 +335,7 @@ void Transform::_setAngle(double new_angle, const time duration) {
|
||||
current.angle = final.angle;
|
||||
} else {
|
||||
time start = util::now();
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(
|
||||
transitions.emplace_front(std::make_shared<util::ease_transition>(
|
||||
current.angle, final.angle, current.angle, start, duration));
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ void Transform::startRotating() {
|
||||
current.rotating = true;
|
||||
time start = util::now();
|
||||
rotate_timeout = std::make_shared<util::timeout<bool>>(false, current.rotating, start, 200_milliseconds);
|
||||
animations.emplace_front(rotate_timeout);
|
||||
transitions.emplace_front(rotate_timeout);
|
||||
}
|
||||
|
||||
void Transform::stopRotating() {
|
||||
@@ -369,31 +369,31 @@ void Transform::_clearRotating() {
|
||||
|
||||
current.rotating = false;
|
||||
if (rotate_timeout) {
|
||||
animations.remove(rotate_timeout);
|
||||
transitions.remove(rotate_timeout);
|
||||
rotate_timeout.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Animation
|
||||
#pragma mark - Transition
|
||||
|
||||
bool Transform::needsAnimation() const {
|
||||
bool Transform::needsTransition() const {
|
||||
uv::readlock lock(mtx);
|
||||
|
||||
return !animations.empty();
|
||||
return !transitions.empty();
|
||||
}
|
||||
|
||||
void Transform::updateAnimations(const time now) {
|
||||
void Transform::updateTransitions(const time now) {
|
||||
uv::writelock lock(mtx);
|
||||
|
||||
animations.remove_if([now](const std::shared_ptr<util::animation> &animation) {
|
||||
return animation->update(now) == util::animation::complete;
|
||||
transitions.remove_if([now](const std::shared_ptr<util::transition> &transition) {
|
||||
return transition->update(now) == util::transition::complete;
|
||||
});
|
||||
}
|
||||
|
||||
void Transform::cancelAnimations() {
|
||||
void Transform::cancelTransitions() {
|
||||
uv::writelock lock(mtx);
|
||||
|
||||
animations.clear();
|
||||
transitions.clear();
|
||||
}
|
||||
|
||||
#pragma mark - Transform state
|
||||
|
||||
@@ -185,18 +185,18 @@ void Raster::bind(bool linear) {
|
||||
}
|
||||
}
|
||||
|
||||
void Raster::beginFadeInAnimation() {
|
||||
void Raster::beginFadeInTransition() {
|
||||
time start = util::now();
|
||||
fade_animation = std::make_shared<util::ease_animation>(opacity, 1.0, opacity, start, 250_milliseconds);
|
||||
fade_transition = std::make_shared<util::ease_transition>(opacity, 1.0, opacity, start, 250_milliseconds);
|
||||
}
|
||||
|
||||
bool Raster::needsAnimation() const {
|
||||
return fade_animation != nullptr;
|
||||
bool Raster::needsTransition() const {
|
||||
return fade_transition != nullptr;
|
||||
}
|
||||
|
||||
void Raster::updateAnimations(time now) {
|
||||
if (fade_animation->update(now) == util::animation::complete) {
|
||||
fade_animation = nullptr;
|
||||
void Raster::updateTransitions(time now) {
|
||||
if (fade_transition->update(now) == util::transition::complete) {
|
||||
fade_transition = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <llmr/util/animation.hpp>
|
||||
#include <llmr/util/transition.hpp>
|
||||
#include <llmr/util/unitbezier.hpp>
|
||||
#include <llmr/platform/platform.hpp>
|
||||
|
||||
@@ -6,16 +6,16 @@ using namespace llmr::util;
|
||||
|
||||
UnitBezier ease(0.25, 0.1, 0.25, 1);
|
||||
|
||||
animation::~animation() {}
|
||||
transition::~transition() {}
|
||||
|
||||
ease_animation::ease_animation(double from, double to, double &value, time start, time duration)
|
||||
: animation(start, duration),
|
||||
ease_transition::ease_transition(double from, double to, double &value, time start, time duration)
|
||||
: transition(start, duration),
|
||||
from(from),
|
||||
to(to),
|
||||
value(value) {
|
||||
}
|
||||
|
||||
animation::state ease_animation::update(time now) const {
|
||||
transition::state ease_transition::update(time now) const {
|
||||
float t = progress(now);
|
||||
if (t >= 1) {
|
||||
value = to;
|
||||
Reference in New Issue
Block a user