[elc_naviframe]: As hide signal was sent twice, control bar was hidden
[framework/uifw/elementary.git] / src / lib / elm_colorselector.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 #define BASE_STEP 360.0
5 #define HUE_STEP 360.0
6 #define SAT_STEP 128.0
7 #define LIG_STEP 256.0
8 #define ALP_STEP 256.0
9
10 typedef enum _Color_Type
11 {
12    HUE,
13    SATURATION,
14    LIGHTNESS,
15    ALPHA
16 } Color_Type;
17
18 typedef struct _Colorselector_Data Colorselector_Data;
19 struct _Colorselector_Data
20 {
21    Evas_Object *parent;
22    Evas_Object *colorbar;
23    Evas_Object *bar;
24    Evas_Object *lbt;
25    Evas_Object *rbt;
26    Evas_Object *bg_rect;
27    Evas_Object *arrow;
28    Evas_Object *touch_area;
29    Color_Type color_type;
30 };
31
32 typedef struct _Widget_Data Widget_Data;
33 struct _Widget_Data
34 {
35    Evas_Object *base;
36    Colorselector_Data *cp[4];
37    Evas_Coord _x, _y, _w, _h;
38    int r, g, b, a;
39    int er, eg, eb;
40    int sr, sg, sb;
41    int lr, lg, lb;
42    double h, s, l;
43 };
44
45 static const char *widtype = NULL;
46
47 static void _del_hook(Evas_Object *obj);
48 static void _theme_hook(Evas_Object *obj);
49 static void _sizing_eval(Evas_Object *obj);
50 static void _rgb_to_hsl(void *data);
51 static void _hsl_to_rgb(void *data);
52 static void _color_with_saturation(void *data);
53 static void _color_with_lightness(void *data);
54 static void _draw_rects(void *data, double x);
55 static void _arrow_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
56 static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
57 static void _left_button_clicked_cb(void *data, Evas_Object * obj, void *event_info);
58 static void _left_button_repeat_cb(void *data, Evas_Object * obj, void *event_info);
59 static void _right_button_clicked_cb(void *data, Evas_Object * obj, void *event_info);
60 static void _right_button_repeat_cb(void *data, Evas_Object * obj, void *event_info);
61 static void _add_colorbar(Evas_Object *obj);
62 static void _set_color(Evas_Object *obj, int r, int g, int b, int a);
63
64 static const char SIG_CHANGED[] = "changed";
65
66 static const Evas_Smart_Cb_Description _signals[] =
67 {
68      {SIG_CHANGED, ""},
69      {NULL, NULL}
70 };
71
72 static void
73 _del_hook(Evas_Object *obj)
74 {
75    Widget_Data *wd = elm_widget_data_get(obj);
76    int i = 0;
77
78    if (!wd) return;
79    for (i = 0; i < 4; i++) free(wd->cp[i]);
80    free(wd);
81 }
82
83 static void
84 _theme_hook(Evas_Object *obj)
85 {
86    Widget_Data *wd = elm_widget_data_get(obj);
87    int i;
88
89    if ((!wd) || (!wd->base)) return;
90
91    _elm_theme_object_set(obj, wd->base, "colorselector", "bg",
92                          elm_widget_style_get(obj));
93
94    for (i = 0; i < 4; i++)
95      {
96         evas_object_del(wd->cp[i]->colorbar);
97         wd->cp[i]->colorbar = NULL;
98         evas_object_del(wd->cp[i]->bar);
99         wd->cp[i]->bar = NULL;
100         evas_object_del(wd->cp[i]->lbt);
101         wd->cp[i]->lbt = NULL;
102         evas_object_del(wd->cp[i]->rbt);
103         wd->cp[i]->rbt = NULL;
104         if (i != 0)
105           {
106              evas_object_del(wd->cp[i]->bg_rect);
107              wd->cp[i]->bg_rect = NULL;
108           }
109         evas_object_del(wd->cp[i]->arrow);
110         wd->cp[i]->arrow = NULL;
111         evas_object_del(wd->cp[i]->touch_area);
112         wd->cp[i]->touch_area = NULL;
113      }
114
115    _add_colorbar(obj);
116    elm_colorselector_color_set(obj, wd->r, wd->g, wd->b, wd->a);
117    _sizing_eval(obj);
118 }
119
120 static void
121 _colorselector_set_size_hints(Evas_Object *obj, int timesw, int timesh)
122 {
123    Evas_Coord minw = -1, minh = -1;
124
125    elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
126    edje_object_size_min_restricted_calc(obj, &minw, &minh,
127                                         minw, minh);
128    evas_object_size_hint_min_set(obj, minw, minh);
129    evas_object_size_hint_max_set(obj, -1, -1);
130 }
131
132 static void
133 _sizing_eval(Evas_Object *obj)
134 {
135    Widget_Data *wd = elm_widget_data_get(obj);
136    Evas_Coord minw = -1, minh = -1;
137    int i;
138
139    if (!wd) return;
140    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
141    for (i = 0; i < 4; i++)
142      {
143         if (wd->cp[i]->bg_rect)
144           _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
145         _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
146         _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
147         _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
148
149         _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
150      }
151
152    elm_coords_finger_size_adjust(4, &minw, 4, &minh);
153    edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
154    evas_object_size_hint_min_set(obj, minw, minh);
155    evas_object_size_hint_max_set(obj, -1, -1);
156 }
157
158 static void
159 _rgb_to_hsl(void *data)
160 {
161    Widget_Data *wd = data;
162    double r, g, b;
163    double v, m, vm;
164    double r2, g2, b2;
165
166    r = wd->r;
167    g = wd->g;
168    b = wd->b;
169
170    r /= 255.0;
171    g /= 255.0;
172    b /= 255.0;
173
174    v = (r > g) ? r : g;
175    v = (v > b) ? v : b;
176
177    m = (r < g) ? r : g;
178    m = (m < b) ? m : b;
179
180    wd->h = 0.0;
181    wd->s = 0.0;
182    wd->l = 0.0;
183
184    wd->l = (m + v) / 2.0;
185
186    if (wd->l <= 0.0) return;
187
188    vm = v - m;
189    wd->s = vm;
190
191    if (wd->s > 0.0) wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m);
192    else return;
193
194    r2 = (v - r) / vm;
195    g2 = (v - g) / vm;
196    b2 = (v - b) / vm;
197
198    if (r == v) wd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
199    else if (g == v) wd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
200    else wd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
201
202    wd->h *= 60.0;
203 }
204
205 static void
206 _hsl_to_rgb(void *data)
207 {
208    Widget_Data *wd = data;
209    double r = 0, g = 0, b = 0;
210    double _h, _s, _l;
211    int i = 0;
212    double sv, vsf, f, p, q, t, v;
213
214    _h = wd->h;
215    _s = wd->s;
216    _l = wd->l;
217
218    if (_s == 0.0) r = g = b = _l;
219    else
220      {
221         if (_h == 360.0) _h = 0.0;
222         _h /= 60.0;
223
224         v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
225         p = _l + _l - v;
226
227         if (v) sv = (v - p) / v;
228         else sv = 0;
229
230         i = (int)_h;
231         f = _h - i;
232
233         vsf = v * sv * f;
234
235         t = p + vsf;
236         q = v - vsf;
237
238         switch (i)
239           {
240            case 0:
241               r = v;
242               g = t;
243               b = p;
244               break;
245            case 1:
246               r = q;
247               g = v;
248               b = p;
249               break;
250            case 2:
251               r = p;
252               g = v;
253               b = t;
254               break;
255            case 3:
256               r = p;
257               g = q;
258               b = v;
259               break;
260            case 4:
261               r = t;
262               g = p;
263               b = v;
264               break;
265            case 5:
266               r = v;
267               g = p;
268               b = q;
269               break;
270           }
271      }
272    i = (int)(r * 255.0);
273    f = (r * 255.0) - i;
274    wd->r = (f <= 0.5) ? i : (i + 1);
275
276    i = (int)(g * 255.0);
277    f = (g * 255.0) - i;
278    wd->g = (f <= 0.5) ? i : (i + 1);
279
280    i = (int)(b * 255.0);
281    f = (b * 255.0) - i;
282    wd->b = (f <= 0.5) ? i : (i + 1);
283 }
284
285 static void
286 _color_with_saturation(void *data)
287 {
288    Widget_Data *wd = data;
289
290    if (wd->er > 127)
291      wd->sr = 127 + (int)((double)(wd->er - 127) * wd->s);
292    else
293      wd->sr = 127 - (int)((double)(127 - wd->er) * wd->s);
294
295    if (wd->eg > 127)
296      wd->sg = 127 + (int)((double)(wd->eg - 127) * wd->s);
297    else
298      wd->sg = 127 - (int)((double)(127 - wd->eg) * wd->s);
299
300    if (wd->eb > 127)
301      wd->sb = 127 + (int)((double)(wd->eb - 127) * wd->s);
302    else
303      wd->sb = 127 - (int)((double)(127 - wd->eb) * wd->s);
304 }
305
306 static void
307 _color_with_lightness(void *data)
308 {
309    Widget_Data *wd = data;
310
311    if (wd->l > 0.5)
312      {
313         wd->lr = wd->er + (int)((double)(255 - wd->er) * (wd->l - 0.5) * 2.0);
314         wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (wd->l - 0.5) * 2.0);
315         wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (wd->l - 0.5) * 2.0);
316      }
317    else if (wd->l < 0.5)
318      {
319         wd->lr = (double)wd->er * wd->l * 2.0;
320         wd->lg = (double)wd->eg * wd->l * 2.0;
321         wd->lb = (double)wd->eb * wd->l * 2.0;
322      }
323    else
324      {
325         wd->lr = wd->er;
326         wd->lg = wd->eg;
327         wd->lb = wd->eb;
328      }
329 }
330
331 static void
332 _draw_rects(void *data, double x)
333 {
334    Colorselector_Data *cp = data;
335    Widget_Data *wd = elm_widget_data_get(cp->parent);
336    double one_six = 1.0 / 6.0;
337
338    switch (cp->color_type)
339      {
340       case HUE:
341          wd->h = 360.0 * x;
342
343          if (x < one_six)
344            {
345               wd->er = 255;
346               wd->eg = (255.0 * x * 6.0);
347               wd->eb = 0;
348            }
349          else if (x < 2 * one_six)
350            {
351               wd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
352               wd->eg = 255;
353               wd->eb = 0;
354            }
355          else if (x < 3 * one_six)
356            {
357               wd->er = 0;
358               wd->eg = 255;
359               wd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
360            }
361          else if (x < 4 * one_six)
362            {
363               wd->er = 0;
364               wd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
365               wd->eb = 255;
366            }
367          else if (x < 5 * one_six)
368            {
369               wd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
370               wd->eg = 0;
371               wd->eb = 255;
372            }
373          else
374            {
375               wd->er = 255;
376               wd->eg = 0;
377               wd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
378            }
379
380          evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255);
381          evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255);
382          evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255);
383          evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255);
384
385          _color_with_saturation(wd);
386          evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
387
388          _color_with_lightness(wd);
389          evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
390
391          evas_object_color_set(wd->cp[3]->arrow,
392                                (wd->er * wd->a) / 255,
393                                (wd->eg * wd->a) / 255,
394                                (wd->eb * wd->a) / 255,
395                                wd->a);
396          break;
397       case SATURATION:
398          wd->s = 1.0 - x;
399          _color_with_saturation(wd);
400          evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
401          break;
402       case LIGHTNESS:
403          wd->l = x;
404          _color_with_lightness(wd);
405          evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
406          break;
407       case ALPHA:
408          wd->a = 255.0 * x;
409          evas_object_color_set(wd->cp[3]->arrow, wd->er, wd->eg, wd->eb, wd->a);
410          break;
411       default:
412          break;
413      }
414    _hsl_to_rgb(wd);
415 }
416
417 static void
418 _arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
419 {
420    Colorselector_Data *cp = data;
421    double x, y;
422
423    edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
424    _draw_rects(data, x);
425    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
426 }
427
428 static void
429 _colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
430 {
431    Colorselector_Data *cp = data;
432    Evas_Event_Mouse_Down *ev = event_info;
433    Evas_Coord x, y, w, h;
434    double arrow_x = 0, arrow_y;
435
436    evas_object_geometry_get(cp->bar, &x, &y, &w, &h);
437    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow",
438                                    &arrow_x, &arrow_y);
439    if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
440    if (arrow_x > 1) arrow_x = 1;
441    if (arrow_x < 0) arrow_x = 0;
442    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y);
443    _draw_rects(data, arrow_x);
444    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
445    evas_event_feed_mouse_cancel(e, 0, NULL);
446    evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
447 }
448
449 static void
450 _left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
451 {
452    Colorselector_Data *cp = data;
453    double x, y;
454
455    edje_object_signal_emit(cp->lbt, "elm,state,left,button,down",
456                            "left_button");
457    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
458
459    switch(cp->color_type)
460      {
461       case HUE :
462          x -= 1.0 / HUE_STEP;
463          break;
464       case SATURATION :
465          x -= 1.0 / SAT_STEP;
466          break;
467       case LIGHTNESS :
468          x -= 1.0 / LIG_STEP;
469          break;
470       case ALPHA :
471          x -= 1.0 / ALP_STEP;
472          break;
473       default :
474          break;
475      }
476
477    if (x < 0.0) x = 0.0;
478
479    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
480    _draw_rects(data, x);
481    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
482 }
483
484 static void
485 _left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
486 {
487    Colorselector_Data *cp = data;
488    double x, y;
489
490    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
491    x -= 1.0 / BASE_STEP;
492    if (x < 0.0) x = 0.0;
493    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
494    _draw_rects(data, x);
495    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
496
497 }
498
499 static void
500 _right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
501 {
502    Colorselector_Data *cp = data;
503    double x, y;
504
505    edje_object_signal_emit(cp->rbt, "elm,state,right,button,down",
506                            "right_button");
507    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
508
509    switch(cp->color_type)
510      {
511       case HUE :
512          x += 1.0 / HUE_STEP;
513          break;
514       case SATURATION :
515          x += 1.0 / SAT_STEP;
516          break;
517       case LIGHTNESS :
518          x += 1.0 / LIG_STEP;
519          break;
520       case ALPHA :
521          x += 1.0 / ALP_STEP;
522          break;
523       default :
524          break;
525      }
526
527    if (x > 1.0) x = 1.0;
528
529    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
530    _draw_rects(data, x);
531    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
532 }
533
534 static void
535 _right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
536 {
537    Colorselector_Data *cp = data;
538    double x, y;
539
540    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
541    x += 1.0 / BASE_STEP;
542    if (x > 1.0) x = 1.0;
543    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
544    _draw_rects(data, x);
545    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
546 }
547
548 static void
549 _add_colorbar(Evas_Object *obj)
550 {
551    char colorbar_name[128];
552    char colorbar_s[128];
553    Widget_Data *wd;
554    Evas *e;
555    int i = 0;
556    char buf[1024];
557
558    wd = elm_widget_data_get(obj);
559    if (!wd) return;
560
561    e = evas_object_evas_get(obj);
562
563    for (i = 0; i < 4; i++)
564      {
565         wd->cp[i] = ELM_NEW(Colorselector_Data);
566         wd->cp[i]->parent = obj;
567         switch(i)
568           {
569            case 0 :
570               wd->cp[i]->color_type = HUE;
571               break;
572            case 1 :
573               wd->cp[i]->color_type = SATURATION;
574               break;
575            case 2 :
576               wd->cp[i]->color_type = LIGHTNESS;
577               break;
578            case 3 :
579               wd->cp[i]->color_type = ALPHA;
580               break;
581            default :
582               break;
583           }
584         /* load colorbar area */
585         wd->cp[i]->colorbar = edje_object_add(e);
586         _elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorselector", "base",
587                               elm_widget_style_get(obj));
588         snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
589         snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
590         edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*",
591                                         _arrow_cb, wd->cp[i]);
592         edje_object_part_swallow(wd->base, colorbar_s, wd->cp[i]->colorbar);
593         elm_widget_sub_object_add(obj, wd->cp[i]->colorbar);
594
595         /* load colorbar image */
596         wd->cp[i]->bar = edje_object_add(e);
597         snprintf(buf, sizeof(buf), "%s/%s", colorbar_name, elm_widget_style_get(obj));
598         _elm_theme_object_set(obj, wd->cp[i]->bar, "colorselector", "image",
599                               buf);
600         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar",
601                                  wd->cp[i]->bar);
602         elm_widget_sub_object_add(obj, wd->cp[i]->bar);
603
604         /* provide expanded touch area */
605         wd->cp[i]->touch_area = evas_object_rectangle_add(e);
606         evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0);
607         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg",
608                                  wd->cp[i]->touch_area);
609         evas_object_event_callback_add(wd->cp[i]->touch_area,
610                                        EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
611                                        wd->cp[i]);
612         elm_widget_sub_object_add(obj, wd->cp[i]->touch_area);
613
614         /* load background rectangle of the colorbar. used for
615            changing color of the opacity bar */
616         if ((i == 1) || (i == 2))
617           {
618              wd->cp[i]->bg_rect = evas_object_rectangle_add(e);
619              evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb,
620                                    255);
621              edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
622                                       wd->cp[i]->bg_rect);
623
624              elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
625           }
626         if (i == 3)
627           {
628              wd->cp[i]->bg_rect = edje_object_add(e);
629              snprintf(buf, sizeof(buf), "%s/%s", colorbar_name, elm_widget_style_get(obj));
630              _elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorselector",
631                                    "bg_image", buf);
632              edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
633                                       wd->cp[i]->bg_rect);
634              elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
635              evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255);
636           }
637         /* load arrow image, pointing the colorbar */
638         wd->cp[i]->arrow = edje_object_add(e);
639         _elm_theme_object_set(obj, wd->cp[i]->arrow, "colorselector", "arrow",
640                               elm_widget_style_get(obj));
641         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_icon",
642                                  wd->cp[i]->arrow);
643         elm_widget_sub_object_add(obj, wd->cp[i]->arrow);
644         if (i == 2)
645           evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255);
646         else
647           evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255);
648
649         /* load left button */
650         wd->cp[i]->lbt = elm_button_add(obj);
651         snprintf(buf, sizeof(buf), "colorselector/left/%s", elm_widget_style_get(obj));
652         elm_object_style_set(wd->cp[i]->lbt, buf);
653         elm_widget_sub_object_add(obj, wd->cp[i]->lbt);
654         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button",
655                                  wd->cp[i]->lbt);
656         evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked", _left_button_clicked_cb, wd->cp[i]);
657         elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE);
658         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt, _elm_config->longpress_timeout);
659         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt, (1.0 / _elm_config->fps));
660         evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated",_left_button_repeat_cb, wd->cp[i]);
661
662         /* load right button */
663         wd->cp[i]->rbt = elm_button_add(obj);
664         snprintf(buf, sizeof(buf), "colorselector/right/%s", elm_widget_style_get(obj));
665         elm_object_style_set(wd->cp[i]->rbt, buf);
666         elm_widget_sub_object_add(obj, wd->cp[i]->rbt);
667         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button",
668                                  wd->cp[i]->rbt);
669         evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked", _right_button_clicked_cb, wd->cp[i]);
670         elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE);
671         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt, _elm_config->longpress_timeout);
672         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt, (1.0 / _elm_config->fps));
673         evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated",_right_button_repeat_cb, wd->cp[i]);
674      }
675 }
676
677 static void
678 _set_color(Evas_Object *obj, int r, int g, int b, int a)
679 {
680    Widget_Data *wd = elm_widget_data_get(obj);
681    double x, y;
682
683    wd->r = r;
684    wd->g = g;
685    wd->b = b;
686    wd->a = a;
687
688    _rgb_to_hsl(wd);
689
690    edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y);
691    x = wd->h / 360.0;
692    edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y);
693    _draw_rects(wd->cp[0], x);
694
695    edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y);
696    x = 1.0 - wd->s;
697    edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y);
698    _draw_rects(wd->cp[1], x);
699
700    edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y);
701    x = wd->l;
702    edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y);
703    _draw_rects(wd->cp[2], x);
704
705    edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y);
706    x = wd->a / 255.0;
707    edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y);
708    _draw_rects(wd->cp[3], x);
709 }
710
711 EAPI Evas_Object *
712 elm_colorselector_add(Evas_Object *parent)
713 {
714    Evas_Object *obj = NULL;
715    Widget_Data *wd = NULL;
716    Evas *e;
717
718    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
719
720    ELM_SET_WIDTYPE(widtype, "colorselector");
721    elm_widget_type_set(obj, "colorselector");
722    elm_widget_sub_object_add(parent, obj);
723    elm_widget_data_set(obj, wd);
724    elm_widget_del_hook_set(obj, _del_hook);
725    elm_widget_theme_hook_set(obj, _theme_hook);
726
727    /* load background edj */
728    wd->base = edje_object_add(e);
729    _elm_theme_object_set(obj, wd->base, "colorselector", "bg", "default");
730    elm_widget_resize_object_set(obj, wd->base);
731
732    wd->er = 255;
733    wd->eg = 0;
734    wd->eb = 0;
735    wd->h = 0.0;
736    wd->s = 1.0;
737    wd->l = 0.0;
738    wd->a = 255;
739
740    _hsl_to_rgb(wd);
741    _add_colorbar(obj);
742    _sizing_eval(obj);
743
744    evas_object_smart_callbacks_descriptions_set(obj, _signals);
745    return obj;
746 }
747
748 EAPI void
749 elm_colorselector_color_set(Evas_Object *obj, int r, int g, int b, int a)
750 {
751    ELM_CHECK_WIDTYPE(obj, widtype);
752    _set_color(obj, r, g, b, a);
753 }
754
755 EAPI void
756 elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int*a)
757 {
758    Widget_Data *wd = elm_widget_data_get(obj);
759    ELM_CHECK_WIDTYPE(obj, widtype);
760
761    if (r) *r = wd->r;
762    if (g) *g = wd->g;
763    if (b) *b = wd->b;
764    if (a) *a = wd->a;
765 }