d7ab7e654e13e3a86c79c9ebb83615f63d451d2f
[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 <<<<<<< HEAD
56 static void _arrow_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
57 static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
58 static void _left_button_clicked_cb(void *data, Evas_Object * obj, void *event_info);
59 static void _left_button_repeat_cb(void *data, Evas_Object * obj, void *event_info);
60 static void _right_button_clicked_cb(void *data, Evas_Object * obj, void *event_info);
61 static void _right_button_repeat_cb(void *data, Evas_Object * obj, void *event_info);
62 =======
63 static void _arrow_cb(void *data, Evas_Object *obj, const char *emission,
64                       const char *source);
65 static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj,
66                          void *event_info);
67 static void _left_button_clicked_cb(void *data, Evas_Object * obj,
68                                     void *event_info);
69 static void _left_button_repeat_cb(void *data, Evas_Object * obj,
70                                    void *event_info);
71 static void _right_button_clicked_cb(void *data, Evas_Object * obj,
72                                      void *event_info);
73 static void _right_button_repeat_cb(void *data, Evas_Object * obj,
74                                     void *event_info);
75 >>>>>>> remotes/origin/upstream
76 static void _add_colorbar(Evas_Object *obj);
77 static void _set_color(Evas_Object *obj, int r, int g, int b, int a);
78
79 static const char SIG_CHANGED[] = "changed";
80
81 static const Evas_Smart_Cb_Description _signals[] =
82 {
83      {SIG_CHANGED, ""},
84      {NULL, NULL}
85 };
86
87 static void
88 _del_hook(Evas_Object *obj)
89 {
90    Widget_Data *wd = elm_widget_data_get(obj);
91    int i = 0;
92
93    if (!wd) return;
94    for (i = 0; i < 4; i++) free(wd->cp[i]);
95    free(wd);
96 }
97
98 static void
99 _theme_hook(Evas_Object *obj)
100 {
101    Widget_Data *wd = elm_widget_data_get(obj);
102    int i;
103
104    if ((!wd) || (!wd->base)) return;
105
106    _elm_theme_object_set(obj, wd->base, "colorselector", "bg",
107                          elm_widget_style_get(obj));
108
109    for (i = 0; i < 4; i++)
110      {
111         evas_object_del(wd->cp[i]->colorbar);
112         wd->cp[i]->colorbar = NULL;
113         evas_object_del(wd->cp[i]->bar);
114         wd->cp[i]->bar = NULL;
115         evas_object_del(wd->cp[i]->lbt);
116         wd->cp[i]->lbt = NULL;
117         evas_object_del(wd->cp[i]->rbt);
118         wd->cp[i]->rbt = NULL;
119         if (i != 0)
120           {
121              evas_object_del(wd->cp[i]->bg_rect);
122              wd->cp[i]->bg_rect = NULL;
123           }
124         evas_object_del(wd->cp[i]->arrow);
125         wd->cp[i]->arrow = NULL;
126         evas_object_del(wd->cp[i]->touch_area);
127         wd->cp[i]->touch_area = NULL;
128      }
129
130    _add_colorbar(obj);
131    elm_colorselector_color_set(obj, wd->r, wd->g, wd->b, wd->a);
132    _sizing_eval(obj);
133 }
134
135 static void
136 _colorselector_set_size_hints(Evas_Object *obj, int timesw, int timesh)
137 {
138    Evas_Coord minw = -1, minh = -1;
139
140    elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
141    edje_object_size_min_restricted_calc(obj, &minw, &minh,
142                                         minw, minh);
143    evas_object_size_hint_min_set(obj, minw, minh);
144    evas_object_size_hint_max_set(obj, -1, -1);
145 }
146
147 static void
148 _sizing_eval(Evas_Object *obj)
149 {
150    Widget_Data *wd = elm_widget_data_get(obj);
151    Evas_Coord minw = -1, minh = -1;
152    int i;
153
154    if (!wd) return;
155    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
156    for (i = 0; i < 4; i++)
157      {
158         if (wd->cp[i]->bg_rect)
159           _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
160         _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
161         _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
162         _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
163
164         _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
165      }
166
167    elm_coords_finger_size_adjust(4, &minw, 4, &minh);
168    edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
169    evas_object_size_hint_min_set(obj, minw, minh);
170    evas_object_size_hint_max_set(obj, -1, -1);
171 }
172
173 static void
174 _rgb_to_hsl(void *data)
175 {
176    Widget_Data *wd = data;
177    double r, g, b;
178    double v, m, vm;
179    double r2, g2, b2;
180
181    r = wd->r;
182    g = wd->g;
183    b = wd->b;
184
185    r /= 255.0;
186    g /= 255.0;
187    b /= 255.0;
188
189    v = (r > g) ? r : g;
190    v = (v > b) ? v : b;
191
192    m = (r < g) ? r : g;
193    m = (m < b) ? m : b;
194
195    wd->h = 0.0;
196    wd->s = 0.0;
197    wd->l = 0.0;
198
199    wd->l = (m + v) / 2.0;
200
201    if (wd->l <= 0.0) return;
202
203    vm = v - m;
204    wd->s = vm;
205
206    if (wd->s > 0.0) wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m);
207    else return;
208
209    r2 = (v - r) / vm;
210    g2 = (v - g) / vm;
211    b2 = (v - b) / vm;
212
213    if (r == v) wd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
214    else if (g == v) wd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
215    else wd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
216
217    wd->h *= 60.0;
218 }
219
220 static void
221 _hsl_to_rgb(void *data)
222 {
223    Widget_Data *wd = data;
224    double r = 0, g = 0, b = 0;
225    double _h, _s, _l;
226    int i = 0;
227    double sv, vsf, f, p, q, t, v;
228
229    _h = wd->h;
230    _s = wd->s;
231    _l = wd->l;
232
233    if (_s == 0.0) r = g = b = _l;
234    else
235      {
236         if (_h == 360.0) _h = 0.0;
237         _h /= 60.0;
238
239         v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
240         p = _l + _l - v;
241
242         if (v) sv = (v - p) / v;
243         else sv = 0;
244
245         i = (int)_h;
246         f = _h - i;
247
248         vsf = v * sv * f;
249
250         t = p + vsf;
251         q = v - vsf;
252
253         switch (i)
254           {
255            case 0:
256               r = v;
257               g = t;
258               b = p;
259               break;
260            case 1:
261               r = q;
262               g = v;
263               b = p;
264               break;
265            case 2:
266               r = p;
267               g = v;
268               b = t;
269               break;
270            case 3:
271               r = p;
272               g = q;
273               b = v;
274               break;
275            case 4:
276               r = t;
277               g = p;
278               b = v;
279               break;
280            case 5:
281               r = v;
282               g = p;
283               b = q;
284               break;
285           }
286      }
287    i = (int)(r * 255.0);
288    f = (r * 255.0) - i;
289    wd->r = (f <= 0.5) ? i : (i + 1);
290
291    i = (int)(g * 255.0);
292    f = (g * 255.0) - i;
293    wd->g = (f <= 0.5) ? i : (i + 1);
294
295    i = (int)(b * 255.0);
296    f = (b * 255.0) - i;
297    wd->b = (f <= 0.5) ? i : (i + 1);
298 }
299
300 static void
301 _color_with_saturation(void *data)
302 {
303    Widget_Data *wd = data;
304
305    if (wd->er > 127)
306      wd->sr = 127 + (int)((double)(wd->er - 127) * wd->s);
307    else
308      wd->sr = 127 - (int)((double)(127 - wd->er) * wd->s);
309
310    if (wd->eg > 127)
311      wd->sg = 127 + (int)((double)(wd->eg - 127) * wd->s);
312    else
313      wd->sg = 127 - (int)((double)(127 - wd->eg) * wd->s);
314
315    if (wd->eb > 127)
316      wd->sb = 127 + (int)((double)(wd->eb - 127) * wd->s);
317    else
318      wd->sb = 127 - (int)((double)(127 - wd->eb) * wd->s);
319 }
320
321 static void
322 _color_with_lightness(void *data)
323 {
324    Widget_Data *wd = data;
325
326    if (wd->l > 0.5)
327      {
328         wd->lr = wd->er + (int)((double)(255 - wd->er) * (wd->l - 0.5) * 2.0);
329         wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (wd->l - 0.5) * 2.0);
330         wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (wd->l - 0.5) * 2.0);
331      }
332    else if (wd->l < 0.5)
333      {
334         wd->lr = (double)wd->er * wd->l * 2.0;
335         wd->lg = (double)wd->eg * wd->l * 2.0;
336         wd->lb = (double)wd->eb * wd->l * 2.0;
337      }
338    else
339      {
340         wd->lr = wd->er;
341         wd->lg = wd->eg;
342         wd->lb = wd->eb;
343      }
344 }
345
346 static void
347 _draw_rects(void *data, double x)
348 {
349    Colorselector_Data *cp = data;
350    Widget_Data *wd = elm_widget_data_get(cp->parent);
351    double one_six = 1.0 / 6.0;
352
353    switch (cp->color_type)
354      {
355       case HUE:
356          wd->h = 360.0 * x;
357
358          if (x < one_six)
359            {
360               wd->er = 255;
361               wd->eg = (255.0 * x * 6.0);
362               wd->eb = 0;
363            }
364          else if (x < 2 * one_six)
365            {
366               wd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
367               wd->eg = 255;
368               wd->eb = 0;
369            }
370          else if (x < 3 * one_six)
371            {
372               wd->er = 0;
373               wd->eg = 255;
374               wd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
375            }
376          else if (x < 4 * one_six)
377            {
378               wd->er = 0;
379               wd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
380               wd->eb = 255;
381            }
382          else if (x < 5 * one_six)
383            {
384               wd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
385               wd->eg = 0;
386               wd->eb = 255;
387            }
388          else
389            {
390               wd->er = 255;
391               wd->eg = 0;
392               wd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
393            }
394
395          evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255);
396          evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255);
397          evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255);
398          evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255);
399
400          _color_with_saturation(wd);
401          evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
402
403          _color_with_lightness(wd);
404          evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
405
406          evas_object_color_set(wd->cp[3]->arrow,
407                                (wd->er * wd->a) / 255,
408                                (wd->eg * wd->a) / 255,
409                                (wd->eb * wd->a) / 255,
410                                wd->a);
411          break;
412       case SATURATION:
413          wd->s = 1.0 - x;
414          _color_with_saturation(wd);
415          evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
416          break;
417       case LIGHTNESS:
418          wd->l = x;
419          _color_with_lightness(wd);
420          evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
421          break;
422       case ALPHA:
423          wd->a = 255.0 * x;
424          evas_object_color_set(wd->cp[3]->arrow,
425                                (wd->er * wd->a) / 255,
426                                (wd->eg * wd->a) / 255,
427                                (wd->eb * wd->a) / 255,
428                                wd->a);
429          break;
430       default:
431          break;
432      }
433    _hsl_to_rgb(wd);
434 }
435
436 static void
437 <<<<<<< HEAD
438 _arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
439 =======
440 _arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__,
441           const char *source __UNUSED__)
442 >>>>>>> remotes/origin/upstream
443 {
444    Colorselector_Data *cp = data;
445    double x, y;
446
447    edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
448    _draw_rects(data, x);
449    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
450 }
451
452 static void
453 _colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
454 {
455    Colorselector_Data *cp = data;
456    Evas_Event_Mouse_Down *ev = event_info;
457    Evas_Coord x, y, w, h;
458    double arrow_x = 0, arrow_y;
459
460    evas_object_geometry_get(cp->bar, &x, &y, &w, &h);
461    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow",
462                                    &arrow_x, &arrow_y);
463    if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
464    if (arrow_x > 1) arrow_x = 1;
465    if (arrow_x < 0) arrow_x = 0;
466    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y);
467    _draw_rects(data, arrow_x);
468    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
469    evas_event_feed_mouse_cancel(e, 0, NULL);
470    evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
471 }
472
473 static void
474 <<<<<<< HEAD
475 _left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
476 =======
477 _left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
478                         void *event_info __UNUSED__)
479 >>>>>>> remotes/origin/upstream
480 {
481    Colorselector_Data *cp = data;
482    double x, y;
483
484    edje_object_signal_emit(cp->lbt, "elm,state,left,button,down",
485                            "left_button");
486    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
487
488    switch(cp->color_type)
489      {
490       case HUE :
491          x -= 1.0 / HUE_STEP;
492          break;
493       case SATURATION :
494          x -= 1.0 / SAT_STEP;
495          break;
496       case LIGHTNESS :
497          x -= 1.0 / LIG_STEP;
498          break;
499       case ALPHA :
500          x -= 1.0 / ALP_STEP;
501          break;
502       default :
503          break;
504      }
505
506    if (x < 0.0) x = 0.0;
507
508    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
509    _draw_rects(data, x);
510    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
511 }
512
513 static void
514 <<<<<<< HEAD
515 _left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
516 =======
517 _left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
518                        void *event_info __UNUSED__)
519 >>>>>>> remotes/origin/upstream
520 {
521    Colorselector_Data *cp = data;
522    double x, y;
523
524    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
525    x -= 1.0 / BASE_STEP;
526    if (x < 0.0) x = 0.0;
527    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
528    _draw_rects(data, x);
529    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
530
531 }
532
533 static void
534 <<<<<<< HEAD
535 _right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
536 =======
537 _right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
538                          void *event_info __UNUSED__)
539 >>>>>>> remotes/origin/upstream
540 {
541    Colorselector_Data *cp = data;
542    double x, y;
543
544    edje_object_signal_emit(cp->rbt, "elm,state,right,button,down",
545                            "right_button");
546    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
547
548    switch(cp->color_type)
549      {
550       case HUE :
551          x += 1.0 / HUE_STEP;
552          break;
553       case SATURATION :
554          x += 1.0 / SAT_STEP;
555          break;
556       case LIGHTNESS :
557          x += 1.0 / LIG_STEP;
558          break;
559       case ALPHA :
560          x += 1.0 / ALP_STEP;
561          break;
562       default :
563          break;
564      }
565
566    if (x > 1.0) x = 1.0;
567
568    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
569    _draw_rects(data, x);
570    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
571 }
572
573 static void
574 <<<<<<< HEAD
575 _right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__, void *event_info __UNUSED__)
576 =======
577 _right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
578                         void *event_info __UNUSED__)
579 >>>>>>> remotes/origin/upstream
580 {
581    Colorselector_Data *cp = data;
582    double x, y;
583
584    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
585    x += 1.0 / BASE_STEP;
586    if (x > 1.0) x = 1.0;
587    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
588    _draw_rects(data, x);
589    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
590 }
591
592 static void
593 _add_colorbar(Evas_Object *obj)
594 {
595    char colorbar_name[128];
596    char colorbar_s[128];
597    Widget_Data *wd;
598    Evas *e;
599    int i = 0;
600    char buf[1024];
601
602    wd = elm_widget_data_get(obj);
603    if (!wd) return;
604
605    e = evas_object_evas_get(obj);
606
607    for (i = 0; i < 4; i++)
608      {
609         wd->cp[i] = ELM_NEW(Colorselector_Data);
610         wd->cp[i]->parent = obj;
611         switch(i)
612           {
613            case 0 :
614               wd->cp[i]->color_type = HUE;
615               break;
616            case 1 :
617               wd->cp[i]->color_type = SATURATION;
618               break;
619            case 2 :
620               wd->cp[i]->color_type = LIGHTNESS;
621               break;
622            case 3 :
623               wd->cp[i]->color_type = ALPHA;
624               break;
625            default :
626               break;
627           }
628         /* load colorbar area */
629         wd->cp[i]->colorbar = edje_object_add(e);
630         _elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorselector", "base",
631                               elm_widget_style_get(obj));
632         snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
633         snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
634         edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*",
635                                         _arrow_cb, wd->cp[i]);
636         edje_object_part_swallow(wd->base, colorbar_s, wd->cp[i]->colorbar);
637         elm_widget_sub_object_add(obj, wd->cp[i]->colorbar);
638
639         /* load colorbar image */
640         wd->cp[i]->bar = edje_object_add(e);
641 <<<<<<< HEAD
642         snprintf(buf, sizeof(buf), "%s/%s", colorbar_name, elm_widget_style_get(obj));
643 =======
644         snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
645                  elm_widget_style_get(obj));
646 >>>>>>> remotes/origin/upstream
647         _elm_theme_object_set(obj, wd->cp[i]->bar, "colorselector", "image",
648                               buf);
649         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar",
650                                  wd->cp[i]->bar);
651         elm_widget_sub_object_add(obj, wd->cp[i]->bar);
652
653         /* provide expanded touch area */
654         wd->cp[i]->touch_area = evas_object_rectangle_add(e);
655         evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0);
656         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg",
657                                  wd->cp[i]->touch_area);
658         evas_object_event_callback_add(wd->cp[i]->touch_area,
659                                        EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
660                                        wd->cp[i]);
661         elm_widget_sub_object_add(obj, wd->cp[i]->touch_area);
662
663         /* load background rectangle of the colorbar. used for
664            changing color of the opacity bar */
665         if ((i == 1) || (i == 2))
666           {
667              wd->cp[i]->bg_rect = evas_object_rectangle_add(e);
668              evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb,
669                                    255);
670              edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
671                                       wd->cp[i]->bg_rect);
672
673              elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
674           }
675         if (i == 3)
676           {
677              wd->cp[i]->bg_rect = edje_object_add(e);
678 <<<<<<< HEAD
679              snprintf(buf, sizeof(buf), "%s/%s", colorbar_name, elm_widget_style_get(obj));
680 =======
681              snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
682                       elm_widget_style_get(obj));
683 >>>>>>> remotes/origin/upstream
684              _elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorselector",
685                                    "bg_image", buf);
686              edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
687                                       wd->cp[i]->bg_rect);
688              elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
689              evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255);
690           }
691         /* load arrow image, pointing the colorbar */
692         wd->cp[i]->arrow = edje_object_add(e);
693         _elm_theme_object_set(obj, wd->cp[i]->arrow, "colorselector", "arrow",
694                               elm_widget_style_get(obj));
695         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_icon",
696                                  wd->cp[i]->arrow);
697         elm_widget_sub_object_add(obj, wd->cp[i]->arrow);
698         if (i == 2)
699           evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255);
700         else
701           evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255);
702
703         /* load left button */
704         wd->cp[i]->lbt = elm_button_add(obj);
705 <<<<<<< HEAD
706         snprintf(buf, sizeof(buf), "colorselector/left/%s", elm_widget_style_get(obj));
707 =======
708         snprintf(buf, sizeof(buf), "colorselector/left/%s",
709                  elm_widget_style_get(obj));
710 >>>>>>> remotes/origin/upstream
711         elm_object_style_set(wd->cp[i]->lbt, buf);
712         elm_widget_sub_object_add(obj, wd->cp[i]->lbt);
713         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button",
714                                  wd->cp[i]->lbt);
715 <<<<<<< HEAD
716         evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked", _left_button_clicked_cb, wd->cp[i]);
717         elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE);
718         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt, _elm_config->longpress_timeout);
719         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt, (1.0 / _elm_config->fps));
720         evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated",_left_button_repeat_cb, wd->cp[i]);
721
722         /* load right button */
723         wd->cp[i]->rbt = elm_button_add(obj);
724         snprintf(buf, sizeof(buf), "colorselector/right/%s", elm_widget_style_get(obj));
725 =======
726         evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked",
727                                        _left_button_clicked_cb, wd->cp[i]);
728         elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE);
729         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt,
730                                                   _elm_config->longpress_timeout);
731         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt,
732                                               (1.0 / _elm_config->fps));
733         evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated",
734                                        _left_button_repeat_cb, wd->cp[i]);
735
736         /* load right button */
737         wd->cp[i]->rbt = elm_button_add(obj);
738         snprintf(buf, sizeof(buf), "colorselector/right/%s",
739                  elm_widget_style_get(obj));
740 >>>>>>> remotes/origin/upstream
741         elm_object_style_set(wd->cp[i]->rbt, buf);
742         elm_widget_sub_object_add(obj, wd->cp[i]->rbt);
743         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button",
744                                  wd->cp[i]->rbt);
745 <<<<<<< HEAD
746         evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked", _right_button_clicked_cb, wd->cp[i]);
747         elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE);
748         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt, _elm_config->longpress_timeout);
749         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt, (1.0 / _elm_config->fps));
750         evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated",_right_button_repeat_cb, wd->cp[i]);
751 =======
752         evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked",
753                                        _right_button_clicked_cb, wd->cp[i]);
754         elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE);
755         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt,
756                                                   _elm_config->longpress_timeout);
757         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt,
758                                               (1.0 / _elm_config->fps));
759         evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated",
760                                        _right_button_repeat_cb, wd->cp[i]);
761 >>>>>>> remotes/origin/upstream
762      }
763 }
764
765 static void
766 _set_color(Evas_Object *obj, int r, int g, int b, int a)
767 {
768    Widget_Data *wd = elm_widget_data_get(obj);
769    double x, y;
770
771    wd->r = r;
772    wd->g = g;
773    wd->b = b;
774    wd->a = a;
775
776    _rgb_to_hsl(wd);
777
778    edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y);
779    x = wd->h / 360.0;
780    edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y);
781    _draw_rects(wd->cp[0], x);
782
783    edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y);
784    x = 1.0 - wd->s;
785    edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y);
786    _draw_rects(wd->cp[1], x);
787
788    edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y);
789    x = wd->l;
790    edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y);
791    _draw_rects(wd->cp[2], x);
792
793    edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y);
794    x = wd->a / 255.0;
795    edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y);
796    _draw_rects(wd->cp[3], x);
797 }
798
799 EAPI Evas_Object *
800 elm_colorselector_add(Evas_Object *parent)
801 {
802    Evas_Object *obj = NULL;
803    Widget_Data *wd = NULL;
804    Evas *e;
805
806    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
807
808    ELM_SET_WIDTYPE(widtype, "colorselector");
809    elm_widget_type_set(obj, "colorselector");
810    elm_widget_sub_object_add(parent, obj);
811    elm_widget_data_set(obj, wd);
812    elm_widget_del_hook_set(obj, _del_hook);
813    elm_widget_theme_hook_set(obj, _theme_hook);
814
815    /* load background edj */
816    wd->base = edje_object_add(e);
817    _elm_theme_object_set(obj, wd->base, "colorselector", "bg", "default");
818    elm_widget_resize_object_set(obj, wd->base);
819
820    wd->er = 255;
821    wd->eg = 0;
822    wd->eb = 0;
823    wd->h = 0.0;
824    wd->s = 1.0;
825    wd->l = 0.0;
826    wd->a = 255;
827
828    _hsl_to_rgb(wd);
829    _add_colorbar(obj);
830    _sizing_eval(obj);
831
832    evas_object_smart_callbacks_descriptions_set(obj, _signals);
833    return obj;
834 }
835
836 EAPI void
837 elm_colorselector_color_set(Evas_Object *obj, int r, int g, int b, int a)
838 {
839    ELM_CHECK_WIDTYPE(obj, widtype);
840    _set_color(obj, r, g, b, a);
841 }
842
843 EAPI void
844 <<<<<<< HEAD
845 elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int*a)
846 =======
847 elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
848 >>>>>>> remotes/origin/upstream
849 {
850    Widget_Data *wd = elm_widget_data_get(obj);
851    ELM_CHECK_WIDTYPE(obj, widtype);
852
853    if (r) *r = wd->r;
854    if (g) *g = wd->g;
855    if (b) *b = wd->b;
856    if (a) *a = wd->a;
857 }
858 <<<<<<< HEAD
859 =======
860
861 EAPI void
862 elm_colorselector_mode_set(Evas_Object *obj, Elm_Colorselector_Mode mode __UNUSED__)
863 {
864    ELM_CHECK_WIDTYPE(obj, widtype);
865    //TODO: Implement!
866 }
867
868 EAPI Elm_Colorselector_Mode
869 elm_colorselector_mode_get(const Evas_Object *obj)
870 {
871    ELM_CHECK_WIDTYPE(obj, widtype) ELM_COLORSELECTOR_PALETTE;
872    //TODO: Implement!
873    return ELM_COLORSELECTOR_PALETTE;
874 }
875
876 EAPI void
877 elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, int *r __UNUSED__, int *g __UNUSED__, int *b __UNUSED__, int*a __UNUSED__)
878 {
879    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
880    //TODO: Implement!
881 }
882
883 EAPI void
884 elm_colorselector_palette_item_color_set(Elm_Object_Item *it, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__)
885 {
886    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
887    //TODO: Implement!
888 }
889
890 EAPI Elm_Object_Item *
891 elm_colorselector_palette_color_add(Evas_Object *obj, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__)
892 {
893    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
894    //TODO: Implement!
895    return NULL;
896 }
897
898 EAPI void
899 elm_colorselector_palette_clear(Evas_Object *obj)
900 {
901    ELM_CHECK_WIDTYPE(obj, widtype);
902    //TODO: Implement!
903 }
904
905 EAPI void
906 elm_colorselector_palette_name_set(Evas_Object *obj, const char *palette_name __UNUSED__)
907 {
908    ELM_CHECK_WIDTYPE(obj, widtype);
909    //TODO: Implement!
910 }
911
912 EAPI const char*
913 elm_colorselector_palette_name_get(const Evas_Object *obj)
914 {
915    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
916    //TODO: Implement!
917    return NULL;
918 }
919 >>>>>>> remotes/origin/upstream