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;
132 if ((!wd) || (!wd->sel)) return;
134 _elm_theme_object_set(obj, wd->base, "colorselector", "palette",
135 elm_widget_style_get(obj));
136 _elm_theme_object_set(obj, wd->sel, "colorselector", "bg",
137 elm_widget_style_get(obj));
138 EINA_LIST_FOREACH(wd->items, elist, item)
140 elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
141 _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
143 for (i = 0; i < 4; i++)
145 evas_object_del(wd->cp[i]->colorbar);
146 wd->cp[i]->colorbar = NULL;
147 evas_object_del(wd->cp[i]->bar);
148 wd->cp[i]->bar = NULL;
149 evas_object_del(wd->cp[i]->lbt);
150 wd->cp[i]->lbt = NULL;
151 evas_object_del(wd->cp[i]->rbt);
152 wd->cp[i]->rbt = NULL;
155 evas_object_del(wd->cp[i]->bg_rect);
156 wd->cp[i]->bg_rect = NULL;
158 evas_object_del(wd->cp[i]->arrow);
159 wd->cp[i]->arrow = NULL;
160 evas_object_del(wd->cp[i]->touch_area);
161 wd->cp[i]->touch_area = NULL;
165 elm_colorselector_color_set(obj, wd->r, wd->g, wd->b, wd->a);
170 _colorselector_set_size_hints(Evas_Object *obj, int timesw, int timesh)
172 Evas_Coord minw = -1, minh = -1;
174 elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
175 edje_object_size_min_restricted_calc(obj, &minw, &minh,
177 evas_object_size_hint_min_set(obj, minw, minh);
178 evas_object_size_hint_max_set(obj, -1, -1);
182 _item_sizing_eval(Elm_Color_Item *item)
184 Evas_Coord minw = -1, minh = -1;
188 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
189 edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw,
191 evas_object_size_hint_min_set(VIEW(item), minw, minh);
194 static void _resize_cb(void *data, Evas *a __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
200 _sizing_eval_palette(Evas_Object *obj)
202 Widget_Data *wd = elm_widget_data_get(obj);
204 Elm_Color_Item *item;
205 Evas_Coord bw = 0, bh = 0;
206 Evas_Coord w = 0, h = 0;
209 EINA_LIST_FOREACH(wd->items, elist, item)
211 _item_sizing_eval(item);
213 evas_object_size_hint_min_get(wd->box, &bw, &bh);
214 evas_object_size_hint_min_set(obj, bw, bh);
215 evas_object_size_hint_max_set(obj, -1, -1);
216 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
219 evas_object_resize(obj, w, h);
223 _sizing_eval_selector(Evas_Object *obj)
225 Widget_Data *wd = elm_widget_data_get(obj);
226 Evas_Coord minw = -1, minh = -1;
227 Evas_Coord w = 0, h = 0;
231 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
232 for (i = 0; i < 4; i++)
234 if (wd->cp[i]->bg_rect)
235 _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
236 _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
237 _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
238 _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
240 _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
243 elm_coords_finger_size_adjust(4, &minw, 4, &minh);
244 edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
245 evas_object_size_hint_min_set(obj, minw, minh);
246 evas_object_size_hint_max_set(obj, -1, -1);
247 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
248 if (w < minw) w = minw;
249 if (h < minh) h = minh;
250 evas_object_resize(obj, w, h);
254 _sizing_eval_palette_selector(Evas_Object *obj)
256 Widget_Data *wd = elm_widget_data_get(obj);
257 Evas_Coord minw = -1, minh = -1;
258 Evas_Coord bw = 0, bh = 0;
259 Evas_Coord w = 0, h = 0;
262 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
263 for (i = 0; i < 4; i++)
265 if (wd->cp[i]->bg_rect)
266 _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
267 _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
268 _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
269 _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
271 _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
274 elm_coords_finger_size_adjust(4, &minw, 4, &minh);
275 edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
276 evas_object_size_hint_min_get(wd->box, &bw, &bh);
277 evas_object_size_hint_min_set(obj, minw, minh+bh);
278 evas_object_size_hint_max_set(obj, -1, -1);
279 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
280 if (w < minw) w = minw;
281 if (h < (minh+bh)) h = (minh+bh);
282 evas_object_resize(obj, w, h);
286 _sizing_eval(Evas_Object *obj)
288 Widget_Data *wd = elm_widget_data_get(obj);
292 case ELM_COLORSELECTOR_PALETTE:
293 _sizing_eval_palette(obj);
295 case ELM_COLORSELECTOR_COMPONENTS:
296 _sizing_eval_selector(obj);
298 case ELM_COLORSELECTOR_BOTH:
299 _sizing_eval_palette_selector(obj);
307 _long_press(void *data)
309 Elm_Color_Item *item = (Elm_Color_Item *) data;
310 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
311 if (!wd) return ECORE_CALLBACK_CANCEL;
312 wd->longpress_timer = NULL;
313 wd->longpressed = EINA_TRUE;
314 evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
315 return ECORE_CALLBACK_CANCEL;
319 _item_highlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
321 Elm_Color_Item *item = (Elm_Color_Item *) data;
322 Evas_Event_Mouse_Down *ev = event_info;
324 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
326 if (ev->button != 1) return;
327 elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
328 wd->longpressed = EINA_FALSE;
329 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
330 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
334 _item_unhighlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
336 Elm_Color_Item *item = (Elm_Color_Item *) data;
337 Evas_Event_Mouse_Down *ev = event_info;
339 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
341 if (ev->button != 1) return;
342 if (wd->longpress_timer)
344 ecore_timer_del(wd->longpress_timer);
345 wd->longpress_timer = NULL;
347 elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
348 if (!wd->longpressed)
350 evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
351 elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g, item->color->b, item->color->a);
356 _remove_items(Widget_Data *wd)
358 Elm_Color_Item *item;
360 if (!wd->items) return;
362 EINA_LIST_FREE(wd->items, item)
365 elm_widget_item_free(item);
371 static Elm_Color_Item*
372 _item_new(Evas_Object *obj)
374 Elm_Color_Item *item;
377 wd = elm_widget_data_get(obj);
378 if (!wd) return NULL;
380 item = elm_widget_item_new(obj, Elm_Color_Item);
381 if (!item) return NULL;
383 VIEW(item) = elm_layout_add(obj);
384 elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
385 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
386 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
387 item->color_obj = edje_object_add(evas_object_evas_get(obj));
388 _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
389 evas_object_size_hint_weight_set(item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
390 evas_object_size_hint_align_set(item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
391 evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _item_highlight, item);
392 evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_UP, _item_unhighlight, item);
393 elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj);
394 _item_sizing_eval(item);
395 evas_object_show(VIEW(item));
401 _colors_remove(Evas_Object *obj)
403 Widget_Data *wd = elm_widget_data_get(obj);
406 _elm_config_colors_free(wd->palette_name);
409 static void _colors_save(Evas_Object *obj)
412 Widget_Data *wd = elm_widget_data_get(obj);
413 Elm_Color_Item *item;
414 _elm_config_colors_free(wd->palette_name);
415 EINA_LIST_FOREACH(wd->items, elist, item)
417 _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
418 item->color->b, item->color->a);
423 _colors_load_apply(Evas_Object *obj)
425 Elm_Color_RGBA *color;
427 Eina_List *color_list;
428 Elm_Color_Item *item;
429 Widget_Data *wd = elm_widget_data_get(obj);
430 color_list = _elm_config_color_list_get(wd->palette_name);
431 if (!color_list) return;
432 EINA_LIST_FOREACH(color_list, elist, color)
434 item = _item_new(obj);
436 item->color = ELM_NEW(Elm_Color_RGBA);
437 if (!item->color) return;
438 item->color->r = color->r;
439 item->color->g = color->g;
440 item->color->b = color->b;
441 item->color->a = color->a;
442 elm_box_pack_end(wd->box, VIEW(item));
443 evas_object_color_set(item->color_obj, item->color->r, item->color->g,
444 item->color->b, item->color->a);
445 wd->items = eina_list_append(wd->items, item);
446 _sizing_eval_palette(obj);
448 wd->config_load = EINA_TRUE;
452 _rgb_to_hsl(void *data)
454 Widget_Data *wd = data;
477 wd->l = (m + v) / 2.0;
479 if (wd->l <= 0.0) return;
484 if (wd->s > 0.0) wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m);
491 if (r == v) wd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
492 else if (g == v) wd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
493 else wd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
499 _hsl_to_rgb(void *data)
501 Widget_Data *wd = data;
502 double r = 0, g = 0, b = 0;
505 double sv, vsf, f, p, q, t, v;
511 if (_s == 0.0) r = g = b = _l;
514 if (_h == 360.0) _h = 0.0;
517 v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
520 if (v) sv = (v - p) / v;
565 i = (int)(r * 255.0);
567 wd->r = (f <= 0.5) ? i : (i + 1);
569 i = (int)(g * 255.0);
571 wd->g = (f <= 0.5) ? i : (i + 1);
573 i = (int)(b * 255.0);
575 wd->b = (f <= 0.5) ? i : (i + 1);
579 _color_with_saturation(void *data)
581 Widget_Data *wd = data;
584 wd->sr = 127 + (int)((double)(wd->er - 127) * wd->s);
586 wd->sr = 127 - (int)((double)(127 - wd->er) * wd->s);
589 wd->sg = 127 + (int)((double)(wd->eg - 127) * wd->s);
591 wd->sg = 127 - (int)((double)(127 - wd->eg) * wd->s);
594 wd->sb = 127 + (int)((double)(wd->eb - 127) * wd->s);
596 wd->sb = 127 - (int)((double)(127 - wd->eb) * wd->s);
600 _color_with_lightness(void *data)
602 Widget_Data *wd = data;
606 wd->lr = wd->er + (int)((double)(255 - wd->er) * (wd->l - 0.5) * 2.0);
607 wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (wd->l - 0.5) * 2.0);
608 wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (wd->l - 0.5) * 2.0);
610 else if (wd->l < 0.5)
612 wd->lr = (double)wd->er * wd->l * 2.0;
613 wd->lg = (double)wd->eg * wd->l * 2.0;
614 wd->lb = (double)wd->eb * wd->l * 2.0;
625 _draw_rects(void *data, double x)
627 Colorselector_Data *cp = data;
628 Widget_Data *wd = elm_widget_data_get(cp->parent);
629 double one_six = 1.0 / 6.0;
631 switch (cp->color_type)
639 wd->eg = (255.0 * x * 6.0);
642 else if (x < 2 * one_six)
644 wd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
648 else if (x < 3 * one_six)
652 wd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
654 else if (x < 4 * one_six)
657 wd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
660 else if (x < 5 * one_six)
662 wd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
670 wd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
673 evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255);
674 evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255);
675 evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255);
676 evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255);
678 _color_with_saturation(wd);
679 evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
681 _color_with_lightness(wd);
682 evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
684 evas_object_color_set(wd->cp[3]->arrow,
685 (wd->er * wd->a) / 255,
686 (wd->eg * wd->a) / 255,
687 (wd->eb * wd->a) / 255,
692 _color_with_saturation(wd);
693 evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
697 _color_with_lightness(wd);
698 evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
702 evas_object_color_set(wd->cp[3]->arrow,
703 (wd->er * wd->a) / 255,
704 (wd->eg * wd->a) / 255,
705 (wd->eb * wd->a) / 255,
715 _arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__,
716 const char *source __UNUSED__)
718 Colorselector_Data *cp = data;
721 edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
722 _draw_rects(data, x);
723 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
727 _colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
729 Colorselector_Data *cp = data;
730 Evas_Event_Mouse_Down *ev = event_info;
731 Evas_Coord x, y, w, h;
732 double arrow_x = 0, arrow_y;
734 evas_object_geometry_get(cp->bar, &x, &y, &w, &h);
735 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow",
737 if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
738 if (arrow_x > 1) arrow_x = 1;
739 if (arrow_x < 0) arrow_x = 0;
740 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y);
741 _draw_rects(data, arrow_x);
742 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
743 evas_event_feed_mouse_cancel(e, 0, NULL);
744 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
748 _left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
749 void *event_info __UNUSED__)
751 Colorselector_Data *cp = data;
754 edje_object_signal_emit(cp->lbt, "elm,state,left,button,down",
756 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
758 switch(cp->color_type)
776 if (x < 0.0) x = 0.0;
778 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
779 _draw_rects(data, x);
780 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
784 _left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
785 void *event_info __UNUSED__)
787 Colorselector_Data *cp = data;
790 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
791 x -= 1.0 / BASE_STEP;
792 if (x < 0.0) x = 0.0;
793 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
794 _draw_rects(data, x);
795 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
800 _right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
801 void *event_info __UNUSED__)
803 Colorselector_Data *cp = data;
806 edje_object_signal_emit(cp->rbt, "elm,state,right,button,down",
808 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
810 switch(cp->color_type)
828 if (x > 1.0) x = 1.0;
830 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
831 _draw_rects(data, x);
832 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
836 _right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
837 void *event_info __UNUSED__)
839 Colorselector_Data *cp = data;
842 edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
843 x += 1.0 / BASE_STEP;
844 if (x > 1.0) x = 1.0;
845 edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
846 _draw_rects(data, x);
847 evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
851 _add_colorbar(Evas_Object *obj)
853 char colorbar_name[128];
854 char colorbar_s[128];
860 wd = elm_widget_data_get(obj);
863 e = evas_object_evas_get(obj);
865 for (i = 0; i < 4; i++)
867 wd->cp[i] = ELM_NEW(Colorselector_Data);
868 wd->cp[i]->parent = obj;
872 wd->cp[i]->color_type = HUE;
875 wd->cp[i]->color_type = SATURATION;
878 wd->cp[i]->color_type = LIGHTNESS;
881 wd->cp[i]->color_type = ALPHA;
886 /* load colorbar area */
887 wd->cp[i]->colorbar = edje_object_add(e);
888 _elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorselector", "base",
889 elm_widget_style_get(obj));
890 snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
891 snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
892 edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*",
893 _arrow_cb, wd->cp[i]);
894 edje_object_part_swallow(wd->sel, colorbar_s, wd->cp[i]->colorbar);
895 elm_widget_sub_object_add(obj, wd->cp[i]->colorbar);
897 /* load colorbar image */
898 wd->cp[i]->bar = edje_object_add(e);
899 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
900 elm_widget_style_get(obj));
901 _elm_theme_object_set(obj, wd->cp[i]->bar, "colorselector", "image",
903 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar",
905 elm_widget_sub_object_add(obj, wd->cp[i]->bar);
907 /* provide expanded touch area */
908 wd->cp[i]->touch_area = evas_object_rectangle_add(e);
909 evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0);
910 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg",
911 wd->cp[i]->touch_area);
912 evas_object_event_callback_add(wd->cp[i]->touch_area,
913 EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
915 elm_widget_sub_object_add(obj, wd->cp[i]->touch_area);
917 /* load background rectangle of the colorbar. used for
918 changing color of the opacity bar */
919 if ((i == 1) || (i == 2))
921 wd->cp[i]->bg_rect = evas_object_rectangle_add(e);
922 evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb,
924 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
927 elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
931 wd->cp[i]->bg_rect = edje_object_add(e);
932 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
933 elm_widget_style_get(obj));
934 _elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorselector",
936 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
938 elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
939 evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255);
941 /* load arrow image, pointing the colorbar */
942 wd->cp[i]->arrow = edje_object_add(e);
943 _elm_theme_object_set(obj, wd->cp[i]->arrow, "colorselector", "arrow",
944 elm_widget_style_get(obj));
945 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_icon",
947 elm_widget_sub_object_add(obj, wd->cp[i]->arrow);
949 evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255);
951 evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255);
953 /* load left button */
954 wd->cp[i]->lbt = elm_button_add(obj);
955 snprintf(buf, sizeof(buf), "colorselector/left/%s",
956 elm_widget_style_get(obj));
957 elm_object_style_set(wd->cp[i]->lbt, buf);
958 elm_widget_sub_object_add(obj, wd->cp[i]->lbt);
959 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button",
961 evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked",
962 _left_button_clicked_cb, wd->cp[i]);
963 elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE);
964 elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt,
965 _elm_config->longpress_timeout);
966 elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt,
967 (1.0 / _elm_config->fps));
968 evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated",
969 _left_button_repeat_cb, wd->cp[i]);
971 /* load right button */
972 wd->cp[i]->rbt = elm_button_add(obj);
973 snprintf(buf, sizeof(buf), "colorselector/right/%s",
974 elm_widget_style_get(obj));
975 elm_object_style_set(wd->cp[i]->rbt, buf);
976 elm_widget_sub_object_add(obj, wd->cp[i]->rbt);
977 edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button",
979 evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked",
980 _right_button_clicked_cb, wd->cp[i]);
981 elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE);
982 elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt,
983 _elm_config->longpress_timeout);
984 elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt,
985 (1.0 / _elm_config->fps));
986 evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated",
987 _right_button_repeat_cb, wd->cp[i]);
992 _set_color(Evas_Object *obj, int r, int g, int b, int a)
994 Widget_Data *wd = elm_widget_data_get(obj);
1004 edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y);
1006 edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y);
1007 _draw_rects(wd->cp[0], x);
1009 edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y);
1011 edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y);
1012 _draw_rects(wd->cp[1], x);
1014 edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y);
1016 edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y);
1017 _draw_rects(wd->cp[2], x);
1019 edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y);
1021 edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y);
1022 _draw_rects(wd->cp[3], x);
1026 elm_colorselector_add(Evas_Object *parent)
1028 Evas_Object *obj = NULL;
1029 Widget_Data *wd = NULL;
1031 const char *hpadstr, *vpadstr;
1032 unsigned int h_pad = DEFAULT_HOR_PAD;
1033 unsigned int v_pad = DEFAULT_VER_PAD;
1035 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1037 ELM_SET_WIDTYPE(widtype, "colorselector");
1038 elm_widget_type_set(obj, "colorselector");
1039 elm_widget_sub_object_add(parent, obj);
1040 elm_widget_data_set(obj, wd);
1041 elm_widget_del_hook_set(obj, _del_hook);
1042 elm_widget_theme_hook_set(obj, _theme_hook);
1043 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1045 /* load background edj */
1046 wd->base = edje_object_add(e);
1047 _elm_theme_object_set(obj, wd->base, "colorselector", "palette", "default");
1048 elm_widget_resize_object_set(obj, wd->base);
1049 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
1052 wd->box = elm_box_add(obj);
1053 elm_box_layout_set(wd->box, evas_object_box_layout_flow_horizontal,
1055 elm_box_horizontal_set(wd->box, EINA_TRUE);
1056 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1058 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0);
1059 elm_box_homogeneous_set(wd->box, EINA_TRUE);
1060 hpadstr = edje_object_data_get(wd->sel, "horizontal_pad");
1061 if (hpadstr) h_pad = atoi(hpadstr);
1062 vpadstr = edje_object_data_get(wd->sel, "vertical_pad");
1063 if (vpadstr) v_pad = atoi(vpadstr);
1064 elm_box_padding_set(wd->box, h_pad, v_pad);
1065 elm_box_align_set(wd->box, 0.5, 0.5);
1066 elm_widget_sub_object_add(obj, wd->box);
1067 evas_object_show(wd->box);
1068 edje_object_part_swallow(wd->base, "palette", wd->box);
1069 wd->palette_name = eina_stringshare_add("default");
1070 _colors_load_apply(obj);
1072 /* load background edj */
1073 wd->sel = edje_object_add(e);
1074 _elm_theme_object_set(obj, wd->sel, "colorselector", "bg", "default");
1075 edje_object_part_swallow(wd->base, "selector", wd->sel);
1076 wd->mode = ELM_COLORSELECTOR_BOTH;
1094 elm_colorselector_color_set(Evas_Object *obj, int r, int g, int b, int a)
1096 ELM_CHECK_WIDTYPE(obj, widtype);
1097 _set_color(obj, r, g, b, a);
1101 elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
1103 ELM_CHECK_WIDTYPE(obj, widtype);
1104 Widget_Data *wd = elm_widget_data_get(obj);
1113 elm_colorselector_mode_set(Evas_Object *obj, Elm_Colorselector_Mode mode)
1115 ELM_CHECK_WIDTYPE(obj, widtype);
1116 Widget_Data *wd = elm_widget_data_get(obj);
1118 if (wd->mode == mode) return;
1122 case ELM_COLORSELECTOR_PALETTE:
1123 if (edje_object_part_swallow_get(wd->base, "selector"))
1125 edje_object_part_unswallow(wd->base, wd->sel);
1126 evas_object_hide(wd->sel);
1128 if (!edje_object_part_swallow_get(wd->base, "palette"))
1130 edje_object_part_swallow(wd->base, "palette", wd->box);
1131 evas_object_show(wd->box);
1134 case ELM_COLORSELECTOR_COMPONENTS:
1135 if (edje_object_part_swallow_get(wd->base, "palette"))
1137 edje_object_part_unswallow(wd->base, wd->box);
1138 evas_object_hide(wd->box);
1140 if (!edje_object_part_swallow_get(wd->base, "selector"))
1142 edje_object_part_swallow(wd->base, "selector", wd->sel);
1143 evas_object_show(wd->sel);
1146 case ELM_COLORSELECTOR_BOTH:
1147 if (!edje_object_part_swallow_get(wd->base, "palette"))
1149 edje_object_part_swallow(wd->base, "palette", wd->box);
1150 evas_object_show(wd->box);
1152 if (!edje_object_part_swallow_get(wd->base, "selector"))
1154 edje_object_part_swallow(wd->base, "selector", wd->sel);
1155 evas_object_show(wd->sel);
1164 EAPI Elm_Colorselector_Mode
1165 elm_colorselector_mode_get(const Evas_Object *obj)
1167 ELM_CHECK_WIDTYPE(obj, widtype) ELM_COLORSELECTOR_BOTH;
1168 Widget_Data *wd = elm_widget_data_get(obj);
1169 if (!wd) return ELM_COLORSELECTOR_BOTH;
1174 elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, int *r __UNUSED__, int *g __UNUSED__, int *b __UNUSED__, int*a __UNUSED__)
1176 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1177 Elm_Color_Item *item;
1178 item = (Elm_Color_Item *) it;
1181 if(r) *r = item->color->r;
1182 if(g) *g = item->color->g;
1183 if(b) *b = item->color->b;
1184 if(a) *a = item->color->a;
1189 elm_colorselector_palette_item_color_set(Elm_Object_Item *it, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__)
1191 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1192 Elm_Color_Item *item;
1193 item = (Elm_Color_Item *) it;
1198 evas_object_color_set(item->color_obj, item->color->r, item->color->g, item->color->b, item->color->a);
1199 _colors_save(WIDGET(it));
1202 EAPI Elm_Object_Item *
1203 elm_colorselector_palette_color_add(Evas_Object *obj, int r, int g, int b, int a)
1205 Elm_Color_Item *item;
1206 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1207 Widget_Data *wd = elm_widget_data_get(obj);
1208 if (!wd) return NULL;
1209 if (wd->config_load)
1211 _colors_remove(obj);
1212 wd->config_load = EINA_FALSE;
1214 item = _item_new(obj);
1215 if (!item) return NULL;
1216 item->color = ELM_NEW(Elm_Color_RGBA);
1217 if (!item->color) return NULL;
1222 _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
1223 item->color->b, item->color->a);
1224 elm_box_pack_end(wd->box, VIEW(item));
1225 evas_object_color_set(item->color_obj, item->color->r, item->color->g,
1226 item->color->b, item->color->a);
1227 wd->items = eina_list_append(wd->items, item);
1229 return (Elm_Object_Item *) item;
1233 elm_colorselector_palette_clear(Evas_Object *obj)
1235 ELM_CHECK_WIDTYPE(obj, widtype);
1236 Widget_Data *wd = elm_widget_data_get(obj);
1238 _colors_remove(obj);
1242 elm_colorselector_palette_name_set(Evas_Object *obj, const char *palette_name)
1244 ELM_CHECK_WIDTYPE(obj, widtype);
1245 Widget_Data *wd = elm_widget_data_get(obj);
1247 if (!strcmp(wd->palette_name, palette_name)) return;
1250 _colors_remove(obj);
1251 eina_stringshare_replace(&wd->palette_name, palette_name);
1252 _colors_load_apply(obj);
1257 elm_colorselector_palette_name_get(const Evas_Object *obj)
1259 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1260 Widget_Data *wd = elm_widget_data_get(obj);
1261 if (!wd) return NULL;
1262 return wd->palette_name;