summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_canvas_animation_rotate.c
blob: ba07733275047b027576dc54379e7c8e485d3277 (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
#include "efl_canvas_animation_rotate_private.h"

#define MY_CLASS EFL_CANVAS_ANIMATION_ROTATE_CLASS

EOLIAN static void
_efl_canvas_animation_rotate_rotate_set(Eo *eo_obj EINA_UNUSED,
                                 Efl_Canvas_Animation_Rotate_Data *pd,
                                 double from_degree,
                                 double to_degree,
                                 Efl_Canvas_Object *pivot,
                                 Eina_Vector2 center_point)
{
   pd->from.degree = from_degree;
   pd->to.degree = to_degree;

   //TODO: check whether ref for pivot should be added.
   pd->rel_pivot.obj = pivot;
   pd->rel_pivot.pos = center_point;
   pd->use_rel_pivot = EINA_TRUE;
}

EOLIAN static void
_efl_canvas_animation_rotate_rotate_get(const Eo *eo_obj EINA_UNUSED,
                                 Efl_Canvas_Animation_Rotate_Data *pd,
                                 double *from_degree,
                                 double *to_degree,
                                 Efl_Canvas_Object **pivot,
                                 Eina_Vector2 *center_point)
{
   if (!pd->use_rel_pivot)
     {
        ERR("Animation is done in absolute value.");
        return;
     }

   if (from_degree)
     *from_degree = pd->from.degree;

   if (to_degree)
     *to_degree = pd->to.degree;

   if (pivot)
     *pivot = pd->rel_pivot.obj;

   if (center_point)
     *center_point = pd->rel_pivot.pos;
}

EOLIAN static void
_efl_canvas_animation_rotate_rotate_absolute_set(Eo *eo_obj EINA_UNUSED,
                                          Efl_Canvas_Animation_Rotate_Data *pd,
                                          double from_degree,
                                          double to_degree,
                                          Eina_Position2D abs)
{
   pd->from.degree = from_degree;
   pd->to.degree = to_degree;

   pd->abs_pivot = abs;
   pd->use_rel_pivot = EINA_FALSE;
}

EOLIAN static void
_efl_canvas_animation_rotate_rotate_absolute_get(const Eo *eo_obj EINA_UNUSED,
                                          Efl_Canvas_Animation_Rotate_Data *pd,
                                          double *from_degree,
                                          double *to_degree,
                                          Eina_Position2D *abs)
{
   if (pd->use_rel_pivot)
     {
        ERR("Animation is done in relative value.");
        return;
     }

   if (from_degree)
     *from_degree = pd->from.degree;

   if (to_degree)
     *to_degree = pd->to.degree;

   if (abs)
     *abs = pd->abs_pivot;
}

EOLIAN static double
_efl_canvas_animation_rotate_efl_canvas_animation_animation_apply(Eo *eo_obj,
                                                    Efl_Canvas_Animation_Rotate_Data *pd,
                                                    double progress,
                                                    Efl_Canvas_Object *target)
{
   double new_degree;

   progress = efl_animation_apply(efl_super(eo_obj, MY_CLASS), progress, target);
   if (!target) return progress;

   new_degree = GET_STATUS(pd->from.degree, pd->to.degree, progress);

   if (pd->use_rel_pivot)
     {
        efl_gfx_mapping_rotate(target,
                               new_degree,
                               (pd->rel_pivot.obj) ? pd->rel_pivot.obj : target,
                               pd->rel_pivot.pos.x, pd->rel_pivot.pos.y);
     }
   else
     {
        efl_gfx_mapping_rotate_absolute(target,
                                        new_degree,
                                        pd->abs_pivot.x, pd->abs_pivot.y);
     }

   return progress;
}

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

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

   pd->rel_pivot.obj = NULL;
   pd->rel_pivot.pos.x = 0.5;
   pd->rel_pivot.pos.y = 0.5;

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

   pd->use_rel_pivot = EINA_TRUE;

   return eo_obj;
}

#include "efl_canvas_animation_rotate.eo.c"