]> O.S.I.I.S - jp/crow.git/commitdiff
debug ColorPicker
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 20 Jan 2017 05:35:36 +0000 (06:35 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 20 Jan 2017 05:35:36 +0000 (06:35 +0100)
Default.style
Templates/ColorPicker.template
src/GraphicObjects/ColorSelector.cs
src/GraphicObjects/HueSelector.cs
src/GraphicObjects/SaturationValueSelector.cs

index dc8abd8651d3d0d6099f53c478e4f37fdb4fd59e..af54c62aa0c8e58c5b6306730bd8189193871252 100644 (file)
@@ -91,6 +91,12 @@ Control {
        Margin=0;
        Spacing=3;
 }
+SaturationValueSelector {
+       Foreground=Red;
+}
+HueSelector {
+       ClipToClientRect=False;
+}
 ColorSpinner {
        Minimum = 0;
        Maximum = 255;
index 4c1e1280452544f0554449f491b41ef5e5940b97..f8dec90be324adebf932d88b5c608b4f5586f6e6 100755 (executable)
@@ -2,19 +2,16 @@
 <Border Background="{./Background}"    Foreground="{./Foreground}"
                CornerRadius="{./CornerRadius}" BorderWidth="1">
                <HorizontalStack Spacing="0">
-                       <VerticalStack Margin="10">
+                       <VerticalStack Margin="4">
                                <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"/>
+                                       Width="120" Height="120"/>
+                               <HueSelector Hue="{²./H}" Focusable="true" Name="hueSelector" Margin="0" Width="120" Height="20"/>
                        </VerticalStack>
-                       <VerticalStack Margin="5" Height="Stretched">
-                               <HorizontalStack Height="Fit" Width="Stretched">
-                                       <GraphicObject Width="40" Height="30" Background="{./SelectedColor}"/>
-                                       <VerticalStack Margin="2">
-                                               <Label Focusable="true" Selectable="true" Width="Stretched" Text="{./SelectedColor}" />
-                                               <Label Focusable="true" Selectable="true" Width="Stretched" Text="{./HexColor}" />
-                                       </VerticalStack>
+                       <VerticalStack Margin="4" Height="Stretched">
+                               <HorizontalStack Height="Fit" Width="Stretched" Spacing="4">
+                                       <GraphicObject Width="34" Height="21" Background="{./SelectedColor}"/>
+                                       <Label Focusable="true" Selectable="true" Width="Stretched" Text="{./HexColor}" />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
                                        <Label Text="Red:" Width="40"/>
index 13a588ce43093d19a8f9ede9a1fb4796fd51153a..672eea735f5a88d6fbfaf776642fbcff81f501e2 100644 (file)
@@ -54,36 +54,10 @@ namespace Crow
                        mousePos = mPos - r.Position;
 
                        mousePos.X = Math.Max(cb.X, mousePos.X);
-                       mousePos.X = Math.Min(cb.Right-1, mousePos.X);
+                       mousePos.X = Math.Min(cb.Right, mousePos.X);
                        mousePos.Y = Math.Max(cb.Y, mousePos.Y);
-                       mousePos.Y = Math.Min(cb.Bottom-1, mousePos.Y);
+                       mousePos.Y = Math.Min(cb.Bottom, 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);
-//             }
        }
 }
 
index ec0a6f2ca4f2eb60a26a934652cfcd9c14417a89..ba1d856beda8fe4abbe7a6505aba86f31c25df1a 100644 (file)
@@ -53,9 +53,9 @@ namespace Crow
                                if (hue == value)
                                        return;
                                hue = value;
-
                                notifyHueChanged ();
                                updateMousePosFromHue ();
+                               RegisterForRedraw ();
                        }
                }
                protected override void onDraw (Cairo.Context gr)
@@ -95,11 +95,11 @@ namespace Crow
                        ctx.SetSourceColor (Color.White);
                        Rectangle r = ClientRectangle;
                        if (Orientation == Orientation.Horizontal) {
-                               r.Width = 5;
-                               r.X = mousePos.X;
+                               r.Width = 4;
+                               r.X = mousePos.X - 2;
                        } else {
-                               r.Height = 5;
-                               r.Y = mousePos.Y;
+                               r.Height = 4;
+                               r.Y = mousePos.Y - 2;
                        }
 
                        CairoHelpers.CairoRectangle (ctx, r, 2);
@@ -126,13 +126,13 @@ namespace Crow
                        else
                                hue = (double)mousePos.Y / (double)ClientRectangle.Height;
                        notifyHueChanged ();
+                       RegisterForRedraw ();
                }
                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);
index b71fa7ef8dc4fae19fe77beed7a37e292ff8cd68..a1ddc5b4c020092842e0b93a2025044ee4d3de64 100644 (file)
@@ -42,7 +42,7 @@ namespace Crow
                                NotifyValueChanged ("V", v);
                                mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height);
 
-                               CurrentInterface.EnqueueForRepaint (this);
+                               RegisterForRedraw ();
                        }
                }
                [XmlAttributeAttribute()]
@@ -54,7 +54,8 @@ namespace Crow
                                s = value;
                                NotifyValueChanged ("S", s);
                                mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width);
-                               CurrentInterface.EnqueueForRepaint (this);
+
+                               RegisterForRedraw ();
                        }
                }
                protected override void onDraw (Cairo.Context gr)
@@ -62,8 +63,6 @@ namespace Crow
                        base.onDraw (gr);
 
                        Rectangle r = ClientRectangle;
-                       Rectangle rGrad = r;
-                       rGrad.Inflate (-1);
 
                        if (Foreground != null) {//TODO:test if null should be removed
                                Foreground.SetAsSource (gr, r);
@@ -74,13 +73,13 @@ namespace Crow
                        Crow.Gradient grad = new Gradient (Gradient.Type.Horizontal);
                        grad.Stops.Add (new Gradient.ColorStop (0, new Color (1, 1, 1, 1)));
                        grad.Stops.Add (new Gradient.ColorStop (1, new Color (1, 1, 1, 0)));
-                       grad.SetAsSource (gr, rGrad);
+                       grad.SetAsSource (gr, r);
                        CairoHelpers.CairoRectangle (gr, r, CornerRadius);
                        gr.Fill();
                        grad = new Gradient (Gradient.Type.Vertical);
                        grad.Stops.Add (new Gradient.ColorStop (0, new Color (0, 0, 0, 0)));
                        grad.Stops.Add (new Gradient.ColorStop (1, new Color (0, 0, 0, 1)));
-                       grad.SetAsSource (gr, rGrad);
+                       grad.SetAsSource (gr, r);
                        CairoHelpers.CairoRectangle (gr, r, CornerRadius);
                        gr.Fill();
                }
@@ -95,7 +94,7 @@ namespace Crow
                        ctx.Translate (rb.X, rb.Y);
 
                        ctx.SetSourceColor (Color.White);
-                       ctx.Arc (mousePos.X, mousePos.Y, 3.0, 0, Math.PI * 2.0);
+                       ctx.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0);
                        ctx.LineWidth = 1.0;
                        ctx.Stroke ();
 
@@ -111,6 +110,8 @@ namespace Crow
                        v = 1.0 - (double)mousePos.Y / (double)cb.Height;
                        NotifyValueChanged ("S", s);
                        NotifyValueChanged ("V", v);
+
+                       RegisterForRedraw ();
                }
                public override void OnLayoutChanges (LayoutingType layoutType)
                {