Start of a color selector.


			
			
				devs/princeamd/enlightenment-0.17-elive
			
			
		
rephorm 16 years ago committed by rephorm
parent 35709e2595
commit d7792a9270
  1. 4
      data/themes/Makefile.am
  2. 2
      data/themes/default.edc
  3. 87
      data/themes/default_cslider.edc
  4. 89
      data/themes/default_spectrum.edc
  5. 10
      src/bin/Makefile.am
  6. 19
      src/bin/e_color.c
  7. 27
      src/bin/e_color.h
  8. 5
      src/bin/e_includes.h
  9. 350
      src/bin/e_spectrum.c
  10. 9
      src/bin/e_spectrum.h
  11. 25
      src/bin/e_test.c
  12. 231
      src/bin/e_widget_csel.c
  13. 6
      src/bin/e_widget_csel.h
  14. 441
      src/bin/e_widget_cslider.c
  15. 7
      src/bin/e_widget_cslider.h
  16. 313
      src/bin/e_widget_spectrum.c
  17. 6
      src/bin/e_widget_spectrum.h

@ -53,7 +53,9 @@ default_exebuf.edc \
default_desklock.edc \
default_textblock.edc \
default_shelf.edc \
default_preview.edc
default_preview.edc \
default_cslider.edc \
default_spectrum.edc
default.edj: Makefile $(EXTRA_DIST)
$(EDJE_CC) $(EDJE_FLAGS) \

@ -62,5 +62,7 @@ collections {
#include "default_textblock.edc"
#include "default_shelf.edc"
#include "default_preview.edc"
#include "default_cslider.edc"
#include "default_spectrum.edc"
}

@ -0,0 +1,87 @@
group {
name: "widgets/cslider";
parts {
part {
name: "bg";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
color: 0 0 0 100;
min: 0 20;
max: 99999 20;
rel1.offset: 2 2;
rel2.offset: -3 -3;
}
description {
state: "vertical" 0.0;
inherit: "default" 0.0;
min: 20 0;
max: 20 99999;
}
}
part {
name: "gradient";
type: SWALLOW;
mouse_events: 0;
description {
state: "default" 0.0;
rel1.to: "bg";
rel1.offset: 1 1;
rel2.to: "bg";
rel2.offset: -2 -2;
}
}
part {
name: "cursor";
type: RECT;
dragable {
confine: "gradient";
x: 1 1 0;
y: -1 1 0;
}
description {
state: "default" 0.0;
min: 3 16;
max: 3 9999;
fixed: 1 1;
rel1 {
to: "gradient";
relative: 0.5 0;
offset: 0 0;
}
rel2 {
to: "gradient";
relative: 0.5 1;
offset: 0 -1;
}
}
description {
state: "vertical" 0.0;
min: 16 3;
max: 9999 3;
fixed: 1 1;
rel1 {
to: "gradient";
relative: 0 0.5 ;
offset: 0 0;
}
rel2 {
to: "gradient";
relative: 1 0.5;
offset: -1 0;
}
}
}
}
programs {
program {
name: "go_vertical";
signal: "e,direction,v";
source: "";
action: STATE_SET "vertical" 0.0;
target: "cursor";
target: "bg";
}
}
}

@ -0,0 +1,89 @@
group {
name: "widgets/spectrum";
parts {
part {
name: "bg";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
aspect: 1 1;
color: 0 0 0 100;
rel1.offset: 2 2;
rel2.offset: -3 -3;
}
}
part {
name: "spectrum";
type: SWALLOW;
mouse_events: 0;
description {
state: "default" 0.0;
min: 18 18;
max: 9999 9999;
rel1.to: "bg";
rel1.offset: 1 1;
rel2.to: "bg";
rel2.offset: -2 -2;
}
}
part {
name: "cursor";
type: RECT;
dragable {
confine: "spectrum";
x: 1 1 0;
y: 1 1 0;
}
description {
state: "default" 0.0;
min: 3 3;
max: 3 3;
fixed: 1 1;
visible: 0;
rel1 {
to: "spectrum";
relative: 0.5 0.5;
offset: 0 0;
}
rel2 {
to: "spectrum";
relative: 0.5 0.5;
offset: 0 0;
}
}
}
part {
name: "cursor_x";
type: RECT;
description {
state: "default" 0.0;
rel1 {
to_x: "cursor";
to_y: "spectrum";
}
rel2 {
to_x: "cursor";
to_y: "spectrum";
}
}
}
part {
name: "cursor_y";
type: RECT;
description {
state: "default" 0.0;
rel1 {
to_x: "spectrum";
to_y: "cursor";
}
rel2 {
to_x: "spectrum";
to_y: "cursor";
}
}
}
}
}

@ -167,6 +167,11 @@ e_widget_scrollframe.h \
e_sha1.h \
e_widget_fsel.h \
e_fm_mime.h \
e_color.h \
e_spectrum.h \
e_widget_spectrum.h \
e_widget_cslider.h \
e_widget_csel.h \
e_int_config_wallpaper.h \
e_int_config_wallpaper_import.h
@ -311,6 +316,11 @@ e_widget_scrollframe.c \
e_sha1.c \
e_widget_fsel.c \
e_fm_mime.c \
e_color.c \
e_spectrum.c \
e_widget_spectrum.c \
e_widget_cslider.c \
e_widget_csel.c \
e_int_config_wallpaper.c \
e_int_config_wallpaper_import.c \
$(ENLIGHTENMENTHEADERS)

@ -0,0 +1,19 @@
#include "e.h"
void
e_color_update_rgb(E_Color *ec)
{
if (!ec) return;
evas_color_rgb_to_hsv(ec->r, ec->g, ec->b, &(ec->h), &(ec->s), &(ec->v));
}
void
e_color_update_hsv(E_Color *ec)
{
if (!ec) return;
if (ec->v == 0)
ec->r = ec->g = ec->b = 0;
else
evas_color_hsv_to_rgb(ec->h, ec->s, ec->v, &(ec->r), &(ec->g), &(ec->b));
}

@ -0,0 +1,27 @@
#ifndef E_COLOR_HEADER
#define E_COLOR_HEADER
typedef enum _E_Color_Component E_Color_Component;
enum _E_Color_Component
{
E_COLOR_COMPONENT_R,
E_COLOR_COMPONENT_G,
E_COLOR_COMPONENT_B,
E_COLOR_COMPONENT_H,
E_COLOR_COMPONENT_S,
E_COLOR_COMPONENT_V,
E_COLOR_COMPONENT_MAX
};
// used so that a single color struct can be shared by all elements of the color dialog
typedef struct _E_Color E_Color;
struct _E_Color
{
int r, g, b;
float h, s, v;
int a;
};
void e_color_update_rgb(E_Color *ec);
void e_color_update_hsv(E_Color *ec);
#endif

@ -145,3 +145,8 @@
#include "e_fm_mime.h"
#include "e_int_config_wallpaper.h"
#include "e_int_config_wallpaper_import.h"
#include "e_color.h"
#include "e_spectrum.h"
#include "e_widget_spectrum.h"
#include "e_widget_cslider.h"
#include "e_widget_csel.h"

@ -0,0 +1,350 @@
#include "e.h"
Evas_Smart *_e_spectrum_smart = NULL;
typedef struct _E_Spectrum E_Spectrum;
struct _E_Spectrum
{
Evas_Object *o_spectrum;
Evas_Object *o_event;
Evas_Object *o_cursor;
int iw, ih; /* square image width/height */
E_Color_Component mode;
E_Color *cv;
};
static void
_e_spectrum_smart_add(Evas_Object *o)
{
E_Spectrum *sp;
sp = calloc(1, sizeof(E_Spectrum));
if (!sp) return;
evas_object_smart_data_set(o, sp);
sp->mode = E_COLOR_COMPONENT_R;
sp->o_spectrum = evas_object_image_add(evas_object_evas_get(o));
sp->iw = sp->ih = 255;
evas_object_image_size_set(sp->o_spectrum, sp->iw, sp->ih);
evas_object_image_alpha_set(sp->o_spectrum, 1);
evas_object_smart_member_add(sp->o_spectrum, o);
}
static void
_e_spectrum_smart_del(Evas_Object *o)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_del(sp->o_spectrum);
evas_object_del(sp->o_event);
evas_object_del(sp->o_cursor);
}
static void
_e_spectrum_smart_show(Evas_Object *o)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_show(sp->o_spectrum);
evas_object_show(sp->o_event);
evas_object_show(sp->o_cursor);
}
static void
_e_spectrum_smart_hide(Evas_Object *o)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_hide(sp->o_spectrum);
evas_object_hide(sp->o_event);
evas_object_hide(sp->o_cursor);
}
static void
_e_spectrum_smart_move(Evas_Object *o, Evas_Coord x, Evas_Coord y)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_move(sp->o_spectrum, x, y);
evas_object_move(sp->o_event, x, y);
evas_object_move(sp->o_cursor, x, y);
}
static void
_e_spectrum_smart_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h)
{
E_Spectrum *sp;
Evas_Coord x, y;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_image_fill_set(sp->o_spectrum, 0, 0, w, h);
evas_object_resize(sp->o_spectrum, w, h);
evas_object_resize(sp->o_event, w, h);
evas_object_resize(sp->o_cursor, w, h);
}
static void
_e_spectrum_smart_color_set(Evas_Object *o, int r, int g, int b, int a)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_color_set(sp->o_spectrum, r, g, b, a);
evas_object_color_set(sp->o_event, r, g, b, a);
evas_object_color_set(sp->o_cursor, r, g, b, a);
}
static void
_e_spectrum_smart_clip_set(Evas_Object *o, Evas_Object *o_clip)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_clip_set(sp->o_spectrum, o_clip);
evas_object_clip_set(sp->o_event, o_clip);
evas_object_clip_set(sp->o_cursor, o_clip);
}
static void
_e_spectrum_smart_clip_unset(Evas_Object *o)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
evas_object_clip_unset(sp->o_spectrum);
evas_object_clip_unset(sp->o_event);
evas_object_clip_unset(sp->o_cursor);
}
static void
_e_spectrum_smart_init()
{
Evas_Smart *smart;
if ( _e_spectrum_smart ) return;
_e_spectrum_smart = evas_smart_new("e_spectrum",
_e_spectrum_smart_add,
_e_spectrum_smart_del,
NULL, NULL, NULL, NULL, NULL,
_e_spectrum_smart_move,
_e_spectrum_smart_resize,
_e_spectrum_smart_show,
_e_spectrum_smart_hide,
_e_spectrum_smart_color_set,
_e_spectrum_smart_clip_set,
_e_spectrum_smart_clip_unset,
NULL);
}
void
_e_spectrum_color_calc(E_Spectrum *sp, float vx, float vy, float vz, int *r, int *g, int *b)
{
switch (sp->mode)
{
case E_COLOR_COMPONENT_R:
*r = 255 * vz;
*g = 255 * vy;
*b = 255 * vx;
break;
case E_COLOR_COMPONENT_G:
*r = 255 * vx;
*g = 255 * vz;
*b = 255 * vy;
break;
case E_COLOR_COMPONENT_B:
*r = 255 * vy;
*g = 255 * vx;
*b = 255 * vz;
break;
case E_COLOR_COMPONENT_H:
evas_color_hsv_to_rgb(vz * 360.0, vy, vx, r, g, b);
break;
case E_COLOR_COMPONENT_S:
evas_color_hsv_to_rgb(vx * 360.0, vz, vy, r, g, b);
break;
case E_COLOR_COMPONENT_V:
evas_color_hsv_to_rgb(vy * 360.0, vx, vz, r, g, b);
break;
default:
break;
}
}
void
_e_spectrum_2d_color_at(E_Spectrum *sp, int x, int y, int *r, int *g, int *b)
{
int rr, gg, bb, aa;
float h, s, v;
if (!sp || !sp->cv) return;
switch (sp->mode)
{
case E_COLOR_COMPONENT_R:
rr = sp->cv->r;
gg = (1 - (y / (double)(sp->ih))) * 255;
bb = (x / (double)(sp->iw)) * 255;
break;
case E_COLOR_COMPONENT_G:
rr = (x / (double)(sp->iw)) * 255;
gg = sp->cv->g;
bb = (1 - (y / (double)(sp->ih))) * 255;
break;
case E_COLOR_COMPONENT_B:
rr = (1 - (y / (double)(sp->ih))) * 255;
gg = (x / (double)(sp->iw)) * 255;
bb = sp->cv->b;
break;
case E_COLOR_COMPONENT_H:
h = sp->cv->h;
s = 1 - (y / (double)(sp->ih));
v = x / (double)(sp->iw);
evas_color_hsv_to_rgb(h, s, v, &rr, &gg, &bb);
break;
case E_COLOR_COMPONENT_S:
s = sp->cv->s;
v = 1 - (y / (double)(sp->ih));
h = x / (double)(sp->iw) * 360;
evas_color_hsv_to_rgb(h, s, v, &rr, &gg, &bb);
break;
case E_COLOR_COMPONENT_V:
v = sp->cv->v;
h = (1 - (y / (double)(sp->ih))) * 360;
s = x / (double)(sp->iw);
evas_color_hsv_to_rgb(h, s, v, &rr, &gg, &bb);
break;
}
if (r) *r = rr;
if (g) *g = gg;
if (b) *b = bb;
}
void
_e_spectrum_update(E_Spectrum *sp)
{
int i, j;
int r, g, b;
int *data;
float vx, vy, vz;
if (!sp || !sp->cv) return;
//printf("UPDATE SPECTRUM\n");
data = evas_object_image_data_get(sp->o_spectrum, 1);
if (!data) return;
switch(sp->mode)
{
case E_COLOR_COMPONENT_R:
vz = (float)sp->cv->r / 255;
break;
case E_COLOR_COMPONENT_G:
vz = (float)sp->cv->g / 255;
break;
case E_COLOR_COMPONENT_B:
vz = (float)sp->cv->b / 255;
break;
case E_COLOR_COMPONENT_H:
vz = sp->cv->h / 360;
break;
case E_COLOR_COMPONENT_S:
vz = sp->cv->s;
break;
case E_COLOR_COMPONENT_V:
vz = sp->cv->v;
break;
}
for (i = 0; i < sp->ih; i++)
{
vy = (float)i / sp->ih;
for (j = 0; j < sp->iw; j++)
{
vx = (float)j / sp->iw;
//_e_spectrum_2d_color_at(sp, j, i, &r, &g, &b);
_e_spectrum_color_calc(sp, vx, vy, vz, &r, &g, &b);
data[(i * sp->iw) + j] = (sp->cv->a << 24) | (r << 16) | (g << 8) | b;
}
}
evas_object_image_data_set(sp->o_spectrum, data);
evas_object_image_data_update_add(sp->o_spectrum, 0, 0, sp->iw, sp->ih);
}
Evas_Object *
e_spectrum_add(Evas *e)
{
_e_spectrum_smart_init();
return evas_object_smart_add(e, _e_spectrum_smart);
}
void
e_spectrum_mode_set(Evas_Object *o, E_Color_Component mode)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
if (sp->mode == mode) return;
sp->mode = mode;
_e_spectrum_update(sp);
}
E_Color_Component
e_spectrum_mode_get(Evas_Object *o)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return -1;
return sp->mode;
}
void
e_spectrum_color_value_set(Evas_Object *o, E_Color *cv)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
sp->cv = cv;
_e_spectrum_update(sp);
}
void
e_spectrum_update(Evas_Object *o)
{
E_Spectrum *sp;
sp = evas_object_smart_data_get(o);
if (!sp) return;
_e_spectrum_update(sp);
}

@ -0,0 +1,9 @@
#ifndef E_SPECTRUM_H
#define E_SPECTRUM_H
Evas_Object *e_spectrum_add(Evas *e);
void e_spectrum_color_value_set(Evas_Object *o, E_Color *cv);
void e_spectrum_mode_set(Evas_Object *o, E_Color_Component mode);
void e_spectrum_update(Evas_Object *o);
#endif

@ -331,7 +331,7 @@ _e_test_internal(E_Container *con)
e_dialog_title_set(dia, "A Test Dialog");
o = e_icon_add(dia->win->evas);
e_icon_file_set(o, "/home/raster/t.png");
e_icon_file_set(o, "/home/rephorm/scroll.png");
evas_object_resize(o, 1024, 768);
evas_object_focus_set(o, 1);
evas_object_show(o);
@ -793,6 +793,29 @@ _e_test_internal(E_Container *con)
e_win_resize(dia->win, 400, 300);
}
#elif 0
static void
_e_test_internal(E_Container *con)
{
E_Dialog *dia;
Evas_Object *o;
Evas_Coord mw, mh;
dia = e_dialog_new(con);
e_dialog_title_set(dia, "Test Color Selector");
o = e_widget_csel_add(dia->win->evas);
evas_object_show(o);
e_widget_min_size_get(o, &mw, &mh);
e_dialog_content_set(dia, o, mw, mh);
/* buttons at the bottom */
e_dialog_button_add(dia, "OK", NULL, NULL, NULL);
e_dialog_resizable_set(dia, 1);
e_win_centered_set(dia->win, 1);
e_dialog_show(dia);
e_win_resize(dia->win, 460, 230);
}
#else
static void
_e_test_internal(E_Container *con)

@ -0,0 +1,231 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "e.h"
typedef struct _E_Widget_Data E_Widget_Data;
struct _E_Widget_Data
{
Evas_List *sliders;
Evas_List *entries;
Evas_Object *spectrum, *vert, *current;
E_Color *cv;
char **values;
int mode;
int changing;
};
static void
_e_wid_cb_radio_changed(void *data, Evas_Object *o)
{
E_Widget_Data *wd = data;
e_widget_spectrum_mode_set(wd->spectrum, wd->mode);
e_widget_cslider_mode_set(wd->vert, wd->mode);
}
static void
_e_wid_cb_color_changed(void *data, Evas_Object *o)
{
E_Widget_Data *wd = data;
Evas_List *l;
int i;
int changed = -1;
if (wd->changing) return;
wd->changing = 1;
// entry changed
for(l = wd->entries, i = 0; l; l = l->next, i++)
{
if (o == l->data)
{
changed = i;
switch(i)
{
case E_COLOR_COMPONENT_R:
wd->cv->r = atoi(wd->values[i]);
break;
case E_COLOR_COMPONENT_G:
wd->cv->g = atoi(wd->values[i]);
break;
case E_COLOR_COMPONENT_B:
wd->cv->b = atoi(wd->values[i]);
break;
case E_COLOR_COMPONENT_H:
wd->cv->h = atof(wd->values[i]);
break;
case E_COLOR_COMPONENT_S:
wd->cv->s = atof(wd->values[i]);
break;
case E_COLOR_COMPONENT_V:
wd->cv->v = atof(wd->values[i]);
break;
}
break;
}
}
if (changed != -1)
{
if (changed>= E_COLOR_COMPONENT_H)
e_color_update_hsv(wd->cv);
else if (changed >= E_COLOR_COMPONENT_R)
e_color_update_rgb(wd->cv);
}
if (o == wd->vert)
changed = wd->mode;
else
e_widget_cslider_update(wd->vert);
// update the sliders
for (l = wd->sliders, i = 0; l; l = l->next, i++)
{
Evas_Object *so = l->data;
if (o != so)
{
e_widget_cslider_update(so);
}
else
{
changed = i;
}
}
// and update the sepctrum
if (o != wd->spectrum && changed != -1)
{
if (wd->mode == changed ||
(wd->mode >= E_COLOR_COMPONENT_H && changed <= E_COLOR_COMPONENT_B) ||
(wd->mode <= E_COLOR_COMPONENT_B && changed >= E_COLOR_COMPONENT_H))
e_widget_spectrum_update(wd->spectrum, 1);
else
e_widget_spectrum_update(wd->spectrum, 0);
}
// now update the text fields to show current values
for(l = wd->entries, i = 0; l; l = l->next, i++)
{
char buf[10];
if (o == l->data) continue;
switch(i)
{
case E_COLOR_COMPONENT_R:
snprintf(buf, 10, "%i", wd->cv->r);
break;
case E_COLOR_COMPONENT_G:
snprintf(buf, 10, "%i", wd->cv->g);
break;
case E_COLOR_COMPONENT_B:
snprintf(buf, 10, "%i", wd->cv->b);
break;
case E_COLOR_COMPONENT_H:
snprintf(buf, 10, "%.2f", wd->cv->h);
break;
case E_COLOR_COMPONENT_S:
snprintf(buf, 10, "%.2f", wd->cv->s);
break;
case E_COLOR_COMPONENT_V:
snprintf(buf, 10, "%.2f", wd->cv->v);
break;
}
e_widget_entry_text_set((Evas_Object *)(l->data), buf);
}
wd->changing = 0;
}
Evas_Object *
e_widget_csel_add(Evas *evas)
{
Evas_Object *o;
Evas_Object *frame, *table;
Evas_Coord mw, mh;
E_Color*cv;
int i;
E_Radio_Group *grp = NULL;
char *labels[6] = { "R", "G", "B", "H", "S", "V" };
E_Widget_Data *wd;
table = e_widget_table_add(evas, 0);
frame = e_widget_frametable_add(evas, "colors", 0);
wd = calloc(1, sizeof(E_Widget_Data));
wd->mode = 1;
grp = e_widget_radio_group_new(&wd->mode);
// all sliders update a single color value struct
cv = calloc(1, sizeof(E_Color));
wd->cv = cv;
cv->r = 20; cv->g = 120; cv->b = 79;
cv->a = 255;
e_color_update_rgb(cv);
wd->values = calloc(E_COLOR_COMPONENT_MAX, sizeof(char *));
for(i = 0; i < E_COLOR_COMPONENT_MAX; i++)
{
wd->values[i] = calloc(10, sizeof(char));
switch(i)
{
case E_COLOR_COMPONENT_R:
snprintf(wd->values[i], 10, "%i", cv->r);
break;
case E_COLOR_COMPONENT_G:
snprintf(wd->values[i], 10, "%i", cv->g);
break;
case E_COLOR_COMPONENT_B:
snprintf(wd->values[i], 10, "%i", cv->b);
break;
case E_COLOR_COMPONENT_H:
snprintf(wd->values[i], 10, "%.0f", cv->h);
break;
case E_COLOR_COMPONENT_S:
snprintf(wd->values[i], 10, "%.2f", cv->s);
break;
case E_COLOR_COMPONENT_V:
snprintf(wd->values[i], 11, "%.2f", cv->v);
break;
}
o = e_widget_radio_add(evas, labels[i], i, grp);
e_widget_on_change_hook_set(o, _e_wid_cb_radio_changed, wd);
e_widget_frametable_object_append(frame, o, 0, i, 1, 1, 1, 1, 0, 0);
o = e_widget_cslider_add(evas, i, cv, 0, 0);
evas_object_show(o);
wd->sliders = evas_list_append(wd->sliders, o);
e_widget_on_change_hook_set(o, _e_wid_cb_color_changed, wd);
e_widget_frametable_object_append(frame, o, 1, i, 1, 1, 1, 1, 1, 0);
o = e_widget_entry_add(evas, &(wd->values[i]));
evas_object_show(o);
wd->entries = evas_list_append(wd->entries, o);
e_widget_frametable_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);
}
o = e_widget_spectrum_add(evas, wd->mode, cv);
evas_object_show(o);
e_widget_on_change_hook_set(o, _e_wid_cb_color_changed, wd);
wd->spectrum = o;
e_widget_table_object_append(table, o, 1, 1, 1, 1, 1, 1, 1, 1);
o = e_widget_cslider_add(evas, wd->mode, cv, 1, 1);
e_widget_on_change_hook_set(o, _e_wid_cb_color_changed, wd);
evas_object_show(o);
wd->vert = o;
e_widget_table_object_append(table, o, 2, 1, 1, 1, 1, 1, 0, 1);
e_widget_table_object_append(table, frame, 3, 1, 1, 1, 1, 1, 1, 1);
return table;
}

@ -0,0 +1,6 @@
#ifndef E_WIDGET_CSEL_H
#define E_WIDGET_CSEL_H
Evas_Object *e_widget_csel_add(Evas *evas);
#endif

@ -0,0 +1,441 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "e.h"
typedef struct _E_Widget_Data E_Widget_Data;
struct _E_Widget_Data
{
Evas_Object *o_cslider;
Evas_Object *o_grad;
Evas_Object *o_event;
int vertical;
int fixed;
E_Color_Component mode;
int valnum;
//int r, g, b, a;
E_Color *color;
int dragging;
};
static void _e_wid_del_hook(Evas_Object *obj);
static void _e_wid_focus_hook(Evas_Object *obj);
static void _e_wid_activate_hook(Evas_Object *obj);
static void _e_wid_disable_hook(Evas_Object *obj);
static void _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_wid_value_set(Evas_Object *obj, double vx);
static void _e_wid_update(E_Widget_Data *wd);
static void _e_wid_update_standard(E_Widget_Data *wd);
static void _e_wid_update_fixed(E_Widget_Data *wd);
static void _e_wid_move(void *data, Evas_Object *o, Evas_Coord x, Evas_Coord y);
static void _e_wid_resize(void *data, Evas_Object *o, Evas_Coord w, Evas_Coord h);
static void _e_wid_cb_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_wid_cb_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_wid_cb_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
Evas_Object *
e_widget_cslider_add(Evas *evas, E_Color_Component mode, E_Color *color, int vertical, int fixed)
{
Evas_Object *obj, *o;
E_Widget_Data *wd;
Evas_Coord mw, mh;
obj = e_widget_add(evas);
e_widget_del_hook_set(obj, _e_wid_del_hook);
e_widget_focus_hook_set(obj, _e_wid_focus_hook);
e_widget_activate_hook_set(obj, _e_wid_activate_hook);
e_widget_disable_hook_set(obj, _e_wid_disable_hook);
wd = calloc(1, sizeof(E_Widget_Data));
e_widget_data_set(obj, wd);
wd->vertical = vertical;
wd->fixed = fixed;
wd->mode = mode;
wd->color = color;
o = edje_object_add(evas);
wd->o_cslider = o;
e_theme_edje_object_set(o, "base/theme/widgets",
"widgets/cslider");
if (wd->vertical)
edje_object_signal_emit(o, "e,direction,v", "");
else
edje_object_signal_emit(o, "e,direction,h", "");
evas_object_show(o);
edje_object_size_min_calc(o, &mw, &mh);
e_widget_min_size_set(obj, mw, mh);
e_widget_sub_object_add(obj, o);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_wid_focus_steal, obj);
e_widget_resize_object_set(obj, o);
// add gradient obj
o = evas_object_gradient_add(evas);
e_widget_sub_object_add(obj, o);
if (wd->vertical)
evas_object_gradient_angle_set(o, 180);
else
evas_object_gradient_angle_set(o, 270);
evas_object_show(o);
e_widget_sub_object_add(obj, o);
wd->o_grad = o;
edje_object_part_swallow(wd->o_cslider, "gradient", o);
evas_object_intercept_resize_callback_add(o, _e_wid_resize, wd);
evas_object_intercept_move_callback_add(o, _e_wid_move, wd);
_e_wid_update(wd);
o = evas_object_rectangle_add(evas);
evas_object_color_set(o, 0, 0, 0, 0);
evas_object_show(o);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_wid_cb_down, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _e_wid_cb_move, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _e_wid_cb_up, obj);
wd->o_event = o;
return obj;
}
static void
_e_wid_move(void *data, Evas_Object *o, Evas_Coord x, Evas_Coord y)
{
E_Widget_Data *wd = data;
evas_object_move(wd->o_grad, x, y);
evas_object_move(wd->o_event, x, y);
}
static void
_e_wid_resize(void *data, Evas_Object *o, Evas_Coord w, Evas_Coord h)
{
E_Widget_Data *wd = data;
if (wd->vertical)
evas_object_gradient_fill_set(o, 0, 0, w, h);
else
evas_object_gradient_fill_set(o, 0, 0, h, w);
evas_object_resize(o, w, h);
evas_object_resize(wd->o_event, w, h);
}
static void
_e_wid_value_set(Evas_Object *o, double vx)
{
E_Widget_Data *wd;
wd = e_widget_data_get(o);
switch(wd->mode)
{
case E_COLOR_COMPONENT_R:
wd->color->r = 255 * vx;
e_color_update_rgb(wd->color);
break;
case E_COLOR_COMPONENT_G:
wd->color->g = 255 * vx;
e_color_update_rgb(wd->color);
break;
case E_COLOR_COMPONENT_B:
wd->color->b = 255 * vx;
e_color_update_rgb(wd->color);
break;
case E_COLOR_COMPONENT_H:
wd->color->h = 360 * vx;
e_color_update_hsv(wd->color);
break;
case E_COLOR_COMPONENT_S:
wd->color->s = vx;
e_color_update_hsv(wd->color);
break;
case E_COLOR_COMPONENT_V:
wd->color->v = vx;
e_color_update_hsv(wd->color);
break;
}
_e_wid_update(wd);
e_widget_change(o);
}
void
e_widget_cslider_color_value_set(Evas_Object *obj, E_Color *val)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
wd->color = val;
_e_wid_update(wd);
}
void
e_widget_cslider_update(Evas_Object *obj)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
_e_wid_update(wd);
}
void
e_widget_cslider_mode_set(Evas_Object *obj, E_Color_Component mode)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
if (wd->mode == mode) return;
wd->mode = mode;
_e_wid_update(wd);
}
static void
_e_wid_update(E_Widget_Data *wd)
{
if (wd->fixed)
_e_wid_update_fixed(wd);
else
_e_wid_update_standard(wd);
}
static void
_e_wid_update_standard(E_Widget_Data *wd)
{
int r, g, b;
float h, s, v;
int max, min;
float vx;
if (!wd->color) return;
evas_object_gradient_colors_clear(wd->o_grad);
switch(wd->mode)
{
case E_COLOR_COMPONENT_R:
evas_object_gradient_color_add(wd->o_grad, 0, wd->color->g, wd->color->b, 255, 1);
evas_object_gradient_color_add(wd->o_grad, 255, wd->color->g, wd->color->b, 255, 1);
vx = wd->color->r / 255.0;
break;
case E_COLOR_COMPONENT_G:
evas_object_gradient_color_add(wd->o_grad, wd->color->r, 0, wd->color->b, 255, 1);
evas_object_gradient_color_add(wd->o_grad, wd->color->r, 255, wd->color->b, 255, 1);
vx = wd->color->g / 255.0;
break;
case E_COLOR_COMPONENT_B:
evas_object_gradient_color_add(wd->o_grad, wd->color->r, wd->color->g, 0, 255, 1);
evas_object_gradient_color_add(wd->o_grad, wd->color->r, wd->color->g, 255, 255, 1);
vx = wd->color->b / 255.0;
break;
case E_COLOR_COMPONENT_H:
evas_color_hsv_to_rgb(0, wd->color->s, wd->color->v, &max, &min, NULL);
evas_object_gradient_color_add(wd->o_grad, max, min, min, 255, 1);
evas_object_gradient_color_add(wd->o_grad, max, max, min, 255, 1);
evas_object_gradient_color_add(wd->o_grad, min, max, min, 255, 1);
evas_object_gradient_color_add(wd->o_grad, min, max, max, 255, 1);
evas_object_gradient_color_add(wd->o_grad, min, min, max, 255, 1);
evas_object_gradient_color_add(wd->o_grad, max, min, max, 255, 1);
evas_object_gradient_color_add(wd->o_grad, max, min, min, 255, 1);
vx = wd->color->h / 360.0;
break;
case E_COLOR_COMPONENT_S:
evas_color_hsv_to_rgb(wd->color->h, 0, wd->color->v, &r, &g, &b);
evas_object_gradient_color_add(wd->o_grad, r, g, b, 255, 1);
evas_color_hsv_to_rgb(wd->color->h, 1, wd->color->v, &r, &g, &b);
evas_object_gradient_color_add(wd->o_grad, r, g, b, 255, 1);
vx = wd->color->s;
break;
case E_COLOR_COMPONENT_V:
evas_color_hsv_to_rgb(wd->color->h, wd->color->s, 0, &r, &g, &b);
evas_object_gradient_color_add(wd->o_grad, r, g, b, 255, 1);
evas_color_hsv_to_rgb(wd->color->h, wd->color->s, 1, &r, &g, &b);
evas_object_gradient_color_add(wd->o_grad, r, g, b, 255, 1);
vx = wd->color->v;
break;
}
edje_object_part_drag_value_set(wd->o_cslider, "cursor", vx, vx);
}
void
_e_wid_update_fixed(E_Widget_Data *wd)
{
int r, g, b;
int max, min;
float vx;
if (!wd) return;
evas_object_gradient_colors_clear(wd->o_grad);
switch(wd->mode)
{
case E_COLOR_COMPONENT_R:
evas_object_gradient_color_add(wd->o_grad, 255, 0, 0, 255, 1);
evas_object_gradient_color_add(wd->o_grad, 0, 0, 0, 255, 1);
vx = wd->color->r / 255.0;
break;
case E_COLOR_COMPONENT_G:
evas_object_gradient_color_add(wd->o_grad, 0, 255, 0, 255, 1);
evas_object_gradient_color_add(wd->o_grad, 0, 0, 0, 255, 1);
vx = wd->color->g / 255.0;
break;
case E_COLOR_COMPONENT_B:
evas_object_gradient_color_add(wd->o_grad, 0, 0, 255, 255, 1);
evas_object_gradient_color_add(wd->o_grad, 0, 0, 0, 255, 1);
vx = wd->color->b / 255.0;
break;
case E_COLOR_COMPONENT_H:
/*
* Color Stops:
* 0 x n n
* 60 x x n
* 120 n x n
* 180 n x x
* 240 n n x
* 300 x n x
* 360 x n n
*/
min = 0;
max = 255;
evas_object_gradient_color_add(wd->o_grad, max, min, min, 255, 1);
evas_object_gradient_color_add(wd->o_grad, max, min, max, 255, 1);
evas_object_gradient_color_add(wd->o_grad, min, min, max, 255, 1);
evas_object_gradient_color_add(wd->o_grad, min, max, max, 255, 1);
evas_object_gradient_color_add(wd->o_grad, min, max, min, 255, 1);
evas_object_gradient_color_add(wd->o_grad, max, max, min, 255, 1);
evas_object_gradient_color_add(wd->o_grad, max, min, min, 255, 1);
vx = wd->color->h / 360.0;
break;
case E_COLOR_COMPONENT_S:
evas_object_gradient_color_add(wd->o_grad, 255, 255, 255, 255, 1);
evas_object_gradient_color_add(wd->o_grad, 0, 0, 0, 255, 1);
vx = wd->color->s;
break;
case E_COLOR_COMPONENT_V:
evas_object_gradient_color_add(wd->o_grad, 255, 255, 255, 255, 1);
evas_object_gradient_color_add(wd->o_grad, 0, 0, 0, 255, 1);
vx = wd->color->v;
break;
}
edje_object_part_drag_value_set(wd->o_cslider, "cursor", vx, vx);
}
static void
_e_wid_del_hook(Evas_Object *obj)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
free(wd);
}
static void
_e_wid_focus_hook(Evas_Object *obj)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
if (e_widget_focus_get(obj))
{
edje_object_signal_emit(wd->o_cslider, "focus_in", "");
evas_object_focus_set(wd->o_cslider, 1);
}
else
{
edje_object_signal_emit(wd->o_cslider, "focus_out", "");
evas_object_focus_set(wd->o_cslider, 0);
}
}
static void
_e_wid_activate_hook(Evas_Object *obj)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
}
static void
_e_wid_disable_hook(Evas_Object *obj)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
if (e_widget_disabled_get(obj))
edje_object_signal_emit(wd->o_cslider, "disabled", "");
else
edje_object_signal_emit(wd->o_cslider, "enabled", "");
}
static void
_e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
e_widget_focus_steal(data);
}
static void
_e_wid_cb_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Down *ev;
Evas_Object *o_wid;
E_Widget_Data *wd;
Evas_Coord ox, oy, ow, oh;
double val;
ev = event_info;
o_wid = data;
wd = e_widget_data_get(o_wid);
wd->dragging = 1;
evas_object_geometry_get(wd->o_grad, &ox, &oy, &ow, &oh);
if (wd->vertical)
val = 1 - ((ev->canvas.y - oy) / (double)oh);
else
val = (ev->canvas.x - ox) / (double)ow;
if (val > 1) val = 1;
if (val < 0) val = 0;
_e_wid_value_set(o_wid, val);
}
static void
_e_wid_cb_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Object *o_wid;
E_Widget_Data *wd;
o_wid = data;
wd = e_widget_data_get(o_wid);
wd->dragging = 0;
}
static void
_e_wid_cb_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Move *ev;
Evas_Object *o_wid;
E_Widget_Data *wd;
o_wid = data;
wd = e_widget_data_get(o_wid);
ev = event_info;
if (wd->dragging == 1)
{
Evas_Coord ox, oy, ow, oh;
double val;
evas_object_geometry_get(wd->o_grad, &ox, &oy, &ow, &oh);
if (wd->vertical)
val = 1 - ((ev->cur.canvas.y - oy) / (double)oh);
else
val = (ev->cur.canvas.x - ox) / (double)ow;
if (val > 1) val = 1;
if (val < 0) val = 0;
_e_wid_value_set(o_wid, val);
}
}

@ -0,0 +1,7 @@
#ifndef E_WIDGET_CSLIDER_H
#define E_WIDGET_CSLIDER_H
Evas_Object * e_widget_cslider_add(Evas *e, E_Color_Component mode, E_Color *color, int vertical, int fixed);
void e_widget_cslider_color_value_set(Evas_Object *obj, E_Color *ec);
void e_widget_cslider_update(Evas_Object *obj);
void e_widget_cslider_mode_set(Evas_Object *obj, E_Color_Component mode);
#endif

313