Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_colorpicker.c ewl_enums.h ewl_spectrum.c ewl_spectrum.h Log Message: - fix namespacing of Ewl_Pick_Mode - first pass cleanup of Ewl_Spectrum =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_colorpicker.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- ewl_colorpicker.c 5 Sep 2005 14:12:15 -0000 1.6 +++ ewl_colorpicker.c 27 Sep 2005 05:38:32 -0000 1.7 @@ -46,7 +46,7 @@ */ cp->range = ewl_spectrum_new(); ewl_spectrum_mode_set(EWL_SPECTRUM(cp->range), - EWL_PICK_MODE_HSV_HUE); + 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); @@ -71,7 +71,7 @@ ewl_colorpicker_spectrum_up_cb, cp); ewl_callback_append(cp->spectrum, EWL_CALLBACK_MOUSE_MOVE, ewl_colorpicker_spectrum_move_cb, cp); - ewl_spectrum_mode_set(EWL_SPECTRUM(cp->spectrum), EWL_PICK_MODE_RGB); + 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); ewl_container_child_append(EWL_CONTAINER(cp), cp->spectrum); =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_enums.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- ewl_enums.h 27 Sep 2005 04:20:16 -0000 1.10 +++ ewl_enums.h 27 Sep 2005 05:38:32 -0000 1.11 @@ -273,7 +273,7 @@ /** * @enum Ewl_Response_Type */ -enum _Ewl_Response_Type +enum Ewl_Response_Type { EWL_RESPONSE_OPEN = -5, EWL_RESPONSE_SAVE = -6, @@ -288,20 +288,22 @@ EWL_RESPONSE_HOME = -25, }; -typedef enum _Ewl_Response_Type Ewl_Response_Type; +typedef enum Ewl_Response_Type Ewl_Response_Type; /** - * @enum Ewl_Pick_Mode + * @enum Ewl_Color_Pick_Mode */ -enum Ewl_Pick_Mode { - EWL_PICK_MODE_RGB, - EWL_PICK_MODE_HSV_HUE, - EWL_PICK_MODE_HSV_SATURATION, - EWL_PICK_MODE_HSV_VALUE +enum Ewl_Color_Pick_Mode +{ + EWL_COLOR_PICK_MODE_RGB, + EWL_COLOR_PICK_MODE_HSV_HUE, + EWL_COLOR_PICK_MODE_HSV_SATURATION, + EWL_COLOR_PICK_MODE_HSV_VALUE }; -typedef enum Ewl_Pick_Mode Ewl_Pick_Mode; +typedef enum Ewl_Color_Pick_Mode Ewl_Color_Pick_Mode; -enum Ewl_Text_Style { +enum Ewl_Text_Style +{ EWL_TEXT_STYLE_NONE = 0x00, EWL_TEXT_STYLE_UNDERLINE = 0x01, EWL_TEXT_STYLE_DOUBLE_UNDERLINE = 0x02, @@ -314,19 +316,22 @@ }; typedef enum Ewl_Text_Style Ewl_Text_Style; -enum Ewl_Text_Trigger_Type { +enum Ewl_Text_Trigger_Type +{ EWL_TEXT_TRIGGER_TYPE_NONE, EWL_TEXT_TRIGGER_TYPE_SELECTION, EWL_TEXT_TRIGGER_TYPE_TRIGGER }; typedef enum Ewl_Text_Trigger_Type Ewl_Text_Trigger_Type; -enum Ewl_Attach_Type { +enum Ewl_Attach_Type +{ EWL_ATTACH_TYPE_TOOLTIP }; typedef enum Ewl_Attach_Type Ewl_Attach_Type; -enum Ewl_Attach_Data_Type { +enum Ewl_Attach_Data_Type +{ EWL_ATTACH_DATA_TYPE_TEXT, EWL_ATTACH_DATA_TYPE_WIDGET }; =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_spectrum.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- ewl_spectrum.c 5 Sep 2005 14:12:15 -0000 1.7 +++ ewl_spectrum.c 27 Sep 2005 05:38:32 -0000 1.8 @@ -13,16 +13,24 @@ * * Returns a newly allocated color picker widget on success, NULL on failure. */ -Ewl_Widget *ewl_spectrum_new() +Ewl_Widget * +ewl_spectrum_new(void) { Ewl_Spectrum *sp = NULL; DENTER_FUNCTION(DLEVEL_STABLE); + sp = NEW(Ewl_Spectrum, 1); if (!sp) + { DRETURN_PTR(NULL, DLEVEL_STABLE); + } - ewl_spectrum_init(sp); + if (!ewl_spectrum_init(sp)) + { + ewl_widget_destroy(EWL_WIDGET(sp)); + sp = NULL; + } DRETURN_PTR(EWL_WIDGET(sp), DLEVEL_STABLE); } @@ -32,12 +40,13 @@ * @return Returns no value. * @brief Initializes the given spectrum widget */ -void ewl_spectrum_init(Ewl_Spectrum * sp) +int +ewl_spectrum_init(Ewl_Spectrum * sp) { Ewl_Widget *w; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("sp", sp); + DCHECK_PARAM_PTR_RET("sp", sp, FALSE); w = EWL_WIDGET(sp); @@ -49,17 +58,20 @@ ewl_spectrum_configure_cb, NULL); sp->orientation = EWL_ORIENTATION_VERTICAL; - sp->mode = EWL_PICK_MODE_HSV_HUE; + sp->mode = EWL_COLOR_PICK_MODE_HSV_HUE; sp->dimensions = 2; sp->redraw = 1; - sp->r = 255; - sp->g = 255; - sp->b = 255; - sp->h = 0.0; - sp->s = 0.0; - sp->v = 1.0; - DRETURN(DLEVEL_STABLE); + sp->rgba.r = 255; + sp->rgba.g = 255; + sp->rgba.b = 255; + sp->rgba.a = 255; + + sp->hsv.h = 0.0; + sp->hsv.s = 0.0; + sp->hsv.v = 1.0; + + DRETURN_INT(TRUE, DLEVEL_STABLE); } /** @@ -69,14 +81,17 @@ * @brief Sets the orientation on the spectrum to the given value either * EWL_ORIENTATION_HORIZONTAL or EWL_ORIENTATION_VERTICAL. */ -void ewl_spectrum_orientation_set(Ewl_Spectrum *sp, int o) +void +ewl_spectrum_orientation_set(Ewl_Spectrum *sp, Ewl_Orientation o) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); - if (sp->orientation != o) { + if (sp->orientation != o) + { sp->orientation = o; - if (sp->dimensions == 1) { + if (sp->dimensions == 1) + { sp->redraw = 1; ewl_widget_configure(EWL_WIDGET(sp)); } @@ -86,17 +101,32 @@ } /** + * @param sp: The spectrum to get the orientation from + * @return Returns the orientation of the spectrum + */ +Ewl_Orientation +ewl_spectrum_orientation_get(Ewl_Spectrum *sp) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("sp", sp, EWL_ORIENTATION_HORIZONTAL); + + DRETURN_INT(sp->orientation, DLEVEL_STABLE); +} + +/** * @param sp: The spectrum to set the mode on * @param mode: The mode to set * @return Returns no value. * @brief Sets to the mode of the spectrum to the given value. */ -void ewl_spectrum_mode_set(Ewl_Spectrum * sp, Ewl_Pick_Mode mode) +void +ewl_spectrum_mode_set(Ewl_Spectrum * sp, Ewl_Color_Pick_Mode mode) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); - if (sp->mode != mode) { + if (sp->mode != mode) + { sp->mode = mode; sp->redraw = 1; ewl_widget_configure(EWL_WIDGET(sp)); @@ -106,19 +136,32 @@ } /** + * @param sp: The spectrum to get the pick mode from + * @return Returns the Ewl_Color_Pick_Mode set on the spectrum + */ +Ewl_Color_Pick_Mode +ewl_spectrum_mode_get(Ewl_Spectrum *sp) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("sp", sp, EWL_COLOR_PICK_MODE_RGB); + + DRETURN_INT(sp->mode, DLEVEL_STABLE); +} + +/** * @param sp: The spectrum to set the dimension on * @param dimensions: The number of dimensions, 1 or 2 * @return Returns no value. * @brief Sets the number of dimensions the spectrum has. */ void -ewl_spectrum_dimensions_set(Ewl_Spectrum * sp, - int dimensions) +ewl_spectrum_dimensions_set(Ewl_Spectrum *sp, unsigned int dimensions) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); - if (dimensions == 1 || dimensions == 2) { + if ((dimensions == 1) || (dimensions == 2)) + { sp->dimensions = dimensions; sp->redraw = 1; ewl_widget_configure(EWL_WIDGET(sp)); @@ -128,6 +171,19 @@ } /** + * @param sp: The spectrum to get the dimension from + * @return Returns the dimension of the spectrum + */ +unsigned int +ewl_spectrum_dimensions_get(Ewl_Spectrum *sp) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("sp", sp, 1); + + DRETURN_INT(sp->dimensions, DLEVEL_STABLE); +} + +/** * @param sp: The spectrum to set the r, g, b values of * @param r: The red value to set * @param g: The green value to set @@ -135,18 +191,22 @@ * @return Returns no value. */ void -ewl_spectrum_rgb_set(Ewl_Spectrum * sp, int r, int g, - int b) +ewl_spectrum_rgb_set(Ewl_Spectrum * sp, int r, int g, int b, int a) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("sp", sp); - if (r >= 0 && r < 256) - sp->r = r; - if (g >= 0 && g < 256) - sp->g = g; - if (b >= 0 && b < 256) - sp->b = b; + if ((r >= 0) && (r < 256)) sp->rgba.r = r; + else sp->rgba.r = 0; + + if ((g >= 0) && (g < 256)) sp->rgba.g = g; + else sp->rgba.g = 0; + + if ((b >= 0) && (b < 256)) sp->rgba.b = b; + else sp->rgba.b = 0; + + if ((a >= 0) && (a < 256)) sp->rgba.a = a; + else sp->rgba.a = 0; sp->redraw = 1; ewl_widget_configure(EWL_WIDGET(sp)); @@ -158,25 +218,25 @@ * @param sp: The spectrum to work on * @param h: The hue value to set * @param s: The saturation value to set - * @param v: The ??? value to set + * @param v: The value value to set * @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); - if (h >= 0 && h <= 360) - sp->h = h; - if (s >= 0 && s <= 1) - sp->s = s; - if (v >= 0 && v <= 1) - sp->v = v; + if ((h >= 0) && (h <= 360)) sp->hsv.h = h; + else sp->hsv.h = 0; - sp->redraw = 1; + if ((s >= 0) && (s <= 1)) sp->hsv.s = s; + else sp->hsv.s = 0; + if ((v >= 0) && (v <= 1)) sp->hsv.v = v; + else sp->hsv.v = 0; + + sp->redraw = 1; ewl_widget_configure(EWL_WIDGET(sp)); DRETURN(DLEVEL_STABLE); @@ -221,32 +281,42 @@ Ewl_Spectrum *sp; DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); if (!REALIZED(w)) + { DRETURN(DLEVEL_STABLE); + } sp = EWL_SPECTRUM(w); if (!sp->redraw) + { DRETURN(DLEVEL_STABLE); + } o = EWL_IMAGE(sp)->image; if (!o) - return; + { + DRETURN(DLEVEL_STABLE); + } /* set/get the spectrum size and image data */ evas_object_image_size_set(o, CURRENT_W(sp), CURRENT_H(sp)); evas_object_image_size_get(o, &pw, &ph); data = evas_object_image_data_get(o, 1); if (!data) - return; + { + DRETURN(DLEVEL_STABLE); + } /* draw the spectrum */ - for (j = 0; j < ph; j++) { - for (i = 0; i < pw; i++) { + for (j = 0; j < ph; j++) + { + for (i = 0; i < pw; i++) + { int r, g, b, a; ewl_spectrum_color_coord_map(sp, i, j, &r, &g, &b, &a); - data[(j * pw) + i] = - (a << 24) | (r << 16) | (g << 8) | b; + data[(j * pw) + i] = (a << 24) | (r << 16) | (g << 8) | b; } } @@ -264,12 +334,15 @@ float vs, vsf; int r, g, b; + DENTER_FUNCTION(DLEVEL_STABLE); + i = (int) (value * 255.0); if (saturation == 0) r = g = b = i; - else { - if (hue == 360) - hue = 0; + else + { + if (hue == 360) hue = 0; + hue = hue / 60.0; h = (int) hue; vs = value * saturation; @@ -312,12 +385,11 @@ } } - if (_r) - *_r = r; - if (_g) - *_g = g; - if (_b) - *_b = b; + if (_r) *_r = r; + if (_g) *_g = g; + if (_b) *_b = b; + + DLEAVE_FUNCTION(DLEVEL_STABLE); } void @@ -326,32 +398,34 @@ { int min, max, delta; + DENTER_FUNCTION(DLEVEL_STABLE); + min = MIN(r,MIN(g,b)); max = MAX(r,MAX(g,b)); *v = (float)max / 255.0; // v delta = max - min; - if( max != 0 ) - *s = (float)delta / (float)max; // s - else { + if (max != 0) *s = (float)delta / (float)max; // s + else + { *s = 0; *h = 0; return; } - if(delta == 0) - *h = 0; - else if( r == max ) + if (delta == 0) *h = 0; + else if (r == max) *h = (float)( g - b ) / (float)delta; // between yellow & magenta - else if( g == max ) + else if (g == max) *h = 2.0 + (float)( b - r ) / (float)delta; // between cyan & yellow else *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); } static void @@ -360,18 +434,21 @@ { int width, height; + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("sp", sp); + width = CURRENT_W(sp); height = CURRENT_H(sp); - if (a) - *a = 255; + if (a) *a = 255; - if (sp->mode == EWL_PICK_MODE_RGB) { + if (sp->mode == EWL_COLOR_PICK_MODE_RGB) + { int red, green, blue; - red = sp->r; - green = sp->g; - blue = sp->b; + red = sp->rgba.r; + green = sp->rgba.g; + blue = sp->rgba.b; red = red + (y) * (255 - red) / height; red = red * x / width; @@ -380,33 +457,38 @@ blue = blue + (y) * (255 - blue) / height; blue = blue * x / width; - if (r) - *r = red; - if (g) - *g = green; - if (b) - *b = blue; - } else { + if (r) *r = red; + if (g) *g = green; + if (b) *b = blue; + } + else + { float h, s, v; - h = sp->h; - s = sp->s; - v = sp->v; + h = sp->hsv.h; + s = sp->hsv.s; + v = sp->hsv.v; - if (sp->mode == EWL_PICK_MODE_HSV_HUE) { + if (sp->mode == EWL_COLOR_PICK_MODE_HSV_HUE) + { s = 1 - (float) x / (float) width; v = 1 - (float) y / (float) height; - } else if (sp->mode == EWL_PICK_MODE_HSV_SATURATION) { + } + else if (sp->mode == EWL_COLOR_PICK_MODE_HSV_SATURATION) + { h = (float) x / (float) width *360; v = 1 - (float) y / (float) height; - } else if (sp->mode == EWL_PICK_MODE_HSV_VALUE) { - + } + else if (sp->mode == EWL_COLOR_PICK_MODE_HSV_VALUE) + { h = (float) x / (float) width *360; s = 1 - (float) y / (float) height; } ewl_spectrum_hsv_to_rgb(h, s, v, r, g, b); } + + DLEAVE_FUNCTION(DLEVEL_STABLE); } static void @@ -415,35 +497,42 @@ { int height; + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("sp", sp); + height = CURRENT_H(sp); /* draw the spectrum */ - if (a) - *a = 255; + if (a) *a = 255; - if (sp->mode == EWL_PICK_MODE_RGB) { - if (r) - *r = sp->r * (1 - (float) y / (float) height); - if (g) - *g = sp->g * (1 - (float) y / (float) height); - if (b) - *b = sp->b * (1 - (float) y / (float) height); - } else { + if (sp->mode == EWL_COLOR_PICK_MODE_RGB) + { + if (r) *r = sp->rgba.r * (1 - (float) y / (float) height); + if (g) *g = sp->rgba.g * (1 - (float) y / (float) height); + if (b) *b = sp->rgba.b * (1 - (float) y / (float) height); + } + else + { int h, s, v; - h = sp->h; - s = sp->s; - v = sp->v; - if (sp->mode == EWL_PICK_MODE_HSV_HUE) { + h = sp->hsv.h; + s = sp->hsv.s; + v = sp->hsv.v; + if (sp->mode == EWL_COLOR_PICK_MODE_HSV_HUE) + { h = 360 * (float) y / (float) height; s = 1.0; v = 1.0; - } else if (sp->mode == EWL_PICK_MODE_HSV_SATURATION) { + } + else if (sp->mode == EWL_COLOR_PICK_MODE_HSV_SATURATION) s = 1 - (float) y / (float) height; - } else if (sp->mode == EWL_PICK_MODE_HSV_VALUE) { + + else if (sp->mode == EWL_COLOR_PICK_MODE_HSV_VALUE) v = 1 - (float) y / (float) height; - } ewl_spectrum_hsv_to_rgb(h, s, v, r, g, b); } + + DLEAVE_FUNCTION(DLEVEL_STABLE); } + =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_spectrum.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- ewl_spectrum.h 14 Jun 2005 20:59:44 -0000 1.5 +++ ewl_spectrum.h 27 Sep 2005 05:38:32 -0000 1.6 @@ -13,44 +13,66 @@ * @themekey /spectrum/group */ -typedef struct _ewl_spectrum Ewl_Spectrum; +/** + * @def EWL_SPECTRUM(sp) + * Typecasts a pointer to an Ewl_Spectrum pointer. + */ +#define EWL_SPECTRUM(sp) ((Ewl_Spectrum *)sp) + +/** + * Provides a colour spectrum. + */ +typedef struct Ewl_Spectrum Ewl_Spectrum; -#define EWL_SPECTRUM(cp) ((Ewl_Spectrum *)cp) +/** + * Inherits from Ewl_Image and extends to privide a colour spectrum + */ +struct Ewl_Spectrum +{ + Ewl_Image widget; + + Ewl_Orientation orientation; + Ewl_Color_Pick_Mode mode; + unsigned int dimensions; + int redraw; + + Ewl_Color_Set rgba; + struct + { + float h, s, v; + } hsv; +}; -struct _ewl_spectrum { - Ewl_Image widget; +Ewl_Widget *ewl_spectrum_new(void); +int ewl_spectrum_init(Ewl_Spectrum *sp); - int orientation; - Ewl_Pick_Mode mode; - int dimensions; +void ewl_spectrum_orientation_set(Ewl_Spectrum *sp, Ewl_Orientation o); +Ewl_Orientation ewl_spectrum_orientation_get(Ewl_Spectrum *sp); - int r, g, b; - float h, s, v; +void ewl_spectrum_mode_set(Ewl_Spectrum *sp, Ewl_Color_Pick_Mode mode); +Ewl_Color_Pick_Mode ewl_spectrum_mode_get(Ewl_Spectrum *sp); - int redraw; -}; +void ewl_spectrum_dimensions_set(Ewl_Spectrum *sp, unsigned int dimensions); +unsigned int ewl_spectrum_dimensions_get(Ewl_Spectrum *sp); -Ewl_Widget *ewl_spectrum_new(void); -void ewl_spectrum_init(Ewl_Spectrum * cp); +void ewl_spectrum_rgba_set(Ewl_Spectrum *sp, int r, int g, int b, int a); +void ewl_spectrum_rgba_get(Ewl_Spectrum *sp, int *r, int *g, int *b, int *a); -void ewl_spectrum_mode_set(Ewl_Spectrum * sp, Ewl_Pick_Mode mode); -void ewl_spectrum_dimensions_set(Ewl_Spectrum * sp, int dimensions); +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_rgb_set(Ewl_Spectrum * sp, int r, int g, int b); -void ewl_spectrum_hsv_set(Ewl_Spectrum * sp, - float h, float s, float v); void ewl_spectrum_color_coord_map(Ewl_Spectrum *sp, int x, int y, int *r, int *g, int *b, int *a); -void ewl_spectrum_hsv_to_rgb(float hue, float saturation, float value, - int *r, int *g, int *b); -void ewl_spectrum_rgb_to_hsv(int r, int g, int b, - float *h, float *s, float *v); + +void ewl_spectrum_hsv_to_rgb(float hue, float saturation, float value, + int *r, int *g, int *b); +void ewl_spectrum_rgb_to_hsv(int r, int g, int b, + float *h, float *s, float *v); /* * 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_configure_cb(Ewl_Widget * w, void *ev_data, void *user_data); /** * @} ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs