blob: 5ded3adc405fd83c70830f3b8b05e0f5a88f2612 [file] [log] [blame]
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +02001/*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
Daniel Stonec228e232013-05-22 18:03:19 +030023#include "config.h"
24
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +020025#include <stdlib.h>
26#include <string.h>
27#include <stdio.h>
28#include <math.h>
29
30#include <unistd.h>
31#include <fcntl.h>
32
33#include "compositor.h"
34
35WL_EXPORT void
36weston_spring_init(struct weston_spring *spring,
Jason Ekstranda7af7042013-10-12 22:38:11 -050037 double k, double current, double target)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +020038{
39 spring->k = k;
40 spring->friction = 400.0;
41 spring->current = current;
42 spring->previous = current;
43 spring->target = target;
Kristian Høgsberg7eec9b32013-06-17 09:15:22 -040044 spring->clip = WESTON_SPRING_OVERSHOOT;
Kristian Høgsberg091b0962013-06-17 09:23:14 -040045 spring->min = 0.0;
46 spring->max = 1.0;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +020047}
48
49WL_EXPORT void
50weston_spring_update(struct weston_spring *spring, uint32_t msec)
51{
52 double force, v, current, step;
53
54 /* Limit the number of executions of the loop below by ensuring that
55 * the timestamp for last update of the spring is no more than 1s ago.
56 * This handles the case where time moves backwards or forwards in
57 * large jumps.
58 */
59 if (msec - spring->timestamp > 1000) {
60 weston_log("unexpectedly large timestamp jump (from %u to %u)\n",
61 spring->timestamp, msec);
62 spring->timestamp = msec - 1000;
63 }
64
65 step = 0.01;
66 while (4 < msec - spring->timestamp) {
67 current = spring->current;
68 v = current - spring->previous;
69 force = spring->k * (spring->target - current) / 10.0 +
70 (spring->previous - current) - v * spring->friction;
71
72 spring->current =
73 current + (current - spring->previous) +
74 force * step * step;
75 spring->previous = current;
76
Kristian Høgsberg7eec9b32013-06-17 09:15:22 -040077 switch (spring->clip) {
78 case WESTON_SPRING_OVERSHOOT:
79 break;
80
81 case WESTON_SPRING_CLAMP:
Kristian Høgsberg091b0962013-06-17 09:23:14 -040082 if (spring->current > spring->max) {
83 spring->current = spring->max;
84 spring->previous = spring->max;
85 } else if (spring->current < 0.0) {
86 spring->current = spring->min;
87 spring->previous = spring->min;
Kristian Høgsberg7eec9b32013-06-17 09:15:22 -040088 }
89 break;
90
91 case WESTON_SPRING_BOUNCE:
Kristian Høgsberg091b0962013-06-17 09:23:14 -040092 if (spring->current > spring->max) {
93 spring->current =
94 2 * spring->max - spring->current;
95 spring->previous =
96 2 * spring->max - spring->previous;
97 } else if (spring->current < spring->min) {
98 spring->current =
99 2 * spring->min - spring->current;
100 spring->previous =
101 2 * spring->min - spring->previous;
Kristian Høgsberg7eec9b32013-06-17 09:15:22 -0400102 }
103 break;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200104 }
105
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200106 spring->timestamp += 4;
107 }
108}
109
110WL_EXPORT int
111weston_spring_done(struct weston_spring *spring)
112{
Kristian Høgsbergc24744e2013-06-17 08:59:20 -0400113 return fabs(spring->previous - spring->target) < 0.002 &&
114 fabs(spring->current - spring->target) < 0.002;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200115}
116
Jason Ekstranda7af7042013-10-12 22:38:11 -0500117typedef void (*weston_view_animation_frame_func_t)(struct weston_view_animation *animation);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200118
Jason Ekstranda7af7042013-10-12 22:38:11 -0500119struct weston_view_animation {
120 struct weston_view *view;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200121 struct weston_animation animation;
122 struct weston_spring spring;
123 struct weston_transform transform;
124 struct wl_listener listener;
125 float start, stop;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500126 weston_view_animation_frame_func_t frame;
127 weston_view_animation_frame_func_t reset;
128 weston_view_animation_done_func_t done;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200129 void *data;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100130 void *private;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200131};
132
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100133WL_EXPORT void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500134weston_view_animation_destroy(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200135{
136 wl_list_remove(&animation->animation.link);
137 wl_list_remove(&animation->listener.link);
138 wl_list_remove(&animation->transform.link);
Axel Davy5e396ae2013-09-17 14:55:55 +0200139 if (animation->reset)
140 animation->reset(animation);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500141 weston_view_geometry_dirty(animation->view);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200142 if (animation->done)
143 animation->done(animation, animation->data);
144 free(animation);
145}
146
147static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500148handle_animation_view_destroy(struct wl_listener *listener, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200149{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500150 struct weston_view_animation *animation =
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200151 container_of(listener,
Jason Ekstranda7af7042013-10-12 22:38:11 -0500152 struct weston_view_animation, listener);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200153
Jason Ekstranda7af7042013-10-12 22:38:11 -0500154 weston_view_animation_destroy(animation);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200155}
156
157static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500158weston_view_animation_frame(struct weston_animation *base,
159 struct weston_output *output, uint32_t msecs)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200160{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500161 struct weston_view_animation *animation =
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200162 container_of(base,
Jason Ekstranda7af7042013-10-12 22:38:11 -0500163 struct weston_view_animation, animation);
Jonny Lambf8bfd052014-05-22 22:41:33 +0200164 struct weston_compositor *compositor =
165 animation->view->surface->compositor;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200166
167 if (base->frame_counter <= 1)
168 animation->spring.timestamp = msecs;
169
170 weston_spring_update(&animation->spring, msecs);
171
172 if (weston_spring_done(&animation->spring)) {
Kristian Høgsberg90dfb112013-10-30 09:07:04 -0700173 weston_view_schedule_repaint(animation->view);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500174 weston_view_animation_destroy(animation);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200175 return;
176 }
177
178 if (animation->frame)
179 animation->frame(animation);
180
Jason Ekstranda7af7042013-10-12 22:38:11 -0500181 weston_view_geometry_dirty(animation->view);
182 weston_view_schedule_repaint(animation->view);
Jonny Lambf8bfd052014-05-22 22:41:33 +0200183
184 /* The view's output_mask will be zero if its position is
185 * offscreen. Animations should always run but as they are also
186 * run off the repaint cycle, if there's nothing to repaint
187 * the animation stops running. Therefore if we catch this situation
188 * and schedule a repaint on all outputs it will be avoided.
189 */
190 if (animation->view->output_mask == 0)
191 weston_compositor_schedule_repaint(compositor);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200192}
193
Jason Ekstranda7af7042013-10-12 22:38:11 -0500194static struct weston_view_animation *
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300195weston_view_animation_create(struct weston_view *view,
196 float start, float stop,
197 weston_view_animation_frame_func_t frame,
198 weston_view_animation_frame_func_t reset,
199 weston_view_animation_done_func_t done,
200 void *data,
201 void *private)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200202{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500203 struct weston_view_animation *animation;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200204
205 animation = malloc(sizeof *animation);
206 if (!animation)
207 return NULL;
208
Jason Ekstranda7af7042013-10-12 22:38:11 -0500209 animation->view = view;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200210 animation->frame = frame;
Axel Davy5e396ae2013-09-17 14:55:55 +0200211 animation->reset = reset;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200212 animation->done = done;
213 animation->data = data;
214 animation->start = start;
215 animation->stop = stop;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100216 animation->private = private;
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300217
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200218 weston_matrix_init(&animation->transform.matrix);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500219 wl_list_insert(&view->geometry.transformation_list,
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200220 &animation->transform.link);
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300221
Jason Ekstranda7af7042013-10-12 22:38:11 -0500222 animation->animation.frame = weston_view_animation_frame;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200223
Jason Ekstranda7af7042013-10-12 22:38:11 -0500224 animation->listener.notify = handle_animation_view_destroy;
225 wl_signal_add(&view->destroy_signal, &animation->listener);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200226
Jason Ekstranda7af7042013-10-12 22:38:11 -0500227 wl_list_insert(&view->output->animation_list,
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200228 &animation->animation.link);
229
230 return animation;
231}
232
233static void
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300234weston_view_animation_run(struct weston_view_animation *animation)
235{
236 animation->animation.frame_counter = 0;
237 weston_view_animation_frame(&animation->animation, NULL, 0);
238}
239
240static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500241reset_alpha(struct weston_view_animation *animation)
Axel Davy5e396ae2013-09-17 14:55:55 +0200242{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500243 struct weston_view *view = animation->view;
Axel Davy5e396ae2013-09-17 14:55:55 +0200244
Jason Ekstranda7af7042013-10-12 22:38:11 -0500245 view->alpha = animation->stop;
Axel Davy5e396ae2013-09-17 14:55:55 +0200246}
247
248static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500249zoom_frame(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200250{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500251 struct weston_view *es = animation->view;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200252 float scale;
253
254 scale = animation->start +
255 (animation->stop - animation->start) *
256 animation->spring.current;
257 weston_matrix_init(&animation->transform.matrix);
258 weston_matrix_translate(&animation->transform.matrix,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600259 -0.5f * es->surface->width,
260 -0.5f * es->surface->height, 0);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200261 weston_matrix_scale(&animation->transform.matrix, scale, scale, scale);
262 weston_matrix_translate(&animation->transform.matrix,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600263 0.5f * es->surface->width,
264 0.5f * es->surface->height, 0);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200265
266 es->alpha = animation->spring.current;
267 if (es->alpha > 1.0)
268 es->alpha = 1.0;
269}
270
Jason Ekstranda7af7042013-10-12 22:38:11 -0500271WL_EXPORT struct weston_view_animation *
272weston_zoom_run(struct weston_view *view, float start, float stop,
273 weston_view_animation_done_func_t done, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200274{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500275 struct weston_view_animation *zoom;
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400276
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300277 zoom = weston_view_animation_create(view, start, stop,
278 zoom_frame, reset_alpha,
279 done, data, NULL);
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400280
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800281 if (zoom == NULL)
282 return NULL;
283
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400284 weston_spring_init(&zoom->spring, 300.0, start, stop);
285 zoom->spring.friction = 1400;
286 zoom->spring.previous = start - (stop - start) * 0.03;
287
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300288 weston_view_animation_run(zoom);
289
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400290 return zoom;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200291}
292
293static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500294fade_frame(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200295{
Ander Conselvan de Oliveira8a913242013-02-21 18:35:18 +0200296 if (animation->spring.current > 0.999)
Jason Ekstranda7af7042013-10-12 22:38:11 -0500297 animation->view->alpha = 1;
Ander Conselvan de Oliveira8a913242013-02-21 18:35:18 +0200298 else if (animation->spring.current < 0.001 )
Jason Ekstranda7af7042013-10-12 22:38:11 -0500299 animation->view->alpha = 0;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200300 else
Jason Ekstranda7af7042013-10-12 22:38:11 -0500301 animation->view->alpha = animation->spring.current;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200302}
303
Jason Ekstranda7af7042013-10-12 22:38:11 -0500304WL_EXPORT struct weston_view_animation *
305weston_fade_run(struct weston_view *view,
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200306 float start, float end, float k,
Jason Ekstranda7af7042013-10-12 22:38:11 -0500307 weston_view_animation_done_func_t done, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200308{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500309 struct weston_view_animation *fade;
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200310
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300311 fade = weston_view_animation_create(view, start, end,
312 fade_frame, reset_alpha,
313 done, data, NULL);
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200314
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800315 if (fade == NULL)
316 return NULL;
317
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300318 weston_spring_init(&fade->spring, 1000.0, start, end);
Kristian Høgsberg3a869012014-03-19 16:45:23 -0700319 fade->spring.friction = 4000;
320 fade->spring.previous = start - (end - start) * 0.1;
Kristian Høgsberg5281fb12013-06-17 10:10:28 -0400321
Jason Ekstranda7af7042013-10-12 22:38:11 -0500322 view->alpha = start;
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200323
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300324 weston_view_animation_run(fade);
325
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200326 return fade;
327}
328
329WL_EXPORT void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500330weston_fade_update(struct weston_view_animation *fade, float target)
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200331{
Kristian Høgsberg5281fb12013-06-17 10:10:28 -0400332 fade->spring.target = target;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200333}
334
335static void
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100336stable_fade_frame(struct weston_view_animation *animation)
337{
338 struct weston_view *back_view;
339
340 if (animation->spring.current > 0.999)
341 animation->view->alpha = 1;
342 else if (animation->spring.current < 0.001 )
343 animation->view->alpha = 0;
344 else
345 animation->view->alpha = animation->spring.current;
346
347 back_view = (struct weston_view *) animation->private;
348 back_view->alpha =
349 (animation->spring.target - animation->view->alpha) /
350 (1.0 - animation->view->alpha);
351 weston_view_geometry_dirty(back_view);
352}
353
354WL_EXPORT struct weston_view_animation *
355weston_stable_fade_run(struct weston_view *front_view, float start,
356 struct weston_view *back_view, float end,
357 weston_view_animation_done_func_t done, void *data)
358{
359 struct weston_view_animation *fade;
360
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300361 fade = weston_view_animation_create(front_view, 0, 0,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100362 stable_fade_frame, NULL,
363 done, data, back_view);
364
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800365 if (fade == NULL)
366 return NULL;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100367
368 weston_spring_init(&fade->spring, 400, start, end);
369 fade->spring.friction = 1150;
370
371 front_view->alpha = start;
372 back_view->alpha = end;
373
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300374 weston_view_animation_run(fade);
375
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100376 return fade;
377}
378
379static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500380slide_frame(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200381{
382 float scale;
383
384 scale = animation->start +
385 (animation->stop - animation->start) *
386 animation->spring.current;
387 weston_matrix_init(&animation->transform.matrix);
388 weston_matrix_translate(&animation->transform.matrix, 0, scale, 0);
389}
390
Jason Ekstranda7af7042013-10-12 22:38:11 -0500391WL_EXPORT struct weston_view_animation *
392weston_slide_run(struct weston_view *view, float start, float stop,
393 weston_view_animation_done_func_t done, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200394{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500395 struct weston_view_animation *animation;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200396
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300397 animation = weston_view_animation_create(view, start, stop,
Jason Ekstranda7af7042013-10-12 22:38:11 -0500398 slide_frame, NULL, done,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100399 data, NULL);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200400 if (!animation)
401 return NULL;
402
Ander Conselvan de Oliveiraa4a6f162014-04-14 15:48:06 +0300403 weston_spring_init(&animation->spring, 400.0, 0.0, 1.0);
Kristian Høgsbergdd2df782013-06-17 10:31:58 -0400404 animation->spring.friction = 600;
Kristian Høgsbergdd2df782013-06-17 10:31:58 -0400405 animation->spring.clip = WESTON_SPRING_BOUNCE;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200406
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300407 weston_view_animation_run(animation);
408
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200409 return animation;
410}
Daniel Stonea67e6b92013-11-19 11:37:13 +0100411
412struct weston_move_animation {
413 int dx;
414 int dy;
415 int reverse;
416 weston_view_animation_done_func_t done;
417};
418
419static void
420move_frame(struct weston_view_animation *animation)
421{
422 struct weston_move_animation *move = animation->private;
423 float scale;
424 float progress = animation->spring.current;
425
426 if (move->reverse)
427 progress = 1.0 - progress;
428
429 scale = animation->start +
430 (animation->stop - animation->start) *
431 progress;
432 weston_matrix_init(&animation->transform.matrix);
433 weston_matrix_scale(&animation->transform.matrix, scale, scale, 1.0f);
434 weston_matrix_translate(&animation->transform.matrix,
435 move->dx * progress, move->dy * progress,
436 0);
437}
438
439static void
440move_done(struct weston_view_animation *animation, void *data)
441{
442 struct weston_move_animation *move = animation->private;
443
444 if (move->done)
445 move->done(animation, data);
446
447 free(move);
448}
449
450WL_EXPORT struct weston_view_animation *
451weston_move_scale_run(struct weston_view *view, int dx, int dy,
452 float start, float end, int reverse,
453 weston_view_animation_done_func_t done, void *data)
454{
455 struct weston_move_animation *move;
456 struct weston_view_animation *animation;
457
458 move = malloc(sizeof(*move));
459 if (!move)
460 return NULL;
461 move->dx = dx;
462 move->dy = dy;
463 move->reverse = reverse;
464 move->done = done;
465
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300466 animation = weston_view_animation_create(view, start, end, move_frame,
467 NULL, move_done, data, move);
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800468
469 if (animation == NULL)
470 return NULL;
471
Jonny Lamb91f80f22014-05-22 22:41:30 +0200472 weston_spring_init(&animation->spring, 400.0, 0.0, 1.0);
Daniel Stonea67e6b92013-11-19 11:37:13 +0100473 animation->spring.friction = 1150;
474
Jonny Lamb91f80f22014-05-22 22:41:30 +0200475 weston_view_animation_run(animation);
476
Daniel Stonea67e6b92013-11-19 11:37:13 +0100477 return animation;
478}