diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-11-05 23:02:49 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-11-05 23:02:49 +0100 |
| commit | 5185d70ddd14728576bafdfea267981baed88d84 (patch) | |
| tree | 28ecf610198dc524f927f953a952cbc7f1717498 /src | |
| parent | 8d59e42e78db11afaf9b2f6530403a12b1d1926c (diff) | |
| parent | 28788991d650bc8ba29b9c2817dbb757129977e5 (diff) | |
merge
Diffstat (limited to 'src')
26 files changed, 260 insertions, 142 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 752655f8..827ee617 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -76,7 +76,7 @@ namespace Crow internal static MethodInfo miDSChangeEmitHelper = typeof(Instantiator).GetMethod("dataSourceChangedEmitHelper", BindingFlags.Instance | BindingFlags.NonPublic); internal static MethodInfo miDSReverseBinding = typeof(Instantiator).GetMethod("dataSourceReverseBinding", BindingFlags.Static | BindingFlags.NonPublic); - internal static FieldInfo miSetCurIface = typeof(GraphicObject).GetField ("currentInterface", BindingFlags.Public | BindingFlags.Instance); + internal static FieldInfo miSetCurIface = typeof(GraphicObject).GetField ("currentInterface", BindingFlags.NonPublic | BindingFlags.Instance); internal static MethodInfo miFindByName = typeof (GraphicObject).GetMethod ("FindByName"); internal static MethodInfo miGetGObjItem = typeof(List<GraphicObject>).GetMethod("get_Item", new Type[] { typeof(Int32) }); internal static MethodInfo miLoadDefaultVals = typeof (GraphicObject).GetMethod ("loadDefaultValues"); @@ -295,18 +295,25 @@ namespace Crow else if (miDest.MemberType == MemberTypes.Field) destType =(miDest as FieldInfo).FieldType; - if (value != null) { - if (destType == TObject)//TODO: check that test of destType is not causing problems - convertedVal = value; - else { - origType = value.GetType (); - if (destType.IsAssignableFrom (origType)) - convertedVal = Convert.ChangeType (value, destType); - else if (origType.IsPrimitive & destType.IsPrimitive) - convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); - else - convertedVal = getImplicitOp (origType, destType).Invoke (value, null); + try { + if (value != null) { + if (destType == TObject)//TODO: check that test of destType is not causing problems + convertedVal = value; + else { + origType = value.GetType (); + if (destType.IsAssignableFrom (origType)) + convertedVal = Convert.ChangeType (value, destType); + else if (origType == typeof(string) & destType.IsPrimitive) + convertedVal = Convert.ChangeType(value, destType); + else if (origType.IsPrimitive & destType.IsPrimitive) + convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); + else + convertedVal = getImplicitOp (origType, destType).Invoke (value, null); + } } + } catch (Exception ex) { + Debug.WriteLine (ex.ToString ()); + return; } if (miDest.MemberType == MemberTypes.Property) diff --git a/src/CrowThread.cs b/src/CrowThread.cs index 823fe1a6..c3a4ba3b 100644 --- a/src/CrowThread.cs +++ b/src/CrowThread.cs @@ -41,15 +41,15 @@ namespace Crow thread = new Thread (start); thread.IsBackground = true; Host = host; - lock (Host.currentInterface.CrowThreads) - Host.currentInterface.CrowThreads.Add (this); + lock (Host.CurrentInterface.CrowThreads) + Host.CurrentInterface.CrowThreads.Add (this); } public void CheckState(){ if (thread.ThreadState != ThreadState.Stopped) return; Finished.Raise (Host, null); - lock (Host.currentInterface.CrowThreads) - Host.currentInterface.CrowThreads.Remove (this); + lock (Host.CurrentInterface.CrowThreads) + Host.CurrentInterface.CrowThreads.Remove (this); } public void Start() { thread.Start();} public void Cancel(){ @@ -57,8 +57,8 @@ namespace Crow cancelRequested = true; thread.Join (); } - lock (Host.currentInterface.CrowThreads) - Host.currentInterface.CrowThreads.Remove (this); + lock (Host.CurrentInterface.CrowThreads) + Host.CurrentInterface.CrowThreads.Remove (this); } } } diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index 1e502e9a..ef210b57 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -46,19 +46,19 @@ namespace Crow #region private fields int _borderWidth; BorderStyle _borderStyle; - Fill raiseColor = Color.Gray; + Fill raisedColor = Color.Gray; Fill sunkenColor = Color.Jet; #endregion #region public properties [XmlAttributeAttribute] - public virtual Fill RaiseColor { - get { return raiseColor; } + public virtual Fill RaisedColor { + get { return raisedColor; } set { - if (raiseColor == value) + if (raisedColor == value) return; - raiseColor = value; - NotifyValueChanged ("RaiseColor", raiseColor); + raisedColor = value; + NotifyValueChanged ("RaisedColor", raisedColor); RegisterForRedraw (); } } @@ -109,47 +109,62 @@ namespace Crow } protected override void onDraw (Cairo.Context gr) { + drawborder2 (gr); + + gr.Save (); + if (ClipToClientRect) { + //clip to client zone + CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin)); + gr.Clip (); + } + + if (child != null) + child.Paint (ref gr); + gr.Restore (); + } + void drawborder2(Cairo.Context gr){ Rectangle rBack = new Rectangle (Slot.Size); //rBack.Inflate (-Margin); -// if (BorderWidth > 0) -// rBack.Inflate (-BorderWidth / 2); + // if (BorderWidth > 0) + // rBack.Inflate (-BorderWidth / 2); Background.SetAsSource (gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill (); + if (BorderStyle == BorderStyle.Normal) { if (BorderWidth > 0) { Foreground.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); + CairoHelpers.CairoRectangle (gr, rBack, CornerRadius, BorderWidth); } - }else{ + } else { gr.LineWidth = 1.0; if (CornerRadius > 0.0) { double radius = CornerRadius; if ((radius > rBack.Height / 2.0) || (radius > rBack.Width / 2.0)) - radius = Math.Min(rBack.Height / 2.0, rBack.Width / 2.0); + radius = Math.Min (rBack.Height / 2.0, rBack.Width / 2.0); gr.SetSourceColor (sunkenColor); - gr.MoveTo(0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); - gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75); - gr.MoveTo(0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); - gr.LineTo(0.5 + rBack.Left, 0.5 + rBack.Top + radius); - gr.Arc (0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius, Math.PI , Math.PI*1.5); - gr.LineTo(-0.5 + rBack.Right - radius, 0.5 + rBack.Top); - gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, Math.PI*1.5 , Math.PI*1.75); - gr.Stroke(); + gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); + gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75); + gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); + gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Top + radius); + gr.Arc (0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius, Math.PI, Math.PI * 1.5); + gr.LineTo (-0.5 + rBack.Right - radius, 0.5 + rBack.Top); + gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, Math.PI * 1.5, Math.PI * 1.75); + gr.Stroke (); if (BorderStyle == BorderStyle.Raised) { - gr.MoveTo (-1.5 + rBack.Right , 1.5 + rBack.Top + radius); - gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius-1.0, 0, -Math.PI * 0.25); - gr.MoveTo (-1.5 + rBack.Right , 1.5 + rBack.Top + radius); - gr.LineTo (-1.5 + rBack.Right , -1.5 + rBack.Bottom - radius); - gr.Arc (-0.5 + rBack.Right -radius, -0.5 + rBack.Bottom - radius, radius-1.0, 0, Math.PI /2.0); + gr.MoveTo (-1.5 + rBack.Right, 1.5 + rBack.Top + radius); + gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, 0, -Math.PI * 0.25); + gr.MoveTo (-1.5 + rBack.Right, 1.5 + rBack.Top + radius); + gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom - radius); + gr.Arc (-0.5 + rBack.Right - radius, -0.5 + rBack.Bottom - radius, radius - 1.0, 0, Math.PI / 2.0); gr.LineTo (1.5 + rBack.Left + radius, -1.5 + rBack.Bottom); - gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius-1.0, Math.PI / 2.0, Math.PI*0.75 ); + gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI / 2.0, Math.PI * 0.75); gr.Stroke (); - gr.SetSourceColor (raiseColor); + gr.SetSourceColor (raisedColor); gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI, Math.PI * 0.75); gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); @@ -159,15 +174,15 @@ namespace Crow gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI * 1.5, Math.PI * 1.75); } else { gr.Stroke (); - gr.SetSourceColor (raiseColor); + gr.SetSourceColor (raisedColor); } - gr.MoveTo (-0.5 + rBack.Right , 0.5 + rBack.Top + radius); + gr.MoveTo (-0.5 + rBack.Right, 0.5 + rBack.Top + radius); gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, 0, -Math.PI * 0.25); - gr.MoveTo (-0.5 + rBack.Right , 0.5 + rBack.Top + radius); - gr.LineTo (-0.5 + rBack.Right , -0.5 + rBack.Bottom - radius); - gr.Arc (-0.5 + rBack.Right -radius, -0.5 + rBack.Bottom - radius, radius, 0, Math.PI /2.0); + gr.MoveTo (-0.5 + rBack.Right, 0.5 + rBack.Top + radius); + gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom - radius); + gr.Arc (-0.5 + rBack.Right - radius, -0.5 + rBack.Bottom - radius, radius, 0, Math.PI / 2.0); gr.LineTo (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom); - gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI*0.75 ); + gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI * 0.75); gr.Stroke (); } else { gr.SetSourceColor (sunkenColor); @@ -179,13 +194,13 @@ namespace Crow gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom); gr.LineTo (2.0 + rBack.Left, -1.5 + rBack.Bottom); gr.Stroke (); - gr.SetSourceColor (raiseColor); + gr.SetSourceColor (raisedColor); gr.MoveTo (1.5 + rBack.Left, -1.0 + rBack.Bottom); gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Y); gr.LineTo (rBack.Right, 1.5 + rBack.Y); } else { gr.Stroke (); - gr.SetSourceColor (raiseColor); + gr.SetSourceColor (raisedColor); } gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y); gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom); @@ -193,18 +208,45 @@ namespace Crow gr.Stroke (); } } + } + void drawborder1(Cairo.Context gr){ + Rectangle rBack = new Rectangle (Slot.Size); - gr.Save (); - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin)); - gr.Clip (); - } + //rBack.Inflate (-Margin); + // if (BorderWidth > 0) + // rBack.Inflate (-BorderWidth / 2); - if (child != null) - child.Paint (ref gr); - gr.Restore (); - } + Background.SetAsSource (gr, rBack); + CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); + gr.Fill (); + + double bw = _borderWidth; + double crad = CornerRadius; + + if (bw > 0) { + if (BorderStyle == BorderStyle.Normal) + Foreground.SetAsSource (gr, rBack); + else { + if (BorderStyle == BorderStyle.Sunken) + gr.SetSourceColor (raisedColor); + else + gr.SetSourceColor (sunkenColor); + + CairoHelpers.CairoRectangle (gr, rBack, crad, bw); + + if (BorderStyle == BorderStyle.Sunken) + gr.SetSourceColor (sunkenColor); + else + gr.SetSourceColor (raisedColor); + + bw /= 2.0; + rBack.Width -= (int)Math.Round(bw); + rBack.Height -= (int)Math.Round(bw); + } + + CairoHelpers.CairoRectangle (gr, rBack, crad, bw); + } + } #endregion } } diff --git a/src/GraphicObjects/ColorSelector.cs b/src/GraphicObjects/ColorSelector.cs index 596d332e..c9f3a198 100644 --- a/src/GraphicObjects/ColorSelector.cs +++ b/src/GraphicObjects/ColorSelector.cs @@ -43,7 +43,7 @@ namespace Crow public override void onMouseMove (object sender, MouseMoveEventArgs e) { base.onMouseMove (sender, e); - if (currentInterface.Mouse.LeftButton == ButtonState.Released) + if (CurrentInterface.Mouse.LeftButton == ButtonState.Released) return; updateMouseLocalPos (e.Position); } diff --git a/src/GraphicObjects/FileDialog.cs b/src/GraphicObjects/FileDialog.cs index 47a6fb54..8182e021 100644 --- a/src/GraphicObjects/FileDialog.cs +++ b/src/GraphicObjects/FileDialog.cs @@ -117,11 +117,11 @@ namespace Crow CurrentDirectory = SelectedDirectory; else { OkClicked.Raise (this, null); - unloadDialog ((sender as GraphicObject).currentInterface); + unloadDialog ((sender as GraphicObject).CurrentInterface); } } void onCancel(object sender, MouseButtonEventArgs e){ - unloadDialog ((sender as GraphicObject).currentInterface); + unloadDialog ((sender as GraphicObject).CurrentInterface); } void unloadDialog(Interface host){ host.DeleteWidget (this); diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 77f1cb1f..cecdaffd 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -127,7 +127,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && IsDirty) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index d443915e..1ba524d7 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -91,7 +91,20 @@ namespace Crow internal static ulong currentUid = 0; internal ulong uid = 0; - public Interface currentInterface = null; + Interface currentInterface = null; + + [XmlIgnore]public Interface CurrentInterface { + get { + if (currentInterface == null) { + currentInterface = Interface.CurrentInterface; + Initialize (); + } + return currentInterface; + } + set { + currentInterface = value; + } + } public Region Clipping; @@ -107,12 +120,23 @@ namespace Crow #region CTOR public GraphicObject () { + Clipping = new Region (); #if DEBUG uid = currentUid; currentUid++; #endif } #endregion + internal bool initialized = false; + /// <summary> + /// Initialize this Graphic object instance by setting style and default values and loading template if required + /// </summary> + public virtual void Initialize(){ + if (currentInterface == null) + currentInterface = Interface.CurrentInterface; + loadDefaultValues (); + initialized = true; + } #region private fields LayoutingType registeredLayoutings = LayoutingType.All; ILayoutable logicalParent; @@ -677,8 +701,6 @@ namespace Crow Debug.WriteLine ("LoadDefValues for " + this.ToString ()); #endif - Clipping = new Region (); - Type thisType = this.GetType (); if (!string.IsNullOrEmpty (Style)) { @@ -917,7 +939,7 @@ namespace Crow if (Width.IsFit || Height.IsFit) RegisterForLayouting (LayoutingType.Sizing); else if (RegisteredLayoutings == LayoutingType.None) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); } /// <summary> query an update of the content, a redraw </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -928,7 +950,7 @@ namespace Crow #endif IsDirty = true; if (RegisteredLayoutings == LayoutingType.None) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); } #endregion @@ -940,12 +962,13 @@ namespace Crow contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; } /// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary> - public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){} + public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){ + } public virtual bool ArrangeChildren { get { return false; } } public virtual void RegisterForLayouting(LayoutingType layoutType){ if (Parent == null) return; - lock (currentInterface.LayoutMutex) { + lock (CurrentInterface.LayoutMutex) { //prevent queueing same LayoutingType for this layoutType &= (~RegisteredLayoutings); @@ -964,20 +987,23 @@ namespace Crow if (Parent is GraphicObject) (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType); +// //prevent queueing same LayoutingType for this +// layoutType &= (~RegisteredLayoutings); + if (layoutType == LayoutingType.None) return; //enqueue LQI LayoutingTypes separately if (layoutType.HasFlag (LayoutingType.Width)) - currentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); if (layoutType.HasFlag (LayoutingType.Height)) - currentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); if (layoutType.HasFlag (LayoutingType.X)) - currentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); if (layoutType.HasFlag (LayoutingType.Y)) - currentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); if (layoutType.HasFlag (LayoutingType.ArrangeChildren)) - currentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); } } @@ -1153,7 +1179,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (this.registeredLayoutings == LayoutingType.None && IsDirty) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } @@ -1290,8 +1316,8 @@ namespace Crow } public virtual void checkHoverWidget(MouseMoveEventArgs e) { - if (currentInterface.HoverWidget != this) { - currentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } @@ -1307,19 +1333,19 @@ namespace Crow MouseMove.Raise (this, e); } public virtual void onMouseDown(object sender, MouseButtonEventArgs e){ - if (currentInterface.eligibleForDoubleClick == this && currentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) + if (CurrentInterface.eligibleForDoubleClick == this && CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) onMouseDoubleClick (this, e); else currentInterface.clickTimer.Restart(); - currentInterface.eligibleForDoubleClick = null; + CurrentInterface.eligibleForDoubleClick = null; - if (currentInterface.ActiveWidget == null) - currentInterface.ActiveWidget = this; + if (CurrentInterface.ActiveWidget == null) + CurrentInterface.ActiveWidget = this; if (this.Focusable && !Interface.FocusOnHover) { BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg; if (be.Focused == null) { be.Focused = this; - currentInterface.FocusedWidget = this; + CurrentInterface.FocusedWidget = this; } } //bubble event to the top @@ -1338,8 +1364,8 @@ namespace Crow MouseUp.Raise (this, e); if (MouseIsIn (e.Position) && IsActive) { - if (currentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) - currentInterface.eligibleForDoubleClick = this; + if (CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) + CurrentInterface.eligibleForDoubleClick = this; onMouseClick (this, e); } } diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index b2a13150..3d1847a2 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -161,7 +161,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && IsDirty) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 917087cc..e4e9ba20 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -73,9 +73,14 @@ namespace Crow public virtual void RemoveChild(GraphicObject child) { child.LayoutChanged -= OnChildLayoutChanges; + //check if HoverWidget is removed from Tree + if (CurrentInterface.HoverWidget != null) { + if (this.Contains (CurrentInterface.HoverWidget)) + CurrentInterface.HoverWidget = null; + } lock (children) - Children.Remove(child); + Children.Remove(child); child.Dispose (); if (child == largestChild && Width == Measure.Fit) @@ -344,8 +349,8 @@ namespace Crow #region Mouse handling public override void checkHoverWidget (MouseMoveEventArgs e) { - if (currentInterface.HoverWidget != this) { - currentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } for (int i = Children.Count - 1; i >= 0; i--) { diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index f2d540be..6a4c590d 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -79,7 +79,7 @@ namespace Crow if (string.IsNullOrEmpty(value)) Picture = null; else { - lock(currentInterface.LayoutMutex){ + lock(CurrentInterface.LayoutMutex){ LoadImage (value); } } diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 7a802bda..e477c3f6 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -686,12 +686,12 @@ namespace Crow { base.onMouseEnter (sender, e); if (Selectable) - currentInterface.MouseCursor = XCursor.Text; + CurrentInterface.MouseCursor = XCursor.Text; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - currentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } protected override void onFocused (object sender, EventArgs e) { @@ -775,6 +775,19 @@ namespace Crow if (CurrentLine >= lines.Count) CurrentLine = lines.Count - 1; + switch (TextAlignment) { + case Alignment.Center: + case Alignment.Top: + case Alignment.Bottom: + cPos+= ClientRectangle.Width - gr.TextExtents(lines [CurrentLine]).Width/2.0; + break; + case Alignment.Right: + case Alignment.TopRight: + case Alignment.BottomRight: + cPos += ClientRectangle.Width - gr.TextExtents(lines [CurrentLine]).Width; + break; + } + for (int i = 0; i < lines[CurrentLine].Length; i++) { string c = lines [CurrentLine].Substring (i, 1); diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index 8c8380ef..d8ce1dae 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -134,8 +134,8 @@ namespace Crow public static MessageBox Show (Type msgBoxType, string message, string okMsg = "", string cancelMsg = ""){ lock (Interface.CurrentInterface.UpdateMutex) { MessageBox mb = new MessageBox (); - mb.loadDefaultValues (); - mb.currentInterface.AddWidget (mb); + mb.Initialize (); + mb.CurrentInterface.AddWidget (mb); mb.MsgType = msgBoxType; mb.Message = message; if (!string.IsNullOrEmpty(okMsg)) diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index 9b511831..8ab60edb 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -44,10 +44,24 @@ namespace Crow #region private fields double _actualValue, minValue, maxValue, smallStep, bigStep; + int _decimals; #endregion #region public properties - [XmlAttributeAttribute()][DefaultValue(0.0)] + [XmlAttributeAttribute][DefaultValue(2)] + public int Decimals + { + get { return _decimals; } + set + { + if (value == _decimals) + return; + _decimals = value; + NotifyValueChanged("Decimals", _decimals); + RegisterForGraphicUpdate(); + } + } + [XmlAttributeAttribute][DefaultValue(0.0)] public virtual double Minimum { get { return minValue; } set { @@ -59,7 +73,7 @@ namespace Crow RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue(100.0)] + [XmlAttributeAttribute][DefaultValue(100.0)] public virtual double Maximum { get { return maxValue; } @@ -72,7 +86,7 @@ namespace Crow RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue(1.0)] + [XmlAttributeAttribute][DefaultValue(1.0)] public virtual double SmallIncrement { get { return smallStep; } @@ -85,7 +99,7 @@ namespace Crow RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue(5.0)] + [XmlAttributeAttribute][DefaultValue(5.0)] public virtual double LargeIncrement { get { return bigStep; } @@ -98,7 +112,7 @@ namespace Crow RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue(0.0)] + [XmlAttributeAttribute][DefaultValue(0.0)] public double Value { get { return _actualValue; } @@ -114,6 +128,8 @@ namespace Crow else _actualValue = value; + _actualValue = Math.Round (_actualValue, _decimals); + NotifyValueChanged("Value", _actualValue); RegisterForGraphicUpdate(); } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index d6e36346..72a3fa8d 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -204,8 +204,8 @@ namespace Crow } public override void checkHoverWidget (MouseMoveEventArgs e) { - if (currentInterface.HoverWidget != this) { - currentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } if (Content != null){ @@ -225,10 +225,10 @@ namespace Crow if (Content != null) { Content.Visible = true; if (Content.Parent == null) - currentInterface.AddWidget (Content, true); + CurrentInterface.AddWidget (Content, true); if (Content.LogicalParent != this) Content.LogicalParent = this; - currentInterface.PutOnTop (Content, true); + CurrentInterface.PutOnTop (Content, true); _content_LayoutChanged (this, new LayoutingEventArgs (LayoutingType.Sizing)); } Popped.Raise (this, e); diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 077f732f..c40bceb4 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -54,6 +54,10 @@ namespace Crow if (child != null) { //check if HoverWidget is removed from Tree + if (CurrentInterface.HoverWidget != null) { + if (this.Contains (CurrentInterface.HoverWidget)) + CurrentInterface.HoverWidget = null; + } contentSize = new Size (0, 0); child.LayoutChanged -= OnChildLayoutChanges; child.Dispose (); diff --git a/src/GraphicObjects/ScrollingObject.cs b/src/GraphicObjects/ScrollingObject.cs index 42acdbf9..09558984 100644 --- a/src/GraphicObjects/ScrollingObject.cs +++ b/src/GraphicObjects/ScrollingObject.cs @@ -146,7 +146,7 @@ namespace Crow public override void onMouseWheel (object sender, MouseWheelEventArgs e) { base.onMouseWheel (sender, e); - if (currentInterface.Keyboard.IsKeyDown (Key.ShiftLeft)) + if (CurrentInterface.Keyboard.IsKeyDown (Key.ShiftLeft)) ScrollX += e.Delta * MouseWheelSpeed; else ScrollY -= e.Delta * MouseWheelSpeed; diff --git a/src/GraphicObjects/ScrollingTextBox.cs b/src/GraphicObjects/ScrollingTextBox.cs index c409d022..a435f9ee 100644 --- a/src/GraphicObjects/ScrollingTextBox.cs +++ b/src/GraphicObjects/ScrollingTextBox.cs @@ -464,12 +464,12 @@ namespace Crow public override void onMouseEnter (object sender, MouseMoveEventArgs e) { base.onMouseEnter (sender, e); - currentInterface.MouseCursor = XCursor.Text; + CurrentInterface.MouseCursor = XCursor.Text; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - currentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } protected override void onFocused (object sender, EventArgs e) { @@ -555,7 +555,7 @@ namespace Crow if (!MoveRight ()) return; }else if (e.Shift) - currentInterface.Clipboard = this.SelectedText; + CurrentInterface.Clipboard = this.SelectedText; this.DeleteChar (); break; case Key.Enter: @@ -601,9 +601,9 @@ namespace Crow break; case Key.Insert: if (e.Shift) - this.Insert (currentInterface.Clipboard); + this.Insert (CurrentInterface.Clipboard); else if (e.Control && !selectionIsEmpty) - currentInterface.Clipboard = this.SelectedText; + CurrentInterface.Clipboard = this.SelectedText; break; case Key.Left: if (e.Shift) { diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index 36f7e731..97c8b384 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -165,14 +165,14 @@ namespace Crow cursor = new Rectangle (new Size (_cursorSize, (int)(r.Height))); p1 = r.TopLeft + new Point (_cursorSize / 2, r.Height / 2); unity = (double)(r.Width - _cursorSize) / (Maximum - Minimum); - cursor.TopLeft = new Point (r.Left + (int)(Value * unity), + cursor.TopLeft = new Point (r.Left + (int)((Value - Minimum) * unity), (int)(p1.Y - cursor.Height / 2)); } else { cursor = new Rectangle (new Size ((int)(r.Width), _cursorSize)); p1 = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2); unity = (double)(r.Height - _cursorSize) / (Maximum - Minimum); cursor.TopLeft = new Point ((int)(p1.X - r.Width / 2), - r.Top + (int)(Value * unity)); + r.Top + (int)((Value - Minimum) * unity)); } cursor.Inflate (-1); } diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs index 503e1eca..2f5dd15b 100644 --- a/src/GraphicObjects/Splitter.cs +++ b/src/GraphicObjects/Splitter.cs @@ -86,14 +86,14 @@ namespace Crow { base.onMouseEnter (sender, e); if ((Parent as GenericStack).Orientation == Orientation.Horizontal) - currentInterface.MouseCursor = XCursor.H; + CurrentInterface.MouseCursor = XCursor.H; else - currentInterface.MouseCursor = XCursor.V; + CurrentInterface.MouseCursor = XCursor.V; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - currentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } public override void onMouseDown (object sender, MouseButtonEventArgs e) { diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index c0c07fc7..ecf38f10 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -139,7 +139,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && IsDirty) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } @@ -177,8 +177,8 @@ namespace Crow #region Mouse handling public override void checkHoverWidget (MouseMoveEventArgs e) { - if (currentInterface.HoverWidget != this) { - currentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index ba580dae..c4ef5788 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -62,7 +62,7 @@ namespace Crow if (string.IsNullOrEmpty(_template)) loadTemplate (); else - loadTemplate (currentInterface.Load (_template)); + loadTemplate (CurrentInterface.Load (_template)); } } [XmlAttributeAttribute()][DefaultValue("Templated Control")] @@ -76,6 +76,11 @@ namespace Crow } } #region GraphicObject overrides + public override void Initialize () + { + loadTemplate (); + base.Initialize (); + } public override GraphicObject FindByName (string nameToFind) { //prevent name searching in template @@ -108,7 +113,7 @@ namespace Crow if (template == null) { if (!Interface.DefaultTemplates.ContainsKey (this.GetType ().FullName)) throw new Exception (string.Format ("No default template found for '{0}'", this.GetType ().FullName)); - this.SetChild (currentInterface.Load (Interface.DefaultTemplates[this.GetType ().FullName])); + this.SetChild (CurrentInterface.Load (Interface.DefaultTemplates[this.GetType ().FullName])); }else this.SetChild (template); } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index 1cbc4935..60f18994 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -159,7 +159,7 @@ namespace Crow NotifyValueChanged ("Data", data); - lock (currentInterface.LayoutMutex) + lock (CurrentInterface.LayoutMutex) ClearItems (); if (data == null) @@ -298,8 +298,8 @@ namespace Crow itemPerPage = int.MaxValue; } else if (typeof(GenericStack).IsAssignableFrom (items.GetType ())) { GenericStack gs = new GenericStack (); - gs.currentInterface = items.currentInterface; - gs.loadDefaultValues (); + gs.CurrentInterface = items.CurrentInterface; + gs.Initialize (); gs.Orientation = (items as GenericStack).Orientation; gs.Width = items.Width; gs.Height = items.Height; @@ -327,7 +327,7 @@ namespace Crow if (page == items) return; - lock (currentInterface.LayoutMutex) + lock (CurrentInterface.LayoutMutex) items.AddChild (page); #if DEBUG_LOAD @@ -380,8 +380,8 @@ namespace Crow iTemp = ItemTemplates ["default"]; } - lock (currentInterface.LayoutMutex) { - g = iTemp.CreateInstance(currentInterface); + lock (CurrentInterface.LayoutMutex) { + g = iTemp.CreateInstance(CurrentInterface); page.AddChild (g); //g.LogicalParent = this; registerItemClick (g); diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 5e2d55cb..0cbee9f8 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -85,7 +85,7 @@ namespace Crow if (!MoveRight ()) return; }else if (e.Shift) - currentInterface.Clipboard = this.SelectedText; + CurrentInterface.Clipboard = this.SelectedText; this.DeleteChar (); break; case Key.Enter: @@ -134,9 +134,9 @@ namespace Crow break; case Key.Insert: if (e.Shift) - this.Insert (currentInterface.Clipboard); + this.Insert (CurrentInterface.Clipboard); else if (e.Control && !selectionIsEmpty) - currentInterface.Clipboard = this.SelectedText; + CurrentInterface.Clipboard = this.SelectedText; break; case Key.Left: if (e.Shift) { diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 176e8d90..7ea4db75 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -152,7 +152,7 @@ namespace Crow alwaysOnTop = value; if (alwaysOnTop && Parent != null) - currentInterface.PutOnTop (this); + CurrentInterface.PutOnTop (this); NotifyValueChanged ("AlwaysOnTop", alwaysOnTop); } @@ -178,11 +178,11 @@ namespace Crow { base.onMouseMove (sender, e); - Interface otkgw = currentInterface; + Interface otkgw = CurrentInterface; if (!hoverBorder) { currentDirection = Direction.None; - currentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; return; } @@ -323,7 +323,7 @@ namespace Crow #endregion protected void onMaximized (object sender, EventArgs e){ - lock (currentInterface.LayoutMutex) { + lock (CurrentInterface.LayoutMutex) { if (!IsMinimized) savedBounds = this.LastPaintedSlot; this.Left = this.Top = 0; @@ -342,7 +342,7 @@ namespace Crow } protected void onUnmaximized (object sender, EventArgs e){ - lock (currentInterface.LayoutMutex) { + lock (CurrentInterface.LayoutMutex) { this.Left = savedBounds.Left; this.Top = savedBounds.Top; this.Width = savedBounds.Width; @@ -357,7 +357,7 @@ namespace Crow Unmaximized.Raise (sender, e); } protected void onMinimized (object sender, EventArgs e){ - lock (currentInterface.LayoutMutex) { + lock (CurrentInterface.LayoutMutex) { if (IsNormal) savedBounds = this.LastPaintedSlot; Width = 200; @@ -375,7 +375,7 @@ namespace Crow { hoverBorder = false; currentDirection = Direction.None; - currentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } protected void onBorderMouseEnter (object sender, MouseMoveEventArgs e) { @@ -385,7 +385,7 @@ namespace Crow protected void butQuitPress (object sender, MouseButtonEventArgs e) { - currentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; close (); } diff --git a/src/GraphicObjects/Wrapper.cs b/src/GraphicObjects/Wrapper.cs index 22410919..8b282ebb 100644 --- a/src/GraphicObjects/Wrapper.cs +++ b/src/GraphicObjects/Wrapper.cs @@ -189,7 +189,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && IsDirty) - currentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 302169bb..e87c4146 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -116,7 +116,7 @@ namespace Crow #endif if (LayoutingTries < Interface.MaxLayoutingTries) { Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as GraphicObject).currentInterface.LayoutingQueue.Enqueue (this); + (Layoutable as GraphicObject).CurrentInterface.LayoutingQueue.Enqueue (this); } else if (DiscardCount < Interface.MaxDiscardCount) { #if DEBUG_LAYOUTING Debug.WriteLine ("\t\tDiscarded"); @@ -124,7 +124,7 @@ namespace Crow LayoutingTries = 0; DiscardCount++; Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as GraphicObject).currentInterface.DiscardQueue.Enqueue (this); + (Layoutable as GraphicObject).CurrentInterface.DiscardQueue.Enqueue (this); } #if DEBUG_LAYOUTING else |