Debian Codegraph @

clutter/deprecated/clutter-behaviour-ellipse.c

raw
1
2 /* -*- mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 /*
4 * Clutter.
5 *
6 * An OpenGL based 'interactive canvas' library.
7 *
8 * Authored By Tomas Frydrych <[email protected]>
9 *
10 * Copyright (C) 2007 OpenedHand Ltd
11 * Copyright (C) 2009 Intel Corp.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27 /**
28 * SECTION:clutter-behaviour-ellipse
29 * @Title: ClutterBehaviourEllipse
30 * @short_description: A behaviour interpolating position along an ellipse
31 * @Deprecated: 1.6: Use clutter_actor_animate() instead
32 *
33 * #ClutterBehaviourEllipse interpolates actors along a path defined by
34 * an ellipse.
35 *
36 * When applying an ellipse behaviour to an actor, the
37 * behaviour will update the actor's position and depth and set them
38 * to what is dictated by the ellipses initial position.
39 *
40 * Deprecated: 1.6: Use clutter_actor_animate(), #ClutterPath and a
41 * #ClutterPathConstraint instead.
42 *
43 * Since: 0.4
44 */
45
46 #ifdef HAVE_CONFIG_H
47 #include "config.h"
48 #endif
49
50 #include <math.h>
51 #include <stdlib.h>
52
53 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
54 #include "deprecated/clutter-actor.h"
55
56 #include "clutter-alpha.h"
57 #include "clutter-behaviour.h"
58 #include "clutter-behaviour-ellipse.h"
59 #include "clutter-debug.h"
60 #include "clutter-enum-types.h"
61 #include "clutter-private.h"
62
63 enum
64 {
65 PROP_0,
66
67 PROP_CENTER,
68 PROP_WIDTH,
69 PROP_HEIGHT,
70 PROP_ANGLE_START,
71 PROP_ANGLE_END,
72 PROP_ANGLE_TILT_X,
73 PROP_ANGLE_TILT_Y,
74 PROP_ANGLE_TILT_Z,
75 PROP_DIRECTION,
76
77 PROP_LAST
78 };
79
80 static GParamSpec *obj_props[PROP_LAST];
81
82 struct _ClutterBehaviourEllipsePrivate
83 {
84 ClutterKnot center;
85
86 /* a = width / 2 */
87 gint a;
88
89 /* b = height / 2 */
90 gint b;
91
92 gdouble angle_start;
93 gdouble angle_end;
94
95 gdouble angle_tilt_x;
96 gdouble angle_tilt_y;
97 gdouble angle_tilt_z;
98
99 ClutterRotateDirection direction;
100 };
101
102 G_DEFINE_TYPE_WITH_PRIVATE (ClutterBehaviourEllipse,
103 clutter_behaviour_ellipse,
104 CLUTTER_TYPE_BEHAVIOUR)
105
106 typedef struct _knot3d
107 {
108 gint x;
109 gint y;
110 gint z;
111 } knot3d;
112
113 static void
114 clutter_behaviour_ellipse_advance (ClutterBehaviourEllipse *e,
115 float angle,
116 knot3d *knot)
117 {
118 ClutterBehaviourEllipsePrivate *priv = e->priv;
119 gint x, y, z;
120
121 x = priv->a * cosf (angle * (G_PI / 180.0));
122 y = priv->b * sinf (angle * (G_PI / 180.0));
123 z = 0;
124
125 if (priv->angle_tilt_z)
126 {
127 /*
128 * x2 = r * cos (angle + tilt_z)
129 * y2 = r * sin (angle + tilt_z)
130 *
131 * These can be trasformed to the formulas below using properties of
132 * sin (a + b) and cos (a + b)
133 *
134 */
135 gfloat x2, y2;
136
137 x2 = x * cosf (priv->angle_tilt_z * (G_PI / 180.0))
138 - y * sinf (priv->angle_tilt_z * (G_PI / 180.0));
139
140 y2 = y * cosf (priv->angle_tilt_z * (G_PI / 180.0))
141 + x * sinf (priv->angle_tilt_z * (G_PI / 180.0));
142
143 x = (x2);
144 y = (y2);
145 }
146
147 if (priv->angle_tilt_x)
148 {
149 gfloat z2, y2;
150
151 z2 = - y * sinf (priv->angle_tilt_x * (G_PI / 180.0));
152 y2 = y * cosf (priv->angle_tilt_x * (G_PI / 180.0));
153
154 z = z2;
155 y = y2;
156 }
157
158 if (priv->angle_tilt_y)
159 {
160 gfloat x2, z2;
161
162 x2 = x * cosf (priv->angle_tilt_y * (G_PI / 180.0))
163 - z * sinf (priv->angle_tilt_y * (G_PI / 180.0));
164
165 z2 = z * cosf (priv->angle_tilt_y * (G_PI / 180.0))
166 + x * sinf (priv->angle_tilt_y * (G_PI / 180.0));
167
168 x = x2;
169 z = z2;
170 }
171
172 knot->x = x;
173 knot->y = y;
174 knot->z = z;
175
176 CLUTTER_NOTE (ANIMATION, "advancing to angle %.2f [%d, %d] (a: %d, b: %d)",
177 angle,
178 knot->x, knot->y,
179 priv->a, priv->b);
180 }
181
182
183 static void
184 actor_apply_knot_foreach (ClutterBehaviour *behave,
185 ClutterActor *actor,
186 gpointer data)
187 {
188 ClutterBehaviourEllipsePrivate *priv;
189 knot3d *knot = data;
190
191 priv = ((ClutterBehaviourEllipse *) behave)->priv;
192
193 clutter_actor_set_position (actor, knot->x, knot->y);
194
195 if (priv->angle_tilt_x != 0 || priv->angle_tilt_y != 0)
196 clutter_actor_set_depth (actor, knot->z);
197 }
198
199 static inline float
200 clamp_angle (float a)
201 {
202 gint rounds;
203
204 rounds = a / 360;
205 if (a < 0)
206 rounds--;
207
208 return a - 360 * rounds;
209 }
210
211 static void
212 clutter_behaviour_ellipse_alpha_notify (ClutterBehaviour *behave,
213 gdouble alpha)
214 {
215 ClutterBehaviourEllipse *self = CLUTTER_BEHAVIOUR_ELLIPSE (behave);
216 ClutterBehaviourEllipsePrivate *priv = self->priv;
217 gfloat start, end;
218 gfloat angle = 0;
219 knot3d knot;
220
221 /* we do everything in single precision because it's easier, even
222 * though all the parameters are stored in double precision for
223 * consistency with the equivalent ClutterActor API
224 */
225 start = priv->angle_start;
226 end = priv->angle_end;
227
228 if (priv->direction == CLUTTER_ROTATE_CW && start >= end)
229 end += 360;
230 else if (priv->direction == CLUTTER_ROTATE_CCW && start <= end)
231 end -= 360;
232
233 angle = (end - start) * alpha + start;
234
235 clutter_behaviour_ellipse_advance (self, angle, &knot);
236
237 knot.x += priv->center.x;
238 knot.y += priv->center.y;
239
240 clutter_behaviour_actors_foreach (behave, actor_apply_knot_foreach, &knot);
241 }
242
243 static void
244 clutter_behaviour_ellipse_set_property (GObject *gobject,
245 guint prop_id,
246 const GValue *value,
247 GParamSpec *pspec)
248 {
249 ClutterBehaviourEllipse *el = CLUTTER_BEHAVIOUR_ELLIPSE (gobject);
250 ClutterBehaviourEllipsePrivate *priv = el->priv;
251
252 switch (prop_id)
253 {
254 case PROP_ANGLE_START:
255 priv->angle_start = g_value_get_double (value);
256 break;
257
258 case PROP_ANGLE_END:
259 priv->angle_end = g_value_get_double (value);
260 break;
261
262 case PROP_ANGLE_TILT_X:
263 priv->angle_tilt_x = g_value_get_double (value);
264 break;
265
266 case PROP_ANGLE_TILT_Y:
267 priv->angle_tilt_y = g_value_get_double (value);
268 break;
269
270 case PROP_ANGLE_TILT_Z:
271 priv->angle_tilt_z = g_value_get_double (value);
272 break;
273
274 case PROP_WIDTH:
275 clutter_behaviour_ellipse_set_width (el, g_value_get_int (value));
276 break;
277
278 case PROP_HEIGHT:
279 clutter_behaviour_ellipse_set_height (el, g_value_get_int (value));
280 break;
281
282 case PROP_CENTER:
283 {
284 ClutterKnot *knot = g_value_get_boxed (value);
285 if (knot)
286 clutter_behaviour_ellipse_set_center (el, knot->x, knot->y);
287 }
288 break;
289
290 case PROP_DIRECTION:
291 priv->direction = g_value_get_enum (value);
292 break;
293
294 default:
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
296 break;
297 }
298 }
299
300 static void
301 clutter_behaviour_ellipse_get_property (GObject *gobject,
302 guint prop_id,
303 GValue *value,
304 GParamSpec *pspec)
305 {
306 ClutterBehaviourEllipsePrivate *priv;
307
308 priv = CLUTTER_BEHAVIOUR_ELLIPSE (gobject)->priv;
309
310 switch (prop_id)
311 {
312 case PROP_ANGLE_START:
313 g_value_set_double (value, priv->angle_start);
314 break;
315
316 case PROP_ANGLE_END:
317 g_value_set_double (value, priv->angle_end);
318 break;
319
320 case PROP_ANGLE_TILT_X:
321 g_value_set_double (value, priv->angle_tilt_x);
322 break;
323
324 case PROP_ANGLE_TILT_Y:
325 g_value_set_double (value, priv->angle_tilt_y);
326 break;
327
328 case PROP_ANGLE_TILT_Z:
329 g_value_set_double (value, priv->angle_tilt_z);
330 break;
331
332 case PROP_WIDTH:
333 g_value_set_int (value, (priv->a * 2));
334 break;
335
336 case PROP_HEIGHT:
337 g_value_set_int (value, (priv->b * 2));
338 break;
339
340 case PROP_CENTER:
341 g_value_set_boxed (value, &priv->center);
342 break;
343
344 case PROP_DIRECTION:
345 g_value_set_enum (value, priv->direction);
346 break;
347
348 default:
349 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
350 break;
351 }
352 }
353
354 static void
355 clutter_behaviour_ellipse_applied (ClutterBehaviour *behave,
356 ClutterActor *actor)
357 {
358 ClutterBehaviourEllipse *e = CLUTTER_BEHAVIOUR_ELLIPSE (behave);
359 ClutterBehaviourEllipsePrivate *priv = e->priv;
360 knot3d knot = { 0, };
361
362 clutter_behaviour_ellipse_advance (e, priv->angle_start, &knot);
363
364 clutter_actor_set_position (actor, knot.x, knot.y);
365
366 /* the depth should be changed only if there is a tilt on
367 * any of the X or the Y axis
368 */
369 if (priv->angle_tilt_x != 0 || priv->angle_tilt_y != 0)
370 clutter_actor_set_depth (actor, knot.z);
371 }
372
373 static void
374 clutter_behaviour_ellipse_class_init (ClutterBehaviourEllipseClass *klass)
375 {
376 GObjectClass *object_class = G_OBJECT_CLASS (klass);
377 ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
378 GParamSpec *pspec = NULL;
379
380 object_class->set_property = clutter_behaviour_ellipse_set_property;
381 object_class->get_property = clutter_behaviour_ellipse_get_property;
382
383 behave_class->alpha_notify = clutter_behaviour_ellipse_alpha_notify;
384 behave_class->applied = clutter_behaviour_ellipse_applied;
385
386 /**
387 * ClutterBehaviourEllipse:angle-start:
388 *
389 * The initial angle from where the rotation should start.
390 *
391 * Since: 0.4
392 */
393 pspec = g_param_spec_double ("angle-start",
394 P_("Start Angle"),
395 P_("Initial angle"),
396 0.0, 360.0,
397 0.0,
398 CLUTTER_PARAM_READWRITE);
399 obj_props[PROP_ANGLE_START] = pspec;
400 g_object_class_install_property (object_class, PROP_ANGLE_START, pspec);
401
402 /**
403 * ClutterBehaviourEllipse:angle-end:
404 *
405 * The final angle to where the rotation should end.
406 *
407 * Since: 0.4
408 */
409 pspec = g_param_spec_double ("angle-end",
410 P_("End Angle"),
411 P_("Final angle"),
412 0.0, 360.0,
413 0.0,
414 CLUTTER_PARAM_READWRITE);
415 obj_props[PROP_ANGLE_END] = pspec;
416 g_object_class_install_property (object_class, PROP_ANGLE_END, pspec);
417
418 /**
419 * ClutterBehaviourEllipse:angle-tilt-x:
420 *
421 * The tilt angle for the rotation around center in X axis
422 *
423 * Since: 0.4
424 */
425 pspec = g_param_spec_double ("angle-tilt-x",
426 P_("Angle x tilt"),
427 P_("Tilt of the ellipse around x axis"),
428 0.0, 360.0,
429 360.0,
430 CLUTTER_PARAM_READWRITE);
431 obj_props[PROP_ANGLE_TILT_X] = pspec;
432 g_object_class_install_property (object_class, PROP_ANGLE_TILT_X, pspec);
433
434 /**
435 * ClutterBehaviourEllipse:angle-tilt-y:
436 *
437 * The tilt angle for the rotation around center in Y axis
438 *
439 * Since: 0.4
440 */
441 pspec = g_param_spec_double ("angle-tilt-y",
442 P_("Angle y tilt"),
443 P_("Tilt of the ellipse around y axis"),
444 0.0, 360.0,
445 360.0,
446 CLUTTER_PARAM_READWRITE);
447 obj_props[PROP_ANGLE_TILT_Y] = pspec;
448 g_object_class_install_property (object_class, PROP_ANGLE_TILT_Y, pspec);
449
450 /**
451 * ClutterBehaviourEllipse:angle-tilt-z:
452 *
453 * The tilt angle for the rotation on the Z axis
454 *
455 * Since: 0.4
456 */
457 pspec = g_param_spec_double ("angle-tilt-z",
458 P_("Angle z tilt"),
459 P_("Tilt of the ellipse around z axis"),
460 0.0, 360.0,
461 360.0,
462 CLUTTER_PARAM_READWRITE);
463 obj_props[PROP_ANGLE_TILT_Z] = pspec;
464 g_object_class_install_property (object_class, PROP_ANGLE_TILT_Z, pspec);
465
466 /**
467 * ClutterBehaviourEllipse:width:
468 *
469 * Width of the ellipse, in pixels
470 *
471 * Since: 0.4
472 */
473 pspec = g_param_spec_int ("width",
474 P_("Width"),
475 P_("Width of the ellipse"),
476 0, G_MAXINT,
477 100,
478 CLUTTER_PARAM_READWRITE);
479 obj_props[PROP_WIDTH] = pspec;
480 g_object_class_install_property (object_class, PROP_WIDTH, pspec);
481
482 /**
483 * ClutterBehaviourEllipse:height:
484 *
485 * Height of the ellipse, in pixels
486 *
487 * Since: 0.4
488 */
489 pspec = g_param_spec_int ("height",
490 P_("Height"),
491 P_("Height of ellipse"),
492 0, G_MAXINT,
493 50,
494 CLUTTER_PARAM_READWRITE);
495 obj_props[PROP_HEIGHT] = pspec;
496 g_object_class_install_property (object_class, PROP_HEIGHT, pspec);
497
498 /**
499 * ClutterBehaviourEllipse:center:
500 *
501 * The center of the ellipse.
502 *
503 * Since: 0.4
504 */
505 pspec = g_param_spec_boxed ("center",
506 P_("Center"),
507 P_("Center of ellipse"),
508 CLUTTER_TYPE_KNOT,
509 CLUTTER_PARAM_READWRITE);
510 obj_props[PROP_CENTER] = pspec;
511 g_object_class_install_property (object_class, PROP_CENTER, pspec);
512
513 /**
514 * ClutterBehaviourEllipse:direction:
515 *
516 * The direction of the rotation.
517 *
518 * Since: 0.4
519 */
520 pspec = g_param_spec_enum ("direction",
521 P_("Direction"),
522 P_("Direction of rotation"),
523 CLUTTER_TYPE_ROTATE_DIRECTION,
524 CLUTTER_ROTATE_CW,
525 CLUTTER_PARAM_READWRITE);
526 obj_props[PROP_DIRECTION] = pspec;
527 g_object_class_install_property (object_class, PROP_DIRECTION, pspec);
528 }
529
530 static void
531 clutter_behaviour_ellipse_init (ClutterBehaviourEllipse * self)
532 {
533 ClutterBehaviourEllipsePrivate *priv;
534
535 self->priv = priv = clutter_behaviour_ellipse_get_instance_private (self);
536
537 priv->direction = CLUTTER_ROTATE_CW;
538
539 priv->angle_start = 0;
540 priv->angle_end = 0;
541
542 priv->a = 50;
543 priv->b = 25;
544
545 priv->angle_tilt_x = 360;
546 priv->angle_tilt_y = 360;
547 priv->angle_tilt_z = 360;
548 }
549
550 /**
551 * clutter_behaviour_ellipse_new:
552 * @alpha: (allow-none): a #ClutterAlpha instance, or %NULL
553 * @x: x coordinace of the center
554 * @y: y coordiance of the center
555 * @width: width of the ellipse
556 * @height: height of the ellipse
557 * @direction: #ClutterRotateDirection of rotation
558 * @start: angle in degrees at which movement starts, between 0 and 360
559 * @end: angle in degrees at which movement ends, between 0 and 360
560 *
561 * Creates a behaviour that drives actors along an elliptical path with
562 * given center, width and height; the movement starts at @start
563 * degrees (with 0 corresponding to 12 o'clock) and ends at @end
564 * degrees. Angles greated than 360 degrees get clamped to the canonical
565 * interval <0, 360); if @start is equal to @end, the behaviour will
566 * rotate by exacly 360 degrees.
567 *
568 * If @alpha is not %NULL, the #ClutterBehaviour will take ownership
569 * of the #ClutterAlpha instance. In the case when @alpha is %NULL,
570 * it can be set later with clutter_behaviour_set_alpha().
571 *
572 * Return value: the newly created #ClutterBehaviourEllipse
573 *
574 * Since: 0.4
575 */
576 ClutterBehaviour *
577 clutter_behaviour_ellipse_new (ClutterAlpha *alpha,
578 gint x,
579 gint y,
580 gint width,
581 gint height,
582 ClutterRotateDirection direction,
583 gdouble start,
584 gdouble end)
585 {
586 ClutterKnot center;
587
588 g_return_val_if_fail (alpha == NULL || CLUTTER_IS_ALPHA (alpha), NULL);
589
590 center.x = x;
591 center.y = y;
592
593 return g_object_new (CLUTTER_TYPE_BEHAVIOUR_ELLIPSE,
594 "alpha", alpha,
595 "center", &center,
596 "width", width,
597 "height", height,
598 "direction", direction,
599 "angle-start", start,
600 "angle-end", end,
601 NULL);
602 }
603
604 /**
605 * clutter_behaviour_ellipse_set_center:
606 * @self: a #ClutterBehaviourEllipse
607 * @x: x coordinace of centre
608 * @y: y coordinace of centre
609 *
610 * Sets the center of the elliptical path to the point represented by knot.
611 *
612 * Since: 0.4
613 */
614 void
615 clutter_behaviour_ellipse_set_center (ClutterBehaviourEllipse *self,
616 gint x,
617 gint y)
618 {
619 ClutterBehaviourEllipsePrivate *priv;
620
621 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
622
623 priv = self->priv;
624
625 if (priv->center.x != x || priv->center.y != y)
626 {
627 priv->center.x = x;
628 priv->center.y = y;
629
630 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CENTER]);
631 }
632 }
633
634 /**
635 * clutter_behaviour_ellipse_get_center:
636 * @self: a #ClutterBehaviourEllipse
637 * @x: (out): return location for the X coordinate of the center, or %NULL
638 * @y: (out): return location for the Y coordinate of the center, or %NULL
639 *
640 * Gets the center of the elliptical path path.
641 *
642 * Since: 0.4
643 */
644 void
645 clutter_behaviour_ellipse_get_center (ClutterBehaviourEllipse *self,
646 gint *x,
647 gint *y)
648 {
649 ClutterBehaviourEllipsePrivate *priv;
650
651 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
652
653 priv = self->priv;
654
655 if (x)
656 *x = priv->center.x;
657
658 if (y)
659 *y = priv->center.y;
660 }
661
662
663 /**
664 * clutter_behaviour_ellipse_set_width:
665 * @self: a #ClutterBehaviourEllipse
666 * @width: width of the ellipse
667 *
668 * Sets the width of the elliptical path.
669 *
670 * Since: 0.4
671 */
672 void
673 clutter_behaviour_ellipse_set_width (ClutterBehaviourEllipse *self,
674 gint width)
675 {
676 ClutterBehaviourEllipsePrivate *priv;
677
678 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
679
680 priv = self->priv;
681
682 if (priv->a != width / 2)
683 {
684 priv->a = width / 2;
685
686 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_WIDTH]);
687 }
688 }
689
690 /**
691 * clutter_behaviour_ellipse_get_width:
692 * @self: a #ClutterBehaviourEllipse
693 *
694 * Gets the width of the elliptical path.
695 *
696 * Return value: the width of the path
697 *
698 * Since: 0.4
699 */
700 gint
701 clutter_behaviour_ellipse_get_width (ClutterBehaviourEllipse *self)
702 {
703 g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self), 0);
704
705 return self->priv->a * 2;
706 }
707
708 /**
709 * clutter_behaviour_ellipse_set_height:
710 * @self: a #ClutterBehaviourEllipse
711 * @height: height of the ellipse
712 *
713 * Sets the height of the elliptical path.
714 *
715 * Since: 0.4
716 */
717 void
718 clutter_behaviour_ellipse_set_height (ClutterBehaviourEllipse *self,
719 gint height)
720 {
721 ClutterBehaviourEllipsePrivate *priv;
722
723 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
724
725 priv = self->priv;
726
727 if (priv->b != height / 2)
728 {
729 priv->b = height / 2;
730
731 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_HEIGHT]);
732 }
733 }
734
735 /**
736 * clutter_behaviour_ellipse_get_height:
737 * @self: a #ClutterBehaviourEllipse
738 *
739 * Gets the height of the elliptical path.
740 *
741 * Return value: the height of the path
742 *
743 * Since: 0.4
744 */
745 gint
746 clutter_behaviour_ellipse_get_height (ClutterBehaviourEllipse *self)
747 {
748 g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self), 0);
749
750 return self->priv->b * 2;
751 }
752
753 /**
754 * clutter_behaviour_ellipse_set_angle_start:
755 * @self: a #ClutterBehaviourEllipse
756 * @angle_start: angle at which movement starts in degrees, between 0 and 360.
757 *
758 * Sets the angle at which movement starts; angles >= 360 degress get clamped
759 * to the canonical interval <0, 360).
760 *
761 * Since: 0.6
762 */
763 void
764 clutter_behaviour_ellipse_set_angle_start (ClutterBehaviourEllipse *self,
765 gdouble angle_start)
766 {
767 ClutterBehaviourEllipsePrivate *priv;
768 gdouble new_angle;
769
770 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
771
772 new_angle = clamp_angle (angle_start);
773
774 priv = self->priv;
775
776 if (priv->angle_start != new_angle)
777 {
778 priv->angle_start = new_angle;
779 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_START]);
780 }
781 }
782
783 /**
784 * clutter_behaviour_ellipse_get_angle_start:
785 * @self: a #ClutterBehaviourEllipse
786 *
787 * Gets the angle at which movements starts.
788 *
789 * Return value: angle in degrees
790 *
791 * Since: 0.6
792 */
793 gdouble
794 clutter_behaviour_ellipse_get_angle_start (ClutterBehaviourEllipse *self)
795 {
796 g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self), 0.0);
797
798 return self->priv->angle_start;
799 }
800
801 /**
802 * clutter_behaviour_ellipse_set_angle_end:
803 * @self: a #ClutterBehaviourEllipse
804 * @angle_end: angle at which movement ends in degrees, between 0 and 360.
805 *
806 * Sets the angle at which movement ends; angles >= 360 degress get clamped
807 * to the canonical interval <0, 360).
808 *
809 * Since: 0.4
810 */
811 void
812 clutter_behaviour_ellipse_set_angle_end (ClutterBehaviourEllipse *self,
813 gdouble angle_end)
814 {
815 ClutterBehaviourEllipsePrivate *priv;
816 gdouble new_angle;
817
818 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
819
820 new_angle = clamp_angle (angle_end);
821
822 priv = self->priv;
823
824 if (priv->angle_end != new_angle)
825 {
826 priv->angle_end = new_angle;
827
828 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_END]);
829 }
830 }
831
832 /**
833 * clutter_behaviour_ellipse_get_angle_end:
834 * @self: a #ClutterBehaviourEllipse
835 *
836 * Gets the at which movements ends.
837 *
838 * Return value: angle in degrees
839 *
840 * Since: 0.4
841 */
842 gdouble
843 clutter_behaviour_ellipse_get_angle_end (ClutterBehaviourEllipse *self)
844 {
845 g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self), 0.0);
846
847 return self->priv->angle_end;
848 }
849
850 /**
851 * clutter_behaviour_ellipse_set_angle_tilt:
852 * @self: a #ClutterBehaviourEllipse
853 * @axis: a #ClutterRotateAxis
854 * @angle_tilt: tilt of the elipse around the center in the given axis in
855 * degrees.
856 *
857 * Sets the angle at which the ellipse should be tilted around it's center.
858 *
859 * Since: 0.4
860 */
861 void
862 clutter_behaviour_ellipse_set_angle_tilt (ClutterBehaviourEllipse *self,
863 ClutterRotateAxis axis,
864 gdouble angle_tilt)
865 {
866 ClutterBehaviourEllipsePrivate *priv;
867
868 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
869
870 priv = self->priv;
871
872 switch (axis)
873 {
874 case CLUTTER_X_AXIS:
875 if (priv->angle_tilt_x != angle_tilt)
876 {
877 priv->angle_tilt_x = angle_tilt;
878
879 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_TILT_X]);
880 }
881 break;
882
883 case CLUTTER_Y_AXIS:
884 if (priv->angle_tilt_y != angle_tilt)
885 {
886 priv->angle_tilt_y = angle_tilt;
887
888 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_TILT_Y]);
889 }
890 break;
891
892 case CLUTTER_Z_AXIS:
893 if (priv->angle_tilt_z != angle_tilt)
894 {
895 priv->angle_tilt_z = angle_tilt;
896
897 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_TILT_Z]);
898 }
899 break;
900 }
901 }
902
903 /**
904 * clutter_behaviour_ellipse_get_angle_tilt:
905 * @self: a #ClutterBehaviourEllipse
906 * @axis: a #ClutterRotateAxis
907 *
908 * Gets the tilt of the ellipse around the center in the given axis.
909 *
910 * Return value: angle in degrees.
911 *
912 * Since: 0.4
913 */
914 gdouble
915 clutter_behaviour_ellipse_get_angle_tilt (ClutterBehaviourEllipse *self,
916 ClutterRotateAxis axis)
917 {
918 g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self), 0.0);
919
920 switch (axis)
921 {
922 case CLUTTER_X_AXIS:
923 return self->priv->angle_tilt_x;
924
925 case CLUTTER_Y_AXIS:
926 return self->priv->angle_tilt_y;
927
928 case CLUTTER_Z_AXIS:
929 return self->priv->angle_tilt_z;
930 }
931
932 return 0.0;
933 }
934
935 /**
936 * clutter_behaviour_ellipse_set_tilt:
937 * @self: a #ClutterBehaviourEllipse
938 * @angle_tilt_x: tilt of the elipse around the center in X axis in degrees.
939 * @angle_tilt_y: tilt of the elipse around the center in Y axis in degrees.
940 * @angle_tilt_z: tilt of the elipse around the center in Z axis in degrees.
941 *
942 * Sets the angles at which the ellipse should be tilted around it's center.
943 *
944 * Since: 0.4
945 */
946 void
947 clutter_behaviour_ellipse_set_tilt (ClutterBehaviourEllipse *self,
948 gdouble angle_tilt_x,
949 gdouble angle_tilt_y,
950 gdouble angle_tilt_z)
951 {
952 ClutterBehaviourEllipsePrivate *priv;
953
954 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
955
956 priv = self->priv;
957
958 g_object_freeze_notify (G_OBJECT (self));
959
960 if (priv->angle_tilt_x != angle_tilt_x)
961 {
962 priv->angle_tilt_x = angle_tilt_x;
963
964 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_TILT_X]);
965 }
966
967 if (priv->angle_tilt_y != angle_tilt_y)
968 {
969 priv->angle_tilt_y = angle_tilt_y;
970
971 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_TILT_Y]);
972 }
973
974 if (priv->angle_tilt_z != angle_tilt_z)
975 {
976 priv->angle_tilt_z = angle_tilt_z;
977
978 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ANGLE_TILT_Z]);
979 }
980
981 g_object_thaw_notify (G_OBJECT (self));
982 }
983
984 /**
985 * clutter_behaviour_ellipse_get_tilt:
986 * @self: a #ClutterBehaviourEllipse
987 * @angle_tilt_x: (out): return location for tilt angle on the X axis, or %NULL.
988 * @angle_tilt_y: (out): return location for tilt angle on the Y axis, or %NULL.
989 * @angle_tilt_z: (out): return location for tilt angle on the Z axis, or %NULL.
990 *
991 * Gets the tilt of the ellipse around the center in Y axis.
992 *
993 * Since: 0.4
994 */
995 void
996 clutter_behaviour_ellipse_get_tilt (ClutterBehaviourEllipse *self,
997 gdouble *angle_tilt_x,
998 gdouble *angle_tilt_y,
999 gdouble *angle_tilt_z)
1000 {
1001 ClutterBehaviourEllipsePrivate *priv;
1002
1003 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
1004
1005 priv = self->priv;
1006
1007 if (angle_tilt_x)
1008 *angle_tilt_x = priv->angle_tilt_x;
1009
1010 if (angle_tilt_y)
1011 *angle_tilt_y = priv->angle_tilt_y;
1012
1013 if (angle_tilt_z)
1014 *angle_tilt_z = priv->angle_tilt_z;
1015 }
1016
1017 /**
1018 * clutter_behaviour_ellipse_get_direction:
1019 * @self: a #ClutterBehaviourEllipse
1020 *
1021 * Retrieves the #ClutterRotateDirection used by the ellipse behaviour.
1022 *
1023 * Return value: the rotation direction
1024 *
1025 * Since: 0.4
1026 */
1027 ClutterRotateDirection
1028 clutter_behaviour_ellipse_get_direction (ClutterBehaviourEllipse *self)
1029 {
1030 g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self),
1031 CLUTTER_ROTATE_CW);
1032
1033 return self->priv->direction;
1034 }
1035
1036 /**
1037 * clutter_behaviour_ellipse_set_direction:
1038 * @self: a #ClutterBehaviourEllipse
1039 * @direction: the rotation direction
1040 *
1041 * Sets the rotation direction used by the ellipse behaviour.
1042 *
1043 * Since: 0.4
1044 */
1045 void
1046 clutter_behaviour_ellipse_set_direction (ClutterBehaviourEllipse *self,
1047 ClutterRotateDirection direction)
1048 {
1049 ClutterBehaviourEllipsePrivate *priv;
1050
1051 g_return_if_fail (CLUTTER_IS_BEHAVIOUR_ELLIPSE (self));
1052
1053 priv = self->priv;
1054
1055 if (priv->direction != direction)
1056 {
1057 priv->direction = direction;
1058
1059 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_DIRECTION]);
1060 }
1061 }