From 643d44f381962d6814d3676cee322c41018406eb Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 6 Feb 2016 07:11:22 +0100 Subject: [PATCH] 2 step, 1=> Simple Register, 2=> Enqueue with priority checking --- src/GraphicObjects/GenericStack.cs | 7 +++---- src/GraphicObjects/GraphicObject.cs | 19 +++++++++++++------ src/GraphicObjects/Grid.cs | 6 +++--- src/Interface.cs | 1 + src/LayoutingQueueItem.cs | 1 + src/OpenTKGameWindow.cs | 16 ++++++++-------- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index d4e3ae5d..e2bdcf7a 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -108,16 +108,15 @@ namespace Crow bmp = null; } - public override void RegisterForLayouting (int layoutType) + public override void EnqueueForLayouting () { if (Parent == null) return; - base.RegisterForLayouting (layoutType); + base.EnqueueForLayouting (); - if ((layoutType & (int)LayoutingType.PositionChildren) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.PositionChildren)) Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); - } public override void UpdateLayout (LayoutingType layoutType) { diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 53dee9cc..97afaa7e 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -509,9 +509,16 @@ namespace Crow RegisteredLQINodes.Remove (lqis [i]); } } + public LayoutingType RegisteredLayoutings = 0; + + public virtual void RegisterForLayouting(int layoutType){ + if (RegisteredLayoutings == LayoutingType.None) + Interface.RegisteredGOForLayouting.Enqueue (this); + RegisteredLayoutings |= (LayoutingType)layoutType; + } /// clear current layoutingQueue items for object and /// trigger a new layouting pass for a layoutType - public virtual void RegisterForLayouting(int layoutType) + public virtual void EnqueueForLayouting() { if (Parent == null) return; @@ -519,8 +526,8 @@ namespace Crow Debug.WriteLine ("RegisterForLayouting => {1}->{0}", layoutType, this.ToString()); #endif - deleteLQI (layoutType); - if ((layoutType & (int)LayoutingType.Width) > 0) { + //deleteLQI (RegisteredLayoutings); + if (RegisteredLayoutings.HasFlag(LayoutingType.Width)) { if (Bounds.Width == 0) //stretch in parent Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this); else if (Bounds.Width < 0) //fit @@ -531,7 +538,7 @@ namespace Crow new LayoutingQueueItem (LayoutingType.Width, this))); } - if ((layoutType & (int)LayoutingType.Height) > 0) { + if (RegisteredLayoutings.HasFlag(LayoutingType.Height)) { if (Bounds.Height == 0) //stretch in parent Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this); else if (Bounds.Height < 0) //fit @@ -544,11 +551,11 @@ namespace Crow } } - if ((layoutType & (int)LayoutingType.X) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.X)) //for x positionning, sizing of parent and this have to be done Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.X, this); - if ((layoutType & (int)LayoutingType.Y) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.Y)) //for x positionning, sizing of parent and this have to be done Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this); } diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 1981fc60..571fdc0f 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -125,11 +125,11 @@ namespace Crow } } - public override void RegisterForLayouting (int layoutType) + public override void EnqueueForLayouting () { - base.RegisterForLayouting (layoutType); + base.EnqueueForLayouting (); - if ((layoutType & (int)LayoutingType.PositionChildren) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.PositionChildren)) Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); } public override void UpdateLayout (LayoutingType layoutType) diff --git a/src/Interface.cs b/src/Interface.cs index c96dffa0..cf86ecf3 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -54,6 +54,7 @@ namespace Crow public static int BorderThreshold = 5; public static LayoutingQueue LayoutingQueue = new LayoutingQueue (); + public static Queue RegisteredGOForLayouting = new Queue(); #region Load/Save //internal static List Bindings; diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 80d04dc6..7153429b 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -26,6 +26,7 @@ namespace Crow { public enum LayoutingType { + None = 0x00, X = 0x01, Y = 0x02, Width = 0x04, diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 89df8ee4..23d3e814 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -261,18 +261,18 @@ namespace Crow #endif //Debug.WriteLine ("======= Layouting queue start ======="); + while (Interface.RegisteredGOForLayouting.Count > 0){ + while (Interface.RegisteredGOForLayouting.Count > 0){ + GraphicObject go = Interface.RegisteredGOForLayouting.Dequeue (); + go.EnqueueForLayouting (); + go.RegisteredLayoutings = LayoutingType.None; + } while (Interface.LayoutingQueue.First != null) { -// Stopwatch lqiProcTime = new Stopwatch (); -// lqiProcTime.Start (); LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue (); lqi.ProcessLayouting (); -// lqiProcTime.Stop (); -// if (lqiProcTime.ElapsedMilliseconds > 10) { -// Debug.WriteLine("lqi {2}: {0} ticks \t, {1} ms", -// updateTime.ElapsedTicks, -// updateTime.ElapsedMilliseconds, lqi.ToString()); -// } } + } + #if MEASURE_TIME layoutTime.Stop (); #endif -- 2.47.3