summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_animation_object_alpha.c
blob: f489b314044188e52dc3dc47d28fbc7890698f29 (plain) (blame)
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
#include "efl_animation_object_alpha_private.h"

EOLIAN static void
_efl_animation_object_alpha_alpha_set(Eo *eo_obj,
                                      Efl_Animation_Object_Alpha_Data *pd,
                                      double from_alpha,
                                      double to_alpha)
{
   EFL_ANIMATION_OBJECT_ALPHA_CHECK_OR_RETURN(eo_obj);

   pd->from.alpha = from_alpha;
   pd->to.alpha = to_alpha;
}

EOLIAN static void
_efl_animation_object_alpha_alpha_get(Eo *eo_obj EINA_UNUSED,
                                      Efl_Animation_Object_Alpha_Data *pd,
                                      double *from_alpha,
                                      double *to_alpha)
{
   EFL_ANIMATION_OBJECT_ALPHA_CHECK_OR_RETURN(eo_obj);

   if (from_alpha)
     *from_alpha = pd->from.alpha;
   if (to_alpha)
     *to_alpha = pd->to.alpha;
}

static void
_progress_set(Eo *eo_obj, double progress)
{
   EFL_ANIMATION_OBJECT_ALPHA_DATA_GET(eo_obj, pd);

   Efl_Canvas_Object *target = efl_animation_object_target_get(eo_obj);
   if (!target) return;

   double alpha
      = (pd->from.alpha * (1.0 - progress)) + (pd->to.alpha * progress);

   int r[4], g[4], b[4], a[4];
   int i;
   for (i = 0; i < 4; i++)
     efl_gfx_map_color_get(target, i, &r[i], &g[i], &b[i], &a[i]);

   for (i = 0; i < 4; i++)
     {
        r[i] = (int)(r[i] * alpha);
        g[i] = (int)(g[i] * alpha);
        b[i] = (int)(b[i] * alpha);
        a[i] = (int)(a[i] * alpha);
        efl_gfx_map_color_set(target, i, r[i], g[i], b[i], a[i]);
     }
}

EOLIAN static void
_efl_animation_object_alpha_efl_animation_object_progress_set(Eo *eo_obj,
                                                              Efl_Animation_Object_Alpha_Data *pd EINA_UNUSED,
                                                              double progress)
{
   EFL_ANIMATION_OBJECT_ALPHA_CHECK_OR_RETURN(eo_obj);

   if ((progress < 0.0) || (progress > 1.0)) return;

   _progress_set(eo_obj, progress);

   efl_animation_object_progress_set(efl_super(eo_obj, MY_CLASS), progress);
}

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

   pd->from.alpha = 1.0;
   pd->to.alpha = 1.0;

   return eo_obj;
}

/* Internal EO APIs */

EOAPI EFL_VOID_FUNC_BODYV(efl_animation_object_alpha_set, EFL_FUNC_CALL(from_alpha, to_alpha), double from_alpha, double to_alpha);
EOAPI EFL_VOID_FUNC_BODYV_CONST(efl_animation_object_alpha_get, EFL_FUNC_CALL(from_alpha, to_alpha), double *from_alpha, double *to_alpha);

#define EFL_ANIMATION_OBJECT_ALPHA_EXTRA_OPS \
   EFL_OBJECT_OP_FUNC(efl_animation_object_alpha_set, _efl_animation_object_alpha_alpha_set), \
   EFL_OBJECT_OP_FUNC(efl_animation_object_alpha_get, _efl_animation_object_alpha_alpha_get)

#include "efl_animation_object_alpha.eo.c"