aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-04-27 14:58:27 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-04-27 14:58:27 +0200
commit7b8ff62e3ee75e19d9eeeabd31bedef371215554 (patch)
treef58ee90791028768b69921841cd604e20a3a5c02
parent79224ffe3efe06a99cb5dfb183f16a5427504b2a (diff)
Layouting queue
-rw-r--r--GOLib.csproj8
-rw-r--r--Tests/GOLIBTest_1.1.cs55
-rw-r--r--Tests/GOLIBTest_1.2.cs55
-rwxr-xr-xTests/Interfaces/test0.goml4
-rwxr-xr-xTests/Interfaces/test1.1.goml15
-rwxr-xr-xTests/Interfaces/test1.2.goml18
-rwxr-xr-xTests/Interfaces/test1.goml15
-rw-r--r--Tests/Tests.csproj20
-rw-r--r--src/GraphicObjects/Container.cs60
-rw-r--r--src/GraphicObjects/GenericStack.cs103
-rwxr-xr-xsrc/GraphicObjects/GraphicObject.cs133
-rw-r--r--src/GraphicObjects/Group.cs93
-rw-r--r--src/GraphicObjects/ILayoutable.cs9
-rw-r--r--src/GraphicObjects/Scroller.cs28
-rw-r--r--src/Interface.cs2
-rw-r--r--src/LayoutingQueue.cs40
-rw-r--r--src/LayoutingQueueItem.cs70
-rwxr-xr-xsrc/OpenTKGameWindow.cs27
18 files changed, 489 insertions, 266 deletions
diff --git a/GOLib.csproj b/GOLib.csproj
index 4aad6152..567b61c5 100644
--- a/GOLib.csproj
+++ b/GOLib.csproj
@@ -231,6 +231,14 @@
<LogicalName>
</LogicalName>
</Compile>
+ <Compile Include="src\LayoutingQueueItem.cs">
+ <LogicalName>
+ </LogicalName>
+ </Compile>
+ <Compile Include="src\LayoutingQueue.cs">
+ <LogicalName>
+ </LogicalName>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
diff --git a/Tests/GOLIBTest_1.1.cs b/Tests/GOLIBTest_1.1.cs
new file mode 100644
index 00000000..b9cbdf65
--- /dev/null
+++ b/Tests/GOLIBTest_1.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_1_1 : OpenTKGameWindow
+ {
+ public GOLIBTest_1_1 ()
+ : base(1024, 600,"test")
+ {}
+
+ Group g;
+
+ protected override void OnLoad (EventArgs e)
+ {
+ base.OnLoad (e);
+ LoadInterface("Interfaces/test1.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_1_1 win = new GOLIBTest_1_1( )) {
+ win.Run (30.0);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Tests/GOLIBTest_1.2.cs b/Tests/GOLIBTest_1.2.cs
new file mode 100644
index 00000000..629b2995
--- /dev/null
+++ b/Tests/GOLIBTest_1.2.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_1_2 : OpenTKGameWindow
+ {
+ public GOLIBTest_1_2 ()
+ : base(1024, 600,"test")
+ {}
+
+ VerticalStack g;
+
+ protected override void OnLoad (EventArgs e)
+ {
+ base.OnLoad (e);
+ LoadInterface("Interfaces/test1.2.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_1_2 win = new GOLIBTest_1_2( )) {
+ win.Run (30.0);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Tests/Interfaces/test0.goml b/Tests/Interfaces/test0.goml
index 3163cc9a..102c1cac 100755
--- a/Tests/Interfaces/test0.goml
+++ b/Tests/Interfaces/test0.goml
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<GraphicObject
- Top="10" Left="10"
- Width="10" Height="50"
+ HorizontalAlignment="Right"
+ VerticalAlignment="Bottom"
Margin="10" Background="Green"/>
diff --git a/Tests/Interfaces/test1.1.goml b/Tests/Interfaces/test1.1.goml
new file mode 100755
index 00000000..6ccf2c1c
--- /dev/null
+++ b/Tests/Interfaces/test1.1.goml
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<Group Width="0" Height="0" Margin="50"
+ Focusable="True" Background="Yellow">
+ <Group Width="-1" Height="-1" Margin="50"
+ VerticalAlignment="Top" HorizontalAlignment="Left"
+ Focusable="True" Background="Green">
+ <Image VerticalAlignment="Bottom"
+ Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>
+ <Image Top="100"
+ Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>
+ </Group>
+ <Image Top="100"
+ Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>
+
+</Group> \ No newline at end of file
diff --git a/Tests/Interfaces/test1.2.goml b/Tests/Interfaces/test1.2.goml
new file mode 100755
index 00000000..c41135c9
--- /dev/null
+++ b/Tests/Interfaces/test1.2.goml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<VerticalStack>
+ <Label Text="label11"/>
+ <Label Text="label21"/>
+ <HorizontalStack Width="-1" Height="-1" Margin="50"
+ Focusable="True" Background="DarkBlue">
+ <Label Text="label12"/>
+ <Label Text="label22"/>
+ <Label Text="label32"/>
+ <Label Text="label42"/>
+ <Label Text="label52"/>
+ </HorizontalStack>
+ <Label Text="label33" Background="Green" Width="0"/>
+ <Button/>
+ <Label Text="label43"/>
+ <Label Text="label53"/>
+
+</VerticalStack> \ No newline at end of file
diff --git a/Tests/Interfaces/test1.goml b/Tests/Interfaces/test1.goml
index 43524e85..ff270768 100755
--- a/Tests/Interfaces/test1.goml
+++ b/Tests/Interfaces/test1.goml
@@ -1,9 +1,10 @@
<?xml version="1.0"?>
-<Container
- HorizontalAlignment="Left" VerticalAlignment="Center"
- Margin="10" Focusable="True" Fit="True" Background="Green">
- <Group Background="White" >
- <Image Name="PhaseOverlay" Width="40" Height="40"
- Path="image/u.svg" Background="Red"/>
- </Group>
+<Container Width="0" Height="-1"
+ Margin="100" Focusable="True" Background="Yellow">
+
+ <Container Width="-1" Height="-1"
+ Margin="10" Focusable="True" Background="Green">
+ <Image VerticalAlignment="Bottom"
+ Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>
+ </Container>
</Container> \ No newline at end of file
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index b65edb44..7d37271c 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>Tests</RootNamespace>
<AssemblyName>Tests</AssemblyName>
- <StartupObject>test.GOLIBTest_4</StartupObject>
+ <StartupObject>test.GOLIBTest_5</StartupObject>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputPath>..\bin\$(configuration)</OutputPath>
<IntermediateOutputPath>obj\$(configuration)</IntermediateOutputPath>
@@ -64,6 +64,14 @@
<LogicalName>
</LogicalName>
</Compile>
+ <Compile Include="GOLIBTest_1.1.cs">
+ <LogicalName>
+ </LogicalName>
+ </Compile>
+ <Compile Include="GOLIBTest_1.2.cs">
+ <LogicalName>
+ </LogicalName>
+ </Compile>
</ItemGroup>
<ItemGroup>
<None Include="image\u.svg">
@@ -101,6 +109,16 @@
<LogicalName>
</LogicalName>
</None>
+ <None Include="Interfaces\test1.1.goml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <LogicalName>
+ </LogicalName>
+ </None>
+ <None Include="Interfaces\test1.2.goml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <LogicalName>
+ </LogicalName>
+ </None>
</ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\">
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs
index c1134ec5..1971f00b 100644
--- a/src/GraphicObjects/Container.cs
+++ b/src/GraphicObjects/Container.cs
@@ -77,41 +77,37 @@ namespace go
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 ()
{
- Size raw = Bounds.Size;
-
- if (child != null) {
- if (Bounds.Width < 0 && child.WIsValid)
- raw.Width = child.Slot.Width + 2 * (Margin);
- if (Bounds.Height < 0 && child.HIsValid)
- raw.Height = child.Slot.Height + 2 * (Margin);
- }
+ base.RegisterForLayouting ();
- return raw;
+ if (child != null)
+ child.RegisterForLayouting ();
}
- public override void UpdateLayout()
- {
- if (LayoutIsValid)
- return;
-
- 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 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 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;
-//
-// }
}
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 3ffda14a..c6756db2 100755
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -117,7 +117,7 @@ namespace go
}
}
[XmlIgnore]public virtual IGOLibHost TopContainer {
- get { return Parent.TopContainer; }
+ get { return Parent == null ? null : Parent.TopContainer; }
}
public virtual void InvalidateLayout ()
{
@@ -373,7 +373,8 @@ namespace go
public virtual void registerForGraphicUpdate ()
{
bmp = null;
- registerForRedraw ();
+ RegisterForLayouting ();
+ //registerForRedraw ();
//Interface.registerForGraphicUpdate(this);
}
/// <summary>
@@ -381,7 +382,7 @@ namespace go
/// </summary>
public virtual void registerForRedraw ()
{
- if (LayoutIsValid && Visible)
+ if (Visible && TopContainer != null)
TopContainer.gobjsToRedraw.Add (this);
}
public virtual void registerClipRect()
@@ -392,50 +393,48 @@ namespace go
{
return Bounds.Size;
}
-
- protected virtual void ComputeSize()
+ public virtual void RegisterForLayouting()
{
- Size rawSize = measureRawSize ();
+ //clear previous layouting for item
+ Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this);
- if (!wIsValid) {
- wIsValid = true;
- if (Width > 0)
- Slot.Width = Width;
- else if (Width < 0) {
- if (rawSize.Width > 0)
- Slot.Width = rawSize.Width;
- else
- wIsValid = false;
- } else if (Parent.WIsValid)
- Slot.Width = Parent.ClientRectangle.Width;
- else
- wIsValid = false;
+ 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 (!hIsValid) {
- hIsValid = true;
- if (Height > 0)
- Slot.Height = Height;
- else if (Height < 0) {
- if (rawSize.Height > 0)
- Slot.Height = rawSize.Height;
- else
- hIsValid = false;
- } else if (Parent.HIsValid)
- Slot.Height = Parent.ClientRectangle.Height;
+ 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
- hIsValid = false;
+ 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));
}
+
}
- protected virtual void ComputePosition()
- {
- if (!xIsValid) {
- xIsValid = true;
- if (Width == 0)
- Slot.X = 0;
- else if (Left != 0)
- Slot.X = Left;
- else if (Parent.WIsValid && WIsValid) {
+
+ public virtual void UpdateLayout (LayoutingType layoutType)
+ {
+ switch (layoutType) {
+ case LayoutingType.X:
+ if (Bounds.X == 0) {
switch (HorizontalAlignment) {
case HorizontalAlignment.Left:
Slot.X = 0;
@@ -447,17 +446,12 @@ namespace go
Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2;
break;
}
- } else// if (Parent.getBounds().Width>=0)
- xIsValid = false;
- }
-
- if (!yIsValid) {
- yIsValid = true;
- if (Height== 0)
- Slot.Y = 0;
- else if (Top != 0)
- Slot.Y = Top;
- else if (Parent.HIsValid && HIsValid) {
+ break;
+ }
+ Slot.X = Bounds.X;
+ break;
+ case LayoutingType.Y:
+ if (Bounds.Y == 0) {
switch (VerticalAlignment) {
case VerticalAlignment.Top:
Slot.Y = 0;
@@ -469,19 +463,30 @@ namespace go
Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;
break;
}
- } else// if (Parent.getBounds().Height>=0)
- yIsValid = false;
+ break;
+ }
+ Slot.Y = Bounds.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;
+ break;
+ case LayoutingType.Height:
+ if (Height > 0)
+ Slot.Height = Height;
+ else if (Height < 0)
+ Slot.Height = measureRawSize ().Height;
+ else
+ Slot.Height = Parent.ClientRectangle.Height;
+ break;
}
- }
- public virtual void UpdateLayout ()
- {
- if (!SizeIsValid)
- ComputeSize ();
- if (!PositionIsValid)
- ComputePosition ();
- if (LayoutIsValid)
- registerForRedraw ();
-
+ //if no layouting remains in queue for item, registre for redraw
+ if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count() <= 0)
+ this.registerForRedraw ();
}
protected virtual void onDraw(Context gr)
{
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index d2c48904..8056f06f 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -132,67 +132,58 @@ namespace go
}
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)
- tmp.Width = Math.Max (tmp.Width, c.Slot.Right);
- else
- return raw;
- }
- if (raw.Height < 0) {
- if (c.HIsValid)
- tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);
- else
- return raw;
- }
+ tmp.Width = Math.Max (tmp.Width, c.Slot.Right);
+ tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);
}
- 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;
}
- public override void UpdateLayout()
+ public override void RegisterForLayouting ()
{
- if (LayoutIsValid)
- return;
-
- bool atLeastOneChildHasWNotDependingOnParent = false;
- bool atLeastOneChildHasHNotDependingOnParent = false;
-
- foreach (GraphicObject c in Children) {
- if (c.LayoutIsValid)
- continue;
+ base.RegisterForLayouting ();
- if (Width < 0 && c.WIsValid) {
- if (!atLeastOneChildHasWNotDependingOnParent && !(this is GenericStack))
- c.XIsValid = true;
- atLeastOneChildHasWNotDependingOnParent = true;
- }
- if (Height < 0 && c.HIsValid) {
- if (!atLeastOneChildHasHNotDependingOnParent && !(this is GenericStack))
- c.YIsValid = true;
- atLeastOneChildHasHNotDependingOnParent = true;
- }
-
- c.UpdateLayout ();
- }
-
-// if (Width < 0 && !atLeastOneChildHasWNotDependingOnParent)
-// Debug.WriteLine ("ERROR: no child has fixed width and parent width is set to content!");
-// if (Height < 0 && !atLeastOneChildHasHNotDependingOnParent)
-// Debug.WriteLine ("ERROR: no child has fixed height and parent height is set to content!");
-
- base.UpdateLayout ();
+ foreach (GraphicObject g in Children)
+ g.RegisterForLayouting ();
}
+// public override void UpdateLayout (LayoutingType layoutType)
+// {
+// if (LayoutIsValid)
+// return;
+//
+// bool atLeastOneChildHasWNotDependingOnParent = false;
+// bool atLeastOneChildHasHNotDependingOnParent = false;
+//
+//// foreach (GraphicObject c in Children) {
+//// if (c.LayoutIsValid)
+//// continue;
+////
+//// if (Width < 0 && c.WIsValid) {
+//// if (!atLeastOneChildHasWNotDependingOnParent && !(this is GenericStack))
+//// c.XIsValid = true;
+//// atLeastOneChildHasWNotDependingOnParent = true;
+//// }
+//// if (Height < 0 && c.HIsValid) {
+//// if (!atLeastOneChildHasHNotDependingOnParent && !(this is GenericStack))
+//// c.YIsValid = true;
+//// atLeastOneChildHasHNotDependingOnParent = true;
+//// }
+////
+//// c.UpdateLayout ();
+//// }
+//
+//// if (Width < 0 && !atLeastOneChildHasWNotDependingOnParent)
+//// Debug.WriteLine ("ERROR: no child has fixed width and parent width is set to content!");
+//// if (Height < 0 && !atLeastOneChildHasHNotDependingOnParent)
+//// Debug.WriteLine ("ERROR: no child has fixed height and parent height is set to content!");
+//
+// //base.UpdateLayout ();
+// }
public override Rectangle ContextCoordinates(Rectangle r){
return r + ClientRectangle.Position;
@@ -212,7 +203,7 @@ namespace go
public override void Paint(ref Context ctx, Rectangles clip = null)
{
- if ( !(Visible&LayoutIsValid) )
+ if ( !(Visible) )
return;
// ctx.Save ();
diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs
index 1107f825..088a4e83 100644
--- a/src/GraphicObjects/ILayoutable.cs
+++ b/src/GraphicObjects/ILayoutable.cs
@@ -6,14 +6,6 @@ namespace go
{
ILayoutable Parent { get; set; }
- bool SizeIsValid { get; set; }
- bool WIsValid { get; set; }
- bool HIsValid { get; set; }
- bool PositionIsValid { get; set; }
- bool XIsValid { get; set; }
- bool YIsValid { get; set; }
- bool LayoutIsValid { get; set; }
-
Rectangle ClientRectangle { get; }
Rectangle getSlot();
Rectangle getBounds();
@@ -21,6 +13,7 @@ namespace go
IGOLibHost TopContainer { get; }
void InvalidateLayout ();
+ void UpdateLayout(LayoutingType layoutType);
Rectangle ContextCoordinates(Rectangle r);
diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs
index 45a8a8b3..74e26c72 100644
--- a/src/GraphicObjects/Scroller.cs
+++ b/src/GraphicObjects/Scroller.cs
@@ -115,21 +115,21 @@ namespace go
{
TopContainer.redrawClip.AddRectangle (base.ScreenCoordinates(Slot));
}
- public override void UpdateLayout ()
+ public override void UpdateLayout (LayoutingType layoutType)
{
- base.UpdateLayout ();
-
- if (!LayoutIsValid)
- return;
-
- //override child positionning inside scroller in the
- //scrolling direction
- if (child == null)
- return;
- if (VerticalScrolling)
- child.Slot.Y = 0;
- if (HorizontalScrolling)
- child.Slot.X = 0;
+// base.UpdateLayout ();
+//
+// if (!LayoutIsValid)
+// return;
+//
+// //override child positionning inside scroller in the
+// //scrolling direction
+// if (child == null)
+// return;
+// if (VerticalScrolling)
+// child.Slot.Y = 0;
+// if (HorizontalScrolling)
+// child.Slot.X = 0;
}
public override void Paint(ref Cairo.Context ctx, Rectangles clip = null)
{
diff --git a/src/Interface.cs b/src/Interface.cs
index 8f862381..8684d851 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -35,6 +35,8 @@ namespace go
public static bool ReplaceTabsWithSpace = false;
public static bool DesignerMode = false;
+ public static LayoutingQueue LayoutingQueue = new LayoutingQueue();
+
#region Load/Save
internal static List<EventSource> EventsToResolve;
diff --git a/src/LayoutingQueue.cs b/src/LayoutingQueue.cs
new file mode 100644
index 00000000..90152497
--- /dev/null
+++ b/src/LayoutingQueue.cs
@@ -0,0 +1,40 @@
+//
+// LayoutingQueue.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2015 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Collections.Generic;
+
+namespace go
+{
+ public class LayoutingQueue : List<LayoutingQueueItem>
+ {
+ public LayoutingQueue ()
+ {
+ }
+
+ public LayoutingQueueItem Dequeue()
+ {
+ LayoutingQueueItem tmp = this [0];
+ this.RemoveAt (0);
+ return tmp;
+ }
+ }
+}
+
diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs
new file mode 100644
index 00000000..4005f71e
--- /dev/null
+++ b/src/LayoutingQueueItem.cs
@@ -0,0 +1,70 @@
+//
+// LayoutingQueueItem.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2015 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Diagnostics;
+
+namespace go
+{
+ public enum LayoutingType
+ {
+ X,
+ Y,
+ Width,
+ Height,
+ PositionChildren
+ }
+
+ public class LayoutingQueueItem
+ {
+
+ public ILayoutable GraphicObject;
+ public LayoutingType LayoutType;
+
+ public LayoutingQueueItem (LayoutingType _layoutType, ILayoutable _graphicObject)
+ {
+ LayoutType = _layoutType;
+ GraphicObject = _graphicObject;
+ }
+ public void ProcessLayouting()
+ {
+ Debug.WriteLine ("Layouting => " + this.ToString ());
+ try {
+ GraphicObject.UpdateLayout (LayoutType);
+ } catch (Exception ex) {
+ Debug.WriteLine ("Layouting error: " + ex.ToString ());
+ }
+ }
+
+ public static implicit operator GraphicObject(LayoutingQueueItem queueItem)
+ {
+ return queueItem.GraphicObject as GraphicObject;
+ }
+ public static implicit operator LayoutingType(LayoutingQueueItem lqi)
+ {
+ return lqi.LayoutType;
+ }
+ public override string ToString ()
+ {
+ return string.Format ("{0}->{1}", LayoutType,GraphicObject.ToString());
+ }
+ }
+}
+
diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs
index 644c65c8..2d491b20 100755
--- a/src/OpenTKGameWindow.cs
+++ b/src/OpenTKGameWindow.cs
@@ -78,6 +78,8 @@ namespace go
{
g.Parent = this;
GraphicObjects.Add (g);
+
+ g.RegisterForLayouting ();
}
public void DeleteWidget(GraphicObject g)
{
@@ -224,14 +226,18 @@ namespace go
GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count];
GraphicObjects.CopyTo (invGOList,0);
invGOList = invGOList.Reverse ().ToArray ();
-
- foreach (GraphicObject p in invGOList) {
- if (p.Visible) {
- layoutTime.Start ();
- while(!p.LayoutIsValid)
- p.UpdateLayout ();
- layoutTime.Stop ();
- }
+//
+// foreach (GraphicObject p in invGOList) {
+// if (p.Visible) {
+// layoutTime.Start ();
+// while(!p.LayoutIsValid)
+// p.UpdateLayout ();
+// layoutTime.Stop ();
+// }
+// }
+ while (Interface.LayoutingQueue.Count > 0) {
+ LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
+ lqi.ProcessLayouting ();
}
//Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
@@ -457,6 +463,11 @@ namespace go
#region ILayoutable implementation
+ public void UpdateLayout (LayoutingType layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
public Rectangle ContextCoordinates (Rectangle r)
{
return r;