blob: a29b34adcaf27e0ea172a79e45a42f83f578ac7e [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);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200164
165 if (base->frame_counter <= 1)
166 animation->spring.timestamp = msecs;
167
168 weston_spring_update(&animation->spring, msecs);
169
170 if (weston_spring_done(&animation->spring)) {
Kristian Høgsberg90dfb112013-10-30 09:07:04 -0700171 weston_view_schedule_repaint(animation->view);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500172 weston_view_animation_destroy(animation);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200173 return;
174 }
175
176 if (animation->frame)
177 animation->frame(animation);
178
Jason Ekstranda7af7042013-10-12 22:38:11 -0500179 weston_view_geometry_dirty(animation->view);
180 weston_view_schedule_repaint(animation->view);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200181}
182
Jason Ekstranda7af7042013-10-12 22:38:11 -0500183static struct weston_view_animation *
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300184weston_view_animation_create(struct weston_view *view,
185 float start, float stop,
186 weston_view_animation_frame_func_t frame,
187 weston_view_animation_frame_func_t reset,
188 weston_view_animation_done_func_t done,
189 void *data,
190 void *private)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200191{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500192 struct weston_view_animation *animation;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200193
194 animation = malloc(sizeof *animation);
195 if (!animation)
196 return NULL;
197
Jason Ekstranda7af7042013-10-12 22:38:11 -0500198 animation->view = view;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200199 animation->frame = frame;
Axel Davy5e396ae2013-09-17 14:55:55 +0200200 animation->reset = reset;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200201 animation->done = done;
202 animation->data = data;
203 animation->start = start;
204 animation->stop = stop;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100205 animation->private = private;
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300206
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200207 weston_matrix_init(&animation->transform.matrix);
Jason Ekstranda7af7042013-10-12 22:38:11 -0500208 wl_list_insert(&view->geometry.transformation_list,
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200209 &animation->transform.link);
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300210
Jason Ekstranda7af7042013-10-12 22:38:11 -0500211 animation->animation.frame = weston_view_animation_frame;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200212
Jason Ekstranda7af7042013-10-12 22:38:11 -0500213 animation->listener.notify = handle_animation_view_destroy;
214 wl_signal_add(&view->destroy_signal, &animation->listener);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200215
Jason Ekstranda7af7042013-10-12 22:38:11 -0500216 wl_list_insert(&view->output->animation_list,
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200217 &animation->animation.link);
218
219 return animation;
220}
221
222static void
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300223weston_view_animation_run(struct weston_view_animation *animation)
224{
225 animation->animation.frame_counter = 0;
226 weston_view_animation_frame(&animation->animation, NULL, 0);
227}
228
229static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500230reset_alpha(struct weston_view_animation *animation)
Axel Davy5e396ae2013-09-17 14:55:55 +0200231{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500232 struct weston_view *view = animation->view;
Axel Davy5e396ae2013-09-17 14:55:55 +0200233
Jason Ekstranda7af7042013-10-12 22:38:11 -0500234 view->alpha = animation->stop;
Axel Davy5e396ae2013-09-17 14:55:55 +0200235}
236
237static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500238zoom_frame(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200239{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500240 struct weston_view *es = animation->view;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200241 float scale;
242
243 scale = animation->start +
244 (animation->stop - animation->start) *
245 animation->spring.current;
246 weston_matrix_init(&animation->transform.matrix);
247 weston_matrix_translate(&animation->transform.matrix,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600248 -0.5f * es->surface->width,
249 -0.5f * es->surface->height, 0);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200250 weston_matrix_scale(&animation->transform.matrix, scale, scale, scale);
251 weston_matrix_translate(&animation->transform.matrix,
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600252 0.5f * es->surface->width,
253 0.5f * es->surface->height, 0);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200254
255 es->alpha = animation->spring.current;
256 if (es->alpha > 1.0)
257 es->alpha = 1.0;
258}
259
Jason Ekstranda7af7042013-10-12 22:38:11 -0500260WL_EXPORT struct weston_view_animation *
261weston_zoom_run(struct weston_view *view, float start, float stop,
262 weston_view_animation_done_func_t done, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200263{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500264 struct weston_view_animation *zoom;
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400265
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300266 zoom = weston_view_animation_create(view, start, stop,
267 zoom_frame, reset_alpha,
268 done, data, NULL);
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400269
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800270 if (zoom == NULL)
271 return NULL;
272
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400273 weston_spring_init(&zoom->spring, 300.0, start, stop);
274 zoom->spring.friction = 1400;
275 zoom->spring.previous = start - (stop - start) * 0.03;
276
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300277 weston_view_animation_run(zoom);
278
Kristian Høgsberg1cfd4062013-06-17 11:08:11 -0400279 return zoom;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200280}
281
282static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500283fade_frame(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200284{
Ander Conselvan de Oliveira8a913242013-02-21 18:35:18 +0200285 if (animation->spring.current > 0.999)
Jason Ekstranda7af7042013-10-12 22:38:11 -0500286 animation->view->alpha = 1;
Ander Conselvan de Oliveira8a913242013-02-21 18:35:18 +0200287 else if (animation->spring.current < 0.001 )
Jason Ekstranda7af7042013-10-12 22:38:11 -0500288 animation->view->alpha = 0;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200289 else
Jason Ekstranda7af7042013-10-12 22:38:11 -0500290 animation->view->alpha = animation->spring.current;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200291}
292
Jason Ekstranda7af7042013-10-12 22:38:11 -0500293WL_EXPORT struct weston_view_animation *
294weston_fade_run(struct weston_view *view,
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200295 float start, float end, float k,
Jason Ekstranda7af7042013-10-12 22:38:11 -0500296 weston_view_animation_done_func_t done, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200297{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500298 struct weston_view_animation *fade;
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200299
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300300 fade = weston_view_animation_create(view, start, end,
301 fade_frame, reset_alpha,
302 done, data, NULL);
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200303
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800304 if (fade == NULL)
305 return NULL;
306
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300307 weston_spring_init(&fade->spring, 1000.0, start, end);
Kristian Høgsberg3a869012014-03-19 16:45:23 -0700308 fade->spring.friction = 4000;
309 fade->spring.previous = start - (end - start) * 0.1;
Kristian Høgsberg5281fb12013-06-17 10:10:28 -0400310
Jason Ekstranda7af7042013-10-12 22:38:11 -0500311 view->alpha = start;
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200312
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300313 weston_view_animation_run(fade);
314
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200315 return fade;
316}
317
318WL_EXPORT void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500319weston_fade_update(struct weston_view_animation *fade, float target)
Ander Conselvan de Oliveiraee416052013-02-21 18:35:17 +0200320{
Kristian Høgsberg5281fb12013-06-17 10:10:28 -0400321 fade->spring.target = target;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200322}
323
324static void
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100325stable_fade_frame(struct weston_view_animation *animation)
326{
327 struct weston_view *back_view;
328
329 if (animation->spring.current > 0.999)
330 animation->view->alpha = 1;
331 else if (animation->spring.current < 0.001 )
332 animation->view->alpha = 0;
333 else
334 animation->view->alpha = animation->spring.current;
335
336 back_view = (struct weston_view *) animation->private;
337 back_view->alpha =
338 (animation->spring.target - animation->view->alpha) /
339 (1.0 - animation->view->alpha);
340 weston_view_geometry_dirty(back_view);
341}
342
343WL_EXPORT struct weston_view_animation *
344weston_stable_fade_run(struct weston_view *front_view, float start,
345 struct weston_view *back_view, float end,
346 weston_view_animation_done_func_t done, void *data)
347{
348 struct weston_view_animation *fade;
349
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300350 fade = weston_view_animation_create(front_view, 0, 0,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100351 stable_fade_frame, NULL,
352 done, data, back_view);
353
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800354 if (fade == NULL)
355 return NULL;
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100356
357 weston_spring_init(&fade->spring, 400, start, end);
358 fade->spring.friction = 1150;
359
360 front_view->alpha = start;
361 back_view->alpha = end;
362
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300363 weston_view_animation_run(fade);
364
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100365 return fade;
366}
367
368static void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500369slide_frame(struct weston_view_animation *animation)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200370{
371 float scale;
372
373 scale = animation->start +
374 (animation->stop - animation->start) *
375 animation->spring.current;
376 weston_matrix_init(&animation->transform.matrix);
377 weston_matrix_translate(&animation->transform.matrix, 0, scale, 0);
378}
379
Jason Ekstranda7af7042013-10-12 22:38:11 -0500380WL_EXPORT struct weston_view_animation *
381weston_slide_run(struct weston_view *view, float start, float stop,
382 weston_view_animation_done_func_t done, void *data)
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200383{
Jason Ekstranda7af7042013-10-12 22:38:11 -0500384 struct weston_view_animation *animation;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200385
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300386 animation = weston_view_animation_create(view, start, stop,
Jason Ekstranda7af7042013-10-12 22:38:11 -0500387 slide_frame, NULL, done,
Louis-Francis Ratté-Boulianneb482dbd2013-11-19 11:37:11 +0100388 data, NULL);
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200389 if (!animation)
390 return NULL;
391
Ander Conselvan de Oliveiraa4a6f162014-04-14 15:48:06 +0300392 weston_spring_init(&animation->spring, 400.0, 0.0, 1.0);
Kristian Høgsbergdd2df782013-06-17 10:31:58 -0400393 animation->spring.friction = 600;
Kristian Høgsbergdd2df782013-06-17 10:31:58 -0400394 animation->spring.clip = WESTON_SPRING_BOUNCE;
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200395
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300396 weston_view_animation_run(animation);
397
Ander Conselvan de Oliveiracbdebc22013-02-21 18:35:16 +0200398 return animation;
399}
Daniel Stonea67e6b92013-11-19 11:37:13 +0100400
401struct weston_move_animation {
402 int dx;
403 int dy;
404 int reverse;
405 weston_view_animation_done_func_t done;
406};
407
408static void
409move_frame(struct weston_view_animation *animation)
410{
411 struct weston_move_animation *move = animation->private;
412 float scale;
413 float progress = animation->spring.current;
414
415 if (move->reverse)
416 progress = 1.0 - progress;
417
418 scale = animation->start +
419 (animation->stop - animation->start) *
420 progress;
421 weston_matrix_init(&animation->transform.matrix);
422 weston_matrix_scale(&animation->transform.matrix, scale, scale, 1.0f);
423 weston_matrix_translate(&animation->transform.matrix,
424 move->dx * progress, move->dy * progress,
425 0);
426}
427
428static void
429move_done(struct weston_view_animation *animation, void *data)
430{
431 struct weston_move_animation *move = animation->private;
432
433 if (move->done)
434 move->done(animation, data);
435
436 free(move);
437}
438
439WL_EXPORT struct weston_view_animation *
440weston_move_scale_run(struct weston_view *view, int dx, int dy,
441 float start, float end, int reverse,
442 weston_view_animation_done_func_t done, void *data)
443{
444 struct weston_move_animation *move;
445 struct weston_view_animation *animation;
446
447 move = malloc(sizeof(*move));
448 if (!move)
449 return NULL;
450 move->dx = dx;
451 move->dy = dy;
452 move->reverse = reverse;
453 move->done = done;
454
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300455 animation = weston_view_animation_create(view, start, end, move_frame,
456 NULL, move_done, data, move);
U. Artie Eoffa62e0e02014-01-17 15:08:51 -0800457
458 if (animation == NULL)
459 return NULL;
460
Ander Conselvan de Oliveiraf5cc2b52014-04-14 15:48:05 +0300461 weston_spring_init(&animation->spring, 400.0, start, end);
Daniel Stonea67e6b92013-11-19 11:37:13 +0100462 animation->spring.friction = 1150;
463
464 return animation;
465}