]> O.S.I.I.S - jp/crow.git/commitdiff
new layouting queue with double linked list, buggy
authorjpbruyere <jp.bruyere@hotmail.com>
Thu, 4 Feb 2016 13:10:19 +0000 (14:10 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 4 Feb 2016 14:17:13 +0000 (15:17 +0100)
13 files changed:
.gitignore
Tests/GOLIBTests.cs
Tests/Interfaces/colorItem.crow
Tests/Interfaces/testColorList.crow
Tests/Tests.csproj
UnitTest/NUnitCrowWindow.cs
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Grid.cs
src/GraphicObjects/ILayoutable.cs
src/LayoutingQueue.cs
src/LayoutingQueueItem.cs
src/OpenTKGameWindow.cs

index 6a4d9ce086fc59a1e7e7f886acc84d9caf9c283e..be7a9df439db88edd7179db17ed9adb2b6cde2d6 100644 (file)
@@ -1,13 +1,15 @@
 Win_x86
 
 Debug
-
+packages
 /GOLib.suo
 /bin/*
 /obj/*
 /GOLib.userprefs
 /Tests/obj/*
 /Tests/bin/*
+/UnitTest/obj
+/UnitTest/bin
 MonoDevelop.GOLib/bin/
 MonoDevelop.GOLib/build/
 MonoDevelop.GOLib/obj/
index 41b7eb5e0aea94c89f7f19003333532a12dcb04b..087547c806c84e1e8ffe70f69b34c3dd6dbef753 100644 (file)
@@ -38,11 +38,12 @@ namespace test
                int idx = 0;
                string[] testFiles = {
                        "testColorList.crow",
+                       "testGroupBox.goml",
+                       "testGrid.goml",
                        "test_Listbox.goml",
                        "testButton.crow",
                        "testBorder.goml",
-                       "testButton2.crow",
-                       "testGroupBox.goml",
+//                     "testButton2.crow",
                        "test2WayBinding.crow",
                        "0.crow",
                        "testSpinner.goml",
@@ -67,7 +68,6 @@ namespace test
                        "testContainer.goml",
                        "testRadioButton.goml",
                        "testMsgBox.goml",
-                       "testGrid.goml",
                        "testMeter.goml",
                };
 
index 9901ddf36ed7b3915bdad22c042b21757f0094f6..f0ccb5a196a18689f6c250cf36a627478332daaa 100755 (executable)
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
 <HorizontalStack Height="-1" Width="200"
-       MouseEnter="{Background=SteelBlue}"
-       MouseLeave="{Background=Transparent}">
-       <GraphicObject Height="10" Width="30" Background="{}"/>
-       <TextRun Text="{Name}"/>
+                       MouseEnter="{Background=Red}"
+                       MouseLeave="{Background=Transparent}">
+       <GraphicObject Height="10" Width="30" Background="{}" Margin="0" CornerRadius="3"/>
+       <TextRun Text="{Name}" Margin="0"/>
 </HorizontalStack>
 
index 1eb7437a847e5887f46fef0b5f739521ddac75aa..e00b52b8f4133be1d02a76ed42574eef572190e1 100755 (executable)
@@ -14,7 +14,7 @@
                                                </Scroller>
                                                <ScrollBar Name="scrollbar1" Scroll="{../scroller1.ScrollY}" 
                                                        MaximumScroll="{../scroller1.MaximumScroll}" Orientation="Vertical" 
-                                                       Width="10" Height="{../../../TemplatedHeight}" />
+                                                       Width="14" Height="{../../../TemplatedHeight}" />
                                        </HorizontalStack>
                                </Border>
                        </Template>
index 3e25ee30635eec9d0adf854bb655e58cb16579fa..ad4e7b42f8e737bae8ce7cad101fbddcc209926a 100644 (file)
     <None Include="Interfaces\test2WayBinding.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
-    <None Include="Interfaces\testButton2.crow">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
     <None Include="Interfaces\testColorList.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
index 5c26534344ffa0ffe35e09be96a26398e01a40ab..086e122b552ceeeddd213b6f4b706242b03972ea 100644 (file)
@@ -417,6 +417,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)
index 53aff76b99988a59b45d57ce81fd4de2aed74128..dd27d21a2835161bb787a2f9d219abb2190ea801 100644 (file)
@@ -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);
index 8bbf67b033ab4d737482232c8cb9a9aef14cbe87..1a608f36031402560cfc0ce7250af1401385421a 100644 (file)
@@ -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 ();
                        }
                }
index 6ce9a3c5a8e97a1ece80786cf3d2cb71c6d96338..08241d9c71d71cced9b8659a37383f684a45844d 100644 (file)
@@ -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);
index 000d377bdd3ae3c37777893a0f451c2fb4684978..3a7135e066bb310ce5b97cd8a3992aeac0892a49 100644 (file)
@@ -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);
 
index ca4dede99efb5abe9c93cdfc05e9876de1aa9d32..51ec702ebccc5cae88970304152504c0fe12c819 100644 (file)
@@ -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;
                }
index 9523411234665025f62e63ef2229985420424e58..d1cfaeb95e65a577d64dbde64672d62fa520f1c2 100644 (file)
@@ -45,6 +45,10 @@ namespace Crow
                {
                        LayoutType = _layoutType;
                        GraphicObject = _graphicObject;
+                       GraphicObject.RegisteredLQIs.Add (this);
+               }
+               public void DeleteLayoutableRef(){
+                       GraphicObject.RegisteredLQIs.Remove(this);
                }
                public void ProcessLayouting()
                {
index 078e1c0a2a45b1cadedeb6b492d76c51dd5c87fc..b5317cefc33cbbb54973e464b90c329812ec629b 100644 (file)
@@ -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)