diff options
| -rw-r--r-- | Crow.csproj | 1 | ||||
| -rwxr-xr-x | Templates/Popper.template | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 74 | ||||
| -rw-r--r-- | src/GraphicObjects/ILayoutable.cs | 29 | ||||
| -rw-r--r-- | src/GraphicObjects/Popper.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Splitter.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/TabView.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/TreeView.cs | 2 | ||||
| -rw-r--r-- | src/Interface.cs | 78 | ||||
| -rw-r--r-- | src/LayoutingQueueItem.cs | 9 |
10 files changed, 84 insertions, 117 deletions
diff --git a/Crow.csproj b/Crow.csproj index b541152c..f3e91b21 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -61,7 +61,6 @@ <Compile Include="src\GraphicObjects\Slider.cs" /> <Compile Include="src\GraphicObjects\NumericControl.cs" /> <Compile Include="src\GraphicObjects\Scroller.cs" /> - <Compile Include="src\GraphicObjects\ILayoutable.cs" /> <Compile Include="src\Enums.cs" /> <Compile Include="src\GraphicObjects\GenericStack.cs" /> <Compile Include="src\CompilerServices\CompilerServices.cs" /> diff --git a/Templates/Popper.template b/Templates/Popper.template index c473cecb..cebf1ab0 100755 --- a/Templates/Popper.template +++ b/Templates/Popper.template @@ -1,6 +1,6 @@ <?xml version="1.0"?> <Border Background="{./Background}" BorderWidth="1" Foreground="{./Foreground}" Height="Fit"> - <HorizontalStack Spacing="1" Height="Fit"> + <HorizontalStack Spacing="1"> <Image Style="Icon" Margin="2" Path="#Crow.Images.Icons.expandable.svg" SvgSub="{./IsPopped}"/> <Label Text="{./Caption}" /> diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 25332832..3c9cb061 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -12,7 +12,7 @@ using System.IO; namespace Crow { - public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable + public class GraphicObject : IXmlSerializable, IValueChange, ICloneable { internal static ulong currentUid = 0; internal ulong uid = 0; @@ -58,8 +58,8 @@ namespace Crow } #region private fields LayoutingType registeredLayoutings = LayoutingType.All; - ILayoutable logicalParent; - ILayoutable parent; + GraphicObject logicalParent; + GraphicObject parent; string name; Fill background = Color.Transparent; Fill foreground = Color.White; @@ -118,13 +118,13 @@ namespace Crow #endregion #region ILayoutable - [XmlIgnore]public LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } } + [XmlIgnore]public virtual LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } } //TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject // or we could add to the interface the mouse events /// <summary> /// Parent in the graphic tree, used for rendering and layouting /// </summary> - [XmlIgnore]public virtual ILayoutable Parent { + [XmlIgnore]public virtual GraphicObject Parent { get { return parent; } set { if (parent == value) @@ -135,18 +135,18 @@ namespace Crow onParentChanged (this, e); } } - [XmlIgnore]public ILayoutable LogicalParent { + [XmlIgnore]public GraphicObject LogicalParent { get { return logicalParent == null ? Parent : logicalParent; } set { if (logicalParent == value) return; if (logicalParent != null) - (logicalParent as GraphicObject).DataSourceChanged -= onLogicalParentDataSourceChanged; + logicalParent.DataSourceChanged -= onLogicalParentDataSourceChanged; DataSourceChangeEventArgs dsce = new DataSourceChangeEventArgs (LogicalParent, null); logicalParent = value; dsce.NewDataSource = LogicalParent; if (logicalParent != null) - (logicalParent as GraphicObject).DataSourceChanged += onLogicalParentDataSourceChanged; + logicalParent.DataSourceChanged += onLogicalParentDataSourceChanged; onLogicalParentChanged (this, dsce); } } @@ -158,10 +158,9 @@ namespace Crow } } public virtual Rectangle ContextCoordinates(Rectangle r){ - GraphicObject go = Parent as GraphicObject; - if (go == null) + if (Parent is Interface) return r + Parent.ClientRectangle.Position; - return go.CacheEnabled ? + return Parent.CacheEnabled ? r + Parent.ClientRectangle.Position : Parent.ContextCoordinates (r); } @@ -296,9 +295,7 @@ namespace Crow [XmlAttributeAttribute()][DefaultValue("Inherit")] public virtual Measure Width { get { - return width.Units == Unit.Inherit ? - Parent is GraphicObject ? (Parent as GraphicObject).WidthPolicy : - Measure.Stretched : width; + return width.Units == Unit.Inherit ? Parent == null ? Measure.Stretched : Parent.WidthPolicy : width; } set { if (width == value) @@ -332,9 +329,7 @@ namespace Crow [XmlAttributeAttribute()][DefaultValue("Inherit")] public virtual Measure Height { get { - return height.Units == Unit.Inherit ? - Parent is GraphicObject ? (Parent as GraphicObject).HeightPolicy : - Measure.Stretched : height; + return height.Units == Unit.Inherit ? Parent == null ? Measure.Stretched :Parent.HeightPolicy : height; } set { if (height == value) @@ -573,8 +568,7 @@ namespace Crow get { return dataSource == null ? LogicalParent == null ? null : - LogicalParent is GraphicObject ? (LogicalParent as GraphicObject).DataSource : null : - dataSource; + LogicalParent.DataSource : dataSource; } } protected virtual void onLogicalParentDataSourceChanged(object sender, DataSourceChangeEventArgs e){ @@ -843,8 +837,7 @@ namespace Crow layoutType &= (~LayoutingType.ArrangeChildren); //apply constraints depending on parent type - if (Parent is GraphicObject) - (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType); + Parent.ChildrenLayoutingConstraints (ref layoutType); // //prevent queueing same LayoutingType for this // layoutType &= (~RegisteredLayoutings); @@ -872,6 +865,7 @@ namespace Crow #if DEBUG_LAYOUTING CurrentInterface.currentLQI.Slot = LastSlots; CurrentInterface.currentLQI.NewSlot = Slot; + Debug.WriteLine ("\t{0} => {1}",LastSlots,Slot); #endif switch (layoutType) { @@ -1147,11 +1141,8 @@ namespace Crow return false; if (ScreenCoordinates (Slot).ContainsOrIsEqual (m)) { Scroller scr = Parent as Scroller; - if (scr == null) { - if (Parent is GraphicObject) - return (Parent as GraphicObject).MouseIsIn (m); - else return true; - } + if (scr == null) + return Parent.MouseIsIn (m); return scr.MouseIsIn (scr.savedMousePos); } return false; @@ -1167,10 +1158,8 @@ namespace Crow } public virtual void onMouseMove(object sender, MouseMoveEventArgs e) { - //bubble event to the top - GraphicObject p = Parent as GraphicObject; - if (p != null) - p.onMouseMove(sender,e); + if (Parent != null) + Parent.onMouseMove(sender,e); MouseMove.Raise (sender, e); } @@ -1191,17 +1180,15 @@ namespace Crow } } //bubble event to the top - GraphicObject p = Parent as GraphicObject; - if (p != null) - p.onMouseDown(sender,e); + if (Parent != null) + Parent.onMouseDown(sender,e); MouseDown.Raise (this, e); } public virtual void onMouseUp(object sender, MouseButtonEventArgs e){ //bubble event to the top - GraphicObject p = Parent as GraphicObject; - if (p != null) - p.onMouseUp(sender,e); + if (Parent != null) + Parent.onMouseUp(sender,e); MouseUp.Raise (this, e); @@ -1212,21 +1199,18 @@ namespace Crow } } public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ - GraphicObject p = Parent as GraphicObject; - if (p != null) - p.onMouseClick(sender,e); + if (Parent != null) + Parent.onMouseClick(sender,e); MouseClick.Raise (this, e); } public virtual void onMouseDoubleClick(object sender, MouseButtonEventArgs e){ - GraphicObject p = Parent as GraphicObject; - if (p != null) - p.onMouseDoubleClick(sender,e); + if (Parent != null) + Parent.onMouseDoubleClick(sender,e); MouseDoubleClick.Raise (this, e); } public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){ - GraphicObject p = Parent as GraphicObject; - if (p != null) - p.onMouseWheel(sender,e); + if (Parent != null) + Parent.onMouseWheel(sender,e); MouseWheelChanged.Raise (this, e); } diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs deleted file mode 100644 index 33153935..00000000 --- a/src/GraphicObjects/ILayoutable.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Crow -{ - public interface ILayoutable - { - /// <summary> Parent in the graphic tree </summary> - ILayoutable Parent { get; set; } - /// <summary> The logical parent (used mainly for bindings) as opposed - /// to the parent in the graphic tree </summary> - ILayoutable LogicalParent { get; set; } - - Rectangle ClientRectangle { get; } - Rectangle getSlot(); - - bool ArrangeChildren { get; } - LayoutingType RegisteredLayoutings { get; set; } - void RegisterForLayouting(LayoutingType layoutType); - void RegisterClip(Rectangle clip); - bool UpdateLayout(LayoutingType layoutType); - - - Rectangle ContextCoordinates(Rectangle r); - Rectangle ScreenCoordinates (Rectangle r); - - } -} - diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 38621337..e9887d94 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -119,7 +119,7 @@ namespace Crow protected void _content_LayoutChanged (object sender, LayoutingEventArgs e) { - ILayoutable tc = Content.Parent; + GraphicObject tc = Content.Parent; if (tc == null) return; Rectangle r = this.ScreenCoordinates (this.Slot); diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs index 220fc476..6d4f494e 100644 --- a/src/GraphicObjects/Splitter.cs +++ b/src/GraphicObjects/Splitter.cs @@ -64,7 +64,7 @@ namespace Crow } #region GraphicObject override - public override ILayoutable Parent { + public override GraphicObject Parent { get { return base.Parent; } set { if (value != null) { diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 1debfedc..b79f41eb 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -179,7 +179,7 @@ namespace Crow if (SelectedTab > Children.Count - 1) return; - if (((Children[SelectedTab] as TabItem).Content.Parent as GraphicObject).MouseIsIn(e.Position)) + if ((Children[SelectedTab] as TabItem).Content.Parent.MouseIsIn(e.Position)) { Children[SelectedTab].checkHoverWidget (e); return; diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index 4fa881b4..ee73ed19 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -61,7 +61,7 @@ namespace Crow //register ItemClick on the Root node TreeView tv = this as TreeView; while (!tv.IsRoot) { - ILayoutable tmp = tv.Parent; + GraphicObject tmp = tv.Parent; while (!(tmp is TreeView)) { tmp = tmp.Parent; } diff --git a/src/Interface.cs b/src/Interface.cs index 542cf2dd..d06870ef 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -41,7 +41,7 @@ namespace Crow /// - helpers to load XML interfaces files /// - global constants and variables of CROW /// </summary> - public class Interface : ILayoutable + public class Interface : GraphicObject { #region CTOR static Interface(){ @@ -580,9 +580,9 @@ namespace Crow //check topmost graphicobject first GraphicObject tmp = HoverWidget; GraphicObject topc = null; - while (tmp is GraphicObject) { + while (!(tmp is Interface)) { topc = tmp; - tmp = tmp.LogicalParent as GraphicObject; + tmp = tmp.LogicalParent; } int idxhw = GraphicTree.IndexOf (topc); if (idxhw != 0) { @@ -592,7 +592,7 @@ namespace Crow if (GraphicTree [i].MouseIsIn (e.Position)) { while (HoverWidget != null) { HoverWidget.onMouseLeave (HoverWidget, e); - HoverWidget = HoverWidget.LogicalParent as GraphicObject; + HoverWidget = HoverWidget.LogicalParent; } GraphicTree [i].checkHoverWidget (e); @@ -610,8 +610,8 @@ namespace Crow } else { HoverWidget.onMouseLeave (HoverWidget, e); //seek upward from last focused graph obj's - while (HoverWidget.LogicalParent as GraphicObject != null) { - HoverWidget = HoverWidget.LogicalParent as GraphicObject; + while (!(HoverWidget.LogicalParent is Interface)) { + HoverWidget = HoverWidget.LogicalParent; if (HoverWidget.MouseIsIn (e.Position)) { HoverWidget.checkHoverWidget (e); return true; @@ -683,6 +683,26 @@ namespace Crow HoverWidget.onMouseWheel (this, e); return true; } + + + public override void onMouseMove (object sender, MouseMoveEventArgs e) + { + } + public override void onMouseUp (object sender, MouseButtonEventArgs e) + { + } + public override void onMouseDown (object sender, MouseButtonEventArgs e) + { + } + public override void onMouseClick (object sender, MouseButtonEventArgs e) + { + } + public override void onMouseDoubleClick (object sender, MouseButtonEventArgs e) + { + } + public override void onMouseWheel (object sender, MouseWheelEventArgs e) + { + } #endregion #region Keyboard @@ -752,39 +772,31 @@ namespace Crow #endregion #region ILayoutable implementation - public void RegisterClip(Rectangle r){ - clipping.AddRectangle (r); - } - public bool ArrangeChildren { get { return false; }} - public int LayoutingTries { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } - } - public LayoutingType RegisteredLayoutings { + public override void RegisterClip(Rectangle r){ clipping.AddRectangle (r); } + public override LayoutingType RegisteredLayoutings { get { return LayoutingType.None; } set { throw new NotImplementedException (); } } - public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); } - public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } - public Rectangle ContextCoordinates (Rectangle r) { return r;} - public Rectangle ScreenCoordinates (Rectangle r) { return r; } - - public ILayoutable Parent { - get { return null; } - set { throw new NotImplementedException (); } + public override Rectangle ContextCoordinates (Rectangle r) { return r;} + public override Rectangle ScreenCoordinates (Rectangle r) { return r; } + public override Rectangle ClientRectangle { get { return clientRectangle; }} + public override Rectangle getSlot () { return ClientRectangle; } + public override Measure WidthPolicy { get { return Measure.Stretched; }} + public override Measure HeightPolicy { get { return Measure.Stretched; }} + public override Measure Width { + get { return clientRectangle.Width; } + set {} } - public ILayoutable LogicalParent { - get { return null; } - set { throw new NotImplementedException (); } - } - - public Rectangle ClientRectangle { - get { return clientRectangle; } + public override Measure Height { + get { return clientRectangle.Height; } + set {} } - public Interface HostContainer { - get { return this; } + public override bool MouseIsIn (Point m){ return true; } + public override void RegisterForLayouting (LayoutingType layoutType) + { + //base.RegisterForLayouting (layoutType); + return; } - public Rectangle getSlot () { return ClientRectangle; } #endregion } } diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 95bc6bb7..3c5ceb3e 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -45,7 +45,7 @@ namespace Crow public struct LayoutingQueueItem { /// <summary> Instance of widget to be layouted</summary> - public ILayoutable Layoutable; + public GraphicObject Layoutable; /// <summary> Bitfield containing the element of the layout to performs (x|y|width|height)</summary> public LayoutingType LayoutType; /// <summary> Unsuccessfull UpdateLayout and requeueing count </summary> @@ -72,7 +72,7 @@ namespace Crow #endif #region CTOR - public LayoutingQueueItem (LayoutingType _layoutType, ILayoutable _graphicObject) + public LayoutingQueueItem (LayoutingType _layoutType, GraphicObject _graphicObject) { LayoutType = _layoutType; Layoutable = _graphicObject; @@ -100,17 +100,18 @@ namespace Crow } #if DEBUG_LAYOUTING LQITime.Start(); + Debug.WriteLine ("LAYOUTING: " + this.ToString ()); #endif LayoutingTries++; if (!Layoutable.UpdateLayout (LayoutType)) { if (LayoutingTries < Interface.MaxLayoutingTries) { Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as GraphicObject).CurrentInterface.LayoutingQueue.Enqueue (this); + Layoutable.CurrentInterface.LayoutingQueue.Enqueue (this); } else if (DiscardCount < Interface.MaxDiscardCount) { LayoutingTries = 0; DiscardCount++; Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as GraphicObject).CurrentInterface.DiscardQueue.Enqueue (this); + Layoutable.CurrentInterface.DiscardQueue.Enqueue (this); } #if DEBUG_LAYOUTING else |