From: Jean-Philippe Bruyère Date: Sat, 31 Mar 2018 10:25:56 +0000 (+0200) Subject: convert hsv to integer in color picker X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=135ced0e0a94ae759fba5fec7c0f35ec9be28231;p=jp%2Fcrow.git convert hsv to integer in color picker --- diff --git a/Default.style b/Default.style index 5b36bc2d..0fa3d8d9 100644 --- a/Default.style +++ b/Default.style @@ -178,6 +178,7 @@ HSVSpinner { Minimum = "0"; Maximum = "1"; SmallIncrement = "0.01"; + Decimals = "-1"; } TxtInFileDialog { Margine = "1"; diff --git a/Templates/ColorPicker.template b/Templates/ColorPicker.template index 71965850..8cf05ead 100755 --- a/Templates/ColorPicker.template +++ b/Templates/ColorPicker.template @@ -29,15 +29,15 @@ diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index 6883360d..0684f912 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -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 (); diff --git a/Tests/Interfaces/Divers/colorPicker.crow b/Tests/Interfaces/Divers/colorPicker.crow index fdfd8f3c..8427ded5 100755 --- a/Tests/Interfaces/Divers/colorPicker.crow +++ b/Tests/Interfaces/Divers/colorPicker.crow @@ -1,7 +1,7 @@  - + \ No newline at end of file diff --git a/src/GraphicObjects/ColorPicker.cs b/src/GraphicObjects/ColorPicker.cs index cc955191..dd65e986 100644 --- a/src/GraphicObjects/ColorPicker.cs +++ b/src/GraphicObjects/ColorPicker.cs @@ -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 (); } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index cbcbe7cc..504af1f5 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -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) diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs index 67f4ec6e..6c104d01 100644 --- a/src/GraphicObjects/HueSelector.cs +++ b/src/GraphicObjects/HueSelector.cs @@ -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))); } } diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index f0eda90f..0c513067 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -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(); diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs index 485a33d2..42958b42 100644 --- a/src/GraphicObjects/SaturationValueSelector.cs +++ b/src/GraphicObjects/SaturationValueSelector.cs @@ -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 (); }