From 7b8ff62e3ee75e19d9eeeabd31bedef371215554 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 27 Apr 2015 14:58:27 +0200 Subject: Layouting queue --- src/GraphicObjects/GenericStack.cs | 103 +++++++++---------------------------- 1 file changed, 24 insertions(+), 79 deletions(-) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index a36cd7b1..36d41f99 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -18,7 +18,6 @@ namespace go #endregion #region Private fields - bool childrenArePositionned = false; int _spacing; Orientation _orientation; #endregion @@ -49,49 +48,25 @@ namespace go get { return base.Height; } set { base.Height = value; } } - [XmlIgnore]public override bool LayoutIsValid { - get { return childrenArePositionned && base.LayoutIsValid; } - set { base.LayoutIsValid = value; } - } - public override void InvalidateLayout () - { - childrenArePositionned = false; - base.InvalidateLayout (); - } protected override Size measureRawSize () { - Size raw = Bounds.Size; Size tmp = new Size (); - if (raw.Width >= 0 && raw.Height >= 0) - return raw; - - foreach (GraphicObject c in Children) { - if (raw.Width < 0) { - if (c.WIsValid) { - if (Orientation == Orientation.Horizontal && c.Bounds.Width != 0) - tmp.Width += c.Slot.Width + Spacing; - else - tmp.Width = Math.Max (tmp.Width, c.Slot.Right); - }else - return raw; + if (Orientation == Orientation.Horizontal) { + foreach (GraphicObject c in Children) { + tmp.Width += c.Slot.Width + Spacing; + tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom); } - if (raw.Height < 0) { - if (c.HIsValid) { - if (Orientation == Orientation.Vertical && c.Bounds.Height != 0) - tmp.Height += c.Slot.Height + Spacing; - else - tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom); - }else - return raw; + } else { + foreach (GraphicObject c in Children) { + tmp.Width = Math.Max (tmp.Width, c.Slot.Right); + tmp.Height += c.Slot.Height + Spacing; } } - if (raw.Width < 0) - tmp.Width += 2*Margin; - if (raw.Height < 0) - tmp.Height += 2*Margin; + tmp.Width += 2*Margin; + tmp.Height += 2*Margin; return tmp; } @@ -100,66 +75,36 @@ namespace go int d = 0; if (Orientation == Orientation.Horizontal) { foreach (GraphicObject c in Children) { - if (c.Bounds.Width == 0) - continue; - c.Slot.X = d; - c.XIsValid = true; d += c.Slot.Width + Spacing; } } else { foreach (GraphicObject c in Children) { - if (c.Bounds.Height == 0) - continue; - c.Slot.Y = d; - c.YIsValid = true; d += c.Slot.Height + Spacing; } } - childrenArePositionned = true; } + public override void RegisterForLayouting () + { + base.RegisterForLayouting (); - public override void UpdateLayout() + int idx = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where (lq => lq.GraphicObject.Parent == this).LastOrDefault ()); + if (idx < 0) + return; + Interface.LayoutingQueue.Insert ( + idx+1, + new LayoutingQueueItem (LayoutingType.PositionChildren, this)); + } + public override void UpdateLayout (LayoutingType layoutType) { - base.UpdateLayout(); - - ComputeChildrenPositions (); + if (layoutType == LayoutingType.PositionChildren) + ComputeChildrenPositions (); - if (LayoutIsValid) - registerForRedraw(); + base.UpdateLayout(layoutType); } #endregion - // -// bool enoughtSpaceForWidget(GraphicObject w) -// { -// if (!SizeToContent) -// { -// int nextXForWidget = 0; -// int nextYForWidget = 0; -// -// if (Orientation == Orientation.Horizontal) -// nextXForWidget = currentXForWidget + w.Slot.Width; -// else -// nextYForWidget = nextYForWidget + w.Slot.Height; -// -// -// if (nextXForWidget > ClientRectangle.Right ) -// return false; -// if (currentYForWidget > ClientRectangle.Bottom ) -// return false; -// } -// return true; -// } -// void advance(GraphicObject w) -// { -// if (Orientation == Orientation.Horizontal) -// currentXForWidget = currentXForWidget + WidgetSpacing + w.Slot.Width; -// else -// currentYForWidget = currentYForWidget + WidgetSpacing + w.Slot.Height; -// -// } } } -- cgit v1.3.1-4-g156e From c88d3c2e0b3e9e69df5f1879b9d8935d3ae0d390 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 28 Apr 2015 17:50:42 +0200 Subject: Layouting queue test 2 --- Tests/GOLIBTest_0.cs | 20 ++++- Tests/GOLIBTest_1.2.cs | 2 +- Tests/Interfaces/test0.goml | 6 +- Tests/Interfaces/test1.2.goml | 4 +- Tests/Interfaces/test1.goml | 6 +- Tests/Tests.csproj | 2 +- src/GraphicObjects/Checkbox.cs | 2 +- src/GraphicObjects/Container.cs | 159 ++++++++++++++++++++++++------------ src/GraphicObjects/GenericStack.cs | 40 ++++++--- src/GraphicObjects/GraphicObject.cs | 145 ++++++++++++++++++++++---------- src/GraphicObjects/Group.cs | 34 +------- src/GraphicObjects/ILayoutable.cs | 2 +- src/GraphicObjects/Scroller.cs | 6 +- src/LayoutingQueue.cs | 30 ++++++- src/LayoutingQueueItem.cs | 14 ++-- src/OpenTKGameWindow.cs | 79 ++---------------- 16 files changed, 322 insertions(+), 229 deletions(-) mode change 100755 => 100644 src/GraphicObjects/Checkbox.cs (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/Tests/GOLIBTest_0.cs b/Tests/GOLIBTest_0.cs index 6d479219..8eaac7fa 100644 --- a/Tests/GOLIBTest_0.cs +++ b/Tests/GOLIBTest_0.cs @@ -36,7 +36,25 @@ namespace test base.OnRenderFrame (e); SwapBuffers (); } - + protected override void OnKeyDown (KeyboardKeyEventArgs e) + { + switch (e.Key) { + case Key.Left: + g.Left++; + break; + case Key.Right: + g.Left--; + break; + case Key.Up: + g.Top--; + break; + case Key.Down: + g.Top++; + break; + default: + break; + } + } protected override void OnUpdateFrame (FrameEventArgs e) { base.OnUpdateFrame (e); diff --git a/Tests/GOLIBTest_1.2.cs b/Tests/GOLIBTest_1.2.cs index 629b2995..3337f06c 100644 --- a/Tests/GOLIBTest_1.2.cs +++ b/Tests/GOLIBTest_1.2.cs @@ -22,7 +22,7 @@ namespace test : base(1024, 600,"test") {} - VerticalStack g; + Container g; protected override void OnLoad (EventArgs e) { diff --git a/Tests/Interfaces/test0.goml b/Tests/Interfaces/test0.goml index 102c1cac..18d1550f 100755 --- a/Tests/Interfaces/test0.goml +++ b/Tests/Interfaces/test0.goml @@ -1,5 +1,5 @@  - diff --git a/Tests/Interfaces/test1.2.goml b/Tests/Interfaces/test1.2.goml index c41135c9..1ccc51ec 100755 --- a/Tests/Interfaces/test1.2.goml +++ b/Tests/Interfaces/test1.2.goml @@ -1,4 +1,5 @@  + \ No newline at end of file + + \ No newline at end of file diff --git a/Tests/Interfaces/test1.goml b/Tests/Interfaces/test1.goml index ff270768..9601a87b 100755 --- a/Tests/Interfaces/test1.goml +++ b/Tests/Interfaces/test1.goml @@ -1,9 +1,9 @@  - + + Margin="20" Focusable="True" Background="Green"> diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 7d37271c..a0af8a64 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - test.GOLIBTest_5 + test.GOLIBTest_1 v4.5 ..\bin\$(configuration) obj\$(configuration) diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs old mode 100755 new mode 100644 index 91f8e451..3c25c741 --- a/src/GraphicObjects/Checkbox.cs +++ b/src/GraphicObjects/Checkbox.cs @@ -67,7 +67,7 @@ namespace go if (value == _CurrentState) return; _CurrentState = value; - registerForRedraw(); + RegisterForRedraw(); } } diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs index 1971f00b..862f7947 100644 --- a/src/GraphicObjects/Container.cs +++ b/src/GraphicObjects/Container.cs @@ -3,6 +3,7 @@ using System.Xml.Serialization; using System.Reflection; using OpenTK.Input; using System.ComponentModel; +using System.Linq; namespace go { @@ -24,13 +25,17 @@ namespace go public T setChild(T _child) { - if (child != null) - child.Parent = null; + if (child != null) { + this.RegisterForLayouting ((int)LayoutingType.Sizing); + child.Parent = null; + } child = _child as GraphicObject; - if (child != null) - child.Parent = this; + if (child != null) { + child.Parent = this; + child.RegisterForLayouting ((int)LayoutingType.Sizing); + } return (T)_child; } @@ -43,19 +48,6 @@ namespace go get { return base.Focusable; } set { base.Focusable = value; } } - [XmlIgnore]public override bool LayoutIsValid - { - get - { - if (!Visible) - return true; - - return !base.LayoutIsValid || child == null ? - base.LayoutIsValid : - child.LayoutIsValid; - } - set { base.LayoutIsValid = value; } - } public override GraphicObject FindByName (string nameToFind) { @@ -69,45 +61,112 @@ namespace go return child == goToFind ? true : child == null ? false : child.Contains(goToFind); } - public override void InvalidateLayout() - { - base.InvalidateLayout(); - - if (child != null) - child.InvalidateLayout(); - } protected override Size measureRawSize () { return child == null ? Bounds.Size : new Size(child.Slot.Width + 2 * (Margin),child.Slot.Height + 2 * (Margin)); } - public override void RegisterForLayouting () - { - base.RegisterForLayouting (); - if (child != null) - child.RegisterForLayouting (); + public override void UpdateLayout (LayoutingType layoutType) + { + { + switch (layoutType) { + case LayoutingType.X: + if (Bounds.X == 0) { + switch (HorizontalAlignment) { + case HorizontalAlignment.Left: + Slot.X = 0; + break; + case HorizontalAlignment.Right: + Slot.X = Parent.ClientRectangle.Width - Slot.Width; + break; + case HorizontalAlignment.Center: + Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2; + break; + } + } else + Slot.X = Bounds.X; + if (LastSlots.X == Slot.X) + break; + //register layouting here for objects depending on this.x + LastSlots.X = Slot.X; + break; + case LayoutingType.Y: + if (Bounds.Y == 0) { + switch (VerticalAlignment) { + case VerticalAlignment.Top: + Slot.Y = 0; + break; + case VerticalAlignment.Bottom: + Slot.Y = Parent.ClientRectangle.Height - Slot.Height; + break; + case VerticalAlignment.Center: + Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2; + break; + } + }else + Slot.Y = Bounds.Y; + if (LastSlots.Y == Slot.Y) + break; + //register layouting here for objects depending on this.x + LastSlots.Y = Slot.Y; + break; + case LayoutingType.Width: + if (Width > 0) + Slot.Width = Width; + else if (Width < 0) + Slot.Width = measureRawSize ().Width; + else + Slot.Width = Parent.ClientRectangle.Width; + + if (LastSlots.Width == Slot.Width) + break; + + if (Parent.getBounds ().Width < 0) + this.Parent.RegisterForLayouting ((int)LayoutingType.Width); + else if (Width != 0) //update position in parent + this.RegisterForLayouting ((int)LayoutingType.X); + + if (child != null) { + if (child.getBounds ().Width == 0) + child.RegisterForLayouting ((int)LayoutingType.Width); + else + child.RegisterForLayouting ((int)LayoutingType.X); + } + LastSlots.Width = Slot.Width; + break; + case LayoutingType.Height: + if (Height > 0) + Slot.Height = Height; + else if (Height < 0) + Slot.Height = measureRawSize ().Height; + else + Slot.Height = Parent.ClientRectangle.Height; + + if (LastSlots.Height == Slot.Height) + break; + + if (Parent.getBounds().Height < 0) + this.Parent.RegisterForLayouting((int)LayoutingType.Height); + else if (Height != 0) //update position in parent + this.RegisterForLayouting ((int)LayoutingType.Y); + + if (child != null) { + if (child.getBounds ().Height == 0) + child.RegisterForLayouting ((int)LayoutingType.Height); + else + child.RegisterForLayouting ((int)LayoutingType.Y); + } + + LastSlots.Height = Slot.Height; + break; + } + + //if no layouting remains in queue for item, registre for redraw + if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0) + this.RegisterForRedraw (); + } } -// public override void UpdateLayout (LayoutingType layoutType) -// { -// -//// if (Width < 0 && child.Width == 0) -//// child.Width = -1; -//// if (Height < 0 && child.Height == 0) -//// child.Height = -1; -//// -//// if (!(base.LayoutIsValid)) -//// base.UpdateLayout(); -//// -//// if (child != null) -//// { -//// if (!child.LayoutIsValid) { -//// child.UpdateLayout (); -//// } -//// } -//// -//// if (LayoutIsValid) -//// registerForRedraw(); -// } + public override Rectangle ContextCoordinates (Rectangle r) { return diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 36d41f99..04e63d15 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -22,6 +22,17 @@ namespace go Orientation _orientation; #endregion + public override T addChild (T child) + { + this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + return base.addChild (child); + } + public override void removeChild (GraphicObject child) + { + base.removeChild (child); + this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + } + #region Public Properties [XmlAttributeAttribute()][DefaultValue(2)] public int Spacing @@ -85,23 +96,30 @@ namespace go } } } - public override void RegisterForLayouting () - { - base.RegisterForLayouting (); +// public void RegisterForLayouting () +// { +// base.RegisterForLayouting (); +// +// int idx = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where (lq => lq.GraphicObject.Parent == this).LastOrDefault ()); +// if (idx < 0) +// return; +// Interface.LayoutingQueue.Insert ( +// idx+1, +// new LayoutingQueueItem (LayoutingType.PositionChildren, this)); +// } + public override void RegisterForLayouting (int layoutType) + { + base.RegisterForLayouting (layoutType); - int idx = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where (lq => lq.GraphicObject.Parent == this).LastOrDefault ()); - if (idx < 0) - return; - Interface.LayoutingQueue.Insert ( - idx+1, - new LayoutingQueueItem (LayoutingType.PositionChildren, this)); + if ((layoutType & (int)LayoutingType.PositionChildren) > 0) + Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); } public override void UpdateLayout (LayoutingType layoutType) { if (layoutType == LayoutingType.PositionChildren) ComputeChildrenPositions (); - - base.UpdateLayout(layoutType); + else + base.UpdateLayout(layoutType); } #endregion diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index c6756db2..9317f409 100755 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -190,8 +190,7 @@ namespace go Bounds.X = value; - LayoutIsValid = false; - registerForGraphicUpdate (); + Interface.LayoutingQueue.Enqueue (LayoutingType.X, this); } } [XmlAttributeAttribute()][DefaultValue(0)] @@ -203,8 +202,7 @@ namespace go Bounds.Y = value; - LayoutIsValid = false; - registerForGraphicUpdate (); + Interface.LayoutingQueue.Enqueue (LayoutingType.Y, this); } } [XmlAttributeAttribute()][DefaultValue(0)] @@ -373,63 +371,96 @@ namespace go public virtual void registerForGraphicUpdate () { bmp = null; - RegisterForLayouting (); + if (TopContainer != null) + TopContainer.gobjsToRedraw.Add (this); + //RegisterForLayouting (); //registerForRedraw (); //Interface.registerForGraphicUpdate(this); } /// /// Add clipping region in redraw list of interface, dont update cached object content /// - public virtual void registerForRedraw () + public virtual void RegisterForRedraw () { - if (Visible && TopContainer != null) - TopContainer.gobjsToRedraw.Add (this); + bmp = null; + TopContainer.gobjsToRedraw.Add (this); } + + public Rectangle LastSlots; + public virtual void registerClipRect() { TopContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); } protected virtual Size measureRawSize () - { + { return Bounds.Size; } - public virtual void RegisterForLayouting() + + public virtual void RegisterForLayouting(int layoutType) { - //clear previous layouting for item - Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this); + Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0); - if (Bounds.Width == 0) { //stretch in parent - int idxParentW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Width).FirstOrDefault()); - if (idxParentW < 0) + if ((layoutType & (int)LayoutingType.Width) > 0) { + if (Bounds.Width == 0) //stretch in parent + Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this); + else //fit ou fixed Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this)); - else//insert after parent sizing - Interface.LayoutingQueue.Insert (idxParentW + 1, new LayoutingQueueItem (LayoutingType.Width, this)); - } else {//fit ou fixed - Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this)); - //for x positionning, sizing of obj and parent have to be done - int idxParentW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Width).FirstOrDefault()); - if (idxParentW < 0) - Interface.LayoutingQueue.Insert (1, new LayoutingQueueItem (LayoutingType.X, this)); - else//insert after parent sizing - Interface.LayoutingQueue.Insert (idxParentW + 1, new LayoutingQueueItem (LayoutingType.X, this)); } - if (Bounds.Height == 0) { //stretch - int idxParentH = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Height).FirstOrDefault()); - if (idxParentH < 0) + + if ((layoutType & (int)LayoutingType.Height) > 0) { + if (Bounds.Height == 0) //stretch in parent + Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this); + else//fit ou fixed Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this)); - else - Interface.LayoutingQueue.Insert (idxParentH + 1, new LayoutingQueueItem (LayoutingType.Height, this)); - } else { - Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this)); - int idxParentH = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Height).FirstOrDefault()); - if (idxParentH < 0) - Interface.LayoutingQueue.Insert (1, new LayoutingQueueItem (LayoutingType.Y, this)); - else//insert after parent sizing - Interface.LayoutingQueue.Insert (idxParentH + 1, new LayoutingQueueItem (LayoutingType.Y, this)); } + if ((layoutType & (int)LayoutingType.X) > 0) + //for x positionning, sizing of parent and this have to be done + Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.X, this); + + if ((layoutType & (int)LayoutingType.Y) > 0) + //for x positionning, sizing of parent and this have to be done + Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this); + } +// public virtual void RegisterForLayouting() +// { +// //clear previous layouting for item +// Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this); +// +// if (Bounds.Width == 0) { //stretch in parent +// int idxParentW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Width).FirstOrDefault()); +// if (idxParentW < 0) +// Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this)); +// else//insert after parent sizing +// Interface.LayoutingQueue.Insert (idxParentW + 1, new LayoutingQueueItem (LayoutingType.Width, this)); +// } else {//fit ou fixed +// Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this)); +// //for x positionning, sizing of obj and parent have to be done +//// int idxParentW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Width).FirstOrDefault()); +//// if (idxParentW < 0) +//// Interface.LayoutingQueue.Insert (1, new LayoutingQueueItem (LayoutingType.X, this)); +//// else//insert after parent sizing +//// Interface.LayoutingQueue.Insert (idxParentW + 1, new LayoutingQueueItem (LayoutingType.X, this)); +// } +// if (Bounds.Height == 0) { //stretch +// int idxParentH = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Height).FirstOrDefault()); +// if (idxParentH < 0) +// Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this)); +// else +// Interface.LayoutingQueue.Insert (idxParentH + 1, new LayoutingQueueItem (LayoutingType.Height, this)); +// } else { +// Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this)); +//// int idxParentH = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Height).FirstOrDefault()); +//// if (idxParentH < 0) +//// Interface.LayoutingQueue.Insert (1, new LayoutingQueueItem (LayoutingType.Y, this)); +//// else//insert after parent sizing +//// Interface.LayoutingQueue.Insert (idxParentH + 1, new LayoutingQueueItem (LayoutingType.Y, this)); +// } +// } +// public virtual void UpdateLayout (LayoutingType layoutType) { switch (layoutType) { @@ -446,9 +477,12 @@ namespace go Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2; break; } + } else + Slot.X = Bounds.X; + if (LastSlots.X == Slot.X) break; - } - Slot.X = Bounds.X; + //register layouting here for objects depending on this.x + LastSlots.X = Slot.X; break; case LayoutingType.Y: if (Bounds.Y == 0) { @@ -463,9 +497,12 @@ namespace go Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2; break; } + }else + Slot.Y = Bounds.Y; + if (LastSlots.Y == Slot.Y) break; - } - Slot.Y = Bounds.Y; + //register layouting here for objects depending on this.x + LastSlots.Y = Slot.Y; break; case LayoutingType.Width: if (Width > 0) @@ -474,6 +511,16 @@ namespace go Slot.Width = measureRawSize ().Width; else Slot.Width = Parent.ClientRectangle.Width; + + if (LastSlots.Width == Slot.Width) + break; + + if (Parent.getBounds().Width < 0) + this.Parent.RegisterForLayouting((int)LayoutingType.Width); + else if (Width != 0) //update position in parent + this.RegisterForLayouting ((int)LayoutingType.X); + + LastSlots.Width = Slot.Width; break; case LayoutingType.Height: if (Height > 0) @@ -482,12 +529,24 @@ namespace go Slot.Height = measureRawSize ().Height; else Slot.Height = Parent.ClientRectangle.Height; + + if (LastSlots.Height == Slot.Height) + break; + + if (Parent.getBounds().Height < 0) + this.Parent.RegisterForLayouting((int)LayoutingType.Height); + else if (Height != 0) //update position in parent + this.RegisterForLayouting ((int)LayoutingType.Y); + + LastSlots.Height = Slot.Height; break; } + //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count() <= 0) - this.registerForRedraw (); + if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0) + this.RegisterForRedraw (); } + protected virtual void onDraw(Context gr) { Rectangle rBack = new Rectangle (Slot.Size); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 8056f06f..e1639533 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -36,15 +36,15 @@ namespace go { GraphicObject g = child as GraphicObject; Children.Add(g); - g.Parent = this as GraphicObject; - LayoutIsValid = false; + g.Parent = this as GraphicObject; + g.RegisterForLayouting ((int)LayoutingType.Sizing); return (T)child; } - public void removeChild(GraphicObject child) + public virtual void removeChild(GraphicObject child) { Children.Remove(child); child.Parent = null; - LayoutIsValid = false; + this.RegisterForLayouting ((int)LayoutingType.Sizing); } public void putWidgetOnTop(GraphicObject w) { @@ -81,26 +81,6 @@ namespace go return true; } } - [XmlIgnore]public override bool LayoutIsValid - { - get - { - if (!Visible) - return true; - - if (!base.LayoutIsValid) - return false; - else//le layout n'est valide que si tous les enfents sont validés aussi - { - foreach (GraphicObject w in Children) - if (!w.LayoutIsValid) - return false; - } - - return true; - } - set { base.LayoutIsValid = value; } - } public override GraphicObject FindByName (string nameToFind) { @@ -144,13 +124,7 @@ namespace go return tmp; } - public override void RegisterForLayouting () - { - base.RegisterForLayouting (); - foreach (GraphicObject g in Children) - g.RegisterForLayouting (); - } // public override void UpdateLayout (LayoutingType layoutType) // { // if (LayoutIsValid) diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 088a4e83..f732a2ca 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -12,7 +12,7 @@ namespace go IGOLibHost TopContainer { get; } - void InvalidateLayout (); + void RegisterForLayouting(int layoutType); void UpdateLayout(LayoutingType layoutType); diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 74e26c72..6855e924 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -72,7 +72,7 @@ namespace go if (VerticalScrolling ) { //add redraw call with old bounds to errase old position - registerForRedraw(); + RegisterForRedraw(); scrollY += e.Delta * ScrollSpeed; @@ -85,7 +85,7 @@ namespace go if (HorizontalScrolling ) { //add redraw call with old bounds to errase old position - registerForRedraw(); + RegisterForRedraw(); scrollX += e.Delta * ScrollSpeed; @@ -97,7 +97,7 @@ namespace go //renderBounds.Y = -scrollY; - registerForRedraw(); + RegisterForRedraw(); //Parent.registerForGraphicUpdate (); } #endregion diff --git a/src/LayoutingQueue.cs b/src/LayoutingQueue.cs index 90152497..142a3079 100644 --- a/src/LayoutingQueue.cs +++ b/src/LayoutingQueue.cs @@ -20,6 +20,7 @@ // along with this program. If not, see . using System; using System.Collections.Generic; +using System.Linq; namespace go { @@ -28,7 +29,34 @@ namespace go public LayoutingQueue () { } - + public void Enqueue(LayoutingType _lt, ILayoutable _object) + { + Interface.LayoutingQueue.RemoveAll(lq => lq.GraphicObject == _object && lq.LayoutType == _lt); + Interface.LayoutingQueue.Add (new LayoutingQueueItem (_lt, _object)); + } + + 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()); + + Interface.LayoutingQueue.Insert (idxParentSz + 1, lqi); + } + public void EnqueueAfterThisAndParentSizing (LayoutingType _lt, ILayoutable _object) + { + LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); + LayoutingType sizing = LayoutingType.Width; + + 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); + } + public LayoutingQueueItem Dequeue() { LayoutingQueueItem tmp = this [0]; diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 4005f71e..e1d21792 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -25,11 +25,13 @@ namespace go { public enum LayoutingType { - X, - Y, - Width, - Height, - PositionChildren + X = 0x01, + Y = 0x02, + Width = 0x04, + Height = 0x08, + Sizing = 0x0C, + PositionChildren = 0x10, + All = 0xFF } public class LayoutingQueueItem @@ -63,7 +65,7 @@ namespace go } public override string ToString () { - return string.Format ("{0}->{1}", LayoutType,GraphicObject.ToString()); + return string.Format ("{1}->{0}", LayoutType,GraphicObject.ToString()); } } } diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 2d491b20..86d8d312 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -79,7 +79,7 @@ namespace go g.Parent = this; GraphicObjects.Add (g); - g.RegisterForLayouting (); + g.RegisterForLayouting ((int)LayoutingType.Sizing); } public void DeleteWidget(GraphicObject g) { @@ -463,6 +463,11 @@ namespace go #region ILayoutable implementation + public void RegisterForLayouting (int layoutType) + { + throw new NotImplementedException (); + } + public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); @@ -524,79 +529,7 @@ namespace go return ClientRectangle; } - public bool WIsValid { - get { - return true; - } - set { - throw new NotImplementedException (); - } - } - public bool HIsValid { - get { - return true; - } - set { - throw new NotImplementedException (); - } - } - public bool XIsValid { - get { - return true; - } - set { - throw new NotImplementedException (); - } - } - public bool YIsValid { - get { - return true; - } - set { - throw new NotImplementedException (); - } - } - public virtual void InvalidateLayout () - { -// foreach (GraphicObject g in GraphicObjects) { -// g.InvalidateLayout (); -// } - } -// public Rectangle rectInScreenCoord (Rectangle r) -// { -// throw new NotImplementedException (); -// } -// public Rectangle renderBoundsInContextCoordonate { -// get { return ClientRectangle; } -// } -// public Rectangle ClientBoundsInContextCoordonate { -// get { -// throw new NotImplementedException (); -// } -// } -// public Rectangle renderBoundsInBackendSurfaceCoordonate { -// get { return ClientRectangle; } -// } -// public Rectangle ClientBoundsInBackendSurfaceCoordonate { -// get { -// throw new NotImplementedException (); -// } -// set { -// throw new NotImplementedException (); -// } -// } -// public Rectangle ScreenCoordBounds { -// get { return ClientRectangle; } -// } -// public Rectangle ScreenCoordClientBounds { -// get { -// throw new NotImplementedException (); -// } -// set { -// throw new NotImplementedException (); -// } -// } #endregion } } \ No newline at end of file -- cgit v1.3.1-4-g156e From 40392cc3bcaee5b67d85b0aabfd42d2881823bd6 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 2 May 2015 09:19:19 +0200 Subject: Layouting queue, debug test4 validated --- Tests/GOLIBTest_4.1.cs | 55 ++++++++++++ Tests/GOLIBTest_4.cs | 5 +- Tests/GOLIBTest_fps.cs | 101 +++++++++++++++++++++ Tests/Interfaces/fps.goml | 27 ++++++ Tests/Interfaces/test1.1.goml | 12 +-- Tests/Interfaces/test1.2.goml | 8 +- Tests/Interfaces/test1.3.goml | 14 +++ Tests/Interfaces/test1.goml | 4 +- Tests/Interfaces/test4.1.goml | 98 ++++++++++++++++++++ Tests/Tests.csproj | 25 +++++- src/GraphicObjects/Border.cs | 4 +- src/GraphicObjects/Container.cs | 141 ++++++++++------------------- src/GraphicObjects/GenericStack.cs | 15 +--- src/GraphicObjects/GraphicObject.cs | 170 ++++++++++++++--------------------- src/GraphicObjects/Group.cs | 59 +++--------- src/GraphicObjects/Label.cs | 3 +- src/GraphicObjects/NumericControl.cs | 8 -- src/GraphicObjects/Scroller.cs | 6 +- src/LayoutingQueue.cs | 11 +++ src/LayoutingQueueItem.cs | 2 +- 20 files changed, 480 insertions(+), 288 deletions(-) create mode 100644 Tests/GOLIBTest_4.1.cs create mode 100644 Tests/GOLIBTest_fps.cs create mode 100755 Tests/Interfaces/fps.goml create mode 100755 Tests/Interfaces/test1.3.goml create mode 100755 Tests/Interfaces/test4.1.goml mode change 100755 => 100644 src/GraphicObjects/GraphicObject.cs (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/Tests/GOLIBTest_4.1.cs b/Tests/GOLIBTest_4.1.cs new file mode 100644 index 00000000..01621df8 --- /dev/null +++ b/Tests/GOLIBTest_4.1.cs @@ -0,0 +1,55 @@ +#define MONO_CAIRO_DEBUG_DISPOSE + + +using System; +using System.Runtime.InteropServices; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +using System.Diagnostics; + +//using GGL; +using go; +using System.Threading; + + +namespace test +{ + class GOLIBTest_4_1 : OpenTKGameWindow + { + public GOLIBTest_4_1 () + : base(1024, 600,"test") + {} + + Group g; + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + LoadInterface("Interfaces/test4.1.goml", out g); + + } + protected override void OnRenderFrame (FrameEventArgs e) + { + GL.Clear (ClearBufferMask.ColorBufferBit); + base.OnRenderFrame (e); + SwapBuffers (); + } + + protected override void OnUpdateFrame (FrameEventArgs e) + { + base.OnUpdateFrame (e); + } + + [STAThread] + static void Main () + { + Console.WriteLine ("starting example"); + + using (GOLIBTest_4_1 win = new GOLIBTest_4_1( )) { + win.Run (30.0); + } + } + } +} \ No newline at end of file diff --git a/Tests/GOLIBTest_4.cs b/Tests/GOLIBTest_4.cs index 2482a66e..5ee286b6 100644 --- a/Tests/GOLIBTest_4.cs +++ b/Tests/GOLIBTest_4.cs @@ -113,8 +113,8 @@ namespace test } ); i++; - if (i > 50) - break; +// if (i > 50) +// break; } } void pFps_mousemove(object sender, MouseMoveEventArgs e) @@ -124,7 +124,6 @@ namespace test redrawClip.AddRectangle (c.ScreenCoordinates(c.Slot)); c.Left += e.XDelta; c.Top += e.YDelta; - c.LayoutIsValid = false; c.registerForGraphicUpdate (); } protected override void OnRenderFrame (FrameEventArgs e) diff --git a/Tests/GOLIBTest_fps.cs b/Tests/GOLIBTest_fps.cs new file mode 100644 index 00000000..946eb5e1 --- /dev/null +++ b/Tests/GOLIBTest_fps.cs @@ -0,0 +1,101 @@ +#define MONO_CAIRO_DEBUG_DISPOSE + + +using System; +using System.Runtime.InteropServices; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +using System.Diagnostics; + +//using GGL; +using go; +using System.Threading; + + +namespace test +{ + class GOLIBTest_fps : OpenTKGameWindow + { + #region FPS + static int _fps = 0; + + public static int fps { + get { return _fps; } + set { + _fps = value; + if (_fps > fpsMax) + fpsMax = _fps; + else if (_fps < fpsMin) + fpsMin = _fps; + } + + } + + public static int fpsMin = int.MaxValue; + public static int fpsMax = 0; + + static void resetFps () + { + fpsMin = int.MaxValue; + fpsMax = 0; + _fps = 0; + } + #endregion + + public GOLIBTest_fps () + : base(400, 200,"test") + {} + + Container g; + Label labFps, labFpsMin, labFpsMax, labUpdate; + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + LoadInterface("Interfaces/fps.goml", out g); + + labFps = g.FindByName ("labFps") as Label; + labFpsMin = g.FindByName ("labFpsMin") as Label; + labFpsMax = g.FindByName ("labFpsMax") as Label; + labUpdate = g.FindByName ("labUpdate") as Label; + + } + protected override void OnRenderFrame (FrameEventArgs e) + { + GL.Clear (ClearBufferMask.ColorBufferBit); + base.OnRenderFrame (e); + SwapBuffers (); + } + + private int frameCpt = 0; + protected override void OnUpdateFrame (FrameEventArgs e) + { + base.OnUpdateFrame (e); + + fps = (int)RenderFrequency; + + labFps.Text = fps.ToString(); + labUpdate.Text = this.updateTime.ElapsedMilliseconds.ToString() + " ms"; + if (frameCpt > 200) { + labFpsMin.Text = fpsMin.ToString(); + labFpsMax.Text = fpsMax.ToString(); + resetFps (); + frameCpt = 0; + + } + frameCpt++; + } + + [STAThread] + static void Main () + { + Console.WriteLine ("starting example"); + + using (GOLIBTest_fps win = new GOLIBTest_fps( )) { + win.Run (30.0); + } + } + } +} \ No newline at end of file diff --git a/Tests/Interfaces/fps.goml b/Tests/Interfaces/fps.goml new file mode 100755 index 00000000..85b60afd --- /dev/null +++ b/Tests/Interfaces/fps.goml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/test1.1.goml b/Tests/Interfaces/test1.1.goml index 6ccf2c1c..86faa998 100755 --- a/Tests/Interfaces/test1.1.goml +++ b/Tests/Interfaces/test1.1.goml @@ -1,15 +1,15 @@  - - + Name="PhaseOverlay1" Width="100" Height="100" Path="image/u.svg" Background="Red"/> + Name="PhaseOverlay2" Width="100" Height="100" Path="image/u.svg" Background="Red"/> - + \ No newline at end of file diff --git a/Tests/Interfaces/test1.2.goml b/Tests/Interfaces/test1.2.goml index 1ccc51ec..c467cd51 100755 --- a/Tests/Interfaces/test1.2.goml +++ b/Tests/Interfaces/test1.2.goml @@ -1,10 +1,10 @@  - - + +