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