Enlightenment CVS committal
Author : dj2
Project : e17
Module : libs/ewl
Dir : e17/libs/ewl/src/lib
Modified Files:
ewl_spectrum.c
Log Message:
- spectrum patch from Peter Wehrfritz. Thanks.
- fixes lots of resizing, value changed, initial placement issues with the
cross hairs
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_spectrum.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- ewl_spectrum.c 9 Apr 2006 15:59:33 -0000 1.21
+++ ewl_spectrum.c 10 Apr 2006 16:01:06 -0000 1.22
@@ -13,20 +13,30 @@
static void ewl_spectrum_hsv_from_rgb(Ewl_Spectrum *sp);
static void ewl_spectrum_rgb_from_hsv(Ewl_Spectrum *sp);
static void ewl_spectrum_draw(Ewl_Spectrum *sp);
-static void ewl_spectrum_mouse_process(Ewl_Spectrum *sp, unsigned int x,
- unsigned int y);
-
+static void ewl_spectrum_cross_hairs_draw(Ewl_Spectrum *sp);
+static void ewl_spectrum_mouse_process(Ewl_Spectrum *sp, int x, int y);
static void ewl_spectrum_hsv_to_rgb(double h, double s, double v,
- int *r, int *g, int *b);
+ int *r, int *g, int *b);
+static void ewl_spectrum_rgb_to_hsv(int r, int g, int b,
+ double *h, double *s, double *v);
static void ewl_spectrum_color_coord_map(Ewl_Spectrum *sp, int x, int y,
int w, int h, unsigned int *r,
unsigned int *g, unsigned int *b);
+static void ewl_spectrum_color_coord_xy_get(Ewl_Spectrum *sp, int *x, int *y,
+ int w, int h, unsigned int r,
+ unsigned int g, unsigned int b);
static void ewl_spectrum_color_coord_map_vertical(Ewl_Spectrum *sp, int y,
int img_h, unsigned int *r,
unsigned int *g, unsigned int *b);
static void ewl_spectrum_color_coord_map_square(Ewl_Spectrum *sp, int x,
int y, int img_w, int img_h, unsigned int *r,
unsigned int *g, unsigned int *b);
+static void ewl_spectrum_color_coord_vertical_y_get(Ewl_Spectrum *sp,
+ int *y, int img_h,
+ unsigned int r, unsigned int g, unsigned int b);
+static void ewl_spectrum_color_coord_square_xy_get(Ewl_Spectrum *sp,
+ int *x, int *y, int img_w, int img_h,
+ unsigned int r, unsigned int g, unsigned int b);
/**
* @return Returns a new Ewl_Spectrum widget or NULL on failure
@@ -56,7 +66,7 @@
/**
* @param sp: The Ewl_Spectrum to init
- * @return Returns TRUEE on success or FALSE on failure
+ * @return Returns TRUE on success or FALSE on failure
* @brief Initializes an Ewl_Specturm widget to default values
*/
int
@@ -309,6 +319,7 @@
CURRENT_W(sp), CURRENT_H(sp));
ewl_spectrum_draw(sp);
+ ewl_spectrum_cross_hairs_draw(sp);
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
@@ -370,50 +381,31 @@
}
static void
-ewl_spectrum_mouse_process(Ewl_Spectrum *sp, unsigned int x, unsigned int y)
+ewl_spectrum_mouse_process(Ewl_Spectrum *sp, int x, int y)
{
Evas_Coord img_w, img_h;
unsigned int r, g, b;
- unsigned int mx, my;
DENTER_FUNCTION(DLEVEL_STABLE);
DCHECK_PARAM_PTR("sp", sp);
DCHECK_TYPE("sp", sp, EWL_SPECTRUM_TYPE);
+
+ x -= CURRENT_X(sp->canvas);
+ y -= CURRENT_Y(sp->canvas);
+
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+ if (x > CURRENT_W(sp->canvas))
+ x = CURRENT_W(sp->canvas);
+ if (y > CURRENT_H(sp->canvas))
+ y = CURRENT_H(sp->canvas);
- if (x > (CURRENT_X(sp->canvas) + CURRENT_W(sp->canvas)))
- x = CURRENT_X(sp->canvas) + CURRENT_W(sp->canvas);
- if (y > (CURRENT_Y(sp->canvas) + CURRENT_H(sp->canvas)))
- y = CURRENT_Y(sp->canvas) + CURRENT_H(sp->canvas);
-
- mx = x - CURRENT_X(sp->canvas);
- my = y - CURRENT_Y(sp->canvas);
evas_object_image_size_get(EWL_IMAGE(sp->canvas)->image, &img_w,
&img_h);
- ewl_spectrum_color_coord_map(sp, mx, my, img_w, img_h, &r, &g, &b);
+ ewl_spectrum_color_coord_map(sp, x, y, img_w, img_h, &r, &g, &b);
ewl_spectrum_rgb_set(sp, r, g, b);
- /* place the horizontal cross hair */
- y -= CURRENT_H(sp->cross_hairs.horizontal) / 2;
- ewl_object_position_request(EWL_OBJECT(sp->cross_hairs.horizontal),
- CURRENT_X(sp), y);
- ewl_object_w_request(EWL_OBJECT(sp->cross_hairs.horizontal),
- CURRENT_W(sp));
-
- if (!VISIBLE(sp->cross_hairs.horizontal))
- ewl_widget_show(sp->cross_hairs.horizontal);
-
- /* place the vertical cross hair if needed */
- if (sp->type == EWL_SPECTRUM_TYPE_SQUARE)
- {
- x -= CURRENT_W(sp->cross_hairs.vertical) / 2;
-
ewl_object_position_request(EWL_OBJECT(sp->cross_hairs.vertical),
- x, CURRENT_Y(sp));
- ewl_object_h_request(EWL_OBJECT(sp->cross_hairs.vertical),
- CURRENT_H(sp));
-
- if (!VISIBLE(sp->cross_hairs.vertical))
- ewl_widget_show(sp->cross_hairs.vertical);
- }
-
ewl_callback_call(EWL_WIDGET(sp), EWL_CALLBACK_VALUE_CHANGED);
DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -422,38 +414,16 @@
static void
ewl_spectrum_hsv_from_rgb(Ewl_Spectrum *sp)
{
- unsigned int min, max;
-
DENTER_FUNCTION(DLEVEL_STABLE);
DCHECK_PARAM_PTR("sp", sp);
DCHECK_TYPE("sp", sp, EWL_SPECTRUM_TYPE);
- min = MIN(sp->rgb.r, MIN(sp->rgb.g, sp->rgb.b));
- max = MAX(sp->rgb.r, MAX(sp->rgb.g, sp->rgb.b));
-
- sp->hsv.v = max / 255.0;
- sp->hsv.s = (max != 0) ? ((max - min) / (float)max) : 0.0;
-
- if (sp->hsv.s == 0.0)
- sp->hsv.h = 0;
- else
- {
- unsigned int delta;
-
- delta = max - min;
- if ((unsigned int)sp->rgb.r == max)
- sp->hsv.h = (sp->rgb.g - sp->rgb.b) / (float)delta;
- else if ((unsigned int)sp->rgb.g == max)
- sp->hsv.h = 2.0 + ((sp->rgb.b - sp->rgb.r) /
(float)delta);
- else if ((unsigned int)sp->rgb.b == max)
- sp->hsv.h = 4.0 + ((sp->rgb.r - sp->rgb.g) /
(float)delta);
-
- sp->hsv.h *= 60.0;
- if (sp->hsv.h < 0.0) sp->hsv.h += 360.0;
- }
+ ewl_spectrum_rgb_to_hsv(sp->rgb.r, sp->rgb.g, sp->rgb.b,
+ &(sp->hsv.h), &(sp->hsv.s), &(sp->hsv.v));
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
+
static void
ewl_spectrum_rgb_from_hsv(Ewl_Spectrum *sp)
{
@@ -469,7 +439,7 @@
static void
ewl_spectrum_hsv_to_rgb(double h, double s, double v,
- int *r, int *g, int *b)
+ int *r, int *g, int *b)
{
unsigned int r_tmp = 0, g_tmp = 0, b_tmp = 0;
@@ -551,6 +521,45 @@
}
static void
+ewl_spectrum_rgb_to_hsv(int r, int g, int b,
+ double *h, double *s, double *v)
+{
+ unsigned int min, max;
+ double tmp_h, tmp_s, tmp_v;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+
+ min = MIN(r, MIN(g, b));
+ max = MAX(r, MAX(g, b));
+
+ tmp_v = max / 255.0;
+ tmp_s = (max != 0) ? ((max - min) / (float)max) : 0.0;
+ tmp_h = 0.0;
+
+ if (tmp_s != 0.0)
+ {
+ unsigned int delta;
+
+ delta = max - min;
+ if ((unsigned int)r == max)
+ tmp_h = (g - b) / (float)delta;
+ else if ((unsigned int)g == max)
+ tmp_h = 2.0 + ((b - r) / (float)delta);
+ else if ((unsigned int)b == max)
+ tmp_h = 4.0 + ((r - g) / (float)delta);
+
+ tmp_h *= 60.0;
+ if (tmp_h < 0.0) tmp_h += 360.0;
+ }
+
+ if (h) *h = tmp_h;
+ if (s) *s = tmp_s;
+ if (v) *v = tmp_v;
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+static void
ewl_spectrum_draw(Ewl_Spectrum *sp)
{
Evas_Object *img;
@@ -590,6 +599,47 @@
}
static void
+ewl_spectrum_cross_hairs_draw(Ewl_Spectrum *sp)
+{
+ int x, y;
+ Evas_Coord img_w, img_h;
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("sp", sp);
+ DCHECK_TYPE("sp", sp, EWL_SPECTRUM_TYPE);
+
+ /* get the coords */
+ evas_object_image_size_get(EWL_IMAGE(sp->canvas)->image, &img_w,
&img_h);
+ ewl_spectrum_color_coord_xy_get(sp, &x, &y, img_w, img_h,
+ sp->rgb.r, sp->rgb.g, sp->rgb.b);
+ x += CURRENT_X(sp->canvas);
+ y += CURRENT_Y(sp->canvas);
+ /* place the horizontal cross hair */
+ y -= CURRENT_H(sp->cross_hairs.horizontal) / 2;
+ ewl_object_position_request(EWL_OBJECT(sp->cross_hairs.horizontal),
+ CURRENT_X(sp), y);
+ ewl_object_w_request(EWL_OBJECT(sp->cross_hairs.horizontal),
+ CURRENT_W(sp));
+
+ if (!VISIBLE(sp->cross_hairs.horizontal))
+ ewl_widget_show(sp->cross_hairs.horizontal);
+
+ /* place the vertical cross hair if needed */
+ if (sp->type == EWL_SPECTRUM_TYPE_SQUARE)
+ {
+ x -= CURRENT_W(sp->cross_hairs.vertical) / 2;
+
ewl_object_position_request(EWL_OBJECT(sp->cross_hairs.vertical),
+ x, CURRENT_Y(sp));
+ ewl_object_h_request(EWL_OBJECT(sp->cross_hairs.vertical),
+ CURRENT_H(sp));
+
+ if (!VISIBLE(sp->cross_hairs.vertical))
+ ewl_widget_show(sp->cross_hairs.vertical);
+ }
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+static void
ewl_spectrum_color_coord_map(Ewl_Spectrum *sp, int x, int y, int img_w, int
img_h,
unsigned int *r, unsigned int *g, unsigned int
*b)
{
@@ -605,6 +655,25 @@
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
+static void ewl_spectrum_color_coord_xy_get(Ewl_Spectrum *sp, int *x, int *y,
+ int w, int h, unsigned int r,
+ unsigned int g, unsigned int b)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("sp", sp);
+
+ if (sp->type == EWL_SPECTRUM_TYPE_VERTICAL) {
+ ewl_spectrum_color_coord_vertical_y_get(sp, y, h, r, g, b);
+ if (x) *x = 0;
+ }
+ else
+ ewl_spectrum_color_coord_square_xy_get(sp, x, y, w,
+ h, r, g, b);
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+
static void
ewl_spectrum_color_coord_map_vertical(Ewl_Spectrum *sp, int y, int img_h,
unsigned int *r, unsigned int *g,
unsigned int *b)
@@ -625,14 +694,14 @@
switch (sp->mode)
{
case EWL_COLOR_MODE_RGB_RED:
- r_tmp = sp->rgb.r - ((sp->rgb.r * y) / img_h);
+ r_tmp = 255 - ((255 * y) / img_h);
break;
case EWL_COLOR_MODE_RGB_GREEN:
- g_tmp = sp->rgb.g - ((sp->rgb.g * y) / img_h);
+ g_tmp = 255 - ((255 * y) / img_h);
break;
case EWL_COLOR_MODE_RGB_BLUE:
- b_tmp = sp->rgb.b - ((sp->rgb.b * y) / img_h);
+ b_tmp = 255 - ((255 * y) / img_h);
break;
case EWL_COLOR_MODE_HSV_HUE:
@@ -720,6 +789,113 @@
if (r) *r = r_tmp;
if (g) *g = g_tmp;
if (b) *b = b_tmp;
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+static void
+ewl_spectrum_color_coord_vertical_y_get(Ewl_Spectrum *sp, int *y, int img_h,
+ unsigned int r, unsigned int g,
unsigned int b)
+{
+ int tmp_y;
+ double h, s, v;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("sp", sp);
+
+ tmp_y = 0;
+ switch (sp->mode)
+ {
+ case EWL_COLOR_MODE_RGB_RED:
+ tmp_y = ((255 - r) * img_h) / 255;
+ break;
+
+ case EWL_COLOR_MODE_RGB_GREEN:
+ tmp_y = ((255 - g) * img_h) / 255;
+ break;
+ case EWL_COLOR_MODE_RGB_BLUE:
+ tmp_y = ((255 - b) * img_h) / 255;
+ break;
+
+ case EWL_COLOR_MODE_HSV_HUE:
+ ewl_spectrum_rgb_to_hsv(r, b, g, &h, &s, &v);
+ tmp_y = (int) (((360.0 - h) * img_h) / 360.0);
+ break;
+
+ case EWL_COLOR_MODE_HSV_SATURATION:
+ ewl_spectrum_rgb_to_hsv(r, b, g, &h, &s, &v);
+ tmp_y = (int) ((1.0 - s) * img_h);
+ break;
+
+ case EWL_COLOR_MODE_HSV_VALUE:
+ ewl_spectrum_rgb_to_hsv(r, b, g, &h, &s, &v);
+ tmp_y = (int) ((1.0 - v) * img_h);
+ break;
+
+ default:
+ break;
+ }
+
+ if (y) *y = tmp_y;
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+
+static void
+ewl_spectrum_color_coord_square_xy_get(Ewl_Spectrum *sp, int *x, int *y, int
img_w, int img_h,
+ unsigned int r, unsigned int g,
unsigned int b)
+{
+ int tmp_x, tmp_y;
+ double h, s, v;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("sp", sp);
+
+ tmp_x = 0;
+ tmp_y = 0;
+
+ switch (sp->mode)
+ {
+ case EWL_COLOR_MODE_RGB_RED:
+ tmp_x = (int) ((1.0 - b / 255.0) * img_w);
+ tmp_y = (int) ((1.0 - g / 255.0) * img_h);
+ break;
+
+ case EWL_COLOR_MODE_RGB_GREEN:
+ tmp_x = (int) ((1.0 - b / 255.0) * img_w);
+ tmp_y = (int) ((1.0 - r / 255.0) * img_h);
+ break;
+
+ case EWL_COLOR_MODE_RGB_BLUE:
+ tmp_x = (int) ((1.0 - g / 255.0) * img_w);
+ tmp_y = (int) ((1.0 - r / 255.0) * img_h);
+ break;
+
+ case EWL_COLOR_MODE_HSV_HUE:
+ ewl_spectrum_rgb_to_hsv(r, b, g, &h, &s, &v);
+ tmp_x = (int) ((1.0 - v) * img_w);
+ tmp_y = (int) ((1.0 - s) * img_h);
+ break;
+
+ case EWL_COLOR_MODE_HSV_SATURATION:
+ ewl_spectrum_rgb_to_hsv(r, b, g, &h, &s, &v);
+ tmp_x = (int) ((1.0 - (h / 360.0)) * img_w);
+ tmp_y = (int) ((1.0 - v) * img_h);
+ break;
+
+ case EWL_COLOR_MODE_HSV_VALUE:
+ ewl_spectrum_rgb_to_hsv(r, b, g, &h, &s, &v);
+ tmp_x = (int) ((1.0 - (h / 360.0)) * img_w);
+ tmp_y = (int) ((1.0 - s) * img_h);
+ break;
+
+ default:
+ break;
+ }
+
+ if (x) *x = tmp_x;
+ if (y) *y = tmp_y;
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs