summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_animation_rotate.c
blob: c9ffe524bd41a7bcb75da1cbf78b0a84c55123e0 (plain)
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
#define EFL_ANIMATION_PROTECTED

#include "evas_common_private.h"
#include "evas_private.h"

#define MY_CLASS EFL_ANIMATION_ROTATE_CLASS
#define MY_CLASS_NAME efl_class_name_get(MY_CLASS)

#define EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(anim, ...) \
   do { \
      if (!anim) { \
         CRI("Efl_Animation " # anim " is NULL!"); \
         return __VA_ARGS__; \
      } \
      if (efl_animation_is_deleted(anim)) { \
         ERR("Efl_Animation " # anim " has already been deleted!"); \
         return __VA_ARGS__; \
      } \
   } while (0)

#define EFL_ANIMATION_ROTATE_DATA_GET(o, pd) \
   Evas_Object_Animation_Rotate_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_ROTATE_CLASS)

typedef struct _Evas_Object_Animation_Rotate_Property
{
   double angle;
} Evas_Object_Animation_Rotate_Property;

typedef struct _Evas_Object_Animation_Rotate_Absolute_Pivot
{
   Evas_Coord x, y, z;
} Evas_Object_Animation_Rotate_Absolute_Pivot;

typedef struct _Evas_Object_Animation_Rotate_Relative_Pivot
{
   double x, y, z;
} Evas_Object_Animation_Rotate_Relative_Pivot;


struct _Evas_Object_Animation_Rotate_Data
{
   Evas_Object_Animation_Rotate_Property       from;
   Evas_Object_Animation_Rotate_Property       to;
   Evas_Object_Animation_Rotate_Absolute_Pivot abs_pivot;
   Evas_Object_Animation_Rotate_Relative_Pivot rel_pivot;
   Eina_Bool use_rel_pivot;
};

EOLIAN static void
_efl_animation_rotate_angle_set(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd, double from_angle, double to_angle)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj);

   pd->from.angle = from_angle;

   pd->to.angle = to_angle;
}

EOLIAN static void
_efl_animation_rotate_angle_get(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd, double *from_angle, double *to_angle)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj);

   if (from_angle)
     *from_angle = pd->from.angle;

   if (to_angle)
     *to_angle = pd->to.angle;
}

EOLIAN static void
_efl_animation_rotate_relative_pivot_set(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd, double pivot_x, double pivot_y, double pivot_z)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj);

   pd->rel_pivot.x = pivot_x;
   pd->rel_pivot.y = pivot_y;
   pd->rel_pivot.z = pivot_z;

   pd->use_rel_pivot = EINA_TRUE;
}

EOLIAN static void
_efl_animation_rotate_relative_pivot_get(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd, double *pivot_x, double *pivot_y, double *pivot_z)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj);

   if (pivot_x)
     *pivot_x = pd->rel_pivot.x;

   if (pivot_y)
     *pivot_y = pd->rel_pivot.y;

   if (pivot_z)
     *pivot_z = pd->rel_pivot.z;
}

EOLIAN static void
_efl_animation_rotate_absolute_pivot_set(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd, Evas_Coord pivot_x, Evas_Coord pivot_y, Evas_Coord pivot_z)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj);

   pd->abs_pivot.x = pivot_x;
   pd->abs_pivot.y = pivot_y;
   pd->abs_pivot.z = pivot_z;

   pd->use_rel_pivot = EINA_FALSE;
}

EOLIAN static void
_efl_animation_rotate_absolute_pivot_get(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd, Evas_Coord *pivot_x, Evas_Coord *pivot_y, Evas_Coord *pivot_z)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj);

   if (pivot_x)
     *pivot_x = pd->abs_pivot.x;

   if (pivot_y)
     *pivot_y = pd->abs_pivot.y;

   if (pivot_z)
     *pivot_z = pd->abs_pivot.z;
}

EOLIAN static Efl_Animation *
_efl_animation_rotate_efl_animation_dup(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj, NULL);

   Efl_Animation_Rotate *animation = efl_add(MY_CLASS, NULL);

   double duration = efl_animation_duration_get(eo_obj);
   efl_animation_duration_set(animation, duration);

   Eo *target = efl_animation_target_get(eo_obj);
   efl_animation_target_set(animation, target);

   Eina_Bool state_keep = efl_animation_final_state_keep_get(eo_obj);
   efl_animation_final_state_keep_set(animation, state_keep);

   EFL_ANIMATION_ROTATE_DATA_GET(animation, new_pd);

   new_pd->from.angle = pd->from.angle;
   new_pd->to.angle = pd->to.angle;

   new_pd->rel_pivot.x = pd->rel_pivot.x;
   new_pd->rel_pivot.y = pd->rel_pivot.y;
   new_pd->rel_pivot.z = pd->rel_pivot.z;

   new_pd->abs_pivot.x = pd->rel_pivot.x;
   new_pd->abs_pivot.y = pd->rel_pivot.y;
   new_pd->abs_pivot.z = pd->rel_pivot.z;

   new_pd->use_rel_pivot = pd->use_rel_pivot;

   return animation;
}

EOLIAN static Efl_Animation_Instance *
_efl_animation_rotate_efl_animation_instance_create(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd)
{
   EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj, NULL);

   Efl_Animation_Instance_Rotate *instance
      = efl_add(EFL_ANIMATION_INSTANCE_ROTATE_CLASS, NULL);

   Eo *target = efl_animation_target_get(eo_obj);
   efl_animation_instance_target_set(instance, target);

   Eina_Bool state_keep = efl_animation_final_state_keep_get(eo_obj);
   efl_animation_instance_final_state_keep_set(instance, state_keep);

   double duration = efl_animation_duration_get(eo_obj);
   efl_animation_instance_duration_set(instance, duration);

   efl_animation_instance_rotate_angle_set(instance,
                                           pd->from.angle, pd->to.angle);

   efl_animation_instance_rotate_relative_pivot_set(instance,
                                                    pd->rel_pivot.x,
                                                    pd->rel_pivot.y,
                                                    pd->rel_pivot.z);

   efl_animation_instance_rotate_absolute_pivot_set(instance,
                                                    pd->abs_pivot.x,
                                                    pd->abs_pivot.y,
                                                    pd->abs_pivot.z);

   return instance;
}

EOLIAN static Efl_Object *
_efl_animation_rotate_efl_object_constructor(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd)
{
   eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS));

   pd->from.angle = 0.0;
   pd->to.angle = 0.0;

   pd->rel_pivot.x = 0.5;
   pd->rel_pivot.y = 0.5;
   pd->rel_pivot.z = 0.5;

   pd->abs_pivot.x = 0;
   pd->abs_pivot.y = 0;
   pd->abs_pivot.z = 0;

   pd->use_rel_pivot = EINA_TRUE;

   return eo_obj;
}

EOLIAN static void
_efl_animation_rotate_efl_object_destructor(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd EINA_UNUSED)
{
   efl_destructor(efl_super(eo_obj, MY_CLASS));
}

#include "efl_animation_rotate.eo.c"