compositor: Rename tweener to spring
Because it's a spring model, not a tweener.
This commit is contained in:
+41
-41
@@ -112,54 +112,54 @@ wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wlsc_tweener_init(struct wlsc_tweener *tweener,
|
wlsc_spring_init(struct wlsc_spring *spring,
|
||||||
double k, double current, double target)
|
double k, double current, double target)
|
||||||
{
|
{
|
||||||
tweener->k = k;
|
spring->k = k;
|
||||||
tweener->friction = 100.0;
|
spring->friction = 100.0;
|
||||||
tweener->current = current;
|
spring->current = current;
|
||||||
tweener->previous = current;
|
spring->previous = current;
|
||||||
tweener->target = target;
|
spring->target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
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;
|
double force, v, current, step;
|
||||||
|
|
||||||
step = (msec - tweener->timestamp) / 500.0;
|
step = (msec - spring->timestamp) / 500.0;
|
||||||
tweener->timestamp = msec;
|
spring->timestamp = msec;
|
||||||
|
|
||||||
current = tweener->current;
|
current = spring->current;
|
||||||
v = current - tweener->previous;
|
v = current - spring->previous;
|
||||||
force = tweener->k * (tweener->target - current) / 10.0 +
|
force = spring->k * (spring->target - current) / 10.0 +
|
||||||
(tweener->previous - current) - v * tweener->friction;
|
(spring->previous - current) - v * spring->friction;
|
||||||
|
|
||||||
tweener->current =
|
spring->current =
|
||||||
current + (current - tweener->previous) + force * step * step;
|
current + (current - spring->previous) + force * step * step;
|
||||||
tweener->previous = current;
|
spring->previous = current;
|
||||||
|
|
||||||
if (tweener->current >= 1.0) {
|
if (spring->current >= 1.0) {
|
||||||
#ifdef TWEENER_BOUNCE
|
#ifdef TWEENER_BOUNCE
|
||||||
tweener->current = 2.0 - tweener->current;
|
spring->current = 2.0 - spring->current;
|
||||||
tweener->previous = 2.0 - tweener->previous;
|
spring->previous = 2.0 - spring->previous;
|
||||||
#else
|
#else
|
||||||
tweener->current = 1.0;
|
spring->current = 1.0;
|
||||||
tweener->previous = 1.0;
|
spring->previous = 1.0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tweener->current <= 0.0) {
|
if (spring->current <= 0.0) {
|
||||||
tweener->current = 0.0;
|
spring->current = 0.0;
|
||||||
tweener->previous = 0.0;
|
spring->previous = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT int
|
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 &&
|
return fabs(spring->previous - spring->target) < 0.0002 &&
|
||||||
fabs(tweener->current - tweener->target) < 0.0002;
|
fabs(spring->current - spring->target) < 0.0002;
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT struct wlsc_surface *
|
WL_EXPORT struct wlsc_surface *
|
||||||
@@ -624,14 +624,14 @@ fade_frame(struct wlsc_animation *animation,
|
|||||||
container_of(animation,
|
container_of(animation,
|
||||||
struct wlsc_compositor, fade.animation);
|
struct wlsc_compositor, fade.animation);
|
||||||
|
|
||||||
wlsc_tweener_update(&compositor->fade.tweener, msecs);
|
wlsc_spring_update(&compositor->fade.spring, msecs);
|
||||||
if (wlsc_tweener_done(&compositor->fade.tweener)) {
|
if (wlsc_spring_done(&compositor->fade.spring)) {
|
||||||
if (compositor->fade.tweener.current > 0.999) {
|
if (compositor->fade.spring.current > 0.999) {
|
||||||
compositor->state = WLSC_COMPOSITOR_SLEEPING;
|
compositor->state = WLSC_COMPOSITOR_SLEEPING;
|
||||||
compositor->shell->lock(compositor->shell);
|
compositor->shell->lock(compositor->shell);
|
||||||
}
|
}
|
||||||
compositor->fade.tweener.current =
|
compositor->fade.spring.current =
|
||||||
compositor->fade.tweener.target;
|
compositor->fade.spring.target;
|
||||||
wl_list_remove(&animation->link);
|
wl_list_remove(&animation->link);
|
||||||
wl_list_init(&animation->link);
|
wl_list_init(&animation->link);
|
||||||
}
|
}
|
||||||
@@ -701,7 +701,7 @@ wlsc_output_repaint(struct wlsc_output *output)
|
|||||||
if (ec->focus)
|
if (ec->focus)
|
||||||
if (output->set_hardware_cursor(output, ec->input_device) < 0)
|
if (output->set_hardware_cursor(output, ec->input_device) < 0)
|
||||||
using_hardware_cursor = 0;
|
using_hardware_cursor = 0;
|
||||||
if (ec->fade.tweener.current > 0.001)
|
if (ec->fade.spring.current > 0.001)
|
||||||
using_hardware_cursor = 0;
|
using_hardware_cursor = 0;
|
||||||
|
|
||||||
es = container_of(ec->surface_list.next, struct wlsc_surface, link);
|
es = container_of(ec->surface_list.next, struct wlsc_surface, link);
|
||||||
@@ -749,8 +749,8 @@ wlsc_output_repaint(struct wlsc_output *output)
|
|||||||
&total_damage);
|
&total_damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ec->fade.tweener.current > 0.001)
|
if (ec->fade.spring.current > 0.001)
|
||||||
fade_output(output, ec->fade.tweener.current, &total_damage);
|
fade_output(output, ec->fade.spring.current, &total_damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -806,13 +806,13 @@ wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint)
|
|||||||
{
|
{
|
||||||
int done;
|
int done;
|
||||||
|
|
||||||
done = wlsc_tweener_done(&compositor->fade.tweener);
|
done = wlsc_spring_done(&compositor->fade.spring);
|
||||||
compositor->fade.tweener.target = tint;
|
compositor->fade.spring.target = tint;
|
||||||
if (wlsc_tweener_done(&compositor->fade.tweener))
|
if (wlsc_spring_done(&compositor->fade.spring))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (done)
|
if (done)
|
||||||
compositor->fade.tweener.timestamp =
|
compositor->fade.spring.timestamp =
|
||||||
wlsc_compositor_get_time();
|
wlsc_compositor_get_time();
|
||||||
|
|
||||||
wlsc_compositor_damage_all(compositor);
|
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->output_list);
|
||||||
wl_list_init(&ec->binding_list);
|
wl_list_init(&ec->binding_list);
|
||||||
wl_list_init(&ec->animation_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;
|
ec->fade.animation.frame = fade_frame;
|
||||||
wl_list_init(&ec->fade.animation.link);
|
wl_list_init(&ec->fade.animation.link);
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ struct wlsc_animation {
|
|||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlsc_tweener {
|
struct wlsc_spring {
|
||||||
double k;
|
double k;
|
||||||
double friction;
|
double friction;
|
||||||
double current;
|
double current;
|
||||||
@@ -162,7 +162,7 @@ struct wlsc_compositor {
|
|||||||
struct wl_list binding_list;
|
struct wl_list binding_list;
|
||||||
struct wl_list animation_list;
|
struct wl_list animation_list;
|
||||||
struct {
|
struct {
|
||||||
struct wlsc_tweener tweener;
|
struct wlsc_spring spring;
|
||||||
struct wlsc_animation animation;
|
struct wlsc_animation animation;
|
||||||
} fade;
|
} fade;
|
||||||
|
|
||||||
@@ -234,12 +234,12 @@ struct wlsc_surface {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
wlsc_tweener_init(struct wlsc_tweener *tweener,
|
wlsc_spring_init(struct wlsc_spring *spring,
|
||||||
double k, double current, double target);
|
double k, double current, double target);
|
||||||
void
|
void
|
||||||
wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec);
|
wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec);
|
||||||
int
|
int
|
||||||
wlsc_tweener_done(struct wlsc_tweener *tweener);
|
wlsc_spring_done(struct wlsc_spring *spring);
|
||||||
|
|
||||||
void
|
void
|
||||||
wlsc_surface_activate(struct wlsc_surface *surface,
|
wlsc_surface_activate(struct wlsc_surface *surface,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ struct meego_tablet_client {
|
|||||||
struct meego_tablet_zoom {
|
struct meego_tablet_zoom {
|
||||||
struct wlsc_surface *surface;
|
struct wlsc_surface *surface;
|
||||||
struct wlsc_animation animation;
|
struct wlsc_animation animation;
|
||||||
struct wlsc_tweener tweener;
|
struct wlsc_spring spring;
|
||||||
struct wlsc_transform transform;
|
struct wlsc_transform transform;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,16 +104,16 @@ meego_tablet_zoom_frame(struct wlsc_animation *animation,
|
|||||||
struct wlsc_surface *es = zoom->surface;
|
struct wlsc_surface *es = zoom->surface;
|
||||||
GLfloat scale;
|
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);
|
wl_list_remove(&animation->link);
|
||||||
fprintf(stderr, "animation done\n");
|
fprintf(stderr, "animation done\n");
|
||||||
es->transform = NULL;
|
es->transform = NULL;
|
||||||
free(zoom);
|
free(zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
scale = zoom->tweener.current;
|
scale = zoom->spring.current;
|
||||||
wlsc_matrix_init(&zoom->transform.matrix);
|
wlsc_matrix_init(&zoom->transform.matrix);
|
||||||
wlsc_matrix_translate(&zoom->transform.matrix,
|
wlsc_matrix_translate(&zoom->transform.matrix,
|
||||||
-es->width / 2.0, -es->height / 2.0, 0);
|
-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,
|
wlsc_matrix_translate(&zoom->transform.matrix,
|
||||||
es->width / 2.0, es->height / 2.0, 0);
|
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_init(&zoom->transform.inverse);
|
||||||
wlsc_matrix_scale(&zoom->transform.inverse, scale, scale, scale);
|
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;
|
zoom->surface = surface;
|
||||||
surface->transform = &zoom->transform;
|
surface->transform = &zoom->transform;
|
||||||
scale = 0.3;
|
scale = 0.3;
|
||||||
wlsc_tweener_init(&zoom->tweener, 100.0, scale, 1.0);
|
wlsc_spring_init(&zoom->spring, 100.0, scale, 1.0);
|
||||||
zoom->tweener.timestamp = wlsc_compositor_get_time();
|
zoom->spring.timestamp = wlsc_compositor_get_time();
|
||||||
zoom->animation.frame = meego_tablet_zoom_frame;
|
zoom->animation.frame = meego_tablet_zoom_frame;
|
||||||
meego_tablet_zoom_frame(&zoom->animation, NULL,
|
meego_tablet_zoom_frame(&zoom->animation, NULL,
|
||||||
zoom->tweener.timestamp);
|
zoom->spring.timestamp);
|
||||||
|
|
||||||
wl_list_insert(shell->compositor->animation_list.prev,
|
wl_list_insert(shell->compositor->animation_list.prev,
|
||||||
&zoom->animation.link);
|
&zoom->animation.link);
|
||||||
@@ -559,6 +559,6 @@ shell_init(struct wlsc_compositor *compositor)
|
|||||||
|
|
||||||
launch_switcher(shell);
|
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;
|
shell->starting = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user