Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_spectrum.c ewl_spectrum.h ewl_colorpicker.c 
        ewl_colorpicker.h 


Log Message:
Colorpicker patches from Colin Pitrat.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_spectrum.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ewl_spectrum.c      28 Mar 2005 07:04:29 -0000      1.3
+++ ewl_spectrum.c      14 Jun 2005 20:59:43 -0000      1.4
@@ -2,8 +2,6 @@
 #include "ewl_debug.h"
 #include "ewl_macros.h"
 
-static void  ewl_spectrum_hsv_to_rgb(float hue, float saturation, float value,
-                                    int *r, int *g, int *b);
 static void ewl_spectrum_color_coord_map2d(Ewl_Spectrum *sp, int x, int y, 
                                           int *r, int *g, int *b, int *a);
 static void ewl_spectrum_color_coord_map1d(Ewl_Spectrum *sp, int x, int y, 
@@ -321,6 +319,43 @@
                *_b = b;
 }
 
+void
+ewl_spectrum_rgb_to_hsv(int r, int g, int b,
+                       float *h, float *s, float *v)
+{
+        int min, max, delta;
+
+#undef MIN
+#undef MAX
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+        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 {
+                // r = g = b = 0                // s = 0, v is undefined
+                *s = 0;
+                *h = 0;
+                return;
+        }
+
+        if( r == max )
+                *h = (float)( g - b ) / (float)delta;         // between 
yellow & magenta
+        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;
+}
+
 static void
 ewl_spectrum_color_coord_map2d(Ewl_Spectrum *sp, int x, int y, 
                                int *r, int *g, int *b, int *a)
@@ -354,7 +389,7 @@
                if (b)
                        *b = blue;
        } else {
-               int h, s, v;
+               float h, s, v;
 
                h = sp->h;
                s = sp->s;
@@ -372,7 +407,7 @@
                        s = 1 - (float) y / (float) height;
                }
 
-               ewl_spectrum_hsv_to_rgb(h, s, v, r, g, b);
+                ewl_spectrum_hsv_to_rgb(h, s, v, r, g, b);
        }
 }
 
@@ -414,4 +449,3 @@
                ewl_spectrum_hsv_to_rgb(h, s, v, r, g, b);
        }
 }
-
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_spectrum.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ewl_spectrum.h      28 Mar 2005 07:04:29 -0000      1.4
+++ ewl_spectrum.h      14 Jun 2005 20:59:44 -0000      1.5
@@ -41,6 +41,10 @@
                                                 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);
 
 /*
  * Internally used callbacks, override at your own risk.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_colorpicker.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ewl_colorpicker.c   9 Jun 2005 21:41:55 -0000       1.3
+++ ewl_colorpicker.c   14 Jun 2005 20:59:44 -0000      1.4
@@ -38,7 +38,7 @@
        ewl_widget_appearance_set(EWL_WIDGET(cp), "colorpicker");
        ewl_widget_inherit(EWL_WIDGET(cp), "colorpicker");
 
-       ewl_box_spacing_set(EWL_BOX(cp), 20);
+       ewl_box_spacing_set(EWL_BOX(cp), 5);
 
        /*
         * Setup the range spectrum region for the base color.
@@ -53,8 +53,9 @@
                            ewl_colorpicker_range_up_cb, cp);
        ewl_callback_append(cp->range, EWL_CALLBACK_MOUSE_MOVE,
                            ewl_colorpicker_range_move_cb, cp);
-       ewl_object_preferred_inner_size_set(EWL_OBJECT(cp->range), 20, 200);
-       ewl_object_fill_policy_set(EWL_OBJECT(cp->range), EWL_FLAG_FILL_FILL);
+        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);
        ewl_container_child_append(EWL_CONTAINER(cp), cp->range);
        ewl_widget_show(cp->range);
 
@@ -70,59 +71,50 @@
        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_object_preferred_inner_size_set(EWL_OBJECT(cp->spectrum), 200, 200);
-       ewl_object_fill_policy_set(EWL_OBJECT(cp->spectrum), 
EWL_FLAG_FILL_FILL);
+        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);
        ewl_widget_show(cp->spectrum);
 
-        /*
-         * A text to see the selected color
-         */
-
-        cp->preview = ewl_text_new(NULL);
-        ewl_object_fill_policy_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_FILL_NONE);
-        ewl_object_alignment_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_ALIGN_CENTER);
-        ewl_text_color_set(EWL_TEXT(cp->preview), 0, 0, 0, 255);
-       ewl_container_child_append(EWL_CONTAINER(cp), cp->preview);
-        ewl_text_text_set(EWL_TEXT(cp->preview), "Preview");
-       ewl_widget_show(cp->preview);
-
        DRETURN_INT(TRUE, DLEVEL_STABLE);
 }
 
+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);
+}
+
+void ewl_colorpicker_hue_set(Ewl_ColorPicker *cp, float h)
+{
+        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);
+}
+
 void ewl_colorpicker_range_move_cb(Ewl_Widget *w, void *ev_data, void 
*user_data)
 {
-        #undef R
-        #undef G
-        #undef B
-        #undef A
-        #define R cp->selected.r
-        #define G cp->selected.g
-        #define B cp->selected.b
-        #define A cp->selected.a
        Ewl_ColorPicker *cp = user_data;
        Ewl_Event_Mouse_Move *ev = ev_data;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
 
-       if (cp->drag) 
+       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, &R, &G, &B, 
&A);
-               ewl_spectrum_rgb_set(EWL_SPECTRUM(cp->spectrum), R, G, B);
-               ewl_callback_call_with_event_data(EWL_WIDGET(cp), 
EWL_CALLBACK_VALUE_CHANGED, &cp->selected);
-
-               ewl_widget_hide(cp->preview);
-                IF_FREE(cp->preview);
-                cp->preview = ewl_text_new(NULL);
-                ewl_object_fill_policy_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_FILL_NONE);
-                ewl_object_alignment_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_ALIGN_CENTER);
-                ewl_text_color_set(EWL_TEXT(cp->preview), R, G, B, 255);
-               ewl_container_child_remove(EWL_CONTAINER(cp), cp->preview);
-               ewl_container_child_append(EWL_CONTAINER(cp), cp->preview);
-                ewl_text_text_set(EWL_TEXT(cp->preview), "Preview");
-               ewl_widget_show(cp->preview);
+               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);
@@ -139,21 +131,11 @@
 
         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, &R, &G, &B, &A);
-       ewl_spectrum_rgb_set(EWL_SPECTRUM(cp->spectrum), R, G, B);
-       ewl_callback_call_with_event_data(EWL_WIDGET(cp), 
EWL_CALLBACK_VALUE_CHANGED, &cp->selected);
-        ewl_text_color_set(EWL_TEXT(cp->preview), R, G, B, 255);
-
-       ewl_widget_hide(cp->preview);
-        IF_FREE(cp->preview);
-        cp->preview = ewl_text_new(NULL);
-        ewl_object_fill_policy_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_FILL_NONE);
-        ewl_object_alignment_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_ALIGN_CENTER);
-        ewl_text_color_set(EWL_TEXT(cp->preview), R, G, B, 255);
-        ewl_container_child_remove(EWL_CONTAINER(cp), cp->preview);
-        ewl_container_child_append(EWL_CONTAINER(cp), cp->preview);
-        ewl_text_text_set(EWL_TEXT(cp->preview), "Preview");
-        ewl_widget_show(cp->preview);
+       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);
 }
@@ -177,23 +159,16 @@
 
        DENTER_FUNCTION(DLEVEL_STABLE);
 
-       if (cp->drag) 
+       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, &R, &G, &B, 
&A);
-               ewl_callback_call_with_event_data(EWL_WIDGET(cp), 
EWL_CALLBACK_VALUE_CHANGED, &cp->selected);
-
-               ewl_widget_hide(cp->preview);
-                IF_FREE(cp->preview);
-                cp->preview = ewl_text_new(NULL);
-                ewl_object_fill_policy_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_FILL_NONE);
-                ewl_object_alignment_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_ALIGN_CENTER);
-                ewl_text_color_set(EWL_TEXT(cp->preview), R, G, B, 255);
-               ewl_container_child_remove(EWL_CONTAINER(cp), cp->preview);
-               ewl_container_child_append(EWL_CONTAINER(cp), cp->preview);
-                ewl_text_text_set(EWL_TEXT(cp->preview), "Preview");
-               ewl_widget_show(cp->preview);
+               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);
        }
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -210,20 +185,10 @@
         
         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, &R, &G, &B, &A);
-       ewl_callback_call_with_event_data(EWL_WIDGET(cp), 
EWL_CALLBACK_VALUE_CHANGED, &cp->selected);
-        ewl_text_color_set(EWL_TEXT(cp->preview), R, G, B, 255);
-
-       ewl_widget_hide(cp->preview);
-        IF_FREE(cp->preview);
-        cp->preview = ewl_text_new(NULL);
-        ewl_object_fill_policy_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_FILL_NONE);
-        ewl_object_alignment_set(EWL_OBJECT(cp->preview), 
EWL_FLAG_ALIGN_CENTER);
-        ewl_text_color_set(EWL_TEXT(cp->preview), R, G, B, 255);
-        ewl_container_child_remove(EWL_CONTAINER(cp), cp->preview);
-        ewl_container_child_append(EWL_CONTAINER(cp), cp->preview);
-        ewl_text_text_set(EWL_TEXT(cp->preview), "Preview");
-        ewl_widget_show(cp->preview);
+       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);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_colorpicker.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- ewl_colorpicker.h   9 Jun 2005 21:41:55 -0000       1.5
+++ ewl_colorpicker.h   14 Jun 2005 20:59:44 -0000      1.6
@@ -10,21 +10,28 @@
 
 typedef struct Ewl_ColorPicker Ewl_ColorPicker;
 
+/**
+ * @def EWL_COLORPICKER(cp)
+ * Typecast a pointer to an Ewl_ColorPicker pointer.
+ */
+#define EWL_COLORPICKER(cp) ((Ewl_ColorPicker *) cp)
+
 struct Ewl_ColorPicker
 {
        Ewl_Box box;
-       Ewl_Widget *preview;
        Ewl_Widget *spectrum;
        Ewl_Widget *range;
        int drag;
-        struct color
+        struct _ewl_colorpicker_color
         {
             int r, g, b, a;
         } selected;
 };
 
 Ewl_Widget     *ewl_colorpicker_new();
-int             ewl_colorpicker_init(Ewl_ColorPicker *cp);
+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.




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to