[PATCH weston 14/18] Add move/scale animation

ppaalanen at gmail.com ppaalanen at gmail.com
Wed May 22 08:03:17 PDT 2013


From: Daniel Stone <daniel at fooishbar.org>

Add an animation which moves a surface to a new location, at the same
time as also rescaling it to a different size from the origin, rather
than the existing scale animation which resizes from the centre.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/animation.c  | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/compositor.h |  5 +++++
 2 files changed, 67 insertions(+)

diff --git a/src/animation.c b/src/animation.c
index 835ed13..7dd3683 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -339,3 +339,65 @@ weston_slide_run(struct weston_surface *surface, float start, float stop,
 
 	return animation;
 }
+
+struct weston_move_animation {
+	int dx;
+	int dy;
+	int reverse;
+	weston_surface_animation_done_func_t done;
+};
+
+static void
+move_frame(struct weston_surface_animation *animation)
+{
+	struct weston_move_animation *move = animation->private;
+	float scale;
+	float progress = animation->spring.current;
+
+	if (move->reverse)
+		progress = 1.0 - progress;
+
+	scale = animation->start +
+                (animation->stop - animation->start) *
+                progress;
+	weston_matrix_init(&animation->transform.matrix);
+	weston_matrix_scale(&animation->transform.matrix, scale, scale, 1.0f);
+	weston_matrix_translate(&animation->transform.matrix,
+                                move->dx * progress, move->dy * progress,
+				0);
+}
+
+static void
+move_done(struct weston_surface_animation *animation, void *data)
+{
+	struct weston_move_animation *move = animation->private;
+
+	if (move->done)
+		move->done(animation, data);
+
+	free(move);
+}
+
+WL_EXPORT struct weston_surface_animation *
+weston_move_scale_run(struct weston_surface *surface, int dx, int dy,
+                      float start, float end, int reverse,
+		      weston_surface_animation_done_func_t done, void *data)
+{
+	struct weston_move_animation *move;
+	struct weston_surface_animation *animation;
+
+	move = malloc(sizeof(*move));
+	if (!move)
+		return NULL;
+	move->dx = dx;
+	move->dy = dy;
+	move->reverse = reverse;
+	move->done = done;
+
+	animation = weston_surface_animation_run(surface, start, end, move_frame,
+	                                         move_done, data, move);
+	animation->spring.k = 400;
+	animation->spring.friction = 1150;
+
+	return animation;
+}
diff --git a/src/compositor.h b/src/compositor.h
index 4d70ba2..2de6eb4 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1142,6 +1142,11 @@ struct weston_surface_animation *
 weston_fade_run(struct weston_surface *surface,
 		float start, float end, float k,
 		weston_surface_animation_done_func_t done, void *data);
+
+struct weston_surface_animation *
+weston_move_scale_run(struct weston_surface *surface, int dx, int dy,
+                      float start, float end, int reverse,
+		      weston_surface_animation_done_func_t done, void *data);
 void
 weston_fade_update(struct weston_surface_animation *fade,
 		   float start, float end, float k);
-- 
1.8.1.5



More information about the wayland-devel mailing list