Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_colorpicker.c ewl_colorpicker.h ewl_spectrum.c ewl_spectrum.h Log Message: - move the color selection into the spectrum instead of having it in the colorpicker. - a bit of cleanup =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_colorpicker.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- ewl_colorpicker.c 27 Sep 2005 05:38:32 -0000 1.7 +++ ewl_colorpicker.c 28 Sep 2005 02:10:09 -0000 1.8 @@ -7,7 +7,8 @@ * @return Returns NULL on failure, otherwise a newly allocated color picker. * @brief Allocate and initialize a new color picker widget. */ -Ewl_Widget *ewl_colorpicker_new() +Ewl_Widget * +ewl_colorpicker_new() { Ewl_ColorPicker *cp; @@ -28,7 +29,8 @@ * @return Returns TRUE on success, FALSE on failure. * @brief Initialize a color picker to starting values. */ -int ewl_colorpicker_init(Ewl_ColorPicker *cp) +int +ewl_colorpicker_init(Ewl_ColorPicker *cp) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("cp", cp, 0); @@ -48,12 +50,8 @@ ewl_spectrum_mode_set(EWL_SPECTRUM(cp->range), EWL_COLOR_PICK_MODE_HSV_HUE); ewl_spectrum_dimensions_set(EWL_SPECTRUM(cp->range), 1); - ewl_callback_append(cp->range, EWL_CALLBACK_MOUSE_DOWN, - ewl_colorpicker_range_down_cb, cp); - ewl_callback_append(cp->range, EWL_CALLBACK_MOUSE_UP, - ewl_colorpicker_range_up_cb, cp); - ewl_callback_append(cp->range, EWL_CALLBACK_MOUSE_MOVE, - ewl_colorpicker_range_move_cb, cp); + ewl_callback_append(cp->range, EWL_CALLBACK_VALUE_CHANGED, + ewl_colorpicker_range_change_cb, cp); ewl_object_minimum_size_set(EWL_OBJECT(cp->range), 20, 100); ewl_object_maximum_size_set(EWL_OBJECT(cp->range), 20, EWL_OBJECT_MAX_SIZE); ewl_object_fill_policy_set(EWL_OBJECT(cp->range), EWL_FLAG_FILL_ALL); @@ -65,12 +63,8 @@ * color. */ cp->spectrum = ewl_spectrum_new(); - ewl_callback_append(cp->spectrum, EWL_CALLBACK_MOUSE_DOWN, - ewl_colorpicker_spectrum_down_cb, cp); - ewl_callback_append(cp->spectrum, EWL_CALLBACK_MOUSE_UP, - ewl_colorpicker_spectrum_up_cb, cp); - ewl_callback_append(cp->spectrum, EWL_CALLBACK_MOUSE_MOVE, - ewl_colorpicker_spectrum_move_cb, cp); + ewl_callback_append(cp->spectrum, EWL_CALLBACK_VALUE_CHANGED, + ewl_colorpicker_spectrum_change_cb, cp); ewl_spectrum_mode_set(EWL_SPECTRUM(cp->spectrum), EWL_COLOR_PICK_MODE_RGB); ewl_object_minimum_size_set(EWL_OBJECT(cp->spectrum), 100, 100); ewl_object_fill_policy_set(EWL_OBJECT(cp->spectrum), EWL_FLAG_FILL_ALL); @@ -80,131 +74,54 @@ DRETURN_INT(TRUE, DLEVEL_STABLE); } -void ewl_colorpicker_color_set(Ewl_ColorPicker *cp, int r, int g, int b) +void +ewl_colorpicker_color_set(Ewl_ColorPicker *cp, int r, int g, int b) { - cp->selected.r = r; - cp->selected.g = g; - cp->selected.b = b; - - ewl_callback_call_with_event_data(EWL_WIDGET(cp), EWL_CALLBACK_VALUE_CHANGED, &cp->selected); + ewl_spectrum_rgba_set(EWL_SPECTRUM(cp->spectrum), r, g, b, 255); } -void ewl_colorpicker_hue_set(Ewl_ColorPicker *cp, float h) +void +ewl_colorpicker_hue_set(Ewl_ColorPicker *cp, float h) { - if(h != 0) - { - int ref_r, ref_g, ref_b; - ewl_spectrum_hsv_to_rgb(h, 1, 1, &ref_r, &ref_g, &ref_b); - ewl_spectrum_rgb_set(EWL_SPECTRUM(cp->spectrum), ref_r, ref_g, ref_b); - } + ewl_spectrum_hsv_set(EWL_SPECTRUM(cp->spectrum), h, 1, 1); } -void ewl_colorpicker_range_move_cb(Ewl_Widget *w, void *ev_data, void *user_data) +void +ewl_colorpicker_range_change_cb(Ewl_Widget *w, void *ev, void *data) { - Ewl_ColorPicker *cp = user_data; - Ewl_Event_Mouse_Move *ev = ev_data; + Ewl_ColorPicker *cp; + Ewl_Spectrum *sp; + int r, g, b, a; DENTER_FUNCTION(DLEVEL_STABLE); - if (cp->drag && - ev->x > w->object.current.x && ev->x < w->object.current.x + w->object.current.w && - ev->y > w->object.current.y && ev->y < w->object.current.y + w->object.current.h) - { - int x = ev->x - w->object.current.x; - int y = ev->y - w->object.current.y; - ewl_spectrum_color_coord_map(EWL_SPECTRUM(w), x, y, - &cp->selected.r, &cp->selected.g, - &cp->selected.b, &cp->selected.a); - ewl_spectrum_rgb_set(EWL_SPECTRUM(cp->spectrum), cp->selected.r, - cp->selected.g, cp->selected.b); - ewl_colorpicker_color_set(cp, cp->selected.r, cp->selected.g, - cp->selected.b); - } - - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -void ewl_colorpicker_range_down_cb(Ewl_Widget *w, void *ev_data, void *user_data) -{ - Ewl_ColorPicker *cp = user_data; - Ewl_Event_Mouse_Down *ev = ev_data; - - DENTER_FUNCTION(DLEVEL_STABLE); + cp = data; + sp = EWL_SPECTRUM(w); - cp->drag = 1; + ewl_spectrum_selected_rgba_get(sp, &r, &g, &b, &a); + ewl_spectrum_rgba_set(EWL_SPECTRUM(cp->spectrum), r, g, b, a); - int x = ev->x - w->object.current.x; - int y = ev->y - w->object.current.y; - ewl_spectrum_color_coord_map(EWL_SPECTRUM(w), x, y, &cp->selected.r, - &cp->selected.g, &cp->selected.b, &cp->selected.a); - ewl_spectrum_rgb_set(EWL_SPECTRUM(cp->spectrum), cp->selected.r, - cp->selected.g, cp->selected.b); - ewl_colorpicker_color_set(cp, cp->selected.r, cp->selected.g, cp->selected.b); + ewl_callback_call_with_event_data(EWL_WIDGET(cp), + EWL_CALLBACK_VALUE_CHANGED, &(sp->rgba)); DLEAVE_FUNCTION(DLEVEL_STABLE); } -void ewl_colorpicker_range_up_cb(Ewl_Widget *w __UNUSED__, - void *ev_data __UNUSED__, void *user_data) +void +ewl_colorpicker_spectrum_change_cb(Ewl_Widget *w, void *ev, void *data) { - Ewl_ColorPicker *cp = user_data; - - DENTER_FUNCTION(DLEVEL_STABLE); - - cp->drag = 0; - - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -void ewl_colorpicker_spectrum_move_cb(Ewl_Widget *w, void *ev_data, void *user_data) -{ - Ewl_ColorPicker *cp = user_data; - Ewl_Event_Mouse_Move *ev = ev_data; + Ewl_ColorPicker *cp; + Ewl_Spectrum *sp; DENTER_FUNCTION(DLEVEL_STABLE); - if (cp->drag && - ev->x > w->object.current.x && ev->x < w->object.current.x + w->object.current.w && - ev->y > w->object.current.y && ev->y < w->object.current.y + w->object.current.h) - { - int x = ev->x - w->object.current.x; - int y = ev->y - w->object.current.y; - ewl_spectrum_color_coord_map(EWL_SPECTRUM(w), x, y, - &cp->selected.r, &cp->selected.g, - &cp->selected.b, &cp->selected.a); - ewl_colorpicker_color_set(cp, cp->selected.r, cp->selected.g, cp->selected.b); - } + cp = data; + sp = EWL_SPECTRUM(w); - DLEAVE_FUNCTION(DLEVEL_STABLE); -} - -void ewl_colorpicker_spectrum_down_cb(Ewl_Widget *w, void *ev_data, void *user_data) -{ - Ewl_ColorPicker *cp = user_data; - Ewl_Event_Mouse_Down *ev = ev_data; - - DENTER_FUNCTION(DLEVEL_STABLE); - - cp->drag = 1; - - int x = ev->x - w->object.current.x; - int y = ev->y - w->object.current.y; - ewl_spectrum_color_coord_map(EWL_SPECTRUM(w), x, y, &cp->selected.r, - &cp->selected.g, &cp->selected.b, - &cp->selected.a); - ewl_colorpicker_color_set(cp, cp->selected.r, cp->selected.g, cp->selected.b); + ewl_callback_call_with_event_data(EWL_WIDGET(cp), + EWL_CALLBACK_VALUE_CHANGED, &(sp->selected_rgba)); DLEAVE_FUNCTION(DLEVEL_STABLE); } -void ewl_colorpicker_spectrum_up_cb(Ewl_Widget *w __UNUSED__, - void *ev_data __UNUSED__, void *user_data) -{ - Ewl_ColorPicker *cp = user_data; - - DENTER_FUNCTION(DLEVEL_STABLE); - - cp->drag = 0; - DLEAVE_FUNCTION(DLEVEL_STABLE); -} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_colorpicker.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- ewl_colorpicker.h 20 Jun 2005 20:35:03 -0000 1.8 +++ ewl_colorpicker.h 28 Sep 2005 02:10:09 -0000 1.9 @@ -21,24 +21,18 @@ Ewl_Box box; Ewl_Widget *spectrum; Ewl_Widget *range; - int drag; - Ewl_Color_Set selected; }; Ewl_Widget *ewl_colorpicker_new(); -int ewl_colorpicker_init(Ewl_ColorPicker *cp); -void ewl_colorpicker_color_set(Ewl_ColorPicker *cp, int r, int g, int b); -void ewl_colorpicker_hue_set(Ewl_ColorPicker *cp, float h); +int ewl_colorpicker_init(Ewl_ColorPicker *cp); +void ewl_colorpicker_color_set(Ewl_ColorPicker *cp, int r, int g, int b); +void ewl_colorpicker_hue_set(Ewl_ColorPicker *cp, float h); /* * Internal callbacks, override at your own risk. */ -void ewl_colorpicker_range_down_cb(Ewl_Widget *w, void *ev_data, void *user_data); -void ewl_colorpicker_range_up_cb(Ewl_Widget *w, void *ev_data, void *user_data); -void ewl_colorpicker_range_move_cb(Ewl_Widget *w, void *ev_data, void *user_data); -void ewl_colorpicker_spectrum_down_cb(Ewl_Widget *w, void *ev_data, void *user_data); -void ewl_colorpicker_spectrum_up_cb(Ewl_Widget *w, void *ev_data, void *user_data); -void ewl_colorpicker_spectrum_move_cb(Ewl_Widget *w, void *ev_data, void *user_data); +void ewl_colorpicker_range_change_cb(Ewl_Widget *w, void *ev, void *data); +void ewl_colorpicker_spectrum_change_cb(Ewl_Widget *w, void *ev, void *data); /** * @} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_spectrum.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- ewl_spectrum.c 27 Sep 2005 05:44:36 -0000 1.9 +++ ewl_spectrum.c 28 Sep 2005 02:10:09 -0000 1.10 @@ -41,7 +41,7 @@ * @brief Initializes the given spectrum widget */ int -ewl_spectrum_init(Ewl_Spectrum * sp) +ewl_spectrum_init(Ewl_Spectrum *sp) { Ewl_Widget *w; @@ -71,6 +71,13 @@ sp->hsv.s = 0.0; sp->hsv.v = 1.0; + ewl_callback_append(w, EWL_CALLBACK_MOUSE_DOWN, + ewl_spectrum_mouse_down_cb, NULL); + ewl_callback_append(w, EWL_CALLBACK_MOUSE_UP, + ewl_spectrum_mouse_up_cb, NULL); + ewl_callback_append(w, EWL_CALLBACK_MOUSE_MOVE, + ewl_spectrum_mouse_move_cb, NULL); + DRETURN_INT(TRUE, DLEVEL_STABLE); } @@ -120,7 +127,7 @@ * @brief Sets to the mode of the spectrum to the given value. */ void -ewl_spectrum_mode_set(Ewl_Spectrum * sp, Ewl_Color_Pick_Mode mode) +ewl_spectrum_mode_set(Ewl_Spectrum *sp, Ewl_Color_Pick_Mode mode) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); @@ -191,7 +198,7 @@ * @return Returns no value. */ void -ewl_spectrum_rgb_set(Ewl_Spectrum * sp, int r, int g, int b, int a) +ewl_spectrum_rgba_set(Ewl_Spectrum *sp, int r, int g, int b, int a) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); @@ -209,12 +216,38 @@ else sp->rgba.a = 0; sp->redraw = 1; + + ewl_spectrum_rgb_to_hsv(r, g, b, &(sp->hsv.h), + &(sp->hsv.s), &(sp->hsv.v)); + ewl_widget_configure(EWL_WIDGET(sp)); DRETURN(DLEVEL_STABLE); } /** + * @param sp: The spectrum to get the values from + * @param r: Where to store the red value + * @param g: Where to store the green value + * @param b: Where to store the blue value + * @param a: Where to store the alpha value + * @return Returns no value. + */ +void +ewl_spectrum_rgba_get(Ewl_Spectrum *sp, int *r, int *g, int *b, int *a) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("sp", sp); + + if (r) *r = sp->rgba.r; + if (g) *g = sp->rgba.g; + if (b) *b = sp->rgba.b; + if (a) *a = sp->rgba.a; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param sp: The spectrum to work on * @param h: The hue value to set * @param s: The saturation value to set @@ -222,7 +255,7 @@ * @return Returns no value */ void -ewl_spectrum_hsv_set(Ewl_Spectrum * sp, float h, float s, float v) +ewl_spectrum_hsv_set(Ewl_Spectrum *sp, float h, float s, float v) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); @@ -237,12 +270,50 @@ else sp->hsv.v = 0; sp->redraw = 1; + + ewl_spectrum_hsv_to_rgb(h, s, v, &(sp->rgba.r), + &(sp->rgba.g), &(sp->rgba.b)); + ewl_widget_configure(EWL_WIDGET(sp)); DRETURN(DLEVEL_STABLE); } /** + * @param sp: The spectrum to get the values from + * @param h: Where to store the hue + * @param s: Where to store the saturation + * @param v: Where to store the value + * @return Returns no value. + */ +void +ewl_spectrum_hsv_get(Ewl_Spectrum *sp, float *h, float *s, float *v) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("sp", sp); + + if (h) *h = sp->hsv.h; + if (s) *s = sp->hsv.s; + if (v) *v = sp->hsv.v; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_spectrum_selected_rgba_get(Ewl_Spectrum *sp, int *r, int *g, int *b, int *a) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("sp", sp); + + if (r) *r = sp->selected_rgba.r; + if (g) *g = sp->selected_rgba.g; + if (b) *b = sp->selected_rgba.b; + if (a) *a = sp->selected_rgba.a; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param sp: The spectrum to get the colour from * @param x: The x coord to get the color from * @param y: The y coord to get the color from @@ -301,37 +372,37 @@ q = (int) (255.0 * (value - vsf)); t = (int) (255.0 * (value - vs + vsf)); switch (h) { - case 0: - r = i; - g = t; - b = p; - break; - case 1: - r = q; - g = i; - b = p; - break; - case 2: - r = p; - g = i; - b = t; - break; - case 3: - r = p; - g = q; - b = i; - break; - case 4: - r = t; - g = p; - b = i; - break; - case 5: - default: - r = i; - g = p; - b = q; - break; + case 0: + r = i; + g = t; + b = p; + break; + case 1: + r = q; + g = i; + b = p; + break; + case 2: + r = p; + g = i; + b = t; + break; + case 3: + r = p; + g = q; + b = i; + break; + case 4: + r = t; + g = p; + b = i; + break; + case 5: + default: + r = i; + g = p; + b = q; + break; } } @@ -375,14 +446,14 @@ if (delta == 0) *h = 0; else if (r == max) - *h = (float)( g - b ) / (float)delta; // between yellow & magenta + *h = (float)(g - b) / (float)delta; // between yellow & magenta else if (g == max) - *h = 2.0 + (float)( b - r ) / (float)delta; // between cyan & yellow + *h = 2.0 + (float)(b - r) / (float)delta; // between cyan & yellow else - *h = 4.0 + (float)( r - g ) / (float)delta; // between magenta & cyan + *h = 4.0 + (float)(r - g) / (float)delta; // between magenta & cyan *h *= 60; // degrees - if( *h < 0 ) *h += 360; + if (*h < 0) *h += 360; DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -446,6 +517,75 @@ DLEAVE_FUNCTION(DLEVEL_STABLE); } +void +ewl_spectrum_mouse_move_cb(Ewl_Widget *w, void *ev_data, void *user_data) +{ + Ewl_Spectrum *sp; + Ewl_Event_Mouse_Move *ev; + + DENTER_FUNCTION(DLEVEL_STABLE); + + sp = EWL_SPECTRUM(w); + ev = ev_data; + if ((sp->drag) && (ev->x > CURRENT_X(w)) + && (ev->x < CURRENT_X(w) + CURRENT_W(w)) + && (ev->y > CURRENT_Y(w)) + && (ev->y < CURRENT_Y(w) + CURRENT_H(w))) + { + int x, y; + + x = ev->x - CURRENT_X(w); + y = ev->y - CURRENT_Y(w); + + ewl_spectrum_color_coord_map(EWL_SPECTRUM(w), x, y, + &(sp->selected_rgba.r), &(sp->selected_rgba.g), + &(sp->selected_rgba.b), &(sp->selected_rgba.a)); + + ewl_callback_call(w, EWL_CALLBACK_VALUE_CHANGED); + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_spectrum_mouse_down_cb(Ewl_Widget *w, void *ev_data, void *user_data) +{ + Ewl_Spectrum *sp; + Ewl_Event_Mouse_Down *ev; + int x, y; + + DENTER_FUNCTION(DLEVEL_STABLE); + + sp = EWL_SPECTRUM(w); + ev = ev_data; + sp->drag = 1; + + x = ev->x - CURRENT_X(w); + y = ev->y - CURRENT_Y(w); + + ewl_spectrum_color_coord_map(EWL_SPECTRUM(w), x, y, + &(sp->selected_rgba.r), &(sp->selected_rgba.g), + &(sp->selected_rgba.b), &(sp->selected_rgba.a)); + + ewl_callback_call(w, EWL_CALLBACK_VALUE_CHANGED); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void +ewl_spectrum_mouse_up_cb(Ewl_Widget *w, void *ev_data __UNUSED__, + void *user_data __UNUSED__) +{ + Ewl_Spectrum *sp; + + DENTER_FUNCTION(DLEVEL_STABLE); + + sp = EWL_SPECTRUM(w); + sp->drag = 0; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + static void ewl_spectrum_color_coord_map2d(Ewl_Spectrum *sp, int x, int y, int *r, int *g, int *b, int *a) @@ -520,7 +660,6 @@ height = CURRENT_H(sp); - /* draw the spectrum */ if (a) *a = 255; if (sp->mode == EWL_COLOR_PICK_MODE_RGB) =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_spectrum.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- ewl_spectrum.h 27 Sep 2005 05:38:32 -0000 1.6 +++ ewl_spectrum.h 28 Sep 2005 02:10:09 -0000 1.7 @@ -34,13 +34,16 @@ Ewl_Orientation orientation; Ewl_Color_Pick_Mode mode; unsigned int dimensions; - int redraw; + int redraw:1; + int drag:1; Ewl_Color_Set rgba; struct { - float h, s, v; + float h, s, v; } hsv; + + Ewl_Color_Set selected_rgba; }; Ewl_Widget *ewl_spectrum_new(void); @@ -61,6 +64,9 @@ void ewl_spectrum_hsv_set(Ewl_Spectrum *sp, float h, float s, float v); void ewl_spectrum_hsv_get(Ewl_Spectrum *sp, float *h, float *s, float *v); +void ewl_spectrum_selected_rgba_get(Ewl_Spectrum *sp, + int *r, int *g, int *b, int *a); + void ewl_spectrum_color_coord_map(Ewl_Spectrum *sp, int x, int y, int *r, int *g, int *b, int *a); @@ -73,6 +79,9 @@ * Internally used callbacks, override at your own risk. */ void ewl_spectrum_configure_cb(Ewl_Widget * w, void *ev_data, void *user_data); +void ewl_spectrum_mouse_down_cb(Ewl_Widget *w, void *ev_data, void *user_data); +void ewl_spectrum_mouse_up_cb(Ewl_Widget *w, void *ev_data, void *user_data); +void ewl_spectrum_mouse_move_cb(Ewl_Widget *w, void *ev_data, void *user_data); /** * @} ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs