]> O.S.I.I.S - jp/crow.git/commitdiff
debug
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 21 Oct 2016 04:18:21 +0000 (06:18 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 21 Oct 2016 05:03:18 +0000 (07:03 +0200)
modifié :         Templates/ColorPicker.template
modifié :         Tests/Interfaces/Divers/colorPicker.crow
copié :           src/GraphicObjects/ColorSelector.cs -> src/GraphicObjects/ColorPicker.cs
modifié :         src/GraphicObjects/ColorSelector.cs
modifié :         src/GraphicObjects/HueSelector.cs
modifié :         src/GraphicObjects/SaturationValueSelector.cs
modifié :         src/Colors.cs

Templates/ColorPicker.template
Tests/Interfaces/Divers/colorPicker.crow
src/Colors.cs
src/GraphicObjects/ColorPicker.cs
src/GraphicObjects/ColorSelector.cs
src/GraphicObjects/HueSelector.cs
src/GraphicObjects/SaturationValueSelector.cs

index 4a542631848b00ef874c6fa0830b735a1de4054e..5bf21131286998ee3cf9708205395610ecc8c6f4 100755 (executable)
@@ -3,46 +3,46 @@
                CornerRadius="{./CornerRadius}" BorderWidth="1">
                <HorizontalStack Spacing="0">
                        <VerticalStack Margin="10">
-                               <SaturationValueSelector Focusable="true" Name="colorSelector" Margin="0" Width="140" Height="140" Background="DimGray"
-                                       SelectedColor="{²./SelectedColor}"
-                                       Foreground="{../hueSelector.SelectedColor}"/>
-                               <HueSelector Focusable="true" Name="hueSelector" Margin="0" Width="140" Height="20" Background="DimGray"/>
+                               <SaturationValueSelector S="{²./S}" V="{²./V}" Focusable="true" Name="colorSelector" Margin="0"
+                                       Foreground="{../hueSelector.HueColor}"
+                                       Width="140" Height="140" Background="DimGray"/>
+                               <HueSelector Hue="{²./H}" Focusable="true" Name="hueSelector" Margin="0" Width="140" Height="20" Background="DimGray"/>
                        </VerticalStack>
                        <VerticalStack Margin="5" Height="Stretched">
                                <HorizontalStack Height="Fit" Width="Stretched">
-                                       <GraphicObject Width="30" Height="30" Background="{../../../colorSelector.SelectedColor}"/>
+                                       <GraphicObject Width="30" Height="30" Background="{./SelectedColor}"/>
                                        <VerticalStack Margin="5">
-                                               <Label Focusable="true" Selectable="true" Width="Stretched" Text="{../../../../colorSelector.SelectedColorName}" />
-                                               <Label Focusable="true" Selectable="true" Width="Stretched" Text="{../../../../colorSelector.HexColor}" />
+                                               <Label Focusable="true" Selectable="true" Width="Stretched" Text="{./SelectedColorName}" />
+                                               <Label Focusable="true" Selectable="true" Width="Stretched" Text="{./HexColor}" />
                                        </VerticalStack>
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Red:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²../../../colorSelector.R}" Width="50"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./R}" Width="50"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Green:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²../../../colorSelector.G}" Width="50"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./G}" Width="50"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Blue:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²../../../colorSelector.B}" Width="50"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./B}" Width="50"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Alpha:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²../../../colorSelector.A}" Width="50"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./A}" Width="50"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Hue:" Width="50"/>
-                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.H}" Width="50"  />
+                                       <Spinner Style="HSVSpinner" Value="{²../../../hueSelector.Hue}" Width="150"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Sat:" Width="50"/>
-                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.S}" Width="50"  />
+                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.S}" Width="150"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Val:" Width="50"/>
-                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.V}" Width="50"  />
+                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.V}" Width="150"  />
                                </HorizontalStack>
                        </VerticalStack>
                </HorizontalStack>
index add58965897d91f7fc7d5553b77cfe41bb5c5abe..17700afb665339e32dabd13b87bcbba6d451c07a 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
 <VerticalStack>
-       <ColorPicker SelectedColor="Red" Name="colorPicker" Background="Onyx" Margin="5" Fit="True" />
+       <ColorPicker SelectedColor="DarkBlue" Name="colorPicker" Background="Onyx" Margin="5" Fit="True" />
        <GraphicObject Width="100" Height="60" Background="{../colorPicker.SelectedColor}"/>
 </VerticalStack>
\ No newline at end of file
index 6787c382a3e9af6b03e50d06fa72bee853a7c11d..b76de6235e118145963bc458d3140cd05874c369 100644 (file)
@@ -1071,5 +1071,34 @@ namespace Crow
         {
             return (Color)s;
         }
+               public static Color FromHSV(double _h, double _v = 1.0, double _s = 1.0){
+                       Color c = Color.Black;
+
+                       if (_s == 0) {//HSV from 0 to 1
+                               c.R = _v;
+                               c.G = _v;
+                               c.B = _v;
+                       }else{
+                               double var_h = _h * 6.0;
+
+                               if (var_h == 6.0)
+                                       var_h = 0;      //H must be < 1
+                               double var_i = Math.Floor( var_h );     //Or ... var_i = floor( var_h )
+                               double var_1 = _v * ( 1.0 - _s );
+                               double var_2 = _v * (1.0 - _s * (var_h - var_i));
+                               double var_3 = _v * (1.0 - _s * (1.0 - (var_h - var_i)));
+
+                               if (var_i == 0.0) {
+                                       c.R = _v;
+                                       c.G = var_3;
+                                       c.B = var_1;
+                               }else if ( var_i == 1.0 ) { c.R = var_2 ; c.G = _v     ; c.B = var_1; }
+                               else if ( var_i == 2 ) { c.R = var_1 ; c.G = _v     ; c.B = var_3; }
+                               else if ( var_i == 3 ) { c.R = var_1 ; c.G = var_2 ; c.B = _v;     }
+                               else if ( var_i == 4 ) { c.R = var_3 ; c.G = var_1 ; c.B = _v;    }
+                               else                   { c.R = _v     ; c.G = var_1 ; c.B = var_2; }
+                       }
+                       return c;
+               }
     }
 }
index b95fb0e3e54a2e859277f26ff0710abb1479d790..cc8dfac36068be2d8de3c1b453c3fcaffa14d547 100644 (file)
@@ -30,17 +30,193 @@ namespace Crow
                {
                }
 
-               Fill selectedColor;
+               const double div = 255.0;
+               const double colDiv = 1.0 / div;
+
+               Color curColor;
+               double h,s,v;
+
+               [XmlAttributeAttribute()]
+               public virtual double R {
+                       get { return Math.Round(curColor.R * div); }
+                       set {
+                               if (R == value)
+                                       return;                         
+                               curColor.R = value * colDiv;
+                               NotifyValueChanged ("R", R);
+                               hsvFromRGB ();
+                               notifyCurColorHasChanged ();
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double G {
+                       get { return Math.Round(curColor.G * div); }
+                       set {
+                               if (G == value)
+                                       return;
+                               curColor.G = value * colDiv;
+                               NotifyValueChanged ("G", G);
+                               notifyCurColorHasChanged ();
+                               hsvFromRGB ();
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double B {
+                       get { return Math.Round(curColor.B * div); }
+                       set {
+                               if (B == value)
+                                       return;
+                               curColor.B = value * colDiv;
+                               NotifyValueChanged ("B", B);
+                               notifyCurColorHasChanged ();
+                               hsvFromRGB ();
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double A {
+                       get { return Math.Round(curColor.A * div); }
+                       set {
+                               if (A == value)
+                                       return;
+                               curColor.A = value * colDiv;
+                               NotifyValueChanged ("A", A);
+                               notifyCurColorHasChanged ();
+                               hsvFromRGB ();
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double H {
+                       get { return Math.Round (h, 3); }
+                       set {
+                               if (H == value)
+                                       return;
+                               h = value;
+                               NotifyValueChanged ("H", H);
+                               rgbFromHSV ();
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double S {
+                       get { return Math.Round (s, 2); }
+                       set {
+                               if (s == value)
+                                       return;
+                               s = value;
+                               NotifyValueChanged ("S", S);
+                               rgbFromHSV ();
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double V {
+                       get { return Math.Round (v, 2); }
+                       set {
+                               if (v == value)
+                                       return;
+                               v = value;
+                               NotifyValueChanged ("V", V);
+                               rgbFromHSV ();
+                       }
+               }
 
                [XmlAttributeAttribute]
                public virtual Fill SelectedColor {
-                       get { return selectedColor; }
+                       get { return new SolidColor(curColor); }
                        set {
-                               if (selectedColor == value)
+                               Color c = (value as SolidColor).color;
+                               if (curColor == c)
                                        return;
-                               selectedColor = value;
-                               NotifyValueChanged ("SelectedColor", selectedColor);
+                               curColor = c;
+                               notifyCurColorHasChanged ();
+                               notifyRGBAHasChanged ();
+                               hsvFromRGB ();
+                       }
+               }
+
+               void notifyCurColorHasChanged(){
+                       NotifyValueChanged ("SelectedColor", SelectedColor);
+                       string n = curColor.ToString ();
+                       if (char.IsLetter(n[0]))
+                               NotifyValueChanged ("SelectedColorName", n);
+                       else
+                               NotifyValueChanged ("SelectedColorName", "-");
+                       NotifyValueChanged ("HexColor", ((int)R).ToString ("X2") + ((int)G).ToString ("X2") + ((int)B).ToString ("X2") + ((int)A).ToString ("X2"));
+               }
+               void notifyRGBAHasChanged(){
+                       NotifyValueChanged ("R", R);
+                       NotifyValueChanged ("G", G);
+                       NotifyValueChanged ("B", B);
+                       NotifyValueChanged ("A", A);
+               }
+               void notifyHSVHasChanged(){
+                       NotifyValueChanged ("H", H);
+                       NotifyValueChanged ("S", S);
+                       NotifyValueChanged ("V", V);
+               }
+               void hsvFromRGB(){
+                       Color c = curColor;
+                       double min = Math.Min (c.R, Math.Min (c.G, c.B));       //Min. value of RGB
+                       double max = Math.Max (c.R, Math.Max (c.G, c.B));       //Max. value of RGB
+                       double diff = max - min;                                                        //Delta RGB value
+
+                       v = max;
+
+                       if ( diff == 0 )//This is a gray, no chroma...
+                       {
+                               h = 0;
+                               s = 0;
+                       }else{//Chromatic data...                               
+                               s = diff / max;
+
+                               double diffR = (((max - c.R) / 6.0) + (diff / 2.0)) / diff;
+                               double diffG = (((max - c.G) / 6.0) + (diff / 2.0)) / diff;
+                               double diffB = (((max - c.B) / 6.0) + (diff / 2.0)) / diff;
+
+                               if (c.R == max)
+                                       h = diffB - diffG;
+                               else if (c.G == max)
+                                       h = (1.0 / 3.0) + diffR - diffB;
+                               else if (c.B == max)
+                                       h = (2.0 / 3.0) + diffG - diffR;
+
+                               if (h < 0)
+                                       h += 1;
+                               if (h > 1)
+                                       h -= 1;
+
+                       }
+                       notifyHSVHasChanged ();
+               }
+               void rgbFromHSV(){
+                       Color c = Color.Black;
+
+                       if (s == 0) {//HSV from 0 to 1
+                               c.R = v;
+                               c.G = v;
+                               c.B = v;
+                       }else{
+                               double var_h = h * 6.0;
+
+                               if (var_h == 6.0)
+                                       var_h = 0;      //H must be < 1
+                               double var_i = Math.Floor( var_h );     //Or ... var_i = floor( var_h )
+                               double var_1 = v * ( 1.0 - s );
+                               double var_2 = v * (1.0 - s * (var_h - var_i));
+                               double var_3 = v * (1.0 - s * (1.0 - (var_h - var_i)));
+
+                               if (var_i == 0.0) {
+                                       c.R = v;
+                                       c.G = var_3;
+                                       c.B = var_1;
+                               }else if ( var_i == 1.0 ) { c.R = var_2 ; c.G = v     ; c.B = var_1; }
+                               else if ( var_i == 2 ) { c.R = var_1 ; c.G = v     ; c.B = var_3; }
+                               else if ( var_i == 3 ) { c.R = var_1 ; c.G = var_2 ; c.B = v;     }
+                               else if ( var_i == 4 ) { c.R = var_3 ; c.G = var_1 ; c.B = v;    }
+                               else                   { c.R = v     ; c.G = var_1 ; c.B = var_2; }
                        }
+                               
+                       curColor = c;
+                       notifyCurColorHasChanged ();
+                       notifyRGBAHasChanged ();
                }
        }
 }
index 39db4f251041298f8796d93342e8a9fa56959cb8..13a588ce43093d19a8f9ede9a1fb4796fd51153a 100644 (file)
@@ -32,127 +32,23 @@ namespace Crow
 
                const double div = 255.0;
                const double colDiv = 1.0 / div;
-
-               Fill selectedColor = new SolidColor(Color.Red);
                protected Point mousePos;
-               double h,s,v;
-
-               [XmlAttributeAttribute()]
-               public virtual double R {
-                       get { return Math.Round((selectedColor as SolidColor).color.R * div); }
-                       set {
-                               if (R == value)
-                                       return;
-                               Color c = (SelectedColor as SolidColor).color;
-                               SelectedColor = new SolidColor (new Color (value * colDiv, c.G, c.B, c.A));
-                               NotifyValueChanged ("R", R);
-                               updateHSV ();
-                       }
-               }
-               [XmlAttributeAttribute()]
-               public virtual double G {
-                       get { return Math.Round((selectedColor as SolidColor).color.G * div); }
-                       set {
-                               if (G == value)
-                                       return;
-                               Color c = (SelectedColor as SolidColor).color;
-                               SelectedColor = new SolidColor (new Color (c.R, value * colDiv, c.B, c.A));
-                               NotifyValueChanged ("G", G);
-                               updateHSV ();
-                       }
-               }
-               [XmlAttributeAttribute()]
-               public virtual double B {
-                       get { return Math.Round((selectedColor as SolidColor).color.B * div); }
-                       set {
-                               if (B == value)
-                                       return;
-                               Color c = (SelectedColor as SolidColor).color;
-                               SelectedColor = new SolidColor (new Color (c.R, c.G, value * colDiv, c.A));
-                               NotifyValueChanged ("B", B);
-                               updateHSV ();
-                       }
-               }
-               [XmlAttributeAttribute()]
-               public virtual double A {
-                       get { return Math.Round((selectedColor as SolidColor).color.A * div); }
-                       set {
-                               if (A == value)
-                                       return;
-                               Color c = (SelectedColor as SolidColor).color;
-                               SelectedColor = new SolidColor (new Color (c.R, c.G, c.B, value * colDiv));
-                               NotifyValueChanged ("A", A);
-                               updateHSV ();
-                       }
-               }
-               [XmlAttributeAttribute()]
-               public virtual double H {
-                       get { return Math.Round (h, 3); }
-                       set {
-                               if (H == value)
-                                       return;
-                               h = value;
-                               NotifyValueChanged ("H", H);
-                               computeColorFromHSV ();
-                       }
-               }
-               [XmlAttributeAttribute()]
-               public virtual double S {
-                       get { return Math.Round (s, 2); }
-                       set {
-                               if (s == value)
-                                       return;
-                               s = value;
-                               NotifyValueChanged ("S", S);
-                               computeColorFromHSV ();
-                       }
-               }
-               [XmlAttributeAttribute()]
-               public virtual double V {
-                       get { return Math.Round (v, 2); }
-                       set {
-                               if (v == value)
-                                       return;
-                               v = value;
-                               NotifyValueChanged ("V", V);
-                               computeColorFromHSV ();
-                       }
-               }
-
-               [XmlAttributeAttribute]
-               public virtual Fill SelectedColor {
-                       get { return selectedColor; }
-                       set {
-                               if (selectedColor == value)
-                                       return;
-                               selectedColor = value;
-                               NotifyValueChanged ("SelectedColor", selectedColor);
-                               string n = (selectedColor as SolidColor).color.ToString ();
-                               if (char.IsLetter(n[0]))
-                                       NotifyValueChanged ("SelectedColorName", n);
-                               else
-                                       NotifyValueChanged ("SelectedColorName", "-");
-                               NotifyValueChanged ("HexColor", ((int)R).ToString ("X") + ((int)G).ToString ("X") + ((int)B).ToString ("X") + ((int)A).ToString ("X"));
-                       }
-               }
 
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
                        base.onMouseMove (sender, e);
-                       if (bmp == null || CurrentInterface.Mouse.LeftButton == ButtonState.Released)
+                       if (CurrentInterface.Mouse.LeftButton == ButtonState.Released)
                                return;
                        updateMouseLocalPos (e.Position);
-                       updateColorFromPicking ();
                }
-
-               public override void onMouseClick (object sender, MouseButtonEventArgs e)
+               public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {
-                       base.onMouseClick (sender, e);
-
-                       updateMouseLocalPos (e.Position);
-                       updateColorFromPicking ();
+                       base.onMouseDown (sender, e);
+                       if (e.Button == MouseButton.Left)
+                               updateMouseLocalPos (e.Position);
                }
-               void updateMouseLocalPos(Point mPos){
+
+               protected virtual void updateMouseLocalPos(Point mPos){
                        Rectangle r = ScreenCoordinates (Slot);
                        Rectangle cb = ClientRectangle;
                        mousePos = mPos - r.Position;
@@ -162,104 +58,32 @@ namespace Crow
                        mousePos.Y = Math.Max(cb.Y, mousePos.Y);
                        mousePos.Y = Math.Min(cb.Bottom-1, mousePos.Y);
                }
-               virtual protected void updateColorFromPicking(bool redraw = true){
-                       SelectedColor = new SolidColor(getPixelAt(mousePos.X, mousePos.Y));
-
-                       updateHSV ();
-
-                       NotifyValueChanged ("R", R);
-                       NotifyValueChanged ("G", G);
-                       NotifyValueChanged ("B", B);
-                       NotifyValueChanged ("A", A);
-
-                       if (redraw)
-                               RegisterForRedraw ();
-               }
-
-               protected Color getPixelAt(int x, int y){
-                       if (bmp == null)
-                               return Color.Transparent;
-
-                       int ptr = y * Slot.Width * 4 + x * 4;
-
-                       return new Color(
-                               (double)bmp[ptr + 2] * colDiv,
-                               (double)bmp[ptr + 1] * colDiv,
-                               (double)bmp[ptr] * colDiv,
-                               (double)bmp[ptr + 3] * colDiv);
-               }
-               void updateHSV(){
-                       Color c = (SelectedColor as SolidColor).color;
-                       double min = Math.Min (c.R, Math.Min (c.G, c.B));       //Min. value of RGB
-                       double max = Math.Max (c.R, Math.Max (c.G, c.B));       //Max. value of RGB
-                       double diff = max - min;                                                        //Delta RGB value
-
-                       v = max;
-
-                       if ( diff == 0 )//This is a gray, no chroma...
-                       {
-                               h = 0;
-                               s = 0;
-                       }else{//Chromatic data...                               
-                               s = diff / max;
-
-                               double diffR = (((max - c.R) / 6.0) + (diff / 2.0)) / diff;
-                               double diffG = (((max - c.G) / 6.0) + (diff / 2.0)) / diff;
-                               double diffB = (((max - c.B) / 6.0) + (diff / 2.0)) / diff;
-
-                               if (c.R == max)
-                                       h = diffB - diffG;
-                               else if (c.G == max)
-                                       h = (1.0 / 3.0) + diffR - diffB;
-                               else if (c.B == max)
-                                       h = (2.0 / 3.0) + diffG - diffR;
-                               
-                               if (h < 0)
-                                       h += 1;
-                               if (h > 1)
-                                       h -= 1;
-                               
-                       }
-
-                       NotifyValueChanged ("H", H);
-                       NotifyValueChanged ("S", S);
-                       NotifyValueChanged ("V", V);
-               }
-               void computeColorFromHSV(){
-                       Color c = Color.Black;
-
-                       if (s == 0) {//HSV from 0 to 1
-                               c.R = v;
-                               c.G = v;
-                               c.B = v;
-                       }else{
-                               double var_h = h * 6.0;
-
-                               if (var_h == 6.0)
-                                       var_h = 0;      //H must be < 1
-                               double var_i = Math.Floor( var_h );     //Or ... var_i = floor( var_h )
-                               double var_1 = v * ( 1.0 - s );
-                               double var_2 = v * (1.0 - s * (var_h - var_i));
-                               double var_3 = v * (1.0 - s * (1.0 - (var_h - var_i)));
-
-                               if (var_i == 0.0) {
-                                       c.R = v;
-                                       c.G = var_3;
-                                       c.B = var_1;
-                               }else if ( var_i == 1.0 ) { c.R = var_2 ; c.G = v     ; c.B = var_1; }
-                               else if ( var_i == 2 ) { c.R = var_1 ; c.G = v     ; c.B = var_3; }
-                               else if ( var_i == 3 ) { c.R = var_1 ; c.G = var_2 ; c.B = v;     }
-                               else if ( var_i == 4 ) { c.R = var_3 ; c.G = var_1 ; c.B = v;    }
-                               else                   { c.R = v     ; c.G = var_1 ; c.B = var_2; }
-                       }
-
-                       SelectedColor = new SolidColor (c);
-
-                       NotifyValueChanged ("R", R);
-                       NotifyValueChanged ("G", G);
-                       NotifyValueChanged ("B", B);
-                       NotifyValueChanged ("A", A);
-               }
+//             virtual protected void updateColorFromPicking(bool redraw = true){
+//                     SelectedColor = new SolidColor(getPixelAt(mousePos.X, mousePos.Y));
+//
+//                     updateHSV ();
+//
+//                     NotifyValueChanged ("R", R);
+//                     NotifyValueChanged ("G", G);
+//                     NotifyValueChanged ("B", B);
+//                     NotifyValueChanged ("A", A);
+//
+//                     if (redraw)
+//                             RegisterForRedraw ();
+//             }
+//
+//             protected Color getPixelAt(int x, int y){
+//                     if (bmp == null)
+//                             return Color.Transparent;
+//
+//                     int ptr = y * Slot.Width * 4 + x * 4;
+//
+//                     return new Color(
+//                             (double)bmp[ptr + 2] * colDiv,
+//                             (double)bmp[ptr + 1] * colDiv,
+//                             (double)bmp[ptr] * colDiv,
+//                             (double)bmp[ptr + 3] * colDiv);
+//             }
        }
 }
 
index 0ec92c107d4ad1a4728e5f04982a0e6672c83adb..b291c4c996fd47f8838d8908b7b8f8c734a84b88 100644 (file)
@@ -32,14 +32,32 @@ namespace Crow
                }
 
                Orientation _orientation;
+               double hue;
 
                [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)]
                public virtual Orientation Orientation
                {
                        get { return _orientation; }
-                       set { _orientation = value; }
+                       set {
+                               if (_orientation == value)
+                                       return;
+                               _orientation = value;
+                               NotifyValueChanged ("Orientation", _orientation);
+                               RegisterForGraphicUpdate ();
+                       }
                }
+               [XmlAttributeAttribute()]
+               public virtual double Hue {
+                       get { return hue; }
+                       set {
+                               if (hue == value)
+                                       return;
+                               hue = value;
 
+                               notifyHueChanged ();
+                               updateMousePosFromHue ();
+                       }
+               }
                protected override void onDraw (Cairo.Context gr)
                {
                        base.onDraw (gr);
@@ -90,6 +108,26 @@ namespace Crow
                        ctx.Stroke();
                        ctx.Restore ();
                }
+               protected override void updateMouseLocalPos (Point mPos)
+               {
+                       base.updateMouseLocalPos (mPos);
+                       if (Orientation == Orientation.Horizontal)
+                               hue = (double)mousePos.X / (double)ClientRectangle.Width;
+                       else
+                               hue = (double)mousePos.Y / (double)ClientRectangle.Height;
+                       notifyHueChanged ();
+               }
+               void updateMousePosFromHue(){
+                       if (Orientation == Orientation.Horizontal)
+                               mousePos.X = (int)Math.Floor(hue * (double)ClientRectangle.Width);
+                       else
+                               mousePos.Y = (int)Math.Floor(hue * (double)ClientRectangle.Height);
+                       CurrentInterface.EnqueueForRepaint (this);
+               }
+               void notifyHueChanged(){
+                       NotifyValueChanged ("Hue", hue);
+                       NotifyValueChanged ("HueColor", new SolidColor (Color.FromHSV (hue)));
+               }
        }
 }
 
index 8d6b4228aa7ba228dd5cec2ebe0d194fda6f3296..b8a5bafd32003756d7a298aad1408c7532c79eeb 100644 (file)
@@ -20,6 +20,7 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 using System;
 using Cairo;
+using System.Xml.Serialization;
 
 namespace Crow
 {
@@ -29,6 +30,33 @@ namespace Crow
                {
                }
 
+               double v, s;
+
+               [XmlAttributeAttribute()]
+               public virtual double V {
+                       get { return v; }
+                       set {
+                               if (v == value)
+                                       return;
+                               v = value;
+                               NotifyValueChanged ("V", v);
+                               mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height);
+
+                               CurrentInterface.EnqueueForRepaint (this);
+                       }
+               }
+               [XmlAttributeAttribute()]
+               public virtual double S {
+                       get { return s; }
+                       set {
+                               if (s == value)
+                                       return;
+                               s = value;
+                               NotifyValueChanged ("S", s);
+                               mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width);
+                               CurrentInterface.EnqueueForRepaint (this);
+                       }
+               }
                protected override void onDraw (Cairo.Context gr)
                {
                        base.onDraw (gr);
@@ -53,9 +81,8 @@ namespace Crow
                        grad.SetAsSource (gr, rGrad);
                        CairoHelpers.CairoRectangle (gr, r, CornerRadius);
                        gr.Fill();
-
-                       updateColorFromPicking (false);
                }
+
                public override void Paint (ref Context ctx)
                {
                        base.Paint (ref ctx);
@@ -72,6 +99,17 @@ namespace Crow
 
                        ctx.Restore ();
                }
+
+               protected override void updateMouseLocalPos (Point mPos)
+               {
+                       base.updateMouseLocalPos (mPos);
+
+                       Rectangle cb = ClientRectangle;
+                       s = (double)mousePos.X / (double)cb.Width;
+                       v = 1.0 - (double)mousePos.Y / (double)cb.Height;
+                       NotifyValueChanged ("S", s);
+                       NotifyValueChanged ("V", v);
+               }
        }
 }