From 8771dccd2369447a50485c7649e8a0851b551958 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 23 Apr 2016 19:45:04 +0200 Subject: [PATCH] stack --- OTKCrow/OpenTKGameWindow.cs | 4 +- Tests/GOLIBTestsOTK.cs | 6 +- Tests/Interfaces/Stack/0h.crow | 9 ++ Tests/Interfaces/Stack/1.crow | 6 +- Tests/Interfaces/Stack/1h.crow | 9 ++ Tests/Interfaces/Stack/2.crow | 8 +- Tests/Interfaces/Stack/2h.crow | 9 ++ Tests/Interfaces/Stack/3.crow | 48 +++++++- Tests/Interfaces/Stack/3h.crow | 45 +++++++ Tests/Interfaces/Stack/4.crow | 27 +++++ Tests/Tests.csproj | 17 ++- src/GraphicObjects/GenericStack.cs | 189 ++++++++++------------------- 12 files changed, 231 insertions(+), 146 deletions(-) create mode 100755 Tests/Interfaces/Stack/0h.crow create mode 100755 Tests/Interfaces/Stack/1h.crow create mode 100755 Tests/Interfaces/Stack/2h.crow create mode 100755 Tests/Interfaces/Stack/3h.crow create mode 100755 Tests/Interfaces/Stack/4.crow diff --git a/OTKCrow/OpenTKGameWindow.cs b/OTKCrow/OpenTKGameWindow.cs index 329f83fb..60fa8b89 100644 --- a/OTKCrow/OpenTKGameWindow.cs +++ b/OTKCrow/OpenTKGameWindow.cs @@ -99,7 +99,7 @@ namespace Crow public OpenTKGameWindow(int _width, int _height, string _title="Crow") : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), _title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second), - 3,3,OpenTK.Graphics.GraphicsContextFlags.Debug) + 3,3,OpenTK.Graphics.GraphicsContextFlags.Default) // public OpenTKGameWindow(int _width, int _height, string _title="golib") // : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title) { @@ -131,7 +131,7 @@ namespace Crow while (true) { CrowInterface.Update (); - Thread.Sleep (5); + Thread.Sleep (1); } } diff --git a/Tests/GOLIBTestsOTK.cs b/Tests/GOLIBTestsOTK.cs index bc0d4e03..1383d029 100644 --- a/Tests/GOLIBTestsOTK.cs +++ b/Tests/GOLIBTestsOTK.cs @@ -91,12 +91,12 @@ namespace testOTK //this.AddWidget(new test4()); KeyboardKeyDown += GOLIBTests_KeyboardKeyDown1;; - testFiles = Directory.GetFiles(@"Interfaces/Group", "*.crow").ToArray(); + testFiles = Directory.GetFiles(@"Interfaces/Stack", "*.crow").ToArray(); //testFiles = Directory.GetFiles(@"Interfaces/Stack", "*.crow").ToArray(); //testFiles = Directory.GetFiles(@"Interfaces/GraphicObject", "*.crow").Concat(testFiles).ToArray(); //testFiles = Directory.GetFiles(@"Interfaces", "*.crow").Concat(testFiles).ToArray(); - + this.Title = testFiles [idx]; GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); obj.DataSource = this; @@ -168,7 +168,7 @@ namespace testOTK if (idx == testFiles.Length) idx = 0; this.Title = testFiles [idx]; - GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]); + GraphicObject obj = CrowInterface.LoadInterface(testFiles[2]); obj.DataSource = this; } diff --git a/Tests/Interfaces/Stack/0h.crow b/Tests/Interfaces/Stack/0h.crow new file mode 100755 index 00000000..9e31f04a --- /dev/null +++ b/Tests/Interfaces/Stack/0h.crow @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/Stack/1.crow b/Tests/Interfaces/Stack/1.crow index c2423ef1..f8b28779 100755 --- a/Tests/Interfaces/Stack/1.crow +++ b/Tests/Interfaces/Stack/1.crow @@ -1,9 +1,9 @@  - - - \ No newline at end of file diff --git a/Tests/Interfaces/Stack/1h.crow b/Tests/Interfaces/Stack/1h.crow new file mode 100755 index 00000000..b86b77ac --- /dev/null +++ b/Tests/Interfaces/Stack/1h.crow @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/Stack/2.crow b/Tests/Interfaces/Stack/2.crow index 5f23a7d4..ebf1d1e9 100755 --- a/Tests/Interfaces/Stack/2.crow +++ b/Tests/Interfaces/Stack/2.crow @@ -1,9 +1,9 @@  - - + - - \ No newline at end of file diff --git a/Tests/Interfaces/Stack/2h.crow b/Tests/Interfaces/Stack/2h.crow new file mode 100755 index 00000000..dc05fc0c --- /dev/null +++ b/Tests/Interfaces/Stack/2h.crow @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/Stack/3.crow b/Tests/Interfaces/Stack/3.crow index 0c3987fa..a5ec06ad 100755 --- a/Tests/Interfaces/Stack/3.crow +++ b/Tests/Interfaces/Stack/3.crow @@ -1,9 +1,45 @@  - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/Stack/3h.crow b/Tests/Interfaces/Stack/3h.crow new file mode 100755 index 00000000..a675876e --- /dev/null +++ b/Tests/Interfaces/Stack/3h.crow @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/Stack/4.crow b/Tests/Interfaces/Stack/4.crow new file mode 100755 index 00000000..8e1f757b --- /dev/null +++ b/Tests/Interfaces/Stack/4.crow @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 24042c9f..328511d1 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -322,7 +322,22 @@ PreserveNewest - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + PreserveNewest diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index dd385201..d5ff81c6 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -1,14 +1,10 @@ -using System; +using System.ComponentModel; using System.Diagnostics; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Xml.Serialization; -using System.ComponentModel; namespace Crow { - public class GenericStack : Group + public class GenericStack : Group { #region CTOR public GenericStack() @@ -54,41 +50,13 @@ namespace Crow } protected override int measureRawSize (LayoutingType lt) { - int tmp = 0; - switch (lt) { - case LayoutingType.Width: - if (Orientation == Orientation.Horizontal) { - if (Children.Count > 0) { - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (c.RegisteredLayoutings.HasFlag (LayoutingType.Width)) - return -1; - tmp += c.Slot.Width + Spacing; - } - tmp -= Spacing; - } - break; - } - return base.measureRawSize (lt); - case LayoutingType.Height: - if (Orientation == Orientation.Vertical) { - if (Children.Count > 0) { - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (c.RegisteredLayoutings.HasFlag (LayoutingType.Height)) - return -1; - tmp += c.Slot.Height + Spacing; - } - tmp -= Spacing; - } - break; - } - return base.measureRawSize (lt); - } - - return tmp + 2 * Margin; + if (lt == LayoutingType.Width) { + if (Orientation == Orientation.Horizontal) + return contentSize.Width + (Children.Count - 1) * Spacing + 2 * Margin; + }else if (Orientation == Orientation.Vertical) + return contentSize.Height + (Children.Count - 1) * Spacing + 2 * Margin; + + return base.measureRawSize (lt); } public virtual void ComputeChildrenPositions() { @@ -99,7 +67,6 @@ namespace Crow continue; c.Slot.X = d; d += c.Slot.Width + Spacing; - c.RegisterForLayouting (LayoutingType.Y); } } else { foreach (GraphicObject c in Children) { @@ -107,12 +74,11 @@ namespace Crow continue; c.Slot.Y = d; d += c.Slot.Height + Spacing; - c.RegisterForLayouting (LayoutingType.X); } } bmp = null; } - + GraphicObject stretchedGO = null; public override bool UpdateLayout (LayoutingType layoutType) { RegisteredLayoutings &= (~layoutType); @@ -122,86 +88,6 @@ namespace Crow //this child will occupy remaining space //if stack size policy is Fit, no child may have stretch enabled //in the direction of stacking. - if (Orientation == Orientation.Horizontal) { - GraphicObject stretchedGO = null; - int tmpWidth = Slot.Width; - int cptChildren = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].Visible) - continue; - //requeue Positionning if child is not layouted - if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width)) - return false; - cptChildren++; - if (Children [i].Width == Measure.Stretched) { - if (!(stretchedGO == null && Width != Measure.Fit)) { - //change size policy of other stretched children - Children [i].Width = Measure.Fit; - return false; - } - stretchedGO = Children [i]; - if (i < Children.Count - 1) - tmpWidth -= Spacing; - continue; - } - tmpWidth -= Children [i].Slot.Width + Spacing; - } - if (stretchedGO != null && Width != Measure.Fit) { - tmpWidth += (Spacing - 2 * Margin); - if (tmpWidth < MinimumSize.Width) - tmpWidth = MinimumSize.Width; - else if (tmpWidth > MaximumSize.Width && MaximumSize.Width > 0) - tmpWidth = MaximumSize.Width; - if (stretchedGO.LastSlots.Width != tmpWidth) { - stretchedGO.Slot.Width = tmpWidth; - stretchedGO.bmp = null; - #if DEBUG_LAYOUTING - Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); - #endif - stretchedGO.OnLayoutChanges (LayoutingType.Width); - stretchedGO.LastSlots.Width = stretchedGO.Slot.Width; - } - } - } else { - GraphicObject stretchedGO = null; - int tmpHeight = Slot.Height; - int cptChildren = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].Visible) - continue; - if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) - return false; - cptChildren++; - if (Children [i].Height == Measure.Stretched) { - if (!(stretchedGO == null && Height != Measure.Fit)){ - Children [i].Height = Measure.Fit; - return false; - } - stretchedGO = Children [i]; - if (i < Children.Count - 1) - tmpHeight -= Spacing; - continue; - } - tmpHeight -= Children[i].Slot.Height + Spacing; - } - if (stretchedGO != null && Height != Measure.Fit) { - tmpHeight += (Spacing - 2 * Margin); - if (tmpHeight < MinimumSize.Height) - tmpHeight = MinimumSize.Height; - else if (tmpHeight > MaximumSize.Height && MaximumSize.Height > 0) - tmpHeight = MaximumSize.Height; - if (stretchedGO.LastSlots.Height != tmpHeight) { - stretchedGO.Slot.Height = tmpHeight; - stretchedGO.bmp = null; - #if DEBUG_LAYOUTING - Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString()); - #endif - stretchedGO.OnLayoutChanges (LayoutingType.Height); - stretchedGO.LastSlots.Height = stretchedGO.Slot.Height; - } - } - } - ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw @@ -216,26 +102,75 @@ namespace Crow public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { - base.OnChildLayoutChanges (sender, arg); - GraphicObject go = sender as GraphicObject; - + Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); switch (arg.LayoutType) { case LayoutingType.Width: if (Orientation == Orientation.Horizontal) { + if (go.Width == Measure.Stretched) { + if (stretchedGO == null && Width != Measure.Fit) + stretchedGO = go; + else if (stretchedGO != go) { + go.Slot.Width = 0; + go.Width = Measure.Fit; + return; + } + } else + contentSize.Width += go.Slot.Width - go.LastSlots.Width; + + if (stretchedGO != null) { + stretchedGO.Slot.Width = this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1); + stretchedGO.bmp = null; +#if DEBUG_LAYOUTING + Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); +#endif + stretchedGO.LayoutChanged -= OnChildLayoutChanges; + stretchedGO.OnLayoutChanges (LayoutingType.Width); + stretchedGO.LayoutChanged += OnChildLayoutChanges; + stretchedGO.LastSlots.Width = stretchedGO.Slot.Width; + } + if (Width == Measure.Fit) this.RegisterForLayouting (LayoutingType.Width); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); + return; } break; case LayoutingType.Height: if (Orientation == Orientation.Vertical) { + if (go.Height == Measure.Stretched) { + if (stretchedGO == null && Height != Measure.Fit) + stretchedGO = go; + else if (stretchedGO != go){ + go.Slot.Height = 0; + go.Height = Measure.Fit; + return; + } + } else + contentSize.Height += go.Slot.Height - go.LastSlots.Height; + + if (stretchedGO != null) { + stretchedGO.Slot.Height = this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count -1); + stretchedGO.bmp = null; +#if DEBUG_LAYOUTING + Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); +#endif + stretchedGO.LayoutChanged -= OnChildLayoutChanges; + stretchedGO.OnLayoutChanges (LayoutingType.Height); + stretchedGO.LayoutChanged += OnChildLayoutChanges; + stretchedGO.LastSlots.Height = stretchedGO.Slot.Height; + } + if (Height == Measure.Fit) this.RegisterForLayouting (LayoutingType.Height); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); + return; } break; } + base.OnChildLayoutChanges (sender, arg); } #endregion -- 2.47.3