forked from enlightenment/enlightenment
enables optional alpha edition in color selector.
NOTE: the color selection widget (e_widget_csel) is way too complex. The basic editor should not show HSV as most people have no clue what it is. SVN revision: 46926
This commit is contained in:
parent
d3a7f16b04
commit
f3dcabc3d0
|
@ -6,8 +6,8 @@
|
|||
EAPI int
|
||||
e_color_class_init(void)
|
||||
{
|
||||
Eina_List *l;
|
||||
E_Color_Class *cc;
|
||||
const Eina_List *l;
|
||||
const E_Color_Class *cc;
|
||||
|
||||
EINA_LIST_FOREACH(e_config->color_classes, l, cc)
|
||||
{
|
||||
|
@ -29,78 +29,135 @@ e_color_class_shutdown(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_color_class_set(const char *color_class, int r, int g, int b, int a, int r2, int b2, int g2, int a2, int r3, int g3, int b3, int a3)
|
||||
static Eina_List *
|
||||
e_color_class_node_find_stringshared(const char *name)
|
||||
{
|
||||
E_Color_Class *cc = NULL;
|
||||
Eina_List *l;
|
||||
E_Color_Class *cc;
|
||||
|
||||
cc = e_color_class_find(color_class);
|
||||
if (!cc)
|
||||
{
|
||||
cc = E_NEW(E_Color_Class, 1);
|
||||
e_config->color_classes = eina_list_append(e_config->color_classes, cc);
|
||||
cc->name = eina_stringshare_add(color_class);
|
||||
cc->r = cc->g = cc->b = cc->a = 255;
|
||||
cc->r2 = cc->g2 = cc->b2 = cc->a2 = 255;
|
||||
cc->r3 = cc->g3 = cc->b3 = cc->a3 = 255;
|
||||
}
|
||||
|
||||
if (r != -1) cc->r = E_CLAMP(r, 0, 255);
|
||||
if (g != -1) cc->g = E_CLAMP(g, 0, 255);
|
||||
if (b != -1) cc->b = E_CLAMP(b, 0, 255);
|
||||
if (a != -1) cc->a = E_CLAMP(a, 0, 255);
|
||||
if (r2 != -1) cc->r2 = E_CLAMP(r2, 0, 255);
|
||||
if (g2 != -1) cc->g2 = E_CLAMP(g2, 0, 255);
|
||||
if (b2 != -1) cc->b2 = E_CLAMP(b2, 0, 255);
|
||||
if (a2 != -1) cc->a2 = E_CLAMP(a2, 0, 255);
|
||||
if (r3 != -1) cc->r3 = E_CLAMP(r3, 0, 255);
|
||||
if (g3 != -1) cc->g3 = E_CLAMP(g3, 0, 255);
|
||||
if (b3 != -1) cc->b3 = E_CLAMP(b3, 0, 255);
|
||||
if (a3 != -1) cc->a3 = E_CLAMP(a3, 0, 255);
|
||||
|
||||
edje_color_class_set(cc->name,
|
||||
cc->r, cc->g, cc->b, cc->a,
|
||||
cc->r2, cc->g2, cc->b2, cc->a2,
|
||||
cc->r3, cc->g3, cc->b3, cc->a3);
|
||||
e_config_save_queue();
|
||||
EINA_LIST_FOREACH(e_config->color_classes, l, cc)
|
||||
if (cc && cc->name == name)
|
||||
return l;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_color_class_del(const char *name)
|
||||
EAPI E_Color_Class *
|
||||
e_color_class_find_stringshared(const char *name)
|
||||
{
|
||||
E_Color_Class *cc = NULL;
|
||||
|
||||
cc = e_color_class_find(name);
|
||||
if (cc)
|
||||
{
|
||||
e_config->color_classes = eina_list_remove(e_config->color_classes, cc);
|
||||
edje_color_class_del(cc->name);
|
||||
eina_stringshare_del(cc->name);
|
||||
E_FREE(cc);
|
||||
|
||||
e_config_save_queue();
|
||||
}
|
||||
Eina_List *l = e_color_class_node_find_stringshared(name);
|
||||
if (!l) return NULL;
|
||||
return l->data;
|
||||
}
|
||||
|
||||
EAPI E_Color_Class *
|
||||
e_color_class_find(const char *name)
|
||||
{
|
||||
Eina_List *l;
|
||||
E_Color_Class *cc = NULL;
|
||||
E_Color_Class *cc;
|
||||
|
||||
EINA_LIST_FOREACH(e_config->color_classes, l, cc)
|
||||
{
|
||||
if (!cc) continue;
|
||||
name = eina_stringshare_add(name);
|
||||
cc = e_color_class_find_stringshared(name);
|
||||
eina_stringshare_del(name);
|
||||
|
||||
if (!strcmp(cc->name, name))
|
||||
{
|
||||
return cc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return cc;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_color_class_instance_set(E_Color_Class *cc, int r, int g, int b, int a, int r2, int b2, int g2, int a2, int r3, int g3, int b3, int a3)
|
||||
{
|
||||
if (!cc) return;
|
||||
|
||||
if (r != -1) cc->r = E_CLAMP(r, 0, 255);
|
||||
if (g != -1) cc->g = E_CLAMP(g, 0, 255);
|
||||
if (b != -1) cc->b = E_CLAMP(b, 0, 255);
|
||||
if (a != -1) cc->a = E_CLAMP(a, 0, 255);
|
||||
if (r2 != -1) cc->r2 = E_CLAMP(r2, 0, 255);
|
||||
if (g2 != -1) cc->g2 = E_CLAMP(g2, 0, 255);
|
||||
if (b2 != -1) cc->b2 = E_CLAMP(b2, 0, 255);
|
||||
if (a2 != -1) cc->a2 = E_CLAMP(a2, 0, 255);
|
||||
if (r3 != -1) cc->r3 = E_CLAMP(r3, 0, 255);
|
||||
if (g3 != -1) cc->g3 = E_CLAMP(g3, 0, 255);
|
||||
if (b3 != -1) cc->b3 = E_CLAMP(b3, 0, 255);
|
||||
if (a3 != -1) cc->a3 = E_CLAMP(a3, 0, 255);
|
||||
|
||||
edje_color_class_set(cc->name,
|
||||
cc->r, cc->g, cc->b, cc->a,
|
||||
cc->r2, cc->g2, cc->b2, cc->a2,
|
||||
cc->r3, cc->g3, cc->b3, cc->a3);
|
||||
e_config_save_queue();
|
||||
}
|
||||
|
||||
EAPI E_Color_Class *
|
||||
e_color_class_set_stringshared(const char *color_class, int r, int g, int b, int a, int r2, int b2, int g2, int a2, int r3, int g3, int b3, int a3)
|
||||
{
|
||||
E_Color_Class *cc = e_color_class_find_stringshared(color_class);
|
||||
if (!cc)
|
||||
{
|
||||
cc = E_NEW(E_Color_Class, 1);
|
||||
if (!cc) return NULL;
|
||||
e_config->color_classes = eina_list_append(e_config->color_classes, cc);
|
||||
cc->name = eina_stringshare_ref(color_class);
|
||||
cc->r = cc->g = cc->b = cc->a = 255;
|
||||
cc->r2 = cc->g2 = cc->b2 = cc->a2 = 255;
|
||||
cc->r3 = cc->g3 = cc->b3 = cc->a3 = 255;
|
||||
}
|
||||
|
||||
e_color_class_instance_set(cc,
|
||||
r, g, b, a,
|
||||
r2, g2, b2, a2,
|
||||
r3, g3, b3, a3);
|
||||
return cc;
|
||||
}
|
||||
|
||||
EAPI E_Color_Class *
|
||||
e_color_class_set(const char *color_class, int r, int g, int b, int a, int r2, int b2, int g2, int a2, int r3, int g3, int b3, int a3)
|
||||
{
|
||||
E_Color_Class *cc;
|
||||
|
||||
color_class = eina_stringshare_add(color_class);
|
||||
cc = e_color_class_set_stringshared(color_class,
|
||||
r, g, b, a,
|
||||
r2, g2, b2, a2,
|
||||
r3, g3, b3, a3);
|
||||
eina_stringshare_del(color_class);
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
static void
|
||||
e_color_class_node_del(Eina_List *n)
|
||||
{
|
||||
E_Color_Class *cc = n->data;
|
||||
edje_color_class_del(cc->name);
|
||||
eina_stringshare_del(cc->name);
|
||||
E_FREE(cc);
|
||||
|
||||
e_config->color_classes = eina_list_remove_list(e_config->color_classes, n);
|
||||
e_config_save_queue();
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_color_class_instance_del(E_Color_Class *cc)
|
||||
{
|
||||
Eina_List *n = eina_list_data_find_list(e_config->color_classes, cc);
|
||||
if (!n) return;
|
||||
e_color_class_node_del(n);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_color_class_del_stringshared(const char *name)
|
||||
{
|
||||
Eina_List *n = e_color_class_node_find_stringshared(name);
|
||||
if (!n) return;
|
||||
e_color_class_node_del(n);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_color_class_del(const char *name)
|
||||
{
|
||||
name = eina_stringshare_add(name);
|
||||
e_color_class_del_stringshared(name);
|
||||
eina_stringshare_del(name);
|
||||
}
|
||||
|
||||
EAPI Eina_List *
|
||||
e_color_class_list(void)
|
||||
|
|
|
@ -12,7 +12,7 @@ typedef struct _E_Color_Class E_Color_Class;
|
|||
|
||||
struct _E_Color_Class
|
||||
{
|
||||
const char *name;
|
||||
const char *name; /* stringshared name */
|
||||
int r, g, b, a;
|
||||
int r2, g2, b2, a2;
|
||||
int r3, g3, b3, a3;
|
||||
|
@ -20,11 +20,25 @@ struct _E_Color_Class
|
|||
|
||||
EAPI int e_color_class_init(void);
|
||||
EAPI int e_color_class_shutdown(void);
|
||||
EAPI void e_color_class_set(const char *color_class,
|
||||
int r, int g, int b, int a,
|
||||
int r2, int b2, int g2, int a2,
|
||||
int r3, int g3, int b3, int a3);
|
||||
|
||||
EAPI void e_color_class_instance_set(E_Color_Class *cc,
|
||||
int r, int g, int b, int a,
|
||||
int r2, int b2, int g2, int a2,
|
||||
int r3, int g3, int b3, int a3);
|
||||
EAPI E_Color_Class *e_color_class_set_stringshared(const char *color_class,
|
||||
int r, int g, int b, int a,
|
||||
int r2, int b2, int g2, int a2,
|
||||
int r3, int g3, int b3, int a3);
|
||||
EAPI E_Color_Class *e_color_class_set(const char *color_class,
|
||||
int r, int g, int b, int a,
|
||||
int r2, int b2, int g2, int a2,
|
||||
int r3, int g3, int b3, int a3);
|
||||
EAPI E_Color_Class *e_color_class_find(const char *name);
|
||||
EAPI E_Color_Class *e_color_class_find_stringshared(const char *name);
|
||||
|
||||
|
||||
EAPI void e_color_class_instance_del(E_Color_Class *cc);
|
||||
EAPI void e_color_class_del_stringshared(const char *name);
|
||||
EAPI void e_color_class_del(const char *name);
|
||||
|
||||
EAPI Eina_List *e_color_class_list(void);
|
||||
|
|
|
@ -14,10 +14,11 @@ static void _e_color_dialog_cb_csel_change(void *data, Evas_Object *obj);
|
|||
* Create a color selector dialog.
|
||||
*
|
||||
* @param con container to display on
|
||||
* @param color color to initialize to (or NULL for black).
|
||||
* @param color color to initialize to (or NULL for black).
|
||||
* @param alpha_enabled if set, uses alpha and let user edit it.
|
||||
*/
|
||||
E_Color_Dialog *
|
||||
e_color_dialog_new(E_Container *con, const E_Color *color)
|
||||
e_color_dialog_new(E_Container *con, const E_Color *color, Eina_Bool alpha_enabled)
|
||||
{
|
||||
E_Color_Dialog *dia;
|
||||
Evas_Object *o;
|
||||
|
@ -33,12 +34,13 @@ e_color_dialog_new(E_Container *con, const E_Color *color)
|
|||
|
||||
if (color)
|
||||
e_color_copy(color, dia->color);
|
||||
else
|
||||
dia->color->a = 255;
|
||||
|
||||
if ((!color) || (!alpha_enabled))
|
||||
dia->color->a = 255;
|
||||
|
||||
e_color_copy(dia->color, dia->initial);
|
||||
|
||||
o = e_widget_csel_add(dia->dia->win->evas, dia->color);
|
||||
o = e_widget_csel_add(dia->dia->win->evas, dia->color, alpha_enabled);
|
||||
evas_object_show(o);
|
||||
e_widget_size_min_get(o, &mw, &mh);
|
||||
e_dialog_content_set(dia->dia, o, 460, 260);
|
||||
|
|
|
@ -28,7 +28,7 @@ struct _E_Color_Dialog
|
|||
void *change_data;
|
||||
};
|
||||
|
||||
EAPI E_Color_Dialog *e_color_dialog_new (E_Container *con, const E_Color *initial_color);
|
||||
EAPI E_Color_Dialog *e_color_dialog_new (E_Container *con, const E_Color *initial_color, Eina_Bool alpha_enabled);
|
||||
EAPI void e_color_dialog_show (E_Color_Dialog *dia);
|
||||
EAPI void e_color_dialog_title_set (E_Color_Dialog *dia, const char *title);
|
||||
|
||||
|
|
|
@ -653,7 +653,7 @@ _e_test_internal(E_Container *con)
|
|||
{
|
||||
E_Color_Dialog *d;
|
||||
|
||||
d = e_color_dialog_new(con, NULL);
|
||||
d = e_color_dialog_new(con, NULL, EINA_FALSE);
|
||||
e_color_dialog_show(d);
|
||||
e_color_dialog_select_callback_set(d, _e_test_cb_ok, NULL);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ struct _E_Widget_Data
|
|||
E_Color_Dialog *dia;
|
||||
E_Color *color;
|
||||
E_Container *con; /* container to pop a color dialog up on */
|
||||
int show_color_dialog;
|
||||
Eina_Bool show_color_dialog;
|
||||
Eina_Bool alpha_enabled;
|
||||
};
|
||||
|
||||
static void _e_wid_update(E_Widget_Data *wd);
|
||||
|
@ -48,7 +49,7 @@ _e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission, const char
|
|||
if (!wd->show_color_dialog || !wd->con) return;
|
||||
if (!wd->dia)
|
||||
{
|
||||
wd->dia = e_color_dialog_new(wd->con, wd->color);
|
||||
wd->dia = e_color_dialog_new(wd->con, wd->color, wd->alpha_enabled);
|
||||
e_color_dialog_select_callback_set(wd->dia, _e_wid_color_select_cb, wd);
|
||||
e_color_dialog_cancel_callback_set(wd->dia, _e_wid_color_cancel_cb, wd);
|
||||
e_color_dialog_change_callback_set(wd->dia, _e_wid_color_change_cb, wd);
|
||||
|
@ -122,7 +123,7 @@ _e_wid_disable_hook(Evas_Object *obj)
|
|||
If not NULL, when clicked a color dialog will pop up.
|
||||
*/
|
||||
Evas_Object *
|
||||
e_widget_color_well_add(Evas *evas, E_Color *color, int show_color_dialog)
|
||||
e_widget_color_well_add_full(Evas *evas, E_Color *color, Eina_Bool show_color_dialog, Eina_Bool alpha_enabled)
|
||||
{
|
||||
Evas_Object *obj, *o;
|
||||
E_Widget_Data *wd;
|
||||
|
@ -141,6 +142,7 @@ e_widget_color_well_add(Evas *evas, E_Color *color, int show_color_dialog)
|
|||
wd->con = win->container;
|
||||
|
||||
wd->show_color_dialog = show_color_dialog;
|
||||
wd->alpha_enabled = alpha_enabled;
|
||||
|
||||
o = edje_object_add(evas);
|
||||
e_widget_sub_object_add(obj, o);
|
||||
|
@ -168,14 +170,24 @@ e_widget_color_well_add(Evas *evas, E_Color *color, int show_color_dialog)
|
|||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a color well widget to an evas.
|
||||
* An optional E_Container may be passed in.
|
||||
If not NULL, when clicked a color dialog will pop up.
|
||||
*/
|
||||
Evas_Object *
|
||||
e_widget_color_well_add(Evas *evas, E_Color *color, Eina_Bool show_color_dialog)
|
||||
{
|
||||
return e_widget_color_well_add_full
|
||||
(evas, color, show_color_dialog, EINA_FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Let the color well know that its color data has changed.
|
||||
*/
|
||||
void
|
||||
e_widget_color_well_update(Evas_Object *obj)
|
||||
{
|
||||
E_Widget_Data *wd;
|
||||
|
||||
wd = e_widget_data_get(obj);
|
||||
E_Widget_Data *wd = e_widget_data_get(obj);
|
||||
_e_wid_update(wd);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef E_WIDGET_COLOR_WELL_H
|
||||
#define E_WIDGET_COLOR_WELL_H
|
||||
|
||||
EAPI Evas_Object *e_widget_color_well_add (Evas *evas, E_Color *color, int show_color_dialog);
|
||||
EAPI void e_widget_color_well_update (Evas_Object *obj);
|
||||
EAPI Evas_Object *e_widget_color_well_add (Evas *evas, E_Color *color, Eina_Bool show_color_dialog);
|
||||
EAPI Evas_Object *e_widget_color_well_add_full (Evas *evas, E_Color *color, Eina_Bool show_color_dialog, Eina_Bool alpha_enabled);
|
||||
EAPI void e_widget_color_well_update (Evas_Object *obj);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,7 +38,7 @@ _e_wid_del_hook(Evas_Object *obj)
|
|||
}
|
||||
|
||||
static void
|
||||
_e_wid_cb_radio_changed(void *data, Evas_Object *o)
|
||||
_e_wid_cb_radio_changed(void *data, Evas_Object *o __UNUSED__)
|
||||
{
|
||||
E_Widget_Data *wd = data;
|
||||
|
||||
|
@ -181,8 +181,14 @@ _e_wid_cb_color_changed(void *data, Evas_Object *o)
|
|||
e_widget_change(wd->obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_e_wid_cb_alpha_changed(void *data, Evas_Object *o __UNUSED__)
|
||||
{
|
||||
_e_wid_cb_color_changed(data, NULL);
|
||||
}
|
||||
|
||||
Evas_Object *
|
||||
e_widget_csel_add(Evas *evas, E_Color *color)
|
||||
e_widget_csel_add(Evas *evas, E_Color *color, Eina_Bool alpha_enabled)
|
||||
{
|
||||
Evas_Object *obj, *o;
|
||||
Evas_Object *frame, *table;
|
||||
|
@ -253,7 +259,16 @@ e_widget_csel_add(Evas *evas, E_Color *color)
|
|||
wd->entries = eina_list_append(wd->entries, o);
|
||||
e_widget_table_object_append(frame, o, 2, i, 1, 1, 1, 1, 1, 1);
|
||||
e_widget_on_change_hook_set(o, _e_wid_cb_color_changed, wd);
|
||||
}
|
||||
|
||||
if (alpha_enabled)
|
||||
{
|
||||
o = e_widget_label_add(evas, "Alpha");
|
||||
e_widget_table_object_append(frame, o, 1, i, 1, 1, 1, 1, 0, 0);
|
||||
o = e_widget_slider_add
|
||||
(evas, 1, 0, "%0.0f px", 0, 255, 1, 0, NULL, &(wd->cv->a), 100);
|
||||
e_widget_on_change_hook_set(o, _e_wid_cb_alpha_changed, wd);
|
||||
e_widget_table_object_append(frame, o, 2, i, 1, 1, 1, 1, 0, 0);
|
||||
}
|
||||
|
||||
o = e_widget_spectrum_add(evas, wd->mode, wd->cv);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef E_WIDGET_CSEL_H
|
||||
#define E_WIDGET_CSEL_H
|
||||
|
||||
Evas_Object *e_widget_csel_add(Evas *evas, E_Color *color);
|
||||
Evas_Object *e_widget_csel_add(Evas *evas, E_Color *color, Eina_Bool alpha_enabled);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue