diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-04 14:10:19 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-04 15:17:13 +0100 |
| commit | 14c11116a5a53bc8c628b4963ecdfd31ccd41ee0 (patch) | |
| tree | a4da1b41fbbac0b994089ea6b501f1351f909db6 /src | |
| parent | d5f05d1fb773975e868291dfd1f6b8b69ddedc6d (diff) | |
new layouting queue with double linked list, buggy
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 14 | ||||
| -rw-r--r-- | src/GraphicObjects/Grid.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/ILayoutable.cs | 2 | ||||
| -rw-r--r-- | src/LayoutingQueue.cs | 45 | ||||
| -rw-r--r-- | src/LayoutingQueueItem.cs | 4 | ||||
| -rw-r--r-- | src/OpenTKGameWindow.cs | 2 |
7 files changed, 50 insertions, 21 deletions
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 53aff76b..dd27d21a 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -166,7 +166,7 @@ namespace Crow } ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null) + if (RegisteredLQIs.Count () <= 0 && bmp==null) this.RegisterForRedraw (); }else base.UpdateLayout(layoutType); diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 8bbf67b0..1a608f36 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -90,6 +90,8 @@ namespace Crow #endregion #region ILayoutable + + public List<LayoutingQueueItem> RegisteredLQIs { get; } = new List<LayoutingQueueItem>(); //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 [XmlIgnore]public ILayoutable Parent { @@ -486,6 +488,13 @@ namespace Crow { return Bounds.Size; } + void deleteLQI(int lt){ + LayoutingQueueItem[] lqis = this.RegisteredLQIs.Where (lq => (lt & (int)lq.LayoutType) > 0).ToArray (); + for (int i = 0; i < lqis.Length; i++) { + Interface.LayoutingQueue.Remove (lqis [i]); + lqis [i].DeleteLayoutableRef(); + } + } /// <summary> clear current layoutingQueue items for object and /// trigger a new layouting pass for a layoutType </summary> public virtual void RegisterForLayouting(int layoutType) @@ -496,8 +505,7 @@ namespace Crow Debug.WriteLine ("RegisterForLayouting => {1}->{0}", layoutType, this.ToString()); #endif lock (Interface.LayoutingQueue) { - Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0); - + deleteLQI (layoutType); if ((layoutType & (int)LayoutingType.Width) > 0) { if (Bounds.Width == 0) //stretch in parent Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this); @@ -693,7 +701,7 @@ namespace Crow } lock (Interface.LayoutingQueue) { //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null) + if (this.RegisteredLQIs.Count () <= 0 && bmp == null) this.RegisterForRedraw (); } } diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 6ce9a3c5..08241d9c 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -137,7 +137,7 @@ namespace Crow if (layoutType == LayoutingType.PositionChildren) { ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null) + if (RegisteredLQIs.Count () <= 0 && bmp==null) this.RegisterForRedraw (); }else base.UpdateLayout(layoutType); diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 000d377b..3a7135e0 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Crow { @@ -12,6 +13,7 @@ namespace Crow IGOLibHost HostContainer { get; } + List<LayoutingQueueItem> RegisteredLQIs { get; } void RegisterForLayouting(int layoutType); void UpdateLayout(LayoutingType layoutType); diff --git a/src/LayoutingQueue.cs b/src/LayoutingQueue.cs index ca4dede9..51ec702e 100644 --- a/src/LayoutingQueue.cs +++ b/src/LayoutingQueue.cs @@ -31,28 +31,30 @@ namespace Crow } public void Enqueue(LayoutingType _lt, ILayoutable _object) { - Interface.LayoutingQueue.RemoveAll(lq => lq.GraphicObject == _object && lq.LayoutType == _lt); - Interface.LayoutingQueue.Add (new LayoutingQueueItem (_lt, _object)); + this.Add (new LayoutingQueueItem (_lt, _object)); + } + LayoutingQueueItem searchLqi(ILayoutable go, LayoutingType lt){ + return go.RegisteredLQIs.Where(lq => lq.LayoutType == lt).LastOrDefault(); } - public void EnqueueAfterParentSizing (LayoutingType _lt, ILayoutable _object) { LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - int idxParentSz = Interface.LayoutingQueue.IndexOf - (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == _object.Parent && lq.LayoutType == _lt).LastOrDefault()); + LayoutingQueueItem parentLqi = searchLqi (_object.Parent, _lt); - Interface.LayoutingQueue.Insert (idxParentSz + 1, lqi); + if (parentLqi == null) + this.Insert (0, lqi); + else + this.Insert (this.IndexOf (parentLqi) + 1, lqi); } public void EnqueueBeforeParentSizing (LayoutingType _lt, ILayoutable _object) { LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - int idxParentSz = Interface.LayoutingQueue.IndexOf - (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == _object.Parent && lq.LayoutType == _lt).FirstOrDefault()); + LayoutingQueueItem parentLqi = searchLqi (_object.Parent, _lt); - if (idxParentSz < 0) - Interface.LayoutingQueue.Enqueue (_lt, _object); + if (parentLqi == null) + this.Add (lqi); else - Interface.LayoutingQueue.Insert (idxParentSz, lqi); + this.Insert (this.IndexOf (parentLqi), lqi); } public void EnqueueAfterThisAndParentSizing (LayoutingType _lt, ILayoutable _object) { @@ -61,16 +63,27 @@ namespace Crow if (_lt == LayoutingType.Y) sizing = LayoutingType.Height; - - int idxW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where - (lq => (lq.GraphicObject == _object.Parent || lq.GraphicObject == _object) && lq.LayoutType == sizing).LastOrDefault()); - Interface.LayoutingQueue.Insert (idxW + 1, lqi); - } + LayoutingQueueItem parentLqi = searchLqi (_object.Parent, sizing); + LayoutingQueueItem thisLqi = searchLqi (_object, sizing); + int idx = -1; + + if (parentLqi == null) { + if (thisLqi != null) + idx = this.IndexOf (thisLqi); + } else { + if (thisLqi == null) + idx = this.IndexOf (parentLqi); + else + idx = Math.Max(this.IndexOf (parentLqi), this.IndexOf (thisLqi)); + } + this.Insert (idx + 1, lqi); + } public LayoutingQueueItem Dequeue() { LayoutingQueueItem tmp = this [0]; + tmp.DeleteLayoutableRef (); this.RemoveAt (0); return tmp; } diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 95234112..d1cfaeb9 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -45,6 +45,10 @@ namespace Crow { LayoutType = _layoutType; GraphicObject = _graphicObject; + GraphicObject.RegisteredLQIs.Add (this); + } + public void DeleteLayoutableRef(){ + GraphicObject.RegisteredLQIs.Remove(this); } public void ProcessLayouting() { diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 078e1c0a..b5317cef 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -547,6 +547,8 @@ namespace Crow #region ILayoutable implementation + //TODO:uneeded list, should be removed + public List<LayoutingQueueItem> RegisteredLQIs { get; } = new List<LayoutingQueueItem>(); public void RegisterForLayouting (int layoutType) { throw new NotImplementedException (); } public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } public Rectangle ContextCoordinates (Rectangle r) |