aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
Diffstat (limited to 'src/GraphicObjects')
-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
6 files changed, 178 insertions, 248 deletions
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)
{