diff options
| author | j-p <jp.bruyere@live.be> | 2015-05-02 09:22:03 +0200 |
|---|---|---|
| committer | j-p <jp.bruyere@live.be> | 2015-05-02 09:22:03 +0200 |
| commit | 2a48f25993b48535eb84f0e83e4dd7c064ed6e49 (patch) | |
| tree | 809bc55854f13cb031d26129e7db24076119bca0 /src | |
| parent | 79224ffe3efe06a99cb5dfb183f16a5427504b2a (diff) | |
| parent | 40392cc3bcaee5b67d85b0aabfd42d2881823bd6 (diff) | |
Merge pull request #3 from jpbruyere/LayoutingQueue
Layouting queue
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/Border.cs | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/GraphicObjects/Checkbox.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Container.cs | 116 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 114 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/GraphicObjects/GraphicObject.cs | 262 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 110 | ||||
| -rw-r--r-- | src/GraphicObjects/ILayoutable.cs | 11 | ||||
| -rwxr-xr-x | src/GraphicObjects/Label.cs | 3 | ||||
| -rw-r--r-- | src/GraphicObjects/NumericControl.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/Scroller.cs | 38 | ||||
| -rw-r--r-- | src/Interface.cs | 2 | ||||
| -rw-r--r-- | src/LayoutingQueue.cs | 79 | ||||
| -rw-r--r-- | src/LayoutingQueueItem.cs | 72 | ||||
| -rwxr-xr-x | src/OpenTKGameWindow.cs | 104 |
14 files changed, 463 insertions, 462 deletions
diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index 281db215..e2451582 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -48,9 +48,9 @@ namespace go Size raw = Bounds.Size; if (child != null) { - if (Bounds.Width < 0 && child.WIsValid) + if (Bounds.Width < 0) raw.Width = child.Slot.Width + 2 * (Margin+BorderWidth); - if (Bounds.Height < 0 && child.HIsValid) + if (Bounds.Height < 0) raw.Height = child.Slot.Height + 2 * (Margin+BorderWidth); } diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs index 91f8e451..3c25c741 100755..100644 --- 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 c1134ec5..0d0ad5b3 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>(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,49 +61,63 @@ 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 ()
- {
- 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);
- }
-
- return raw;
+ {
+ return child == null ? Bounds.Size : new Size(child.Slot.Width + 2 * (Margin),child.Slot.Height + 2 * (Margin));
}
- 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 ();
+ protected override void OnLayoutChanges (LayoutingType layoutType)
+ {
+ switch (layoutType) {
+ case LayoutingType.Width:
+ base.OnLayoutChanges (layoutType);
+ if (child != null) {
+ if (child.getBounds ().Width == 0)
+ child.RegisterForLayouting ((int)LayoutingType.Width);
+ else
+ child.RegisterForLayouting ((int)LayoutingType.X);
}
- }
+ break;
+ case LayoutingType.Height:
+ base.OnLayoutChanges (layoutType);
+ if (child != null) {
+ if (child.getBounds ().Height == 0)
+ child.RegisterForLayouting ((int)LayoutingType.Height);
+ else
+ child.RegisterForLayouting ((int)LayoutingType.Y);
+ }
+ break;
+ }
+ }
+
+// public override void RegisterForLayouting(int layoutType)
+// {
+// Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 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.Enqueue (LayoutingType.Width, this);
+// }
+//
+// 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.Enqueue (LayoutingType.Height, 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);
+//
+// }
- if (LayoutIsValid)
- registerForRedraw();
- }
public override Rectangle ContextCoordinates (Rectangle r)
{
return
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index a36cd7b1..f34e13d3 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -18,11 +18,22 @@ namespace go #endregion
#region Private fields
- bool childrenArePositionned = false;
int _spacing;
Orientation _orientation;
#endregion
+ public override T addChild<T> (T child)
+ {
+ T tmp = base.addChild (child);
+ this.RegisterForLayouting ((int)LayoutingType.PositionChildren);
+ return tmp;
+ }
+ public override void removeChild (GraphicObject child)
+ {
+ base.removeChild (child);
+ this.RegisterForLayouting ((int)LayoutingType.PositionChildren);
+ }
+
#region Public Properties
[XmlAttributeAttribute()][DefaultValue(2)]
public int Spacing
@@ -49,49 +60,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 +87,33 @@ 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 UpdateLayout()
- {
- base.UpdateLayout();
-
- ComputeChildrenPositions ();
+ public override void RegisterForLayouting (int layoutType)
+ {
+ base.RegisterForLayouting (layoutType);
- if (LayoutIsValid)
- registerForRedraw();
+ if ((layoutType & (int)LayoutingType.PositionChildren) > 0)
+ Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this);
+ }
+ public override void UpdateLayout (LayoutingType layoutType)
+ {
+ if (layoutType == LayoutingType.PositionChildren)
+ ComputeChildrenPositions ();
+ else
+ 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..a7b9e93e 100755..100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -66,49 +66,6 @@ namespace go get { return _parent; }
set { _parent = value; }
}
- [XmlIgnore]public virtual bool SizeIsValid {
- get { return hIsValid & wIsValid; }
- set {
- hIsValid = value;
- wIsValid = value;
- }
- }
- [XmlIgnore]public virtual bool WIsValid {
- get { return wIsValid; }
- set { wIsValid = value; }
- }
- [XmlIgnore]public virtual bool HIsValid {
- get { return hIsValid; }
- set { hIsValid = value; }
- }
- [XmlIgnore]public virtual bool XIsValid {
- get { return xIsValid; }
- set { xIsValid = value; }
- }
- [XmlIgnore]public virtual bool YIsValid {
- get { return yIsValid; }
- set { yIsValid = value; }
- }
- [XmlIgnore]public virtual bool PositionIsValid {
- get { return xIsValid & yIsValid; }
- set {
- xIsValid = value;
- yIsValid = value;
- }
- }
- [XmlIgnore]public virtual bool LayoutIsValid {
- get { return SizeIsValid & PositionIsValid; }
- set {
- if (value == SizeIsValid & PositionIsValid)
- return;
-
- SizeIsValid = value;
- PositionIsValid = value;
-
- //if (!layoutIsValid && Parent != null)
- // Parent.layoutIsValid = false;
- }
- }
[XmlIgnore]public virtual Rectangle ClientRectangle {
get {
Rectangle cb = Slot.Size;
@@ -117,12 +74,7 @@ namespace go }
}
[XmlIgnore]public virtual IGOLibHost TopContainer {
- get { return Parent.TopContainer; }
- }
- public virtual void InvalidateLayout ()
- {
- bmp = null;
- LayoutIsValid = false;
+ get { return Parent == null ? null : Parent.TopContainer; }
}
public virtual Rectangle ContextCoordinates(Rectangle r){
return
@@ -190,8 +142,7 @@ namespace go Bounds.X = value;
- LayoutIsValid = false;
- registerForGraphicUpdate ();
+ this.RegisterForLayouting ((int)LayoutingType.X);
}
}
[XmlAttributeAttribute()][DefaultValue(0)]
@@ -203,8 +154,7 @@ namespace go Bounds.Y = value;
- LayoutIsValid = false;
- registerForGraphicUpdate ();
+ this.RegisterForLayouting ((int)LayoutingType.Y);
}
}
[XmlAttributeAttribute()][DefaultValue(0)]
@@ -216,7 +166,7 @@ namespace go Bounds.Width = value;
- InvalidateLayout ();
+ this.RegisterForLayouting ((int)LayoutingType.Width);
}
}
[XmlAttributeAttribute()][DefaultValue(0)]
@@ -228,7 +178,7 @@ namespace go Bounds.Height = value;
- InvalidateLayout ();
+ this.RegisterForLayouting ((int)LayoutingType.Height);
}
}
[XmlAttributeAttribute()][DefaultValue(false)]
@@ -239,7 +189,6 @@ namespace go return;
Bounds.Width = Bounds.Height = -1;
- InvalidateLayout ();
}
}
[XmlAttributeAttribute()][DefaultValue(false)]
@@ -373,69 +322,107 @@ namespace go public virtual void registerForGraphicUpdate ()
{
bmp = null;
- registerForRedraw ();
+ if (TopContainer != null)
+ TopContainer.gobjsToRedraw.Add (this);
+ //RegisterForLayouting ();
+ //registerForRedraw ();
//Interface.registerForGraphicUpdate(this);
}
/// <summary>
/// Add clipping region in redraw list of interface, dont update cached object content
/// </summary>
- public virtual void registerForRedraw ()
+ public virtual void RegisterForRedraw ()
{
- if (LayoutIsValid && Visible)
- 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;
}
- protected virtual void ComputeSize()
+ public virtual void RegisterForLayouting(int layoutType)
{
- Size rawSize = measureRawSize ();
+ if (Parent == null)
+ return;
+
+ Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0);
- 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;
+ if ((layoutType & (int)LayoutingType.Width) > 0) {
+
+ //force sizing to fit if parent is sizing on children
+ if (Parent.getBounds ().Width < 0 && Width == 0)
+ Width = -1;
+
+ if (Bounds.Width == 0) //stretch in parent
+ Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this);
+ else if (Bounds.Width < 0) //fit
+ Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this);
else
- wIsValid = false;
+ Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, 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 ((layoutType & (int)LayoutingType.Height) > 0) {
+
+ //force sizing to fit if parent is sizing on children
+ if (Parent.getBounds ().Height < 0 && Height == 0)
+ Height = -1;
+
+ if (Bounds.Height == 0) //stretch in parent
+ Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this);
+ else if (Bounds.Height < 0) //fit
+ Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Height, this);
else
- hIsValid = false;
+ Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, 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);
+
}
- protected virtual void ComputePosition()
+
+ protected virtual void OnLayoutChanges(LayoutingType layoutType)
{
- if (!xIsValid) {
- xIsValid = true;
- if (Width == 0)
- Slot.X = 0;
- else if (Left != 0)
- Slot.X = Left;
- else if (Parent.WIsValid && WIsValid) {
+ switch (layoutType) {
+ case LayoutingType.Width:
+ 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 (!(Parent is GenericStack))
+ break;
+ if ((Parent as GenericStack).Orientation == Orientation.Horizontal)
+ this.Parent.RegisterForLayouting ((int)LayoutingType.PositionChildren);
+ break;
+ case LayoutingType.Height:
+ 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 (!(Parent is GenericStack))
+ break;
+ if ((Parent as GenericStack).Orientation == Orientation.Vertical)
+ this.Parent.RegisterForLayouting ((int)LayoutingType.PositionChildren);
+ break;
+ }
+ }
+ 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 +434,20 @@ namespace go Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2;
break;
}
- } else// if (Parent.getBounds().Width>=0)
- xIsValid = false;
- }
+ } else
+ Slot.X = Bounds.X;
- if (!yIsValid) {
- yIsValid = true;
- if (Height== 0)
- Slot.Y = 0;
- else if (Top != 0)
- Slot.Y = Top;
- else if (Parent.HIsValid && HIsValid) {
+ if (LastSlots.X == Slot.X)
+ break;
+
+ bmp = null;
+
+ OnLayoutChanges (layoutType);
+
+ LastSlots.X = Slot.X;
+ break;
+ case LayoutingType.Y:
+ if (Bounds.Y == 0) {
switch (VerticalAlignment) {
case VerticalAlignment.Top:
Slot.Y = 0;
@@ -469,20 +459,59 @@ namespace go Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;
break;
}
- } else// if (Parent.getBounds().Height>=0)
- yIsValid = false;
+ }else
+ Slot.Y = Bounds.Y;
+
+ if (LastSlots.Y == Slot.Y)
+ break;
+
+ bmp = null;
+
+ OnLayoutChanges (layoutType);
+
+ 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;
+
+ bmp = null;
+
+ OnLayoutChanges (layoutType);
+
+ 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;
+
+ bmp = null;
+
+ OnLayoutChanges (layoutType);
+
+ LastSlots.Height = Slot.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)
{
Rectangle rBack = new Rectangle (Slot.Size);
@@ -505,6 +534,7 @@ namespace go onDraw (gr);
}
draw.Flush ();
+ //draw.WriteToPng ("/mnt/data/test.png");
}
}
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index d2c48904..7b63156f 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -36,16 +36,17 @@ 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)
{
if (Children.Contains(w))
@@ -81,26 +82,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)
{
@@ -124,75 +105,22 @@ namespace go }
return false;
}
- public override void InvalidateLayout()
- {
- base.InvalidateLayout();
- foreach (GraphicObject w in Children)
- w.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)
- 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()
- {
- 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 +140,7 @@ namespace go public override void Paint(ref Context ctx, Rectangles clip = null)
{
- if ( !(Visible&LayoutIsValid) )
+ if ( !(Visible) )
return;
// ctx.Save ();
@@ -281,15 +209,15 @@ namespace go }
#endregion
- public override string ToString()
- {
- string tmp = base.ToString();
- foreach (GraphicObject w in Children)
- {
- tmp += "\n" + w.ToString();
- }
- return tmp;
- }
+// public override string ToString()
+// {
+// string tmp = base.ToString();
+// foreach (GraphicObject w in Children)
+// {
+// tmp += "\n" + w.ToString();
+// }
+// return tmp;
+// }
#region IXmlSerializable
diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 1107f825..f732a2ca 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -6,21 +6,14 @@ 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(); IGOLibHost TopContainer { get; } - void InvalidateLayout (); + void RegisterForLayouting(int layoutType); + void UpdateLayout(LayoutingType layoutType); Rectangle ContextCoordinates(Rectangle r); diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index ee62a266..1f6048d1 100755 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -86,7 +86,8 @@ namespace go return;
registerForGraphicUpdate();
- InvalidateLayout();
+ this.RegisterForLayouting ((int)LayoutingType.Sizing);
+
_text = value;
diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index 51a3fdc5..93aadc84 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -43,8 +43,6 @@ namespace go _minValue = value; - LayoutIsValid = false; - registerForGraphicUpdate (); } } [XmlAttributeAttribute()][DefaultValue(10.0)] @@ -57,8 +55,6 @@ namespace go _maxValue = value; - LayoutIsValid = false; - registerForGraphicUpdate (); } } [XmlAttributeAttribute()][DefaultValue(0.5)] @@ -71,8 +67,6 @@ namespace go _smallStep = value; - LayoutIsValid = false; - registerForGraphicUpdate (); } } [XmlAttributeAttribute()][DefaultValue(2.0)] @@ -85,8 +79,6 @@ namespace go _bigStep = value; - LayoutIsValid = false; - registerForGraphicUpdate (); } } [XmlAttributeAttribute()][DefaultValue(0)] diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 45a8a8b3..19b93cd8 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
@@ -115,22 +115,22 @@ namespace go {
TopContainer.redrawClip.AddRectangle (base.ScreenCoordinates(Slot));
}
- public override void UpdateLayout ()
- {
- 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 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;
+ //}
public override void Paint(ref Cairo.Context ctx, Rectangles clip = null)
{
if (!Visible)//check if necessary??
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..2d96788f --- /dev/null +++ b/src/LayoutingQueue.cs @@ -0,0 +1,79 @@ +// +// 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; +using System.Linq; + +namespace go +{ + public class LayoutingQueue : List<LayoutingQueueItem> + { + 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 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()); + + if (idxParentSz < 0) + Interface.LayoutingQueue.Enqueue (_lt, _object); + else + Interface.LayoutingQueue.Insert (idxParentSz, 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]; + this.RemoveAt (0); + return tmp; + } + } +} + diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs new file mode 100644 index 00000000..b028fb83 --- /dev/null +++ b/src/LayoutingQueueItem.cs @@ -0,0 +1,72 @@ +// +// 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 = 0x01, + Y = 0x02, + Width = 0x04, + Height = 0x08, + Sizing = 0x0C, + PositionChildren = 0x10, + All = 0xFF + } + + 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 ("{1}->{0}", LayoutType,GraphicObject.ToString()); + } + } +} + diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 644c65c8..86d8d312 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -78,6 +78,8 @@ namespace go {
g.Parent = this;
GraphicObjects.Add (g);
+
+ g.RegisterForLayouting ((int)LayoutingType.Sizing);
}
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,16 @@ namespace go #region ILayoutable implementation
+ public void RegisterForLayouting (int layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public void UpdateLayout (LayoutingType layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
public Rectangle ContextCoordinates (Rectangle r)
{
return r;
@@ -513,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 |