diff options
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/Combobox.cs | 86 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 59 | ||||
| -rw-r--r-- | src/GraphicObjects/ListBox.cs | 76 |
4 files changed, 148 insertions, 75 deletions
diff --git a/src/GraphicObjects/Combobox.cs b/src/GraphicObjects/Combobox.cs index c9781f71..02040570 100644 --- a/src/GraphicObjects/Combobox.cs +++ b/src/GraphicObjects/Combobox.cs @@ -16,6 +16,7 @@ using System.ComponentModel; using System.Xml;
using System.IO;
using System.Collections;
+using System.Threading;
namespace go
{
@@ -146,40 +147,75 @@ namespace go _list.registerForGraphicUpdate ();
if (data == null)
return;
+ if (SelectedIndex < 0)
+ return;
- #if DEBUG_LOAD_TIME
- Stopwatch loadingTime = new Stopwatch ();
- loadingTime.Start ();
- #endif
+ //force raise of changes
+ SelectedIndex = SelectedIndex;
- MemoryStream ms = new MemoryStream ();
- using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
- stream.CopyTo (ms);
+ pendingChildrenAddition = new Queue<GraphicObject> ();
+ threadedLoadingFinished = false;
- Type t = Interface.GetTopContainerOfGOMLStream (ms);
+ Thread t = new Thread (loadingThread);
+ t.Start ();
- foreach (var item in data) {
- ms.Seek(0,SeekOrigin.Begin);
- GraphicObject g = Interface.Load (ms, t, item);
- g.MouseClick += itemClick;
- _list.addChild(g);
- }
+ }
+ }
+ public override void UpdateLayout (LayoutingType layoutType)
+ {
+ CheckPendingChildrenAddition ();
+ base.UpdateLayout (layoutType);
+ }
+ internal void CheckPendingChildrenAddition()
+ {
+ if (pendingChildrenAddition == null)
+ return;
+ lock (pendingChildrenAddition) {
+ if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50)
+ return;
+ while (pendingChildrenAddition.Count > 0)
+ _list.addChild (pendingChildrenAddition.Dequeue ());
+ }
+ }
- ms.Dispose ();
+ volatile Queue<GraphicObject> pendingChildrenAddition;
+ volatile bool threadedLoadingFinished = false;
- if (SelectedIndex < 0)
- return;
+ void loadingThread()
+ {
+ #if DEBUG_LOAD_TIME
+ Stopwatch loadingTime = new Stopwatch ();
+ loadingTime.Start ();
+ #endif
- //force raise of changes
- SelectedIndex = SelectedIndex;
+ MemoryStream ms = new MemoryStream ();
+ lock (ItemTemplate) {
+ using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
+ stream.CopyTo (ms);
+ }
+
+ Type t = Interface.GetTopContainerOfGOMLStream (ms);
- #if DEBUG_LOAD_TIME
- loadingTime.Stop ();
- Debug.WriteLine("Listbox Loading: {0} ticks \t, {1} ms",
- loadingTime.ElapsedTicks,
- loadingTime.ElapsedMilliseconds);
- #endif
+ foreach (var item in data) {
+ ms.Seek(0,SeekOrigin.Begin);
+ GraphicObject g = Interface.Load (ms, t, item);
+ g.MouseClick += itemClick;
+
+ lock (pendingChildrenAddition) {
+ pendingChildrenAddition.Enqueue (g);
+ }
}
+
+ ms.Dispose ();
+
+ threadedLoadingFinished = true;
+
+ #if DEBUG_LOAD_TIME
+ loadingTime.Stop ();
+ Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
+ loadingTime.ElapsedTicks,
+ loadingTime.ElapsedMilliseconds, this.ToString());
+ #endif
}
public GraphicObject Overlay {
get { return _overlay; }
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index c6260c6b..f50a4427 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -100,6 +100,8 @@ namespace go public override void RegisterForLayouting (int layoutType)
{
+ if (Parent == null)
+ return;
base.RegisterForLayouting (layoutType);
if ((layoutType & (int)LayoutingType.PositionChildren) > 0)
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 63d10122..0617e927 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -452,46 +452,46 @@ namespace go {
if (Parent == null)
return;
-
- Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0);
+ lock (Interface.LayoutingQueue) {
+ Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0);
- if ((layoutType & (int)LayoutingType.Width) > 0) {
+ if ((layoutType & (int)LayoutingType.Width) > 0) {
- //force sizing to fit if parent is sizing on children and
- //this object has stretched size
- if (Parent.getBounds ().Width < 0 && Width == 0)
- Width = -1;
+ //force sizing to fit if parent is sizing on children and
+ //this object has stretched size
+ if (Parent.getBounds ().Width < 0 && Width == 0)
+ Width = -1;
- if (Bounds.Width == 0) //stretch in parent
+ 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
- Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));
- }
+ else if (Bounds.Width < 0) //fit
+ Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this);
+ else
+ Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));
+ }
- if ((layoutType & (int)LayoutingType.Height) > 0) {
+ 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;
+ //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
+ if (Bounds.Height == 0) //stretch in parent
Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this);
- else if (Bounds.Height < 0) //fit
+ else if (Bounds.Height < 0) //fit
Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Height, this);
- else
- Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));
- }
+ else
+ Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));
+ }
- if ((layoutType & (int)LayoutingType.X) > 0)
+ 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)
+ if ((layoutType & (int)LayoutingType.Y) > 0)
//for x positionning, sizing of parent and this have to be done
Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this);
-
+ }
}
/// <summary> trigger dependant sizing component update </summary>
@@ -629,10 +629,11 @@ namespace go LastSlots.Height = Slot.Height;
break;
}
-
- //if no layouting remains in queue for item, registre for redraw
- if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null)
- this.RegisterForRedraw ();
+ lock (Interface.LayoutingQueue) {
+ //if no layouting remains in queue for item, registre for redraw
+ if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null)
+ this.RegisterForRedraw ();
+ }
}
/// <summary> This is the common overridable drawing routine to create new widget </summary>
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 9435ffbe..9f408b5a 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -26,6 +26,8 @@ using System.ComponentModel; using System.IO; using System.Diagnostics; using System.Xml; +using System.Collections.Generic; +using System.Threading; namespace go { @@ -84,33 +86,65 @@ namespace go if (data == null) return; - #if DEBUG_LOAD_TIME - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif + pendingChildrenAddition = new Queue<GraphicObject> (); + threadedLoadingFinished = false; - MemoryStream ms = new MemoryStream (); - using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) + Thread t = new Thread (loadingThread); + t.Start (); + + } + } + + internal void CheckPendingChildrenAddition() + { + if (pendingChildrenAddition == null) + return; + lock (pendingChildrenAddition) { + if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50) + return; + while (pendingChildrenAddition.Count > 0) + _list.addChild (pendingChildrenAddition.Dequeue ()); + } + } + + volatile Queue<GraphicObject> pendingChildrenAddition; + volatile bool threadedLoadingFinished = false; + + void loadingThread() + { + #if DEBUG_LOAD_TIME + Stopwatch loadingTime = new Stopwatch (); + loadingTime.Start (); + #endif + + MemoryStream ms = new MemoryStream (); + lock (ItemTemplate) { + using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) stream.CopyTo (ms); - - Type t = Interface.GetTopContainerOfGOMLStream (ms); + } - foreach (var item in data) { - ms.Seek(0,SeekOrigin.Begin); - GraphicObject g = Interface.Load (ms, t, item); - g.MouseClick += itemClick; - _list.addChild(g); - } + Type t = Interface.GetTopContainerOfGOMLStream (ms); - ms.Dispose (); + foreach (var item in data) { + ms.Seek(0,SeekOrigin.Begin); + GraphicObject g = Interface.Load (ms, t, item); + g.MouseClick += itemClick; - #if DEBUG_LOAD_TIME - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif + lock (pendingChildrenAddition) { + pendingChildrenAddition.Enqueue (g); + } } + + ms.Dispose (); + + threadedLoadingFinished = true; + + #if DEBUG_LOAD_TIME + loadingTime.Stop (); + Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", + loadingTime.ElapsedTicks, + loadingTime.ElapsedMilliseconds, this.ToString()); + #endif } void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){ |