]> O.S.I.I.S - jp/crow.git/commitdiff
convert hsv to integer in color picker IFaceByParenting
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 31 Mar 2018 10:25:56 +0000 (12:25 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 31 Mar 2018 10:25:56 +0000 (12:25 +0200)
Default.style
Templates/ColorPicker.template
Tests/BasicTests.cs
Tests/Interfaces/Divers/colorPicker.crow
src/GraphicObjects/ColorPicker.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/HueSelector.cs
src/GraphicObjects/NumericControl.cs
src/GraphicObjects/SaturationValueSelector.cs

index 5b36bc2d9275d1d4629191d1052571d2f53a78c8..0fa3d8d93f0c415c56972316aa5e54b0fa6b8cf4 100644 (file)
@@ -178,6 +178,7 @@ HSVSpinner {
        Minimum = "0";
        Maximum = "1";
        SmallIncrement = "0.01";
+       Decimals = "-1";
 }
 TxtInFileDialog {
        Margine = "1";
index 71965850e5f87cee0a1abb7763a050763db21afb..8cf05ead9d6dd66460c182c0aecd86bb210db51c 100755 (executable)
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="H" Width="Fit"/>
-                                       <Spinner Style="HSVSpinner" Value="{²./H}" Width="40"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./H}" Width="40"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="S" Width="Fit"/>
-                                       <Spinner Style="HSVSpinner" Value="{²./S}" Width="40"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./S}" Width="40"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="V" Width="Fit"/>
-                                       <Spinner Style="HSVSpinner" Value="{²./V}" Width="40"  />
+                                       <Spinner Style="ColorSpinner" Value="{²./V}" Width="40"  />
                                </HorizontalStack>
                        </VerticalStack>
                </HorizontalStack>
index 6883360d90a07941006d3fe74bcc299330e58c38..0684f91274df250cad753cbbe2ad9e2fb140f1d3 100644 (file)
@@ -197,9 +197,9 @@ namespace Tests
                        //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
                        //testFiles = new string [] { @"Interfaces/Divers/0.crow" };
                        //testFiles = new string [] { @"Interfaces/Divers/testIMLContainer.crow" };
-                       testFiles = new string [] { @"Interfaces/TemplatedContainer/testTabView.crow" };
+                       //testFiles = new string [] { @"Interfaces/TemplatedContainer/testTabView.crow" };
                        //testFiles = new string [] { @"Interfaces/TemplatedContainer/testTreeView.crow" };
-                       //testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
+                       testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
 //                     testFiles = new string[] { @"Interfaces/TemplatedControl/testItemTemplateTag.crow" };
 
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
index fdfd8f3c1fa56d9b398796edd32a57b109dd7966..8427ded5f11d3c77ab1e638054d0cdfe07522f97 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <VerticalStack>
        <ColorPicker SelectedColor="{²../go.Background}" Name="colorPicker" Background="DimGray" Margin="5" Fit="True" />
-       <GraphicObject Name="go" Width="100" Height="60" Background="DarkBlue"/>
+       <GraphicObject Name="go" Width="100" Height="60" Background="Yellow"/>
        <GraphicObject Name="go" Width="100" Height="60" Background="{../colorPicker.SelectedColor}"/>
        <Label Text="{../colorPicker.SelectedColor}"/>
 </VerticalStack>
\ No newline at end of file
index cc955191f542e9cf08d86c6835a0a53392933317..dd65e986d553136db0e4c9c9b8fee70c0d40db0a 100644 (file)
@@ -46,7 +46,6 @@ namespace Crow
                Color curColor;
                double h,s,v;
 
-               [XmlAttributeAttribute()]
                public virtual double R {
                        get { return Math.Round(curColor.R * div); }
                        set {
@@ -58,7 +57,6 @@ namespace Crow
                                notifyCurColorHasChanged ();
                        }
                }
-               [XmlAttributeAttribute()]
                public virtual double G {
                        get { return Math.Round(curColor.G * div); }
                        set {
@@ -70,7 +68,6 @@ namespace Crow
                                hsvFromRGB ();
                        }
                }
-               [XmlAttributeAttribute()]
                public virtual double B {
                        get { return Math.Round(curColor.B * div); }
                        set {
@@ -82,7 +79,6 @@ namespace Crow
                                hsvFromRGB ();
                        }
                }
-               [XmlAttributeAttribute()]
                public virtual double A {
                        get { return Math.Round(curColor.A * div); }
                        set {
@@ -94,41 +90,36 @@ namespace Crow
                                hsvFromRGB ();
                        }
                }
-               [XmlAttributeAttribute()]
                public virtual double H {
-                       get { return Math.Round (h, 3); }
+                       get { return Math.Round(h * div); }
                        set {
                                if (H == value)
                                        return;
-                               h = value;
+                               h = value * colDiv;
                                NotifyValueChanged ("H", H);
                                rgbFromHSV ();
                        }
                }
-               [XmlAttributeAttribute()]
                public virtual double S {
-                       get { return Math.Round (s, 2); }
+                       get { return Math.Round(s * div); }
                        set {
-                               if (s == value)
+                               if (S == value)
                                        return;
-                               s = value;
+                               s = value * colDiv;
                                NotifyValueChanged ("S", S);
                                rgbFromHSV ();
                        }
                }
-               [XmlAttributeAttribute()]
                public virtual double V {
-                       get { return Math.Round (v, 2); }
+                       get { return Math.Round(v * div); }
                        set {
-                               if (v == value)
+                               if (V == value)
                                        return;
-                               v = value;
+                               v = value * colDiv;
                                NotifyValueChanged ("V", V);
                                rgbFromHSV ();
                        }
                }
-
-               [XmlAttributeAttribute]
                public virtual Fill SelectedColor {
                        get { return new SolidColor(curColor); }
                        set {
@@ -145,7 +136,6 @@ namespace Crow
                                hsvFromRGB ();
                        }
                }
-               [XmlAttributeAttribute]
                public virtual Color SelectedRawColor {
                        get { return curColor; }
                        set {
@@ -219,7 +209,7 @@ namespace Crow
                        notifyHSVHasChanged ();
                }
                void rgbFromHSV(){
-                       curColor = Color.FromHSV (h, v, s, curColor.A);
+                       curColor = Color.FromHSV (h , v, s, curColor.A);
                        notifyCurColorHasChanged ();
                        notifyRGBAHasChanged ();
                }
index cbcbe7ccee83eb07bbfc4b4555d846bbd2a9a550..504af1f56ba0768218fd725b60cfb9f308cc0e1e 100644 (file)
@@ -518,7 +518,7 @@ namespace Crow
                [DesignCategory ("Divers")]
                public virtual string Name {
                        get {                           
-                               return string.IsNullOrEmpty(name) ? design_id : name;
+                               return string.IsNullOrEmpty(name) ? this.GetType().Name + design_id : name;
                        }
                        set {
                                if (Name == value)
index 67f4ec6ee0b8a0c0381e4f97aec02c1a274a72e6..6c104d01d9799b9f2016c139af16e3bf05ff4342 100644 (file)
@@ -43,6 +43,8 @@ namespace Crow
 
                Orientation _orientation;
                double hue;
+               const double div = 255.0;
+               const double colDiv = 1.0 / div;
 
                [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)]
                public virtual Orientation Orientation
@@ -58,11 +60,11 @@ namespace Crow
                }
                [XmlAttributeAttribute()]
                public virtual double Hue {
-                       get { return hue; }
+                       get { return Math.Round(hue * div); }
                        set {
-                               if (hue == value)
+                               if (Hue == value)
                                        return;
-                               hue = value;
+                               hue = value * colDiv;
                                notifyHueChanged ();
                                updateMousePosFromHue ();
                                RegisterForRedraw ();
@@ -147,7 +149,7 @@ namespace Crow
                                mousePos.Y = (int)Math.Floor(hue * (double)ClientRectangle.Height);
                }
                void notifyHueChanged(){
-                       NotifyValueChanged ("Hue", hue);
+                       NotifyValueChanged ("Hue", Hue);
                        NotifyValueChanged ("HueColor", new SolidColor (Color.FromHSV (hue)));
                }
        }
index f0eda90f550e58b7e5ef0de576a00fdf4d3990ff..0c5130671b861d786ee1440a12eb9191f5769157 100644 (file)
@@ -129,7 +129,8 @@ namespace Crow
                                else                    
                                        _actualValue = value;
 
-                               _actualValue = Math.Round (_actualValue, _decimals);
+                               if (_decimals >= 0)
+                                       _actualValue = Math.Round (_actualValue, _decimals);
 
                                NotifyValueChanged("Value",  _actualValue);
                                RegisterForGraphicUpdate();
index 485a33d2e027615e971bc4da3f22fecba21bfc36..42958b42479fc46c064f1ee4c3eb781d12fe4ab0 100644 (file)
@@ -38,16 +38,18 @@ namespace Crow
                {
                }
 
+               const double div = 255.0;
+               const double colDiv = 1.0 / div;
                double v, s;
 
                [XmlAttributeAttribute()]
                public virtual double V {
-                       get { return v; }
+                       get { return Math.Round(v * div); }
                        set {
-                               if (v == value)
+                               if (S == value)
                                        return;
-                               v = value;
-                               NotifyValueChanged ("V", v);
+                               v = value * colDiv;
+                               NotifyValueChanged ("V", V);
                                mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height);
 
                                RegisterForRedraw ();
@@ -55,12 +57,12 @@ namespace Crow
                }
                [XmlAttributeAttribute()]
                public virtual double S {
-                       get { return s; }
+                       get { return Math.Round(s * div); }
                        set {
-                               if (s == value)
+                               if (S == value)
                                        return;
-                               s = value;
-                               NotifyValueChanged ("S", s);
+                               s = value * colDiv;
+                               NotifyValueChanged ("S", S);
                                mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width);
 
                                RegisterForRedraw ();
@@ -121,8 +123,8 @@ namespace Crow
                        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);
+                       NotifyValueChanged ("S", S);
+                       NotifyValueChanged ("V", V);
 
                        RegisterForRedraw ();
                }