diff --git a/legacy/elementary/src/lib/elm_colorselector.c b/legacy/elementary/src/lib/elm_colorselector.c index f650855082..73692d892d 100644 --- a/legacy/elementary/src/lib/elm_colorselector.c +++ b/legacy/elementary/src/lib/elm_colorselector.c @@ -1,11 +1,14 @@ #include #include "elm_priv.h" +#include "elm_widget_layout.h" -#define BASE_STEP 360.0 -#define HUE_STEP 360.0 -#define SAT_STEP 128.0 -#define LIG_STEP 256.0 -#define ALP_STEP 256.0 +static const char COLORSELECTOR_SMART_NAME[] = "elm_colorselector"; + +#define BASE_STEP 360.0 +#define HUE_STEP 360.0 +#define SAT_STEP 128.0 +#define LIG_STEP 256.0 +#define ALP_STEP 256.0 #define DEFAULT_HOR_PAD 10 #define DEFAULT_VER_PAD 10 @@ -17,8 +20,8 @@ typedef enum _Color_Type ALPHA } Color_Type; -typedef struct _Colorselector_Data Colorselector_Data; -struct _Colorselector_Data +typedef struct _Color_Bar_Data Color_Bar_Data; +struct _Color_Bar_Data { Evas_Object *parent; Evas_Object *colorbar; @@ -28,78 +31,85 @@ struct _Colorselector_Data Evas_Object *bg_rect; Evas_Object *arrow; Evas_Object *touch_area; - Color_Type color_type; + Color_Type color_type; }; -typedef struct _Widget_Data Widget_Data; -typedef struct _Elm_Color_Item Elm_Color_Item; -struct _Widget_Data +typedef struct _Elm_Colorselector_Smart_Data Elm_Colorselector_Smart_Data; +typedef struct _Elm_Color_Item Elm_Color_Item; +struct _Elm_Colorselector_Smart_Data { - Evas_Object *sel; - Evas_Object *base; - Evas_Object *box; - Eina_List *items; - Colorselector_Data *cp[4]; - Ecore_Timer *longpress_timer; - const char *palette_name; - Evas_Coord _x, _y, _w, _h; - int r, g, b, a; - int er, eg, eb; - int sr, sg, sb; - int lr, lg, lb; - double h, s, l; + Elm_Layout_Smart_Data base; + + /* for the 2 displaying modes of the widget */ + Evas_Object *col_bars_area; + Evas_Object *palette_box; + + Eina_List *items; + Color_Bar_Data *cb_data[4]; + + Ecore_Timer *longpress_timer; + const char *palette_name; + Evas_Coord _x, _y, _w, _h; + + /* color components */ + int r, g, b, a; + int er, eg, eb; + int sr, sg, sb; + int lr, lg, lb; + + double h, s, l; Elm_Colorselector_Mode mode; - Eina_Bool longpressed : 1; - Eina_Bool config_load: 1; + + Eina_Bool longpressed : 1; + Eina_Bool config_load : 1; }; struct _Elm_Color_Item { ELM_WIDGET_ITEM; - Evas_Object *color_obj; + + Evas_Object *color_obj; Elm_Color_RGBA *color; }; -static const char *widtype = NULL; +#define ELM_COLORSELECTOR_DATA_GET(o, sd) \ + Elm_Colorselector_Smart_Data * sd = evas_object_smart_data_get(o) -static void _del_hook(Evas_Object *obj); -static void _theme_hook(Evas_Object *obj); -static void _sizing_eval(Evas_Object *obj); -static void _resize_cb(void *data, Evas *a, Evas_Object *obj, void *event_info); -static void _rgb_to_hsl(void *data); -static void _hsl_to_rgb(void *data); -static void _color_with_saturation(void *data); -static void _color_with_lightness(void *data); -static void _draw_rects(void *data, double x); -static void _arrow_cb(void *data, Evas_Object *obj, const char *emission, - const char *source); -static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj, - void *event_info); -static void _left_button_clicked_cb(void *data, Evas_Object * obj, - void *event_info); -static void _left_button_repeat_cb(void *data, Evas_Object * obj, - void *event_info); -static void _right_button_clicked_cb(void *data, Evas_Object * obj, - void *event_info); -static void _right_button_repeat_cb(void *data, Evas_Object * obj, - void *event_info); -static void _add_colorbar(Evas_Object *obj); -static void _set_color(Evas_Object *obj, int r, int g, int b, int a); -static Elm_Color_Item *_item_new(Evas_Object *obj); -static void _item_sizing_eval(Elm_Color_Item *item); -static void _item_highlight(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _item_unhighlight(void *data, Evas *e, Evas_Object *obj, void *event_info); -static Eina_Bool _long_press(void *data); -static void _remove_items(Widget_Data *wd); -static void _colors_remove(Evas_Object *obj); -static void _colors_save(Evas_Object *obj); -static void _colors_load_apply(Evas_Object *obj); +#define ELM_COLORSELECTOR_DATA_GET_OR_RETURN(o, ptr) \ + ELM_COLORSELECTOR_DATA_GET(o, ptr); \ + if (!ptr) \ + { \ + CRITICAL("No widget data for object %p (%s)", \ + o, evas_object_type_get(o)); \ + return; \ + } + +#define ELM_COLORSELECTOR_DATA_GET_OR_RETURN_VAL(o, ptr, val) \ + ELM_COLORSELECTOR_DATA_GET(o, ptr); \ + if (!ptr) \ + { \ + CRITICAL("No widget data for object %p (%s)", \ + o, evas_object_type_get(o)); \ + return val; \ + } + +#define ELM_COLORSELECTOR_CHECK(obj) \ + if (!obj || !elm_widget_type_check \ + ((obj), COLORSELECTOR_SMART_NAME, __func__)) \ + return + +#define ELM_COLORSELECTOR_ITEM_CHECK(it) \ + ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \ + ELM_COLORSELECTOR_CHECK(it->base.widget); + +#define ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it, ...) \ + ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \ + ELM_COLORSELECTOR_CHECK(it->base.widget) __VA_ARGS__; static const char SIG_CHANGED[] = "changed"; static const char SIG_COLOR_ITEM_SELECTED[] = "color,item,selected"; static const char SIG_COLOR_ITEM_LONGPRESSED[] = "color,item,longpressed"; - -static const Evas_Smart_Cb_Description _signals[] = +static const Evas_Smart_Cb_Description _smart_callbacks[] = { {SIG_COLOR_ITEM_SELECTED, ""}, {SIG_COLOR_ITEM_LONGPRESSED, ""}, @@ -107,415 +117,81 @@ static const Evas_Smart_Cb_Description _signals[] = {NULL, NULL} }; -static void -_del_hook(Evas_Object *obj) -{ - Widget_Data *wd = elm_widget_data_get(obj); - int i = 0; - - if (!wd) return; - if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer); - if (wd->palette_name) eina_stringshare_del(wd->palette_name); - _remove_items(wd); - for (i = 0; i < 4; i++) free(wd->cp[i]); - free(wd); -} +/* Inheriting from elm_layout. Besides, we need no more than what is + * there */ +EVAS_SMART_SUBCLASS_NEW + (COLORSELECTOR_SMART_NAME, _elm_colorselector, Elm_Layout_Smart_Class, + Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks); static void -_theme_hook(Evas_Object *obj) -{ - Widget_Data *wd = elm_widget_data_get(obj); - Eina_List *elist; - Elm_Color_Item *item; - int i; - const char *hpadstr, *vpadstr; - unsigned int h_pad = DEFAULT_HOR_PAD; - unsigned int v_pad = DEFAULT_VER_PAD; - - if ((!wd) || (!wd->sel)) return; - - _elm_theme_object_set(obj, wd->base, "colorselector", "palette", - elm_widget_style_get(obj)); - _elm_theme_object_set(obj, wd->sel, "colorselector", "bg", - elm_widget_style_get(obj)); - hpadstr = edje_object_data_get(wd->base, "horizontal_pad"); - if (hpadstr) h_pad = atoi(hpadstr); - vpadstr = edje_object_data_get(wd->base, "vertical_pad"); - if (vpadstr) v_pad = atoi(vpadstr); - elm_box_padding_set(wd->box, (Evas_Coord)(h_pad * elm_widget_scale_get(obj) * _elm_config->scale), - (Evas_Coord)(v_pad * elm_widget_scale_get(obj) *_elm_config->scale)); - EINA_LIST_FOREACH(wd->items, elist, item) - { - elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj)); - _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj)); - } - for (i = 0; i < 4; i++) - { - evas_object_del(wd->cp[i]->colorbar); - wd->cp[i]->colorbar = NULL; - evas_object_del(wd->cp[i]->bar); - wd->cp[i]->bar = NULL; - evas_object_del(wd->cp[i]->lbt); - wd->cp[i]->lbt = NULL; - evas_object_del(wd->cp[i]->rbt); - wd->cp[i]->rbt = NULL; - if (i != 0) - { - evas_object_del(wd->cp[i]->bg_rect); - wd->cp[i]->bg_rect = NULL; - } - evas_object_del(wd->cp[i]->arrow); - wd->cp[i]->arrow = NULL; - evas_object_del(wd->cp[i]->touch_area); - wd->cp[i]->touch_area = NULL; - } - - _add_colorbar(obj); - elm_colorselector_color_set(obj, wd->r, wd->g, wd->b, wd->a); - _sizing_eval(obj); -} - -static void -_colorselector_set_size_hints(Evas_Object *obj, int timesw, int timesh) -{ - Evas_Coord minw = -1, minh = -1; - - elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh); - edje_object_size_min_restricted_calc(obj, &minw, &minh, - minw, minh); - evas_object_size_hint_min_set(obj, minw, minh); - evas_object_size_hint_max_set(obj, -1, -1); -} - -static void -_item_sizing_eval(Elm_Color_Item *item) -{ - Evas_Coord minw = -1, minh = -1; - - if (!item) return; - - elm_coords_finger_size_adjust(1, &minw, 1, &minh); - edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw, - minh); - evas_object_size_hint_min_set(VIEW(item), minw, minh); -} - -static void _resize_cb(void *data, Evas *a __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) -{ - _sizing_eval(data); -} - -static void -_sizing_eval_palette(Evas_Object *obj) -{ - Widget_Data *wd = elm_widget_data_get(obj); - Eina_List *elist; - Elm_Color_Item *item; - Evas_Coord bw = 0, bh = 0; - Evas_Coord w = 0, h = 0; - if (!wd) return; - - EINA_LIST_FOREACH(wd->items, elist, item) - { - _item_sizing_eval(item); - } - evas_object_size_hint_min_get(wd->box, &bw, &bh); - evas_object_size_hint_min_set(obj, bw, bh); - evas_object_size_hint_max_set(obj, -1, -1); - evas_object_geometry_get(obj, NULL, NULL, &w, &h); - if (w < bw) w = bw; - if (h < bh) h = bh; - evas_object_resize(obj, w, h); -} - -static void -_sizing_eval_selector(Evas_Object *obj) -{ - Widget_Data *wd = elm_widget_data_get(obj); - Evas_Coord minw = -1, minh = -1; - Evas_Coord w = 0, h = 0; - int i; - - if (!wd) return; - elm_coords_finger_size_adjust(1, &minw, 1, &minh); - for (i = 0; i < 4; i++) - { - if (wd->cp[i]->bg_rect) - _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1); - _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1); - _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1); - _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1); - - _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1); - } - - elm_coords_finger_size_adjust(4, &minw, 4, &minh); - edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh); - evas_object_size_hint_min_set(obj, minw, minh); - evas_object_size_hint_max_set(obj, -1, -1); - evas_object_geometry_get(obj, NULL, NULL, &w, &h); - if (w < minw) w = minw; - if (h < minh) h = minh; - evas_object_resize(obj, w, h); -} - -static void -_sizing_eval_palette_selector(Evas_Object *obj) -{ - Widget_Data *wd = elm_widget_data_get(obj); - Evas_Coord minw = -1, minh = -1; - Evas_Coord bw = 0, bh = 0; - Evas_Coord w = 0, h = 0; - int i; - if (!wd) return; - elm_coords_finger_size_adjust(1, &minw, 1, &minh); - for (i = 0; i < 4; i++) - { - if (wd->cp[i]->bg_rect) - _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1); - _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1); - _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1); - _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1); - - _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1); - } - - elm_coords_finger_size_adjust(4, &minw, 4, &minh); - edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh); - evas_object_size_hint_min_get(wd->box, &bw, &bh); - evas_object_size_hint_min_set(obj, minw, minh+bh); - evas_object_size_hint_max_set(obj, -1, -1); - evas_object_geometry_get(obj, NULL, NULL, &w, &h); - if (w < minw) w = minw; - if (h < (minh+bh)) h = (minh+bh); - evas_object_resize(obj, w, h); -} - -static void -_sizing_eval(Evas_Object *obj) -{ - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; - switch (wd->mode) - { - case ELM_COLORSELECTOR_PALETTE: - _sizing_eval_palette(obj); - break; - case ELM_COLORSELECTOR_COMPONENTS: - _sizing_eval_selector(obj); - break; - case ELM_COLORSELECTOR_BOTH: - _sizing_eval_palette_selector(obj); - break; - default: - break; - } -} - -static Eina_Bool -_long_press(void *data) -{ - Elm_Color_Item *item = (Elm_Color_Item *) data; - Widget_Data *wd = elm_widget_data_get(WIDGET(item)); - if (!wd) return ECORE_CALLBACK_CANCEL; - wd->longpress_timer = NULL; - wd->longpressed = EINA_TRUE; - evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item); - return ECORE_CALLBACK_CANCEL; -} - -static void -_item_highlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) -{ - Elm_Color_Item *item = (Elm_Color_Item *) data; - Evas_Event_Mouse_Down *ev = event_info; - if (!item) return; - Widget_Data *wd = elm_widget_data_get(WIDGET(item)); - if (!wd) return; - if (ev->button != 1) return; - elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm"); - wd->longpressed = EINA_FALSE; - if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer); - wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data); -} - -static void -_item_unhighlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) -{ - Elm_Color_Item *item = (Elm_Color_Item *) data; - Evas_Event_Mouse_Down *ev = event_info; - if (!item) return; - Widget_Data *wd = elm_widget_data_get(WIDGET(item)); - if (!wd) return; - if (ev->button != 1) return; - if (wd->longpress_timer) - { - ecore_timer_del(wd->longpress_timer); - wd->longpress_timer = NULL; - } - elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm"); - if (!wd->longpressed) - { - evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED, item); - elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g, item->color->b, item->color->a); - } -} - -static void -_remove_items(Widget_Data *wd) +_items_del(Elm_Colorselector_Smart_Data *sd) { Elm_Color_Item *item; - if (!wd->items) return; + if (!sd->items) return; - EINA_LIST_FREE(wd->items, item) + EINA_LIST_FREE (sd->items, item) { free(item->color); elm_widget_item_free(item); } - wd->items = NULL; -} - -static Elm_Color_Item* -_item_new(Evas_Object *obj) -{ - Elm_Color_Item *item; - Widget_Data *wd; - - wd = elm_widget_data_get(obj); - if (!wd) return NULL; - - item = elm_widget_item_new(obj, Elm_Color_Item); - if (!item) return NULL; - - VIEW(item) = elm_layout_add(obj); - elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj)); - evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL); - item->color_obj = edje_object_add(evas_object_evas_get(obj)); - _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj)); - evas_object_size_hint_weight_set(item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _item_highlight, item); - evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_UP, _item_unhighlight, item); - elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj); - _item_sizing_eval(item); - evas_object_show(VIEW(item)); - - return item; + sd->items = NULL; } static void -_colors_remove(Evas_Object *obj) +_color_with_saturation(Elm_Colorselector_Smart_Data *sd) { - Widget_Data *wd = elm_widget_data_get(obj); + if (sd->er > 127) + sd->sr = 127 + (int)((double)(sd->er - 127) * sd->s); + else + sd->sr = 127 - (int)((double)(127 - sd->er) * sd->s); - _remove_items(wd); - _elm_config_colors_free(wd->palette_name); + if (sd->eg > 127) + sd->sg = 127 + (int)((double)(sd->eg - 127) * sd->s); + else + sd->sg = 127 - (int)((double)(127 - sd->eg) * sd->s); + + if (sd->eb > 127) + sd->sb = 127 + (int)((double)(sd->eb - 127) * sd->s); + else + sd->sb = 127 - (int)((double)(127 - sd->eb) * sd->s); } -static void _colors_save(Evas_Object *obj) +static void +_color_with_lightness(Elm_Colorselector_Smart_Data *sd) { - Eina_List *elist; - Widget_Data *wd = elm_widget_data_get(obj); - Elm_Color_Item *item; - _elm_config_colors_free(wd->palette_name); - EINA_LIST_FOREACH(wd->items, elist, item) + if (sd->l > 0.5) { - _elm_config_color_set(wd->palette_name, item->color->r, item->color->g, - item->color->b, item->color->a); + sd->lr = sd->er + (int)((double)(255 - sd->er) * (sd->l - 0.5) * 2.0); + sd->lg = sd->eg + (int)((double)(255 - sd->eg) * (sd->l - 0.5) * 2.0); + sd->lb = sd->eb + (int)((double)(255 - sd->eb) * (sd->l - 0.5) * 2.0); + } + else if (sd->l < 0.5) + { + sd->lr = (double)sd->er * sd->l * 2.0; + sd->lg = (double)sd->eg * sd->l * 2.0; + sd->lb = (double)sd->eb * sd->l * 2.0; + } + else + { + sd->lr = sd->er; + sd->lg = sd->eg; + sd->lb = sd->eb; } } static void -_colors_load_apply(Evas_Object *obj) +_hsl_to_rgb(Elm_Colorselector_Smart_Data *sd) { - Elm_Color_RGBA *color; - Eina_List *elist; - Eina_List *color_list; - Elm_Color_Item *item; - Widget_Data *wd = elm_widget_data_get(obj); - color_list = _elm_config_color_list_get(wd->palette_name); - if (!color_list) return; - EINA_LIST_FOREACH(color_list, elist, color) - { - item = _item_new(obj); - if (!item) return; - item->color = ELM_NEW(Elm_Color_RGBA); - if (!item->color) return; - item->color->r = color->r; - item->color->g = color->g; - item->color->b = color->b; - item->color->a = color->a; - elm_box_pack_end(wd->box, VIEW(item)); - evas_object_color_set(item->color_obj, item->color->r, item->color->g, - item->color->b, item->color->a); - wd->items = eina_list_append(wd->items, item); - _sizing_eval_palette(obj); - } - wd->config_load = EINA_TRUE; -} - -static void -_rgb_to_hsl(void *data) -{ - Widget_Data *wd = data; - double r, g, b; - double v, m, vm; - double r2, g2, b2; - - r = wd->r; - g = wd->g; - b = wd->b; - - r /= 255.0; - g /= 255.0; - b /= 255.0; - - v = (r > g) ? r : g; - v = (v > b) ? v : b; - - m = (r < g) ? r : g; - m = (m < b) ? m : b; - - wd->h = 0.0; - wd->s = 0.0; - wd->l = 0.0; - - wd->l = (m + v) / 2.0; - - if (wd->l <= 0.0) return; - - vm = v - m; - wd->s = vm; - - if (wd->s > 0.0) wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m); - else return; - - r2 = (v - r) / vm; - g2 = (v - g) / vm; - b2 = (v - b) / vm; - - if (r == v) wd->h = (g == m ? 5.0 + b2 : 1.0 - g2); - else if (g == v) wd->h = (b == m ? 1.0 + r2 : 3.0 - b2); - else wd->h = (r == m ? 3.0 + g2 : 5.0 - r2); - - wd->h *= 60.0; -} - -static void -_hsl_to_rgb(void *data) -{ - Widget_Data *wd = data; + double sv, vsf, f, p, q, t, v; double r = 0, g = 0, b = 0; double _h, _s, _l; int i = 0; - double sv, vsf, f, p, q, t, v; - _h = wd->h; - _s = wd->s; - _l = wd->l; + _h = sd->h; + _s = sd->s; + _l = sd->l; if (_s == 0.0) r = g = b = _l; else @@ -540,658 +216,1082 @@ _hsl_to_rgb(void *data) switch (i) { case 0: - r = v; - g = t; - b = p; - break; + r = v; + g = t; + b = p; + break; + case 1: - r = q; - g = v; - b = p; - break; + r = q; + g = v; + b = p; + break; + case 2: - r = p; - g = v; - b = t; - break; + r = p; + g = v; + b = t; + break; + case 3: - r = p; - g = q; - b = v; - break; + r = p; + g = q; + b = v; + break; + case 4: - r = t; - g = p; - b = v; - break; + r = t; + g = p; + b = v; + break; + case 5: - r = v; - g = p; - b = q; - break; + r = v; + g = p; + b = q; + break; } } i = (int)(r * 255.0); f = (r * 255.0) - i; - wd->r = (f <= 0.5) ? i : (i + 1); + sd->r = (f <= 0.5) ? i : (i + 1); i = (int)(g * 255.0); f = (g * 255.0) - i; - wd->g = (f <= 0.5) ? i : (i + 1); + sd->g = (f <= 0.5) ? i : (i + 1); i = (int)(b * 255.0); f = (b * 255.0) - i; - wd->b = (f <= 0.5) ? i : (i + 1); + sd->b = (f <= 0.5) ? i : (i + 1); } static void -_color_with_saturation(void *data) +_rectangles_redraw(Color_Bar_Data *cb_data, double x) { - Widget_Data *wd = data; - - if (wd->er > 127) - wd->sr = 127 + (int)((double)(wd->er - 127) * wd->s); - else - wd->sr = 127 - (int)((double)(127 - wd->er) * wd->s); - - if (wd->eg > 127) - wd->sg = 127 + (int)((double)(wd->eg - 127) * wd->s); - else - wd->sg = 127 - (int)((double)(127 - wd->eg) * wd->s); - - if (wd->eb > 127) - wd->sb = 127 + (int)((double)(wd->eb - 127) * wd->s); - else - wd->sb = 127 - (int)((double)(127 - wd->eb) * wd->s); -} - -static void -_color_with_lightness(void *data) -{ - Widget_Data *wd = data; - - if (wd->l > 0.5) - { - wd->lr = wd->er + (int)((double)(255 - wd->er) * (wd->l - 0.5) * 2.0); - wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (wd->l - 0.5) * 2.0); - wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (wd->l - 0.5) * 2.0); - } - else if (wd->l < 0.5) - { - wd->lr = (double)wd->er * wd->l * 2.0; - wd->lg = (double)wd->eg * wd->l * 2.0; - wd->lb = (double)wd->eb * wd->l * 2.0; - } - else - { - wd->lr = wd->er; - wd->lg = wd->eg; - wd->lb = wd->eb; - } -} - -static void -_draw_rects(void *data, double x) -{ - Colorselector_Data *cp = data; - Widget_Data *wd = elm_widget_data_get(cp->parent); double one_six = 1.0 / 6.0; - switch (cp->color_type) + ELM_COLORSELECTOR_DATA_GET(cb_data->parent, sd); + + switch (cb_data->color_type) { case HUE: - wd->h = 360.0 * x; + sd->h = 360.0 * x; - if (x < one_six) - { - wd->er = 255; - wd->eg = (255.0 * x * 6.0); - wd->eb = 0; - } - else if (x < 2 * one_six) - { - wd->er = 255 - (int)(255.0 * (x - one_six) * 6.0); - wd->eg = 255; - wd->eb = 0; - } - else if (x < 3 * one_six) - { - wd->er = 0; - wd->eg = 255; - wd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0); - } - else if (x < 4 * one_six) - { - wd->er = 0; - wd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0); - wd->eb = 255; - } - else if (x < 5 * one_six) - { - wd->er = 255.0 * (x - (4.0 * one_six)) * 6.0; - wd->eg = 0; - wd->eb = 255; - } - else - { - wd->er = 255; - wd->eg = 0; - wd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0); - } + if (x < one_six) + { + sd->er = 255; + sd->eg = (255.0 * x * 6.0); + sd->eb = 0; + } + else if (x < 2 * one_six) + { + sd->er = 255 - (int)(255.0 * (x - one_six) * 6.0); + sd->eg = 255; + sd->eb = 0; + } + else if (x < 3 * one_six) + { + sd->er = 0; + sd->eg = 255; + sd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0); + } + else if (x < 4 * one_six) + { + sd->er = 0; + sd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0); + sd->eb = 255; + } + else if (x < 5 * one_six) + { + sd->er = 255.0 * (x - (4.0 * one_six)) * 6.0; + sd->eg = 0; + sd->eb = 255; + } + else + { + sd->er = 255; + sd->eg = 0; + sd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0); + } - evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255); - evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255); - evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255); - evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255); + evas_object_color_set + (sd->cb_data[0]->arrow, sd->er, sd->eg, sd->eb, 255); + evas_object_color_set + (sd->cb_data[1]->bg_rect, sd->er, sd->eg, sd->eb, 255); + evas_object_color_set + (sd->cb_data[2]->bg_rect, sd->er, sd->eg, sd->eb, 255); + evas_object_color_set + (sd->cb_data[3]->bar, sd->er, sd->eg, sd->eb, 255); - _color_with_saturation(wd); - evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255); + _color_with_saturation(sd); + evas_object_color_set + (sd->cb_data[1]->arrow, sd->sr, sd->sg, sd->sb, 255); - _color_with_lightness(wd); - evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255); + _color_with_lightness(sd); + evas_object_color_set + (sd->cb_data[2]->arrow, sd->lr, sd->lg, sd->lb, 255); + + evas_object_color_set(sd->cb_data[3]->arrow, + (sd->er * sd->a) / 255, + (sd->eg * sd->a) / 255, + (sd->eb * sd->a) / 255, + sd->a); + break; - evas_object_color_set(wd->cp[3]->arrow, - (wd->er * wd->a) / 255, - (wd->eg * wd->a) / 255, - (wd->eb * wd->a) / 255, - wd->a); - break; case SATURATION: - wd->s = 1.0 - x; - _color_with_saturation(wd); - evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255); - break; + sd->s = 1.0 - x; + _color_with_saturation(sd); + evas_object_color_set + (sd->cb_data[1]->arrow, sd->sr, sd->sg, sd->sb, 255); + break; + case LIGHTNESS: - wd->l = x; - _color_with_lightness(wd); - evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255); - break; + sd->l = x; + _color_with_lightness(sd); + evas_object_color_set + (sd->cb_data[2]->arrow, sd->lr, sd->lg, sd->lb, 255); + break; + case ALPHA: - wd->a = 255.0 * x; - evas_object_color_set(wd->cp[3]->arrow, - (wd->er * wd->a) / 255, - (wd->eg * wd->a) / 255, - (wd->eb * wd->a) / 255, - wd->a); - break; + sd->a = 255.0 * x; + evas_object_color_set(sd->cb_data[3]->arrow, + (sd->er * sd->a) / 255, + (sd->eg * sd->a) / 255, + (sd->eb * sd->a) / 255, + sd->a); + break; + default: - break; + break; } - _hsl_to_rgb(wd); + + _hsl_to_rgb(sd); } static void -_arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__, +_arrow_cb(void *data, + Evas_Object *obj, + const char *emission __UNUSED__, const char *source __UNUSED__) { - Colorselector_Data *cp = data; + Color_Bar_Data *cb_data = data; double x, y; edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y); - _draw_rects(data, x); - evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL); + + _rectangles_redraw(data, x); + evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL); } static void -_colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info) +_colorbar_cb(void *data, + Evas *e, + Evas_Object *obj __UNUSED__, + void *event_info) { - Colorselector_Data *cp = data; Evas_Event_Mouse_Down *ev = event_info; - Evas_Coord x, y, w, h; + Color_Bar_Data *cb_data = data; double arrow_x = 0, arrow_y; + Evas_Coord x, y, w, h; + + evas_object_geometry_get(cb_data->bar, &x, &y, &w, &h); + edje_object_part_drag_value_get + (cb_data->colorbar, "elm.arrow", &arrow_x, &arrow_y); - evas_object_geometry_get(cp->bar, &x, &y, &w, &h); - edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", - &arrow_x, &arrow_y); if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w; if (arrow_x > 1) arrow_x = 1; if (arrow_x < 0) arrow_x = 0; - edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y); - _draw_rects(data, arrow_x); - evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL); + edje_object_part_drag_value_set + (cb_data->colorbar, "elm.arrow", arrow_x, arrow_y); + + _rectangles_redraw(data, arrow_x); + evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL); evas_event_feed_mouse_cancel(e, 0, NULL); evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL); } static void -_left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__, - void *event_info __UNUSED__) +_button_clicked_cb(void *data, + Evas_Object *obj, + void *event_info __UNUSED__) { - Colorselector_Data *cp = data; - double x, y; + Eina_Bool is_right = EINA_FALSE; + Color_Bar_Data *cb_data = data; + double x, y, step; + char buf[1024]; - edje_object_signal_emit(cp->lbt, "elm,state,left,button,down", - "left_button"); - edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y); - - switch(cp->color_type) + if (obj == cb_data->rbt) { - case HUE : - x -= 1.0 / HUE_STEP; - break; - case SATURATION : - x -= 1.0 / SAT_STEP; - break; - case LIGHTNESS : - x -= 1.0 / LIG_STEP; - break; - case ALPHA : - x -= 1.0 / ALP_STEP; - break; - default : - break; + is_right = EINA_TRUE; + step = 1.0; + } + else step = -1.0; + + snprintf(buf, sizeof(buf), "elm,state,%s,button,down", is_right ? "right" : + "left"); + + edje_object_signal_emit + (cb_data->lbt, buf, is_right ? "right_button" : "left_button"); + edje_object_part_drag_value_get(cb_data->colorbar, "elm.arrow", &x, &y); + + switch (cb_data->color_type) + { + case HUE: + x += step / HUE_STEP; + break; + + case SATURATION: + x += step / SAT_STEP; + break; + + case LIGHTNESS: + x += step / LIG_STEP; + break; + + case ALPHA: + x += step / ALP_STEP; + break; + + default: + break; } - if (x < 0.0) x = 0.0; - - edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y); - _draw_rects(data, x); - evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL); -} - -static void -_left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__, - void *event_info __UNUSED__) -{ - Colorselector_Data *cp = data; - double x, y; - - edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y); - x -= 1.0 / BASE_STEP; - if (x < 0.0) x = 0.0; - edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y); - _draw_rects(data, x); - evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL); - -} - -static void -_right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__, - void *event_info __UNUSED__) -{ - Colorselector_Data *cp = data; - double x, y; - - edje_object_signal_emit(cp->rbt, "elm,state,right,button,down", - "right_button"); - edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y); - - switch(cp->color_type) + if (is_right) { - case HUE : - x += 1.0 / HUE_STEP; - break; - case SATURATION : - x += 1.0 / SAT_STEP; - break; - case LIGHTNESS : - x += 1.0 / LIG_STEP; - break; - case ALPHA : - x += 1.0 / ALP_STEP; - break; - default : - break; + if (x > 1.0) x = 1.0; + } + else + { + if (x < 0.0) x = 0.0; } - if (x > 1.0) x = 1.0; - - edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y); - _draw_rects(data, x); - evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL); + edje_object_part_drag_value_set(cb_data->colorbar, "elm.arrow", x, y); + _rectangles_redraw(data, x); + evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL); } static void -_right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__, - void *event_info __UNUSED__) +_button_repeat_cb(void *data, + Evas_Object *obj __UNUSED__, + void *event_info __UNUSED__) { - Colorselector_Data *cp = data; - double x, y; + Eina_Bool is_right = EINA_FALSE; + Color_Bar_Data *cb_data = data; + double x, y, step; - edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y); - x += 1.0 / BASE_STEP; - if (x > 1.0) x = 1.0; - edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y); - _draw_rects(data, x); - evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL); + if (obj == cb_data->rbt) + { + is_right = EINA_TRUE; + step = 1.0; + } + else step = -1.0; + + edje_object_part_drag_value_get(cb_data->colorbar, "elm.arrow", &x, &y); + x += step / BASE_STEP; + + if (is_right) + { + if (x > 1.0) x = 1.0; + } + else + { + if (x < 0.0) x = 0.0; + } + + edje_object_part_drag_value_set(cb_data->colorbar, "elm.arrow", x, y); + _rectangles_redraw(data, x); + evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL); } static void -_add_colorbar(Evas_Object *obj) +_color_bars_add(Evas_Object *obj) { char colorbar_name[128]; char colorbar_s[128]; - Widget_Data *wd; - Evas *e; - int i = 0; char buf[1024]; + int i = 0; + Evas *e; - wd = elm_widget_data_get(obj); - if (!wd) return; + ELM_COLORSELECTOR_DATA_GET(obj, sd); e = evas_object_evas_get(obj); for (i = 0; i < 4; i++) { - wd->cp[i] = ELM_NEW(Colorselector_Data); - wd->cp[i]->parent = obj; - switch(i) + sd->cb_data[i] = ELM_NEW(Color_Bar_Data); + sd->cb_data[i]->parent = obj; + + switch (i) { - case 0 : - wd->cp[i]->color_type = HUE; - break; - case 1 : - wd->cp[i]->color_type = SATURATION; - break; - case 2 : - wd->cp[i]->color_type = LIGHTNESS; - break; - case 3 : - wd->cp[i]->color_type = ALPHA; - break; - default : - break; + case 0: + sd->cb_data[i]->color_type = HUE; + break; + + case 1: + sd->cb_data[i]->color_type = SATURATION; + break; + + case 2: + sd->cb_data[i]->color_type = LIGHTNESS; + break; + + case 3: + sd->cb_data[i]->color_type = ALPHA; + break; + + default: + break; } + /* load colorbar area */ - wd->cp[i]->colorbar = edje_object_add(e); - _elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorselector", "base", - elm_widget_style_get(obj)); + sd->cb_data[i]->colorbar = edje_object_add(e); + elm_widget_theme_object_set + (obj, sd->cb_data[i]->colorbar, "colorselector", "base", + elm_widget_style_get(obj)); snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i); snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i); - edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*", - _arrow_cb, wd->cp[i]); - edje_object_part_swallow(wd->sel, colorbar_s, wd->cp[i]->colorbar); - elm_widget_sub_object_add(obj, wd->cp[i]->colorbar); + edje_object_signal_callback_add + (sd->cb_data[i]->colorbar, "drag", "*", _arrow_cb, sd->cb_data[i]); + edje_object_part_swallow + (sd->col_bars_area, colorbar_s, sd->cb_data[i]->colorbar); + elm_widget_sub_object_add(obj, sd->cb_data[i]->colorbar); /* load colorbar image */ - wd->cp[i]->bar = edje_object_add(e); + sd->cb_data[i]->bar = edje_object_add(e); snprintf(buf, sizeof(buf), "%s/%s", colorbar_name, elm_widget_style_get(obj)); - _elm_theme_object_set(obj, wd->cp[i]->bar, "colorselector", "image", - buf); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar", - wd->cp[i]->bar); - elm_widget_sub_object_add(obj, wd->cp[i]->bar); + elm_widget_theme_object_set + (obj, sd->cb_data[i]->bar, "colorselector", "image", buf); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.bar", sd->cb_data[i]->bar); + elm_widget_sub_object_add(obj, sd->cb_data[i]->bar); /* provide expanded touch area */ - wd->cp[i]->touch_area = evas_object_rectangle_add(e); - evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg", - wd->cp[i]->touch_area); - evas_object_event_callback_add(wd->cp[i]->touch_area, - EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb, - wd->cp[i]); - elm_widget_sub_object_add(obj, wd->cp[i]->touch_area); + sd->cb_data[i]->touch_area = evas_object_rectangle_add(e); + evas_object_color_set(sd->cb_data[i]->touch_area, 0, 0, 0, 0); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.arrow_bg", + sd->cb_data[i]->touch_area); + evas_object_event_callback_add + (sd->cb_data[i]->touch_area, EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb, + sd->cb_data[i]); + elm_widget_sub_object_add(obj, sd->cb_data[i]->touch_area); /* load background rectangle of the colorbar. used for changing color of the opacity bar */ if ((i == 1) || (i == 2)) { - wd->cp[i]->bg_rect = evas_object_rectangle_add(e); - evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb, - 255); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg", - wd->cp[i]->bg_rect); + sd->cb_data[i]->bg_rect = evas_object_rectangle_add(e); + evas_object_color_set + (sd->cb_data[i]->bg_rect, sd->er, sd->eg, sd->eb, 255); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.bar_bg", + sd->cb_data[i]->bg_rect); - elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect); + elm_widget_sub_object_add(obj, sd->cb_data[i]->bg_rect); } if (i == 3) { - wd->cp[i]->bg_rect = edje_object_add(e); + sd->cb_data[i]->bg_rect = edje_object_add(e); snprintf(buf, sizeof(buf), "%s/%s", colorbar_name, elm_widget_style_get(obj)); - _elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorselector", - "bg_image", buf); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg", - wd->cp[i]->bg_rect); - elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect); - evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255); + elm_widget_theme_object_set + (obj, sd->cb_data[i]->bg_rect, "colorselector", "bg_image", + buf); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.bar_bg", + sd->cb_data[i]->bg_rect); + elm_widget_sub_object_add(obj, sd->cb_data[i]->bg_rect); + evas_object_color_set + (sd->cb_data[i]->bar, sd->er, sd->eg, sd->eb, 255); } + /* load arrow image, pointing the colorbar */ - wd->cp[i]->arrow = edje_object_add(e); - _elm_theme_object_set(obj, wd->cp[i]->arrow, "colorselector", "arrow", - elm_widget_style_get(obj)); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_icon", - wd->cp[i]->arrow); - elm_widget_sub_object_add(obj, wd->cp[i]->arrow); + sd->cb_data[i]->arrow = edje_object_add(e); + elm_widget_theme_object_set + (obj, sd->cb_data[i]->arrow, "colorselector", "arrow", + elm_widget_style_get(obj)); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.arrow_icon", + sd->cb_data[i]->arrow); + elm_widget_sub_object_add(obj, sd->cb_data[i]->arrow); + if (i == 2) - evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255); + evas_object_color_set(sd->cb_data[i]->arrow, 0, 0, 0, 255); else - evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255); + evas_object_color_set + (sd->cb_data[i]->arrow, sd->er, sd->eg, sd->eb, 255); /* load left button */ - wd->cp[i]->lbt = elm_button_add(obj); + sd->cb_data[i]->lbt = elm_button_add(obj); snprintf(buf, sizeof(buf), "colorselector/left/%s", elm_widget_style_get(obj)); - elm_object_style_set(wd->cp[i]->lbt, buf); - elm_widget_sub_object_add(obj, wd->cp[i]->lbt); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button", - wd->cp[i]->lbt); - evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked", - _left_button_clicked_cb, wd->cp[i]); - elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE); - elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt, - _elm_config->longpress_timeout); - elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt, - (1.0 / _elm_config->fps)); - evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated", - _left_button_repeat_cb, wd->cp[i]); + elm_object_style_set(sd->cb_data[i]->lbt, buf); + elm_widget_sub_object_add(obj, sd->cb_data[i]->lbt); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.l_button", sd->cb_data[i]->lbt); + evas_object_smart_callback_add + (sd->cb_data[i]->lbt, "clicked", _button_clicked_cb, + sd->cb_data[i]); + elm_button_autorepeat_set(sd->cb_data[i]->lbt, EINA_TRUE); + elm_button_autorepeat_initial_timeout_set + (sd->cb_data[i]->lbt, _elm_config->longpress_timeout); + elm_button_autorepeat_gap_timeout_set + (sd->cb_data[i]->lbt, (1.0 / _elm_config->fps)); + evas_object_smart_callback_add + (sd->cb_data[i]->lbt, "repeated", _button_repeat_cb, + sd->cb_data[i]); /* load right button */ - wd->cp[i]->rbt = elm_button_add(obj); + sd->cb_data[i]->rbt = elm_button_add(obj); snprintf(buf, sizeof(buf), "colorselector/right/%s", elm_widget_style_get(obj)); - elm_object_style_set(wd->cp[i]->rbt, buf); - elm_widget_sub_object_add(obj, wd->cp[i]->rbt); - edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button", - wd->cp[i]->rbt); - evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked", - _right_button_clicked_cb, wd->cp[i]); - elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE); - elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt, - _elm_config->longpress_timeout); - elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt, - (1.0 / _elm_config->fps)); - evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated", - _right_button_repeat_cb, wd->cp[i]); + elm_object_style_set(sd->cb_data[i]->rbt, buf); + elm_widget_sub_object_add(obj, sd->cb_data[i]->rbt); + edje_object_part_swallow + (sd->cb_data[i]->colorbar, "elm.r_button", sd->cb_data[i]->rbt); + evas_object_smart_callback_add + (sd->cb_data[i]->rbt, "clicked", _button_clicked_cb, + sd->cb_data[i]); + elm_button_autorepeat_set(sd->cb_data[i]->rbt, EINA_TRUE); + elm_button_autorepeat_initial_timeout_set + (sd->cb_data[i]->rbt, _elm_config->longpress_timeout); + elm_button_autorepeat_gap_timeout_set + (sd->cb_data[i]->rbt, (1.0 / _elm_config->fps)); + evas_object_smart_callback_add + (sd->cb_data[i]->rbt, "repeated", _button_repeat_cb, + sd->cb_data[i]); } } -static void -_set_color(Evas_Object *obj, int r, int g, int b, int a) +static Eina_Bool +_elm_colorselector_smart_theme(Evas_Object *obj) +{ + int i; + Eina_List *elist; + Elm_Color_Item *item; + const char *hpadstr, *vpadstr; + unsigned int h_pad = DEFAULT_HOR_PAD; + unsigned int v_pad = DEFAULT_VER_PAD; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + if (!ELM_WIDGET_CLASS(_elm_colorselector_parent_sc)->theme(obj)) + return EINA_FALSE; + + if (!sd->col_bars_area) return EINA_FALSE; + + elm_widget_theme_object_set + (obj, sd->col_bars_area, "colorselector", "bg", + elm_widget_style_get(obj)); + + hpadstr = edje_object_data_get + (ELM_WIDGET_DATA(sd)->resize_obj, "horizontal_pad"); + if (hpadstr) h_pad = atoi(hpadstr); + vpadstr = edje_object_data_get + (ELM_WIDGET_DATA(sd)->resize_obj, "vertical_pad"); + if (vpadstr) v_pad = atoi(vpadstr); + + elm_box_padding_set + (sd->palette_box, + (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()), + (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get())); + + EINA_LIST_FOREACH (sd->items, elist, item) + { + elm_layout_theme_set + (VIEW(item), "colorselector", "item", elm_widget_style_get(obj)); + elm_widget_theme_object_set + (obj, item->color_obj, "colorselector", "item/color", + elm_widget_style_get(obj)); + } + for (i = 0; i < 4; i++) + { + evas_object_del(sd->cb_data[i]->colorbar); + sd->cb_data[i]->colorbar = NULL; + evas_object_del(sd->cb_data[i]->bar); + sd->cb_data[i]->bar = NULL; + evas_object_del(sd->cb_data[i]->lbt); + sd->cb_data[i]->lbt = NULL; + evas_object_del(sd->cb_data[i]->rbt); + sd->cb_data[i]->rbt = NULL; + if (i != 0) + { + evas_object_del(sd->cb_data[i]->bg_rect); + sd->cb_data[i]->bg_rect = NULL; + } + evas_object_del(sd->cb_data[i]->arrow); + sd->cb_data[i]->arrow = NULL; + evas_object_del(sd->cb_data[i]->touch_area); + sd->cb_data[i]->touch_area = NULL; + } + + _color_bars_add(obj); + elm_colorselector_color_set(obj, sd->r, sd->g, sd->b, sd->a); + + elm_layout_sizing_eval(obj); + + return EINA_TRUE; +} + +static void +_sub_obj_size_hints_set(Evas_Object *sobj, + int timesw, + int timesh) +{ + Evas_Coord minw = -1, minh = -1; + + elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh); + edje_object_size_min_restricted_calc(sobj, &minw, &minh, minw, minh); + evas_object_size_hint_min_set(sobj, minw, minh); + evas_object_size_hint_max_set(sobj, -1, -1); +} + +static void +_item_sizing_eval(Elm_Color_Item *item) +{ + Evas_Coord minw = -1, minh = -1; + + if (!item) return; + + elm_coords_finger_size_adjust(1, &minw, 1, &minh); + edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw, minh); + evas_object_size_hint_min_set(VIEW(item), minw, minh); +} + +/* fix size hints of color palette items, so that the box gets it */ +static void +_palette_sizing_eval(Evas_Object *obj) +{ + Eina_List *elist; + Elm_Color_Item *item; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + EINA_LIST_FOREACH (sd->items, elist, item) + _item_sizing_eval(item); +} + +static void +_component_sizing_eval(Evas_Object *obj) +{ + Evas_Coord minw = -1, minh = -1; + int i; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + for (i = 0; i < 4; i++) + { + if (sd->cb_data[i]->bg_rect) + _sub_obj_size_hints_set(sd->cb_data[i]->bg_rect, 1, 1); + + _sub_obj_size_hints_set(sd->cb_data[i]->bar, 1, 1); + _sub_obj_size_hints_set(sd->cb_data[i]->rbt, 1, 1); + _sub_obj_size_hints_set(sd->cb_data[i]->lbt, 1, 1); + _sub_obj_size_hints_set(sd->cb_data[i]->colorbar, 4, 1); + } + + edje_object_size_min_restricted_calc + (sd->col_bars_area, &minw, &minh, minw, minh); + evas_object_size_hint_min_set(sd->col_bars_area, minw, minh); +} + +static void +_full_sizing_eval(Evas_Object *obj) +{ + _palette_sizing_eval(obj); + _component_sizing_eval(obj); +} + +static void +_elm_colorselector_smart_sizing_eval(Evas_Object *obj) +{ + Evas_Coord minw = -1, minh = -1; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + elm_coords_finger_size_adjust(1, &minw, 1, &minh); + + switch (sd->mode) + { + case ELM_COLORSELECTOR_PALETTE: + _palette_sizing_eval(obj); + break; + + case ELM_COLORSELECTOR_COMPONENTS: + _component_sizing_eval(obj); + break; + + case ELM_COLORSELECTOR_BOTH: + _full_sizing_eval(obj); + break; + + default: + return; + } + + edje_object_size_min_calc(ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh); + evas_object_size_hint_min_set(obj, minw, minh); + evas_object_size_hint_max_set(obj, -1, -1); +} + +static Eina_Bool +_on_color_long_press(void *data) +{ + Elm_Color_Item *item = (Elm_Color_Item *)data; + + ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd); + + sd->longpress_timer = NULL; + sd->longpressed = EINA_TRUE; + evas_object_smart_callback_call + (WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item); + + return ECORE_CALLBACK_CANCEL; +} + +static void +_on_color_pressed(void *data, + Evas *e __UNUSED__, + Evas_Object *obj __UNUSED__, + void *event_info __UNUSED__) +{ + Elm_Color_Item *item = (Elm_Color_Item *)data; + Evas_Event_Mouse_Down *ev = event_info; + + if (!item) return; + + ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd); + + if (ev->button != 1) return; + elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm"); + sd->longpressed = EINA_FALSE; + + if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); + sd->longpress_timer = ecore_timer_add + (_elm_config->longpress_timeout, _on_color_long_press, data); +} + +static void +_on_color_released(void *data, + Evas *e __UNUSED__, + Evas_Object *obj __UNUSED__, + void *event_info __UNUSED__) +{ + Elm_Color_Item *item = (Elm_Color_Item *)data; + Evas_Event_Mouse_Down *ev = event_info; + if (!item) return; + + ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd); + + if (ev->button != 1) return; + if (sd->longpress_timer) + { + ecore_timer_del(sd->longpress_timer); + sd->longpress_timer = NULL; + } + elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm"); + if (!sd->longpressed) + { + evas_object_smart_callback_call + (WIDGET(item), SIG_COLOR_ITEM_SELECTED, item); + elm_colorselector_color_set + (WIDGET(item), item->color->r, item->color->g, item->color->b, + item->color->a); + } +} + +static Elm_Color_Item * +_item_new(Evas_Object *obj) +{ + Elm_Color_Item *item; + + item = elm_widget_item_new(obj, Elm_Color_Item); + if (!item) return NULL; + + VIEW(item) = elm_layout_add(obj); + elm_layout_theme_set + (VIEW(item), "colorselector", "item", elm_widget_style_get(obj)); + evas_object_size_hint_weight_set + (VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL); + + item->color_obj = edje_object_add(evas_object_evas_get(obj)); + elm_widget_theme_object_set + (obj, item->color_obj, "colorselector", "item/color", + elm_widget_style_get(obj)); + evas_object_size_hint_weight_set + (item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set + (item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_event_callback_add + (item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _on_color_pressed, item); + evas_object_event_callback_add + (item->color_obj, EVAS_CALLBACK_MOUSE_UP, _on_color_released, item); + elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj); + + _item_sizing_eval(item); + evas_object_show(VIEW(item)); + + return item; +} + +static void +_colors_remove(Evas_Object *obj) +{ + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + _items_del(sd); + _elm_config_colors_free(sd->palette_name); +} + +static void +_colors_save(Evas_Object *obj) +{ + Eina_List *elist; + Elm_Color_Item *item; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + _elm_config_colors_free(sd->palette_name); + EINA_LIST_FOREACH (sd->items, elist, item) + _elm_config_color_set(sd->palette_name, item->color->r, item->color->g, + item->color->b, item->color->a); +} + +static void +_palette_colors_load(Evas_Object *obj) +{ + Eina_List *elist; + Elm_Color_Item *item; + Eina_List *color_list; + Elm_Color_RGBA *color; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + color_list = _elm_config_color_list_get(sd->palette_name); + if (!color_list) return; + + EINA_LIST_FOREACH (color_list, elist, color) + { + item = _item_new(obj); + if (!item) return; + + item->color = ELM_NEW(Elm_Color_RGBA); + if (!item->color) return; + item->color->r = color->r; + item->color->g = color->g; + item->color->b = color->b; + item->color->a = color->a; + + elm_box_pack_end(sd->palette_box, VIEW(item)); + evas_object_color_set + (item->color_obj, item->color->r, item->color->g, item->color->b, + item->color->a); + + sd->items = eina_list_append(sd->items, item); + } + + sd->config_load = EINA_TRUE; +} + +static void +_rgb_to_hsl(Elm_Colorselector_Smart_Data *sd) +{ + double r2, g2, b2; + double v, m, vm; + double r, g, b; + + r = sd->r; + g = sd->g; + b = sd->b; + + r /= 255.0; + g /= 255.0; + b /= 255.0; + + v = (r > g) ? r : g; + v = (v > b) ? v : b; + + m = (r < g) ? r : g; + m = (m < b) ? m : b; + + sd->h = 0.0; + sd->s = 0.0; + sd->l = 0.0; + + sd->l = (m + v) / 2.0; + + if (sd->l <= 0.0) return; + + vm = v - m; + sd->s = vm; + + if (sd->s > 0.0) sd->s /= (sd->l <= 0.5) ? (v + m) : (2.0 - v - m); + else return; + + r2 = (v - r) / vm; + g2 = (v - g) / vm; + b2 = (v - b) / vm; + + if (r == v) sd->h = (g == m ? 5.0 + b2 : 1.0 - g2); + else if (g == v) + sd->h = (b == m ? 1.0 + r2 : 3.0 - b2); + else sd->h = (r == m ? 3.0 + g2 : 5.0 - r2); + + sd->h *= 60.0; +} + +static void +_colors_set(Evas_Object *obj, + int r, + int g, + int b, + int a) { - Widget_Data *wd = elm_widget_data_get(obj); double x, y; - wd->r = r; - wd->g = g; - wd->b = b; - wd->a = a; + ELM_COLORSELECTOR_DATA_GET(obj, sd); - _rgb_to_hsl(wd); + sd->r = r; + sd->g = g; + sd->b = b; + sd->a = a; - edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y); - x = wd->h / 360.0; - edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y); - _draw_rects(wd->cp[0], x); + _rgb_to_hsl(sd); - edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y); - x = 1.0 - wd->s; - edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y); - _draw_rects(wd->cp[1], x); + edje_object_part_drag_value_get + (sd->cb_data[0]->colorbar, "elm.arrow", &x, &y); + x = sd->h / 360.0; + edje_object_part_drag_value_set + (sd->cb_data[0]->colorbar, "elm.arrow", x, y); + _rectangles_redraw(sd->cb_data[0], x); - edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y); - x = wd->l; - edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y); - _draw_rects(wd->cp[2], x); + edje_object_part_drag_value_get + (sd->cb_data[1]->colorbar, "elm.arrow", &x, &y); + x = 1.0 - sd->s; + edje_object_part_drag_value_set + (sd->cb_data[1]->colorbar, "elm.arrow", x, y); + _rectangles_redraw(sd->cb_data[1], x); - edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y); - x = wd->a / 255.0; - edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y); - _draw_rects(wd->cp[3], x); + edje_object_part_drag_value_get + (sd->cb_data[2]->colorbar, "elm.arrow", &x, &y); + x = sd->l; + edje_object_part_drag_value_set(sd->cb_data[2]->colorbar, "elm.arrow", x, y); + _rectangles_redraw(sd->cb_data[2], x); + + edje_object_part_drag_value_get + (sd->cb_data[3]->colorbar, "elm.arrow", &x, &y); + x = sd->a / 255.0; + edje_object_part_drag_value_set + (sd->cb_data[3]->colorbar, "elm.arrow", x, y); + + _rectangles_redraw(sd->cb_data[3], x); +} + +static void +_elm_colorselector_smart_add(Evas_Object *obj) +{ + const char *hpadstr, *vpadstr; + unsigned int h_pad = DEFAULT_HOR_PAD; + unsigned int v_pad = DEFAULT_VER_PAD; + + EVAS_SMART_DATA_ALLOC(obj, Elm_Colorselector_Smart_Data); + + ELM_WIDGET_CLASS(_elm_colorselector_parent_sc)->base.add(obj); + + elm_layout_theme_set + (obj, "colorselector", "palette", elm_object_style_get(obj)); + + priv->palette_box = elm_box_add(obj); + elm_box_layout_set + (priv->palette_box, evas_object_box_layout_flow_horizontal, NULL, NULL); + elm_box_horizontal_set(priv->palette_box, EINA_TRUE); + evas_object_size_hint_weight_set + (priv->palette_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set + (priv->palette_box, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_homogeneous_set(priv->palette_box, EINA_TRUE); + + hpadstr = + edje_object_data_get(ELM_WIDGET_DATA(priv)->resize_obj, "horizontal_pad"); + if (hpadstr) h_pad = atoi(hpadstr); + vpadstr = edje_object_data_get + (ELM_WIDGET_DATA(priv)->resize_obj, "vertical_pad"); + if (vpadstr) v_pad = atoi(vpadstr); + + elm_box_padding_set + (priv->palette_box, + (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()), + (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get())); + + elm_box_align_set(priv->palette_box, 0.5, 0.5); + elm_layout_content_set(obj, "palette", priv->palette_box); + priv->palette_name = eina_stringshare_add("default"); + _palette_colors_load(obj); + + /* load background edj */ + priv->col_bars_area = edje_object_add(evas_object_evas_get(obj)); + elm_widget_theme_object_set + (obj, priv->col_bars_area, "colorselector", "bg", + elm_widget_style_get(obj)); + elm_layout_content_set(obj, "selector", priv->col_bars_area); + + priv->mode = ELM_COLORSELECTOR_BOTH; + priv->er = 255; + priv->eg = 0; + priv->eb = 0; + priv->h = 0.0; + priv->s = 1.0; + priv->l = 0.0; + priv->a = 255; + + _hsl_to_rgb(priv); + _color_bars_add(obj); + + elm_layout_sizing_eval(obj); +} + +static void +_elm_colorselector_smart_del(Evas_Object *obj) +{ + int i = 0; + + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); + if (sd->palette_name) eina_stringshare_del(sd->palette_name); + + _items_del(sd); + for (i = 0; i < 4; i++) + free(sd->cb_data[i]); + + ELM_WIDGET_CLASS(_elm_colorselector_parent_sc)->base.del(obj); +} + +static void +_elm_colorselector_smart_set_user(Elm_Layout_Smart_Class *sc) +{ + ELM_WIDGET_CLASS(sc)->base.add = _elm_colorselector_smart_add; + ELM_WIDGET_CLASS(sc)->base.del = _elm_colorselector_smart_del; + + /* not a 'focus chain manager' */ + ELM_WIDGET_CLASS(sc)->focus_next = NULL; + ELM_WIDGET_CLASS(sc)->focus_direction = NULL; + + ELM_WIDGET_CLASS(sc)->theme = _elm_colorselector_smart_theme; + + sc->sizing_eval = _elm_colorselector_smart_sizing_eval; } EAPI Evas_Object * elm_colorselector_add(Evas_Object *parent) { - Evas_Object *obj = NULL; - Widget_Data *wd = NULL; Evas *e; - const char *hpadstr, *vpadstr; - unsigned int h_pad = DEFAULT_HOR_PAD; - unsigned int v_pad = DEFAULT_VER_PAD; + Evas_Object *obj; - ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); - ELM_SET_WIDTYPE(widtype, "colorselector"); - elm_widget_type_set(obj, "colorselector"); - elm_widget_sub_object_add(parent, obj); - elm_widget_data_set(obj, wd); - elm_widget_del_hook_set(obj, _del_hook); - elm_widget_theme_hook_set(obj, _theme_hook); - evas_object_smart_callbacks_descriptions_set(obj, _signals); + e = evas_object_evas_get(parent); + if (!e) return NULL; - /* load background edj */ - wd->base = edje_object_add(e); - _elm_theme_object_set(obj, wd->base, "colorselector", "palette", "default"); - elm_widget_resize_object_set(obj, wd->base); - evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE, - _resize_cb, obj); + obj = evas_object_smart_add(e, _elm_colorselector_smart_class_new()); - wd->box = elm_box_add(obj); - elm_box_layout_set(wd->box, evas_object_box_layout_flow_horizontal, - NULL, NULL); - elm_box_horizontal_set(wd->box, EINA_TRUE); - evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, - 0); - evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0); - elm_box_homogeneous_set(wd->box, EINA_TRUE); - hpadstr = edje_object_data_get(wd->base, "horizontal_pad"); - if (hpadstr) h_pad = atoi(hpadstr); - vpadstr = edje_object_data_get(wd->base, "vertical_pad"); - if (vpadstr) v_pad = atoi(vpadstr); - elm_box_padding_set(wd->box, (Evas_Coord)(h_pad * elm_widget_scale_get(obj) * _elm_config->scale), - (Evas_Coord)(v_pad * elm_widget_scale_get(obj) *_elm_config->scale)); - elm_box_align_set(wd->box, 0.5, 0.5); - elm_widget_sub_object_add(obj, wd->box); - evas_object_show(wd->box); - edje_object_part_swallow(wd->base, "palette", wd->box); - wd->palette_name = eina_stringshare_add("default"); - _colors_load_apply(obj); - - /* load background edj */ - wd->sel = edje_object_add(e); - _elm_theme_object_set(obj, wd->sel, "colorselector", "bg", "default"); - edje_object_part_swallow(wd->base, "selector", wd->sel); - elm_widget_sub_object_add(obj, wd->sel); - - wd->mode = ELM_COLORSELECTOR_BOTH; - wd->er = 255; - wd->eg = 0; - wd->eb = 0; - wd->h = 0.0; - wd->s = 1.0; - wd->l = 0.0; - wd->a = 255; - - _hsl_to_rgb(wd); - _add_colorbar(obj); - _sizing_eval(obj); + if (!elm_widget_sub_object_add(parent, obj)) + ERR("could not add %p as sub object of %p", obj, parent); return obj; } EAPI void -elm_colorselector_color_set(Evas_Object *obj, int r, int g, int b, int a) +elm_colorselector_color_set(Evas_Object *obj, + int r, + int g, + int b, + int a) { - ELM_CHECK_WIDTYPE(obj, widtype); - _set_color(obj, r, g, b, a); + ELM_COLORSELECTOR_CHECK(obj); + + _colors_set(obj, r, g, b, a); } EAPI void -elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a) +elm_colorselector_color_get(const Evas_Object *obj, + int *r, + int *g, + int *b, + int *a) { - ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); + ELM_COLORSELECTOR_CHECK(obj); + ELM_COLORSELECTOR_DATA_GET(obj, sd); - if (r) *r = wd->r; - if (g) *g = wd->g; - if (b) *b = wd->b; - if (a) *a = wd->a; + if (r) *r = sd->r; + if (g) *g = sd->g; + if (b) *b = sd->b; + if (a) *a = sd->a; } EAPI void -elm_colorselector_mode_set(Evas_Object *obj, Elm_Colorselector_Mode mode) +elm_colorselector_mode_set(Evas_Object *obj, + Elm_Colorselector_Mode mode) { - ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; - if (wd->mode == mode) return; - wd->mode = mode; - switch (wd->mode) + ELM_COLORSELECTOR_CHECK(obj); + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + if (sd->mode == mode) return; + sd->mode = mode; + + evas_object_hide(elm_layout_content_unset(obj, "selector")); + evas_object_hide(elm_layout_content_unset(obj, "palette")); + + switch (sd->mode) { - case ELM_COLORSELECTOR_PALETTE: - if (edje_object_part_swallow_get(wd->base, "selector")) - { - edje_object_part_unswallow(wd->base, wd->sel); - evas_object_hide(wd->sel); - } - if (!edje_object_part_swallow_get(wd->base, "palette")) - { - edje_object_part_swallow(wd->base, "palette", wd->box); - evas_object_show(wd->box); - } - edje_object_signal_emit(wd->base, "elm,state,palette", "elm"); - break; - case ELM_COLORSELECTOR_COMPONENTS: - if (edje_object_part_swallow_get(wd->base, "palette")) - { - edje_object_part_unswallow(wd->base, wd->box); - evas_object_hide(wd->box); - } - if (!edje_object_part_swallow_get(wd->base, "selector")) - { - edje_object_part_swallow(wd->base, "selector", wd->sel); - evas_object_show(wd->sel); - } - edje_object_signal_emit(wd->base, "elm,state,components", "elm"); - break; - case ELM_COLORSELECTOR_BOTH: - if (!edje_object_part_swallow_get(wd->base, "palette")) - { - edje_object_part_swallow(wd->base, "palette", wd->box); - evas_object_show(wd->box); - } - if (!edje_object_part_swallow_get(wd->base, "selector")) - { - edje_object_part_swallow(wd->base, "selector", wd->sel); - evas_object_show(wd->sel); - } - edje_object_signal_emit(wd->base, "elm,state,both", "elm"); - break; - default: - return; - } - edje_object_message_signal_process(wd->base); + case ELM_COLORSELECTOR_PALETTE: + elm_layout_content_set(obj, "palette", sd->palette_box); + elm_layout_signal_emit(obj, "elm,state,palette", "elm"); + break; - _sizing_eval(obj); + case ELM_COLORSELECTOR_COMPONENTS: + elm_layout_content_set(obj, "selector", sd->col_bars_area); + elm_layout_signal_emit(obj, "elm,state,components", "elm"); + break; + + case ELM_COLORSELECTOR_BOTH: + elm_layout_content_set(obj, "palette", sd->palette_box); + elm_layout_content_set(obj, "selector", sd->col_bars_area); + elm_layout_signal_emit(obj, "elm,state,both", "elm"); + break; + + default: + return; + } + + edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj); + + elm_layout_sizing_eval(obj); } EAPI Elm_Colorselector_Mode elm_colorselector_mode_get(const Evas_Object *obj) { - ELM_CHECK_WIDTYPE(obj, widtype) ELM_COLORSELECTOR_BOTH; - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return ELM_COLORSELECTOR_BOTH; - return wd->mode; + ELM_COLORSELECTOR_CHECK(obj) ELM_COLORSELECTOR_BOTH; + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + return sd->mode; } EAPI void -elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, int *r __UNUSED__, int *g __UNUSED__, int *b __UNUSED__, int*a __UNUSED__) +elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, + int *r, + int *g, + int *b, + int *a) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it); Elm_Color_Item *item; - item = (Elm_Color_Item *) it; + + ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it); + + item = (Elm_Color_Item *)it; if (item) { if (r) *r = item->color->r; @@ -1202,78 +1302,101 @@ elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, int *r __UNU } EAPI void -elm_colorselector_palette_item_color_set(Elm_Object_Item *it, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__) +elm_colorselector_palette_item_color_set(Elm_Object_Item *it, + int r, + int g, + int b, + int a) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it); Elm_Color_Item *item; - item = (Elm_Color_Item *) it; + + ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it); + + item = (Elm_Color_Item *)it; item->color->r = r; item->color->g = g; item->color->b = b; item->color->a = a; - evas_object_color_set(item->color_obj, item->color->r, item->color->g, item->color->b, item->color->a); + evas_object_color_set + (item->color_obj, item->color->r, item->color->g, item->color->b, + item->color->a); + _colors_save(WIDGET(it)); } EAPI Elm_Object_Item * -elm_colorselector_palette_color_add(Evas_Object *obj, int r, int g, int b, int a) +elm_colorselector_palette_color_add(Evas_Object *obj, + int r, + int g, + int b, + int a) { Elm_Color_Item *item; - ELM_CHECK_WIDTYPE(obj, widtype) NULL; - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return NULL; - if (wd->config_load) + + ELM_COLORSELECTOR_CHECK(obj) NULL; + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + if (sd->config_load) { _colors_remove(obj); - wd->config_load = EINA_FALSE; + sd->config_load = EINA_FALSE; } item = _item_new(obj); if (!item) return NULL; + item->color = ELM_NEW(Elm_Color_RGBA); if (!item->color) return NULL; + item->color->r = r; item->color->g = g; item->color->b = b; item->color->a = a; - _elm_config_color_set(wd->palette_name, item->color->r, item->color->g, - item->color->b, item->color->a); - elm_box_pack_end(wd->box, VIEW(item)); - evas_object_color_set(item->color_obj, item->color->r, item->color->g, - item->color->b, item->color->a); - wd->items = eina_list_append(wd->items, item); - _sizing_eval(obj); - return (Elm_Object_Item *) item; + _elm_config_color_set + (sd->palette_name, item->color->r, item->color->g, item->color->b, + item->color->a); + + elm_box_pack_end(sd->palette_box, VIEW(item)); + evas_object_color_set + (item->color_obj, item->color->r, item->color->g, item->color->b, + item->color->a); + + sd->items = eina_list_append(sd->items, item); + + elm_layout_sizing_eval(obj); + + return (Elm_Object_Item *)item; } EAPI void elm_colorselector_palette_clear(Evas_Object *obj) { - ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; + ELM_COLORSELECTOR_CHECK(obj); + _colors_remove(obj); } EAPI void -elm_colorselector_palette_name_set(Evas_Object *obj, const char *palette_name) +elm_colorselector_palette_name_set(Evas_Object *obj, + const char *palette_name) { - ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; - if (!strcmp(wd->palette_name, palette_name)) return; + ELM_COLORSELECTOR_CHECK(obj); + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + if (!strcmp(sd->palette_name, palette_name)) return; + if (palette_name) { _colors_remove(obj); - eina_stringshare_replace(&wd->palette_name, palette_name); - _colors_load_apply(obj); + eina_stringshare_replace(&sd->palette_name, palette_name); + _palette_colors_load(obj); } } -EAPI const char* +EAPI const char * elm_colorselector_palette_name_get(const Evas_Object *obj) { - ELM_CHECK_WIDTYPE(obj, widtype) NULL; - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return NULL; - return wd->palette_name; + ELM_COLORSELECTOR_CHECK(obj) NULL; + ELM_COLORSELECTOR_DATA_GET(obj, sd); + + return sd->palette_name; } diff --git a/legacy/elementary/src/lib/elm_colorselector.h b/legacy/elementary/src/lib/elm_colorselector.h index 22dd78b126..b45150cac5 100644 --- a/legacy/elementary/src/lib/elm_colorselector.h +++ b/legacy/elementary/src/lib/elm_colorselector.h @@ -5,19 +5,26 @@ * @image html img/widget/colorselector/preview-00.png * @image latex img/widget/colorselector/preview-00.eps * - * A ColorSelector is a color selection widget. It allows application to set a - * series of colors.It also allows to load/save colors from/to config with a - * unique identifier, by default, the colors are loaded/saved from/to config - * using "default" identifier. - * The colors can be picked by user from the color set by clicking on individual color - * item on the palette or by selecting it from selector. + * A ColorSelector is a color selection widget. It allows application + * to set a series of colors.It also allows to load/save colors + * from/to config with a unique identifier, by default, the colors are + * loaded/saved from/to config using "default" identifier. The colors + * can be picked by user from the color set by clicking on individual + * color item on the palette or by selecting it from selector. * - * Signals that you can add callbacks for are: - * - "changed" - When the color value changes on selector(event_info is NULL). - * - "color,item,selected" - When user clicks on color item. The event_info parameter - * of the callback will be the selected color item. - * - "color,item,longpressed" - When user long presses on color item. The event info - * parameter of the callback contains selected color item. + * This widget inherits from the @ref Layout one, so that all the + * functions acting on it also work for check objects. + * + * This widget emits the following signals, besides the ones sent from + * @ref Layout: + * - @c "changed" - When the color value changes on selector + * event_info is NULL. + * - @c "color,item,selected" - When user clicks on color item. The + * event_info parameter of the callback will be the selected color + * item. + * - @c "color,item,longpressed" - When user long presses on color + * item. The event info parameter of the callback contains selected + * color item. * * See @ref tutorial_colorselector. * @{