aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-07 21:48:11 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-07 21:48:11 +0100
commit829d1de43b5a9b39ace2f01eeecae5255f01ed1f (patch)
treeca31b0f727b3c91adbab7a235bd1737ebc22a3ab /src
parent2937dc695a03c6359494a0f1a9224766b6d1aa04 (diff)
shape widget
scrollbar improvments debug:perform mousemove event if mouseup had active widget.
Diffstat (limited to 'src')
-rw-r--r--src/GraphicObjects/ScrollBar.cs12
-rw-r--r--src/GraphicObjects/Scroller.cs13
-rw-r--r--src/GraphicObjects/Shape.cs164
-rw-r--r--src/GraphicObjects/Slider.cs7
-rw-r--r--src/Interface.cs4
5 files changed, 199 insertions, 1 deletions
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;
}
/// <summary>