diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-01-20 06:35:36 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-01-20 06:35:36 +0100 |
| commit | 33d043a799a4dc1e57eabd8999bddbf0543f0fbc (patch) | |
| tree | 144a98401c858cf12e1d5ad6cf9165bcda88c360 | |
| parent | 4a7050f54b5da5bbf813ea1fd5329f567930d65c (diff) | |
debug ColorPicker
| -rw-r--r-- | Default.style | 6 | ||||
| -rwxr-xr-x | Templates/ColorPicker.template | 17 | ||||
| -rw-r--r-- | src/GraphicObjects/ColorSelector.cs | 30 | ||||
| -rw-r--r-- | src/GraphicObjects/HueSelector.cs | 12 | ||||
| -rw-r--r-- | src/GraphicObjects/SaturationValueSelector.cs | 15 |
5 files changed, 29 insertions, 51 deletions
diff --git a/Default.style b/Default.style index dc8abd86..af54c62a 100644 --- a/Default.style +++ b/Default.style @@ -91,6 +91,12 @@ Control { Margin=0; Spacing=3; } +SaturationValueSelector { + Foreground=Red; +} +HueSelector { + ClipToClientRect=False; +} ColorSpinner { Minimum = 0; Maximum = 255; diff --git a/Templates/ColorPicker.template b/Templates/ColorPicker.template index 4c1e1280..f8dec90b 100755 --- a/Templates/ColorPicker.template +++ b/Templates/ColorPicker.template @@ -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"/> diff --git a/src/GraphicObjects/ColorSelector.cs b/src/GraphicObjects/ColorSelector.cs index 13a588ce..672eea73 100644 --- a/src/GraphicObjects/ColorSelector.cs +++ b/src/GraphicObjects/ColorSelector.cs @@ -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); -// } } } diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs index ec0a6f2c..ba1d856b 100644 --- a/src/GraphicObjects/HueSelector.cs +++ b/src/GraphicObjects/HueSelector.cs @@ -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); diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs index b71fa7ef..a1ddc5b4 100644 --- a/src/GraphicObjects/SaturationValueSelector.cs +++ b/src/GraphicObjects/SaturationValueSelector.cs @@ -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) { |