1 #include <Elementary.h>
4 #define BASE_STEP 360.0
9 #define DEFAULT_HOR_PAD 10
10 #define DEFAULT_VER_PAD 10
12 typedef enum _Color_Type
20 typedef struct _Colorselector_Data Colorselector_Data;
21 struct _Colorselector_Data
24 Evas_Object *colorbar;
30 Evas_Object *touch_area;
31 Color_Type color_type;
34 typedef struct _Widget_Data Widget_Data;
35 typedef struct _Elm_Color_Item Elm_Color_Item;
42 Colorselector_Data *cp[4];
43 Ecore_Timer *longpress_timer;
44 const char *palette_name;
45 Evas_Coord _x, _y, _w, _h;
51 Elm_Colorselector_Mode mode;
52 Eina_Bool longpressed : 1;
53 Eina_Bool config_load: 1;
56 struct _Elm_Color_Item
59 Evas_Object *color_obj;
60 Elm_Color_RGBA *color;
63 static const char *widtype = NULL;
65 static void _del_hook(Evas_Object *obj);
66 static void _theme_hook(Evas_Object *obj);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _resize_cb(void *data, Evas *a, Evas_Object *obj, void *event_info);
69 static void _rgb_to_hsl(void *data);
70 static void _hsl_to_rgb(void *data);
71 static void _color_with_saturation(void *data);
72 static void _color_with_lightness(void *data);
73 static void _draw_rects(void *data, double x);
74 static void _arrow_cb(void *data, Evas_Object *obj, const char *emission,
76 static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj,
78 static void _left_button_clicked_cb(void *data, Evas_Object * obj,
80 static void _left_button_repeat_cb(void *data, Evas_Object * obj,
82 static void _right_button_clicked_cb(void *data, Evas_Object * obj,
84 static void _right_button_repeat_cb(void *data, Evas_Object * obj,
86 static void _add_colorbar(Evas_Object *obj);
87 static void _set_color(Evas_Object *obj, int r, int g, int b, int a);
88 static Elm_Color_Item *_item_new(Evas_Object *obj);
89 static void _item_sizing_eval(Elm_Color_Item *item);
90 static void _item_highlight(void *data, Evas *e, Evas_Object *obj, void *event_info);
91 static void _item_unhighlight(void *data, Evas *e, Evas_Object *obj, void *event_info);
92 static Eina_Bool _long_press(void *data);
93 static void _remove_items(Widget_Data *wd);
94 static void _colors_remove(Evas_Object *obj);
95 static void _colors_save(Evas_Object *obj);
96 static void _colors_load_apply(Evas_Object *obj);
98 static const char SIG_CHANGED[] = "changed";
99 static const char SIG_COLOR_ITEM_SELECTED[] = "color,item,selected";
100 static const char SIG_COLOR_ITEM_LONGPRESSED[] = "color,item,longpressed";
102 static const Evas_Smart_Cb_Description _signals[] =
104 {SIG_COLOR_ITEM_SELECTED, ""},
105 {SIG_COLOR_ITEM_LONGPRESSED, ""},
111 _del_hook(Evas_Object *obj)
113 Widget_Data *wd = elm_widget_data_get(obj);
117 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
118 if (wd->palette_name) eina_stringshare_del(wd->palette_name);
120 for (i = 0; i < 4; i++) free(wd->cp[i]);
125 _theme_hook(Evas_Object *obj)
127 Widget_Data *wd = elm_widget_data_get(obj);
129 Elm_Color_Item *item;
131 const char *hpadstr, *vpadstr;
132 unsigned int h_pad = DEFAULT_HOR_PAD;
133 unsigned int v_pad = DEFAULT_VER_PAD;
135 if ((!wd) || (!wd->sel)) return;
137 _elm_theme_object_set(obj, wd->base, "colorselector", "palette",
138 elm_widget_style_get(obj));
139 _elm_theme_object_set(obj, wd->sel, "colorselector", "bg",
140 elm_widget_style_get(obj));
141 hpadstr = edje_object_data_get(wd->base, "horizontal_pad");
142 if (hpadstr) h_pad = atoi(hpadstr);
143 vpadstr = edje_object_data_get(wd->base, "vertical_pad");
144 if (vpadstr) v_pad = atoi(vpadstr);
145 elm_box_padding_set(wd->box, h_pad, v_pad);
146 EINA_LIST_FOREACH(wd->items, elist, item)
148 elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
149 _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
151 for (i = 0; i < 4; i++)
153 evas_object_del(wd->cp[i]->colorbar);
154 wd->cp[i]->colorbar = NULL;
155 evas_object_del(wd->cp[i]->bar);
156 wd->cp[i]->bar = NULL;
157 evas_object_del(wd->cp[i]->lbt);
158 wd->cp[i]->lbt = NULL;
159 evas_object_del(wd->cp[i]->rbt);
160 wd->cp[i]->rbt = NULL;
163 evas_object_del(wd->cp[i]->bg_rect);
164 wd->cp[i]->bg_rect = NULL;
166 evas_object_del(wd->cp[i]->arrow);
167 wd->cp[i]->arrow = NULL;
168 evas_object_del(wd->cp[i]->touch_area);
169 wd->cp[i]->touch_area = NULL;
173 elm_colorselector_color_set(obj, wd->r, wd->g, wd->b, wd->a);
178 _colorselector_set_size_hints(Evas_Object *obj, int timesw, int timesh)
180 Evas_Coord minw = -1, minh = -1;
182 elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
183 edje_object_size_min_restricted_calc(obj, &minw, &minh,
185 evas_object_size_hint_min_set(obj, minw, minh);
186 evas_object_size_hint_max_set(obj, -1, -1);
190 _item_sizing_eval(Elm_Color_Item *item)
192 Evas_Coord minw = -1, minh = -1;
196 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
197 edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw,
199 evas_object_size_hint_min_set(VIEW(item), minw, minh);
202 static void _resize_cb(void *data, Evas *a __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
208 _sizing_eval_palette(Evas_Object *obj)
210 Widget_Data *wd = elm_widget_data_get(obj);
212 Elm_Color_Item *item;
213 Evas_Coord bw = 0, bh = 0;
214 Evas_Coord w = 0, h = 0;
217 EINA_LIST_FOREACH(wd->items, elist, item)
219 _item_sizing_eval(item);
221 evas_object_size_hint_min_get(wd->box, &bw, &bh);
222 evas_object_size_hint_min_set(obj, bw, bh);
223 evas_object_size_hint_max_set(obj, -1, -1);
224 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
227 evas_object_resize(obj, w, h);
231 _sizing_eval_selector(Evas_Object *obj)
233 Widget_Data *wd = elm_widget_data_get(obj);
234 Evas_Coord minw = -1, minh = -1;
235 Evas_Coord w = 0, h = 0;
239 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
240 for (i = 0; i < 4; i++)
242 if (wd->cp[i]->bg_rect)
243 _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
244 _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
245 _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
246 _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
248 _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
251 elm_coords_finger_size_adjust(4, &minw, 4, &minh);
252 edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
253 evas_object_size_hint_min_set(obj, minw, minh);
254 evas_object_size_hint_max_set(obj, -1, -1);
255 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
256 if (w < minw) w = minw;
257 if (h < minh) h = minh;
258 evas_object_resize(obj, w, h);
262 _sizing_eval_palette_selector(Evas_Object *obj)
264 Widget_Data *wd = elm_widget_data_get(obj);
265 Evas_Coord minw = -1, minh = -1;
266 Evas_Coord bw = 0, bh = 0;
267 Evas_Coord w = 0, h = 0;
270 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
271 for (i = 0; i < 4; i++)
273 if (wd->cp[i]->bg_rect)
274 _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
275 _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
276 _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
277 _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
279 _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
282 elm_coords_finger_size_adjust(4, &minw, 4, &minh);
283 edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
284 evas_object_size_hint_min_get(wd->box, &bw, &bh);
285 evas_object_size_hint_min_set(obj, minw, minh+bh);
286 evas_object_size_hint_max_set(obj, -1, -1);
287 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
288 if (w < minw) w = minw;
289 if (h < (minh+bh)) h = (minh+bh);
290 evas_object_resize(obj, w, h);
294 _sizing_eval(Evas_Object *obj)
296 Widget_Data *wd = elm_widget_data_get(obj);
300 case ELM_COLORSELECTOR_PALETTE:
301 _sizing_eval_palette(obj);
303 case ELM_COLORSELECTOR_COMPONENTS:
304 _sizing_eval_selector(obj);
306 case ELM_COLORSELECTOR_BOTH:
307 _sizing_eval_palette_selector(obj);
315 _long_press(void *data)
317 Elm_Color_Item *item = (Elm_Color_Item *) data;
318 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
319 if (!wd) return ECORE_CALLBACK_CANCEL;
320 wd->longpress_timer = NULL;
321 wd->longpressed = EINA_TRUE;
322 evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
323 return ECORE_CALLBACK_CANCEL;
327 _item_highlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
329 Elm_Color_Item *item = (Elm_Color_Item *) data;
330 Evas_Event_Mouse_Down *ev = event_info;
332 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
334 if (ev->button != 1) return;
335 elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
336 wd->longpressed = EINA_FALSE;
337 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
338 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
342 _item_unhighlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
344 Elm_Color_Item *item = (Elm_Color_Item *) data;
345 Evas_Event_Mouse_Down *ev = event_info;
347 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
349 if (ev->button != 1) return;
350 if (wd->longpress_timer)
352 ecore_timer_del(wd->longpress_timer);
353 wd->longpress_timer = NULL;
355 elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
356 if (!wd->longpressed)
358 evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
359 elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g, item->color->b, item->color->a);
364 _remove_items(Widget_Data *wd)
366 Elm_Color_Item *item;
368 if (!wd->items) return;
370 EINA_LIST_FREE(wd->items, item)
373 elm_widget_item_free(item);
379 static Elm_Color_Item*
380 _item_new(Evas_Object *obj)
382 Elm_Color_Item *item;
385 wd = elm_widget_data_get(obj);
386 if (!wd) return NULL;
388 item = elm_widget_item_new(obj, Elm_Color_Item);
389 if (!item) return NULL;
391 VIEW(item) = elm_layout_add(obj);
392 elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
393 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
394 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
395 item->color_obj = edje_object_add(evas_object_evas_get(obj));
396 _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
397 evas_object_size_hint_weight_set(item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
398 evas_object_size_hint_align_set(item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
399 evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _item_highlight, item);
400 evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_UP, _item_unhighlight, item);
401 elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj);
402 _item_sizing_eval(item);
403 evas_object_show(VIEW(item));
409 _colors_remove(Evas_Object *obj)
411 Widget_Data *wd = elm_widget_data_get(obj);
414 _elm_config_colors_free(wd->palette_name);
417 static void _colors_save(Evas_Object *obj)
420 Widget_Data *wd = elm_widget_data_get(obj);
421 Elm_Color_Item *item;
422 _elm_config_colors_free(wd->palette_name);
423 EINA_LIST_FOREACH(wd->items, elist, item)
425 _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
426 item->color->b, item->color->a);
431 _colors_load_apply(Evas_Object *obj)
433 Elm_Color_RGBA *color;
435 Eina_List *color_list;
436 Elm_Color_Item *item;
437 Widget_Data *wd = elm_widget_data_get(obj);
438 color_list = _elm_config_color_list_get(wd->palette_name);
439 if (!color_list) return;
440 EINA_LIST_FOREACH(color_list, elist, color)
442 item = _item_new(obj);
444 item->color = ELM_NEW(Elm_Color_RGBA);
445 if (!item->color) return;
446 item->color->r = color->r;
447 item->color->g = color->g;
448 item->color->b = color->b;
449 item->color->a = color->a;
450 elm_box_pack_end(wd->box, VIEW(item));
451 evas_object_color_set(item->color_obj, item->color->r, item->color->g,
452 item->color->b, item->color->a);
453 wd->items = eina_list_append(wd->items, item);
454 _sizing_eval_palette(obj);
456 wd->config_load = EINA_TRUE;
460 _rgb_to_hsl(void *data)
462 Widget_Data *wd = data;
485 wd->l = (m + v) / 2.0;
487 if (wd->l <= 0.0) return;
492 if (wd->s > 0.0) wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m);
499 if (r == v) wd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
500 else if (g == v) wd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
501 else wd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
507 _hsl_to_rgb(void *data)
509 Widget_Data *wd = data;
510 double r = 0, g = 0, b = 0;
513 double sv, vsf, f, p, q, t, v;
519 if (_s == 0.0) r = g = b = _l;
522 if (_h == 360.0) _h = 0.0;
525 v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
528 if (v) sv = (v - p) / v;
573 i = (int)(r * 255.0);
575 wd->r = (f <= 0.5) ? i : (i + 1);
577 i = (int)(g * 255.0);
579 wd->g = (f <= 0.5) ? i : (i + 1);
581 i = (int)(b * 255.0);
583 wd->b = (f <= 0.5) ? i : (i + 1);
587 _color_with_saturation(void *data)
589 Widget_Data *wd = data;
592 wd->sr = 127 + (int)((double)(wd->er - 127) * wd->s);
594 wd->sr = 127 - (int)((double)(127 - wd->er) * wd->s);
597 wd->sg = 127 + (int)((double)(wd->eg - 127) * wd->s);
599 wd->sg = 127 - (int)((double)(127 - wd->eg) * wd->s);
602 wd->sb = 127 + (int)((double)(wd->eb - 127) * wd->s);
604 wd->sb = 127 - (int)((double)(127 - wd->eb) * wd->s);
608 _color_with_lightness(void *data)
610 Widget_Data *wd = data;
614 wd->lr = wd->er + (int)((double)(255 - wd->er) * (wd->l - 0.5) * 2.0);
615 wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (wd->l - 0.5) * 2.0);
616 wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (wd->l - 0.5) * 2.0);
618 else if (wd->l < 0.5)
620 wd->lr = (double)wd->er * wd->l * 2.0;
621 wd->lg = (double)wd->eg * wd->l * 2.0;
622 wd->lb = (double)wd->eb * wd->l * 2.0;
633 _draw_rects(void *data, double x)
635 Colorselector_Data *cp = data;
636 Widget_Data *wd = elm_widget_data_get(cp->parent);
637 double one_six = 1.0 / 6.0;
639 switch (cp->color_type)
647 wd->eg = (255.0 * x * 6.0);
650 else if (x < 2 * one_six)
652 wd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
656 else if (x < 3 * one_six)
660 wd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
662 else if (x < 4 * one_six)
665 wd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
668 else if (x < 5 * one_six)
670 wd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
678 wd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
681 evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255);
682 evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255);
683 evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255);
684 evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255);
686 _color_with_saturation(wd);
687 evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
689 _color_with_lightness(wd);
690 evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
692 evas_object_color_set(wd->cp[3]->arrow,
693 (wd->er * wd->a) / 255,
694 (wd->eg * wd->a) / 255,
695 (wd->eb * wd->a) / 255,
700 _color_with_saturation(wd);
701 evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
705 _color_with_lightness(wd);
706 evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
710 evas_object_color_set(wd->cp[3]->arrow,
711 (wd->er * wd->a) / 255,
712 (wd->eg * wd->a) / 255,
713 (wd->eb * wd->a) / 255,
723 _arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__,
724 const char *source __UNUSED__)
726 Colorselector_Data *cp = data;
729 edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
730 _draw_rects(data, x);
731 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
735 _colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
737 Colorselector_Data *cp = data;
738 Evas_Event_Mouse_Down *ev = event_info;
739 Evas_Coord x, y, w, h;
740 double arrow_x = 0, arrow_y;
742 evas_object_geometry_get(cp->bar, &x, &y, &w, &h);
743 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow",
745 if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
746 if (arrow_x > 1) arrow_x = 1;
747 if (arrow_x < 0) arrow_x = 0;
748 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y);
749 _draw_rects(data, arrow_x);
750 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
751 evas_event_feed_mouse_cancel(e, 0, NULL);
752 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
756 _left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
757 void *event_info __UNUSED__)
759 Colorselector_Data *cp = data;
762 edje_object_signal_emit(cp->lbt, "elm,state,left,button,down",
764 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
766 switch(cp->color_type)
784 if (x < 0.0) x = 0.0;
786 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
787 _draw_rects(data, x);
788 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
792 _left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
793 void *event_info __UNUSED__)
795 Colorselector_Data *cp = data;
798 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
799 x -= 1.0 / BASE_STEP;
800 if (x < 0.0) x = 0.0;
801 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
802 _draw_rects(data, x);
803 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
808 _right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
809 void *event_info __UNUSED__)
811 Colorselector_Data *cp = data;
814 edje_object_signal_emit(cp->rbt, "elm,state,right,button,down",
816 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
818 switch(cp->color_type)
836 if (x > 1.0) x = 1.0;
838 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
839 _draw_rects(data, x);
840 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
844 _right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
845 void *event_info __UNUSED__)
847 Colorselector_Data *cp = data;
850 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
851 x += 1.0 / BASE_STEP;
852 if (x > 1.0) x = 1.0;
853 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
854 _draw_rects(data, x);
855 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
859 _add_colorbar(Evas_Object *obj)
861 char colorbar_name[128];
862 char colorbar_s[128];
868 wd = elm_widget_data_get(obj);
871 e = evas_object_evas_get(obj);
873 for (i = 0; i < 4; i++)
875 wd->cp[i] = ELM_NEW(Colorselector_Data);
876 wd->cp[i]->parent = obj;
880 wd->cp[i]->color_type = HUE;
883 wd->cp[i]->color_type = SATURATION;
886 wd->cp[i]->color_type = LIGHTNESS;
889 wd->cp[i]->color_type = ALPHA;
894 /* load colorbar area */
895 wd->cp[i]->colorbar = edje_object_add(e);
896 _elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorselector", "base",
897 elm_widget_style_get(obj));
898 snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
899 snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
900 edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*",
901 _arrow_cb, wd->cp[i]);
902 edje_object_part_swallow(wd->sel, colorbar_s, wd->cp[i]->colorbar);
903 elm_widget_sub_object_add(obj, wd->cp[i]->colorbar);
905 /* load colorbar image */
906 wd->cp[i]->bar = edje_object_add(e);
907 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
908 elm_widget_style_get(obj));
909 _elm_theme_object_set(obj, wd->cp[i]->bar, "colorselector", "image",
911 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar",
913 elm_widget_sub_object_add(obj, wd->cp[i]->bar);
915 /* provide expanded touch area */
916 wd->cp[i]->touch_area = evas_object_rectangle_add(e);
917 evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0);
918 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg",
919 wd->cp[i]->touch_area);
920 evas_object_event_callback_add(wd->cp[i]->touch_area,
921 EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
923 elm_widget_sub_object_add(obj, wd->cp[i]->touch_area);
925 /* load background rectangle of the colorbar. used for
926 changing color of the opacity bar */
927 if ((i == 1) || (i == 2))
929 wd->cp[i]->bg_rect = evas_object_rectangle_add(e);
930 evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb,
932 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
935 elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
939 wd->cp[i]->bg_rect = edje_object_add(e);
940 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
941 elm_widget_style_get(obj));
942 _elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorselector",
944 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
946 elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
947 evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255);
949 /* load arrow image, pointing the colorbar */
950 wd->cp[i]->arrow = edje_object_add(e);
951 _elm_theme_object_set(obj, wd->cp[i]->arrow, "colorselector", "arrow",
952 elm_widget_style_get(obj));
953 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_icon",
955 elm_widget_sub_object_add(obj, wd->cp[i]->arrow);
957 evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255);
959 evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255);
961 /* load left button */
962 wd->cp[i]->lbt = elm_button_add(obj);
963 snprintf(buf, sizeof(buf), "colorselector/left/%s",
964 elm_widget_style_get(obj));
965 elm_object_style_set(wd->cp[i]->lbt, buf);
966 elm_widget_sub_object_add(obj, wd->cp[i]->lbt);
967 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button",
969 evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked",
970 _left_button_clicked_cb, wd->cp[i]);
971 elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE);
972 elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt,
973 _elm_config->longpress_timeout);
974 elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt,
975 (1.0 / _elm_config->fps));
976 evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated",
977 _left_button_repeat_cb, wd->cp[i]);
979 /* load right button */
980 wd->cp[i]->rbt = elm_button_add(obj);
981 snprintf(buf, sizeof(buf), "colorselector/right/%s",
982 elm_widget_style_get(obj));
983 elm_object_style_set(wd->cp[i]->rbt, buf);
984 elm_widget_sub_object_add(obj, wd->cp[i]->rbt);
985 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button",
987 evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked",
988 _right_button_clicked_cb, wd->cp[i]);
989 elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE);
990 elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt,
991 _elm_config->longpress_timeout);
992 elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt,
993 (1.0 / _elm_config->fps));
994 evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated",
995 _right_button_repeat_cb, wd->cp[i]);
1000 _set_color(Evas_Object *obj, int r, int g, int b, int a)
1002 Widget_Data *wd = elm_widget_data_get(obj);
1012 edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y);
1014 edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y);
1015 _draw_rects(wd->cp[0], x);
1017 edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y);
1019 edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y);
1020 _draw_rects(wd->cp[1], x);
1022 edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y);
1024 edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y);
1025 _draw_rects(wd->cp[2], x);
1027 edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y);
1029 edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y);
1030 _draw_rects(wd->cp[3], x);
1034 elm_colorselector_add(Evas_Object *parent)
1036 Evas_Object *obj = NULL;
1037 Widget_Data *wd = NULL;
1039 const char *hpadstr, *vpadstr;
1040 unsigned int h_pad = DEFAULT_HOR_PAD;
1041 unsigned int v_pad = DEFAULT_VER_PAD;
1043 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1045 ELM_SET_WIDTYPE(widtype, "colorselector");
1046 elm_widget_type_set(obj, "colorselector");
1047 elm_widget_sub_object_add(parent, obj);
1048 elm_widget_data_set(obj, wd);
1049 elm_widget_del_hook_set(obj, _del_hook);
1050 elm_widget_theme_hook_set(obj, _theme_hook);
1051 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1053 /* load background edj */
1054 wd->base = edje_object_add(e);
1055 _elm_theme_object_set(obj, wd->base, "colorselector", "palette", "default");
1056 elm_widget_resize_object_set(obj, wd->base);
1057 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
1060 wd->box = elm_box_add(obj);
1061 elm_box_layout_set(wd->box, evas_object_box_layout_flow_horizontal,
1063 elm_box_horizontal_set(wd->box, EINA_TRUE);
1064 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1066 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0);
1067 elm_box_homogeneous_set(wd->box, EINA_TRUE);
1068 hpadstr = edje_object_data_get(wd->base, "horizontal_pad");
1069 if (hpadstr) h_pad = atoi(hpadstr);
1070 vpadstr = edje_object_data_get(wd->base, "vertical_pad");
1071 if (vpadstr) v_pad = atoi(vpadstr);
1072 elm_box_padding_set(wd->box, h_pad, v_pad);
1073 elm_box_align_set(wd->box, 0.5, 0.5);
1074 elm_widget_sub_object_add(obj, wd->box);
1075 evas_object_show(wd->box);
1076 edje_object_part_swallow(wd->base, "palette", wd->box);
1077 wd->palette_name = eina_stringshare_add("default");
1078 _colors_load_apply(obj);
1080 /* load background edj */
1081 wd->sel = edje_object_add(e);
1082 _elm_theme_object_set(obj, wd->sel, "colorselector", "bg", "default");
1083 edje_object_part_swallow(wd->base, "selector", wd->sel);
1084 elm_widget_sub_object_add(obj, wd->sel);
1086 wd->mode = ELM_COLORSELECTOR_BOTH;
1103 elm_colorselector_color_set(Evas_Object *obj, int r, int g, int b, int a)
1105 ELM_CHECK_WIDTYPE(obj, widtype);
1106 _set_color(obj, r, g, b, a);
1110 elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
1112 ELM_CHECK_WIDTYPE(obj, widtype);
1113 Widget_Data *wd = elm_widget_data_get(obj);
1122 elm_colorselector_mode_set(Evas_Object *obj, Elm_Colorselector_Mode mode)
1124 ELM_CHECK_WIDTYPE(obj, widtype);
1125 Widget_Data *wd = elm_widget_data_get(obj);
1127 if (wd->mode == mode) return;
1131 case ELM_COLORSELECTOR_PALETTE:
1132 if (edje_object_part_swallow_get(wd->base, "selector"))
1134 edje_object_part_unswallow(wd->base, wd->sel);
1135 evas_object_hide(wd->sel);
1137 if (!edje_object_part_swallow_get(wd->base, "palette"))
1139 edje_object_part_swallow(wd->base, "palette", wd->box);
1140 evas_object_show(wd->box);
1143 case ELM_COLORSELECTOR_COMPONENTS:
1144 if (edje_object_part_swallow_get(wd->base, "palette"))
1146 edje_object_part_unswallow(wd->base, wd->box);
1147 evas_object_hide(wd->box);
1149 if (!edje_object_part_swallow_get(wd->base, "selector"))
1151 edje_object_part_swallow(wd->base, "selector", wd->sel);
1152 evas_object_show(wd->sel);
1155 case ELM_COLORSELECTOR_BOTH:
1156 if (!edje_object_part_swallow_get(wd->base, "palette"))
1158 edje_object_part_swallow(wd->base, "palette", wd->box);
1159 evas_object_show(wd->box);
1161 if (!edje_object_part_swallow_get(wd->base, "selector"))
1163 edje_object_part_swallow(wd->base, "selector", wd->sel);
1164 evas_object_show(wd->sel);
1173 EAPI Elm_Colorselector_Mode
1174 elm_colorselector_mode_get(const Evas_Object *obj)
1176 ELM_CHECK_WIDTYPE(obj, widtype) ELM_COLORSELECTOR_BOTH;
1177 Widget_Data *wd = elm_widget_data_get(obj);
1178 if (!wd) return ELM_COLORSELECTOR_BOTH;
1183 elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, int *r __UNUSED__, int *g __UNUSED__, int *b __UNUSED__, int*a __UNUSED__)
1185 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1186 Elm_Color_Item *item;
1187 item = (Elm_Color_Item *) it;
1190 if(r) *r = item->color->r;
1191 if(g) *g = item->color->g;
1192 if(b) *b = item->color->b;
1193 if(a) *a = item->color->a;
1198 elm_colorselector_palette_item_color_set(Elm_Object_Item *it, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__)
1200 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1201 Elm_Color_Item *item;
1202 item = (Elm_Color_Item *) it;
1207 evas_object_color_set(item->color_obj, item->color->r, item->color->g, item->color->b, item->color->a);
1208 _colors_save(WIDGET(it));
1211 EAPI Elm_Object_Item *
1212 elm_colorselector_palette_color_add(Evas_Object *obj, int r, int g, int b, int a)
1214 Elm_Color_Item *item;
1215 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1216 Widget_Data *wd = elm_widget_data_get(obj);
1217 if (!wd) return NULL;
1218 if (wd->config_load)
1220 _colors_remove(obj);
1221 wd->config_load = EINA_FALSE;
1223 item = _item_new(obj);
1224 if (!item) return NULL;
1225 item->color = ELM_NEW(Elm_Color_RGBA);
1226 if (!item->color) return NULL;
1231 _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
1232 item->color->b, item->color->a);
1233 elm_box_pack_end(wd->box, VIEW(item));
1234 evas_object_color_set(item->color_obj, item->color->r, item->color->g,
1235 item->color->b, item->color->a);
1236 wd->items = eina_list_append(wd->items, item);
1238 return (Elm_Object_Item *) item;
1242 elm_colorselector_palette_clear(Evas_Object *obj)
1244 ELM_CHECK_WIDTYPE(obj, widtype);
1245 Widget_Data *wd = elm_widget_data_get(obj);
1247 _colors_remove(obj);
1251 elm_colorselector_palette_name_set(Evas_Object *obj, const char *palette_name)
1253 ELM_CHECK_WIDTYPE(obj, widtype);
1254 Widget_Data *wd = elm_widget_data_get(obj);
1256 if (!strcmp(wd->palette_name, palette_name)) return;
1259 _colors_remove(obj);
1260 eina_stringshare_replace(&wd->palette_name, palette_name);
1261 _colors_load_apply(obj);
1266 elm_colorselector_palette_name_get(const Evas_Object *obj)
1268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1269 Widget_Data *wd = elm_widget_data_get(obj);
1270 if (!wd) return NULL;
1271 return wd->palette_name;