From 829d1de43b5a9b39ace2f01eeecae5255f01ed1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 7 Feb 2018 21:48:11 +0100 Subject: [PATCH] shape widget scrollbar improvments debug:perform mousemove event if mouseup had active widget. --- Crow.csproj | 1 + Default.style | 13 ++ Templates/FileDialog.template | 2 + Templates/ScrollBar.template | 15 +-- Templates/ScrollingListBox.template | 3 +- Templates/TreeView.template | 2 + Tests/Interfaces/Divers/testShape.crow | 6 + Tests/Tests.csproj | 3 + Tests/ui/showcase.crow | 2 + src/GraphicObjects/ScrollBar.cs | 12 ++ src/GraphicObjects/Scroller.cs | 13 ++ src/GraphicObjects/Shape.cs | 164 +++++++++++++++++++++++++ src/GraphicObjects/Slider.cs | 7 +- src/Interface.cs | 4 + 14 files changed, 236 insertions(+), 11 deletions(-) create mode 100644 Tests/Interfaces/Divers/testShape.crow create mode 100644 src/GraphicObjects/Shape.cs diff --git a/Crow.csproj b/Crow.csproj index c45642b5..90cc4495 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -212,6 +212,7 @@ + diff --git a/Default.style b/Default.style index 98c10255..b0cbbb82 100644 --- a/Default.style +++ b/Default.style @@ -146,4 +146,17 @@ CheckBoxAlt { Background = Transparent; Checked={Background=DarkSlateGray;Foreground=LightGray;}; Unchecked = {Background=Transparent;Foreground=DimGray;}; +} + +ArrowBut { + MouseRepeat=true; + Height=Fit; + Width=Fit; + Focusable=true; + Foreground=Jet; + Background=hgradient|0:Gray|1:Jet; + MouseDown={Background=hgradient|0:White|0.2:BlueCrayola|1:Jet}; + MouseUp={Background=hgradient|0:Gray|1:Jet}; + MouseEnter={Foreground=Black}; + MouseLeave={Foreground=Jet}; } \ No newline at end of file diff --git a/Templates/FileDialog.template b/Templates/FileDialog.template index 62a7dc6d..d9f93ed4 100644 --- a/Templates/FileDialog.template +++ b/Templates/FileDialog.template @@ -38,6 +38,8 @@ Name="ItemsContainer" Margin="0" Spacing="1"/> diff --git a/Templates/ScrollBar.template b/Templates/ScrollBar.template index f64b6c8e..c2b9a1ba 100755 --- a/Templates/ScrollBar.template +++ b/Templates/ScrollBar.template @@ -1,21 +1,18 @@ - + - + - + \ No newline at end of file diff --git a/Templates/ScrollingListBox.template b/Templates/ScrollingListBox.template index f294aea6..56b08c03 100644 --- a/Templates/ScrollingListBox.template +++ b/Templates/ScrollingListBox.template @@ -6,7 +6,8 @@ - diff --git a/Templates/TreeView.template b/Templates/TreeView.template index c29e34c5..a1d9bc72 100644 --- a/Templates/TreeView.template +++ b/Templates/TreeView.template @@ -8,6 +8,8 @@ diff --git a/Tests/Interfaces/Divers/testShape.crow b/Tests/Interfaces/Divers/testShape.crow new file mode 100644 index 00000000..61501b5a --- /dev/null +++ b/Tests/Interfaces/Divers/testShape.crow @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index ef4500a1..8096d9a8 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -341,6 +341,9 @@ + + PreserveNewest + diff --git a/Tests/ui/showcase.crow b/Tests/ui/showcase.crow index 24b038d6..20353e33 100755 --- a/Tests/ui/showcase.crow +++ b/Tests/ui/showcase.crow @@ -14,6 +14,8 @@ Font="Courriernew 10"/> diff --git a/src/GraphicObjects/ScrollBar.cs b/src/GraphicObjects/ScrollBar.cs index 31ff7acf..5dac20e1 100644 --- a/src/GraphicObjects/ScrollBar.cs +++ b/src/GraphicObjects/ScrollBar.cs @@ -38,6 +38,7 @@ namespace Crow //TODO:could be replaced by a template for a Slider Orientation _orientation; + int _cursorSize; #region CTOR protected ScrollBar () : base(){} @@ -56,6 +57,17 @@ namespace Crow RegisterForGraphicUpdate (); } } + [XmlAttributeAttribute()][DefaultValue(20)] + public virtual int CursorSize { + get { return _cursorSize; } + set { + if (_cursorSize == value) + return; + _cursorSize = value; + RegisterForGraphicUpdate (); + NotifyValueChanged ("CursorSize", _cursorSize); + } + } public void onScrollBack (object sender, MouseButtonEventArgs e) { Value -= SmallIncrement; diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 8dfed1eb..ec3bc47d 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -136,6 +136,15 @@ namespace Crow base.OnLayoutChanges (layoutType); NotifyValueChanged("MaximumScroll", MaximumScroll); + if (layoutType == LayoutingType.Height) { + NotifyValueChanged ("PageHeight", Slot.Height); + if (child?.Slot.Height > 0) + NotifyValueChanged ("ChildHeightRatio", Slot.Height * Slot.Height / child.Slot.Height); + } else { + NotifyValueChanged ("PageWidth", Slot.Width); + if (child?.Slot.Width > 0) + NotifyValueChanged ("ChildWidthRatio", Slot.Width * Slot.Width / child.Slot.Width); + } } void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { @@ -149,6 +158,8 @@ namespace Crow ScrollY = maxScroll; } NotifyValueChanged("MaximumScroll", maxScroll); + if (child?.Slot.Height > 0) + NotifyValueChanged ("ChildHeightRatio", Slot.Height * Slot.Height / child.Slot.Height); } } else if (arg.LayoutType == LayoutingType.Width) { if (maxScroll < ScrollX) { @@ -156,6 +167,8 @@ namespace Crow ScrollX = maxScroll; } NotifyValueChanged("MaximumScroll", maxScroll); + if (child?.Slot.Width > 0) + NotifyValueChanged ("ChildWidthRatio", Slot.Width * Slot.Width / child.Slot.Width); } } void onChildListCleared(object sender, EventArgs e){ diff --git a/src/GraphicObjects/Shape.cs b/src/GraphicObjects/Shape.cs new file mode 100644 index 00000000..a4b3193e --- /dev/null +++ b/src/GraphicObjects/Shape.cs @@ -0,0 +1,164 @@ +// +// Shape.cs +// +// Author: +// jp <> +// +// Copyright (c) 2013-2017 Jean-Philippe Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Xml.Serialization; +using System.ComponentModel; +using System.IO; +using System.Text; +using Cairo; + +namespace Crow +{ + public class PathParser : StringReader + { + public PathParser (string str) : base (str) {} + + public double ReadDouble () { + StringBuilder tmp = new StringBuilder(); + + while (Peek () >= 0) { + char c = (char)Read(); + if (c.IsWhiteSpaceOrNewLine()) { + if (tmp.Length == 0) + continue; + else + break; + } else if (c == ',') + break; + tmp.Append (c); + } + return double.Parse (tmp.ToString ()); + } + + } + public class Shape : GraphicObject + { + #region CTOR + protected Shape () : base() {} + public Shape (Interface iface) : base (iface) {} + #endregion + + string path; + double strokeWidth; + + public string Path { + get { return path; } + set { + if (path == value) + return; + path = value; + contentSize = default (Size); + NotifyValueChanged ("Path", path); + RegisterForGraphicUpdate (); + } + } + [XmlAttributeAttribute][DefaultValue(1.0)] + public double StokeWidth { + get { return strokeWidth; } + set { + if (strokeWidth == value) + return; + strokeWidth = value; + contentSize = default (Size); + NotifyValueChanged ("StrokeWidth", strokeWidth); + RegisterForGraphicUpdate (); + } + } + + protected override void onDraw (Context gr) + { + + if (string.IsNullOrEmpty (path)) + return; + + Rectangle r = ClientRectangle; + + executePath (gr); + + Background.SetAsSource (gr, r); + gr.FillPreserve (); + gr.LineWidth = strokeWidth; + Foreground.SetAsSource (gr, r); + gr.Stroke (); + } + + void executePath (Context gr){ + using (PathParser sr = new PathParser (path)) { + while (sr.Peek () >= 0) { + char c = (char)sr.Read (); + if (c.IsWhiteSpaceOrNewLine ()) + continue; + switch (c) { + case 'M': + gr.MoveTo (sr.ReadDouble (), sr.ReadDouble ()); + break; + case 'm': + gr.RelMoveTo (sr.ReadDouble (), sr.ReadDouble ()); + break; + case 'L': + gr.LineTo (sr.ReadDouble (), sr.ReadDouble ()); + break; + case 'l': + gr.RelLineTo (sr.ReadDouble (), sr.ReadDouble ()); + break; + case 'C': + gr.CurveTo (sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble ()); + break; + case 'c': + gr.RelCurveTo (sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble ()); + break; + case 'Z': + gr.ClosePath (); + break; + case 'F': + gr.Fill (); + break; + case 'G': + gr.Stroke (); + break; + default: + throw new Exception ("Invalid character in path string of Shape control"); + } + } + } + } + protected override int measureRawSize (LayoutingType lt) + { + if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) { + using (Surface drawing = new ImageSurface (Format.A1, 1,1)) { + using (Context ctx = new Context (drawing)) { + executePath (ctx); + Rectangle r = ctx.StrokeExtents (); + contentSize = new Size (r.Right, r.Bottom); + } + } + } + return lt == LayoutingType.Width ? + contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; + } + } +} + diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index a664f4e7..2e4a5fef 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -83,7 +83,7 @@ namespace Crow public virtual int CursorSize { get { return _cursorSize; } set { - if (_cursorSize == value) + if (_cursorSize == value || value < 8) return; _cursorSize = value; RegisterForGraphicUpdate (); @@ -132,9 +132,14 @@ namespace Crow if (_orientation == Orientation.Horizontal) { pStart = r.TopLeft + new Point (_cursorSize / 2, r.Height / 2); pEnd = r.TopRight + new Point (-_cursorSize / 2, r.Height / 2); + pStart.Y += 0.5; + pEnd.Y += 0.5; } else { pStart = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2); pEnd = r.BottomLeft + new Point (r.Width / 2,- _cursorSize / 2); + pStart.X += 0.5; + pEnd.X += 0.5; + } DrawGraduations (gr, pStart,pEnd); diff --git a/src/Interface.cs b/src/Interface.cs index 7ea61287..ab78e42d 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -848,7 +848,11 @@ namespace Crow } _activeWidget.onMouseUp (_activeWidget, e); + GraphicObject lastActive = _activeWidget; ActiveWidget = null; + if (!lastActive.MouseIsIn (Mouse.Position)) { + ProcessMouseMove (Mouse.X, Mouse.Y); + } return true; } /// -- 2.47.3