summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/efl/interfaces/efl_gfx_color.c120
-rw-r--r--src/lib/efl/interfaces/efl_gfx_color.eo20
-rw-r--r--src/lib/efl/interfaces/efl_interfaces_main.c1
3 files changed, 138 insertions, 3 deletions
diff --git a/src/lib/efl/interfaces/efl_gfx_color.c b/src/lib/efl/interfaces/efl_gfx_color.c
new file mode 100644
index 0000000000..1e65f62977
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_gfx_color.c
@@ -0,0 +1,120 @@
1#include "config.h"
2#include "Efl.h"
3
4static int
5_format_clean_param(Eina_Tmpstr *s)
6{
7 Eina_Tmpstr *ss;
8 char *ds;
9 int len = 0;
10
11 ds = (char*) s;
12 for (ss = s; *ss; ss++, ds++, len++)
13 {
14 if ((*ss == '\\') && *(ss + 1)) ss++;
15 if (ds != ss) *ds = *ss;
16 }
17 *ds = 0;
18
19 return len;
20}
21
22static int
23_hex_string_get(char ch, Eina_Bool *ok)
24{
25 if ((ch >= '0') && (ch <= '9')) return (ch - '0');
26 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
27 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
28 *ok = EINA_FALSE;
29 return 0;
30}
31
32/**
33 * @internal
34 * Parses a string of one of the formas:
35 * 1. "#RRGGBB"
36 * 2. "#RRGGBBAA"
37 * 3. "#RGB"
38 * 4. "#RGBA"
39 * To the rgba values.
40 *
41 * @param[in] str The string to parse - NOT NULL.
42 * @param[out] r The Red value - NOT NULL.
43 * @param[out] g The Green value - NOT NULL.
44 * @param[out] b The Blue value - NOT NULL.
45 * @param[out] a The Alpha value - NOT NULL.
46 */
47static Eina_Bool
48_format_color_parse(const char *str, int slen,
49 unsigned char *r, unsigned char *g,
50 unsigned char *b, unsigned char *a)
51{
52 Eina_Bool v = EINA_TRUE;
53
54 *r = *g = *b = *a = 0;
55
56 if (slen == 7) /* #RRGGBB */
57 {
58 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
59 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
60 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
61 *a = 0xff;
62 }
63 else if (slen == 9) /* #RRGGBBAA */
64 {
65 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
66 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
67 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
68 *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
69 }
70 else if (slen == 4) /* #RGB */
71 {
72 *r = _hex_string_get(str[1], &v);
73 *r = (*r << 4) | *r;
74 *g = _hex_string_get(str[2], &v);
75 *g = (*g << 4) | *g;
76 *b = _hex_string_get(str[3], &v);
77 *b = (*b << 4) | *b;
78 *a = 0xff;
79 }
80 else if (slen == 5) /* #RGBA */
81 {
82 *r = _hex_string_get(str[1], &v);
83 *r = (*r << 4) | *r;
84 *g = _hex_string_get(str[2], &v);
85 *g = (*g << 4) | *g;
86 *b = _hex_string_get(str[3], &v);
87 *b = (*b << 4) | *b;
88 *a = _hex_string_get(str[4], &v);
89 *a = (*a << 4) | *a;
90 }
91 else v = EINA_FALSE;
92
93 *r = (*r * *a) / 255;
94 *g = (*g * *a) / 255;
95 *b = (*b * *a) / 255;
96 return v;
97}
98
99EOLIAN static void
100_efl_gfx_color_color_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *colorcode)
101{
102 int len;
103 unsigned char r, g, b, a;
104
105 len = _format_clean_param(colorcode);
106
107 _format_color_parse(colorcode, len, &r, &g, &b, &a);
108 efl_gfx_color_set(obj, r, g, b, a);
109}
110
111EOLIAN static const char *
112_efl_gfx_color_color_code_get(Eo *obj, void *_pd EINA_UNUSED)
113{
114 int r, g, b, a;
115
116 efl_gfx_color_get(obj, &r, &g, &b, &a);
117 return eina_slstr_printf("#%02X%02X%02X%02X", r, g, b, a);
118}
119
120#include "interfaces/efl_gfx_color.eo.c" \ No newline at end of file
diff --git a/src/lib/efl/interfaces/efl_gfx_color.eo b/src/lib/efl/interfaces/efl_gfx_color.eo
index d6e06f2532..2c2dd4d858 100644
--- a/src/lib/efl/interfaces/efl_gfx_color.eo
+++ b/src/lib/efl/interfaces/efl_gfx_color.eo
@@ -1,6 +1,7 @@
1interface Efl.Gfx.Color 1mixin Efl.Gfx.Color
2{ 2{
3 [[Efl Gfx Color interface class]] 3 [[Efl Gfx Color mixin class]]
4 data: null;
4 methods { 5 methods {
5 @property color @pure_virtual { 6 @property color @pure_virtual {
6 set { 7 set {
@@ -42,5 +43,20 @@ interface Efl.Gfx.Color
42 a: int; 43 a: int;
43 } 44 }
44 } 45 }
46 @property color_code {
47 set {
48 [[Set the color of given Evas object to the given hex color code(#RRGGBBAA).
49 e.g. efl_gfx_color_code_set(obj, "#FFCCAACC");
50 ]]
51 }
52 get {
53 [[Get hex color code of given Evas object.
54 This returns a short lived hex color code string.
55 ]]
56 }
57 values {
58 colorcode: string; [[the hex color code.]]
59 }
60 }
45 } 61 }
46} 62}
diff --git a/src/lib/efl/interfaces/efl_interfaces_main.c b/src/lib/efl/interfaces/efl_interfaces_main.c
index 4c45b95ffd..af61237416 100644
--- a/src/lib/efl/interfaces/efl_interfaces_main.c
+++ b/src/lib/efl/interfaces/efl_interfaces_main.c
@@ -26,7 +26,6 @@
26#include "interfaces/efl_text_markup.eo.c" 26#include "interfaces/efl_text_markup.eo.c"
27 27
28#include "interfaces/efl_gfx.eo.c" 28#include "interfaces/efl_gfx.eo.c"
29#include "interfaces/efl_gfx_color.eo.c"
30#include "interfaces/efl_gfx_buffer.eo.c" 29#include "interfaces/efl_gfx_buffer.eo.c"
31#include "interfaces/efl_gfx_stack.eo.c" 30#include "interfaces/efl_gfx_stack.eo.c"
32#include "interfaces/efl_gfx_fill.eo.c" 31#include "interfaces/efl_gfx_fill.eo.c"