compositor: Rename tweener to spring

Because it's a spring model, not a tweener.
This commit is contained in:
Kristian Høgsberg 2011-05-02 14:38:18 -04:00
parent 0bc0e24968
commit 269c78286f
3 changed files with 56 additions and 56 deletions

View File

@ -112,54 +112,54 @@ wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v)
}
WL_EXPORT void
wlsc_tweener_init(struct wlsc_tweener *tweener,
double k, double current, double target)
wlsc_spring_init(struct wlsc_spring *spring,
double k, double current, double target)
{
tweener->k = k;
tweener->friction = 100.0;
tweener->current = current;
tweener->previous = current;
tweener->target = target;
spring->k = k;
spring->friction = 100.0;
spring->current = current;
spring->previous = current;
spring->target = target;
}
WL_EXPORT void
wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec)
wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec)
{
double force, v, current, step;
step = (msec - tweener->timestamp) / 500.0;
tweener->timestamp = msec;
step = (msec - spring->timestamp) / 500.0;
spring->timestamp = msec;
current = tweener->current;
v = current - tweener->previous;
force = tweener->k * (tweener->target - current) / 10.0 +
(tweener->previous - current) - v * tweener->friction;
current = spring->current;
v = current - spring->previous;
force = spring->k * (spring->target - current) / 10.0 +
(spring->previous - current) - v * spring->friction;
tweener->current =
current + (current - tweener->previous) + force * step * step;
tweener->previous = current;
spring->current =
current + (current - spring->previous) + force * step * step;
spring->previous = current;
if (tweener->current >= 1.0) {
if (spring->current >= 1.0) {
#ifdef TWEENER_BOUNCE
tweener->current = 2.0 - tweener->current;
tweener->previous = 2.0 - tweener->previous;
spring->current = 2.0 - spring->current;
spring->previous = 2.0 - spring->previous;
#else
tweener->current = 1.0;
tweener->previous = 1.0;
spring->current = 1.0;
spring->previous = 1.0;
#endif
}
if (tweener->current <= 0.0) {
tweener->current = 0.0;
tweener->previous = 0.0;
if (spring->current <= 0.0) {
spring->current = 0.0;
spring->previous = 0.0;
}
}
WL_EXPORT int
wlsc_tweener_done(struct wlsc_tweener *tweener)
wlsc_spring_done(struct wlsc_spring *spring)
{
return fabs(tweener->previous - tweener->target) < 0.0002 &&
fabs(tweener->current - tweener->target) < 0.0002;
return fabs(spring->previous - spring->target) < 0.0002 &&
fabs(spring->current - spring->target) < 0.0002;
}
WL_EXPORT struct wlsc_surface *
@ -624,14 +624,14 @@ fade_frame(struct wlsc_animation *animation,
container_of(animation,
struct wlsc_compositor, fade.animation);
wlsc_tweener_update(&compositor->fade.tweener, msecs);
if (wlsc_tweener_done(&compositor->fade.tweener)) {
if (compositor->fade.tweener.current > 0.999) {
wlsc_spring_update(&compositor->fade.spring, msecs);
if (wlsc_spring_done(&compositor->fade.spring)) {
if (compositor->fade.spring.current > 0.999) {
compositor->state = WLSC_COMPOSITOR_SLEEPING;
compositor->shell->lock(compositor->shell);
}
compositor->fade.tweener.current =
compositor->fade.tweener.target;
compositor->fade.spring.current =
compositor->fade.spring.target;
wl_list_remove(&animation->link);
wl_list_init(&animation->link);
}
@ -701,7 +701,7 @@ wlsc_output_repaint(struct wlsc_output *output)
if (ec->focus)
if (output->set_hardware_cursor(output, ec->input_device) < 0)
using_hardware_cursor = 0;
if (ec->fade.tweener.current > 0.001)
if (ec->fade.spring.current > 0.001)
using_hardware_cursor = 0;
es = container_of(ec->surface_list.next, struct wlsc_surface, link);
@ -749,8 +749,8 @@ wlsc_output_repaint(struct wlsc_output *output)
&total_damage);
}
if (ec->fade.tweener.current > 0.001)
fade_output(output, ec->fade.tweener.current, &total_damage);
if (ec->fade.spring.current > 0.001)
fade_output(output, ec->fade.spring.current, &total_damage);
}
static int
@ -806,13 +806,13 @@ wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint)
{
int done;
done = wlsc_tweener_done(&compositor->fade.tweener);
compositor->fade.tweener.target = tint;
if (wlsc_tweener_done(&compositor->fade.tweener))
done = wlsc_spring_done(&compositor->fade.spring);
compositor->fade.spring.target = tint;
if (wlsc_spring_done(&compositor->fade.spring))
return;
if (done)
compositor->fade.tweener.timestamp =
compositor->fade.spring.timestamp =
wlsc_compositor_get_time();
wlsc_compositor_damage_all(compositor);
@ -1836,7 +1836,7 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
wl_list_init(&ec->output_list);
wl_list_init(&ec->binding_list);
wl_list_init(&ec->animation_list);
wlsc_tweener_init(&ec->fade.tweener, 0.8, 0.0, 0.0);
wlsc_spring_init(&ec->fade.spring, 0.8, 0.0, 0.0);
ec->fade.animation.frame = fade_frame;
wl_list_init(&ec->fade.animation.link);

View File

@ -117,7 +117,7 @@ struct wlsc_animation {
struct wl_list link;
};
struct wlsc_tweener {
struct wlsc_spring {
double k;
double friction;
double current;
@ -162,7 +162,7 @@ struct wlsc_compositor {
struct wl_list binding_list;
struct wl_list animation_list;
struct {
struct wlsc_tweener tweener;
struct wlsc_spring spring;
struct wlsc_animation animation;
} fade;
@ -234,12 +234,12 @@ struct wlsc_surface {
};
void
wlsc_tweener_init(struct wlsc_tweener *tweener,
double k, double current, double target);
wlsc_spring_init(struct wlsc_spring *spring,
double k, double current, double target);
void
wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec);
wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec);
int
wlsc_tweener_done(struct wlsc_tweener *tweener);
wlsc_spring_done(struct wlsc_spring *spring);
void
wlsc_surface_activate(struct wlsc_surface *surface,

View File

@ -77,7 +77,7 @@ struct meego_tablet_client {
struct meego_tablet_zoom {
struct wlsc_surface *surface;
struct wlsc_animation animation;
struct wlsc_tweener tweener;
struct wlsc_spring spring;
struct wlsc_transform transform;
};
@ -104,16 +104,16 @@ meego_tablet_zoom_frame(struct wlsc_animation *animation,
struct wlsc_surface *es = zoom->surface;
GLfloat scale;
wlsc_tweener_update(&zoom->tweener, msecs);
wlsc_spring_update(&zoom->spring, msecs);
if (wlsc_tweener_done(&zoom->tweener)) {
if (wlsc_spring_done(&zoom->spring)) {
wl_list_remove(&animation->link);
fprintf(stderr, "animation done\n");
es->transform = NULL;
free(zoom);
}
scale = zoom->tweener.current;
scale = zoom->spring.current;
wlsc_matrix_init(&zoom->transform.matrix);
wlsc_matrix_translate(&zoom->transform.matrix,
-es->width / 2.0, -es->height / 2.0, 0);
@ -121,7 +121,7 @@ meego_tablet_zoom_frame(struct wlsc_animation *animation,
wlsc_matrix_translate(&zoom->transform.matrix,
es->width / 2.0, es->height / 2.0, 0);
scale = 1.0 / zoom->tweener.current;
scale = 1.0 / zoom->spring.current;
wlsc_matrix_init(&zoom->transform.inverse);
wlsc_matrix_scale(&zoom->transform.inverse, scale, scale, scale);
@ -144,11 +144,11 @@ meego_tablet_zoom_run(struct meego_tablet_shell *shell,
zoom->surface = surface;
surface->transform = &zoom->transform;
scale = 0.3;
wlsc_tweener_init(&zoom->tweener, 100.0, scale, 1.0);
zoom->tweener.timestamp = wlsc_compositor_get_time();
wlsc_spring_init(&zoom->spring, 100.0, scale, 1.0);
zoom->spring.timestamp = wlsc_compositor_get_time();
zoom->animation.frame = meego_tablet_zoom_frame;
meego_tablet_zoom_frame(&zoom->animation, NULL,
zoom->tweener.timestamp);
zoom->spring.timestamp);
wl_list_insert(shell->compositor->animation_list.prev,
&zoom->animation.link);
@ -559,6 +559,6 @@ shell_init(struct wlsc_compositor *compositor)
launch_switcher(shell);
wlsc_tweener_init(&compositor->fade.tweener, 40.0, 1.0, 1.0);
wlsc_spring_init(&compositor->fade.spring, 40.0, 1.0, 1.0);
shell->starting = 1;
}