From d57ae20644694ed4862785be98d3ead18100315f Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Wed, 14 Oct 2015 15:06:07 +0200 Subject: [PATCH] debug threaded listbox debug new binding system --- Templates/ComboboxOverlay.goml | 6 +-- Templates/Scrollbar.goml | 4 +- Tests/GOLIBTests.cs | 13 ++++-- Tests/Interfaces/testCombobox.goml | 2 +- src/GraphicObjects/Combobox.cs | 33 +++++++++------ src/GraphicObjects/Group.cs | 12 +++++- src/GraphicObjects/ListBox.cs | 56 ++++++++++++++++---------- src/GraphicObjects/TemplatedControl.cs | 3 +- src/GraphicObjects/Window.cs | 7 +++- src/Interface.cs | 1 + src/OpenTKGameWindow.cs | 6 +++ 11 files changed, 98 insertions(+), 45 deletions(-) diff --git a/Templates/ComboboxOverlay.goml b/Templates/ComboboxOverlay.goml index 4665846f..cab49531 100755 --- a/Templates/ComboboxOverlay.goml +++ b/Templates/ComboboxOverlay.goml @@ -1,7 +1,7 @@  - + - + \ No newline at end of file diff --git a/Templates/Scrollbar.goml b/Templates/Scrollbar.goml index 8dcadc64..08d33a95 100755 --- a/Templates/Scrollbar.goml +++ b/Templates/Scrollbar.goml @@ -2,13 +2,13 @@ \ No newline at end of file diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index 5fcbbc38..83fe00a1 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -20,13 +20,15 @@ namespace test class GOLIBTests : OpenTKGameWindow, IValueChange { #region IValueChange implementation - public event EventHandler ValueChanged; - + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } #endregion public GOLIBTests () - : base(600, 400,"test: press spacebar to toogle test files") + : base(600, 500,"test: press spacebar to toogle test files") { VSync = VSyncMode.Off; } @@ -124,6 +126,11 @@ namespace test base.OnKeyDown (e); if (e.Key == Key.Escape) { this.Quit (); + return; + }else if (e.Key == Key.L) { + TestList.Add ("new string"); + NotifyValueChanged ("TestList", TestList); + return; } ClearInterface (); idx++; diff --git a/Tests/Interfaces/testCombobox.goml b/Tests/Interfaces/testCombobox.goml index c022d22c..ddd92aa5 100755 --- a/Tests/Interfaces/testCombobox.goml +++ b/Tests/Interfaces/testCombobox.goml @@ -1,2 +1,2 @@  - \ No newline at end of file + \ No newline at end of file diff --git a/src/GraphicObjects/Combobox.cs b/src/GraphicObjects/Combobox.cs index 3e841793..bed9f131 100644 --- a/src/GraphicObjects/Combobox.cs +++ b/src/GraphicObjects/Combobox.cs @@ -22,7 +22,7 @@ namespace go { [DefaultTemplate("#go.Templates.Combobox.goml")] [DefaultOverlayTemplate("#go.Templates.ComboboxOverlay.goml")] - public class Combobox : TemplatedControl + public class Combobox : TemplatedContainer { #region CTOR public Combobox() : base(){ } @@ -48,14 +48,14 @@ namespace go base.loadTemplate (template); loadOverlayTemplate (null); } -// public override GraphicObject Content { -// get { -// throw new NotImplementedException (); -// } -// set { -// throw new NotImplementedException (); -// } -// } + public override GraphicObject Content { + get { + throw new NotImplementedException (); + } + set { + throw new NotImplementedException (); + } + } #endregion protected virtual void loadOverlayTemplate(GraphicObject overlayTemplate) @@ -84,7 +84,8 @@ namespace go //TODO:reload list with new template? _overlayTemplate = value; - Overlay = Interface.Load (_overlayTemplate, this, !Interface.DontResoveGOML); + Overlay = Interface.Load (_overlayTemplate); + Overlay.ResolveBindings (); _list = Overlay.FindByName ("List") as Group; } } @@ -111,7 +112,7 @@ namespace go Text = ""; else Text = _selectedItem.ToString (); - } + } } public object SelectedItem{ set { @@ -159,6 +160,7 @@ namespace go Thread t = new Thread (loadingThread); t.Start (); + t.Join (); } } @@ -226,6 +228,7 @@ namespace go if (_overlay != null) { _overlay.LayoutChanged -= _overlay_LayoutChanged; _overlay.MouseLeave -= _overlay_MouseLeave; + _overlay.LogicalParent = null; } _overlay = value; @@ -233,6 +236,7 @@ namespace go if (_overlay == null) return; + _overlay.LogicalParent = this; _overlay.Focusable = true; _overlay.LayoutChanged += _overlay_LayoutChanged; _overlay.MouseLeave += _overlay_MouseLeave; @@ -351,6 +355,11 @@ namespace go base.ClearBinding (); } - + public override void ResolveBindings () + { + base.ResolveBindings (); + if (Overlay != null) + Overlay.ResolveBindings (); + } } } diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 5c2b7df2..78378aa8 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -53,7 +53,17 @@ namespace go Children.Remove(child); this.RegisterForLayouting ((int)LayoutingType.Sizing); } - + public virtual void ClearChildren() + { + int lim = children.Count; + for (int i = 0; i < lim; i++) { + GraphicObject g = Children [0]; + g.ClearBinding (); + g.Parent = null; + Children.Remove(g); + } + this.RegisterForLayouting ((int)LayoutingType.Sizing); + } public void putWidgetOnTop(GraphicObject w) { if (Children.Contains(w)) diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 15752f80..5f2e5454 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -75,45 +75,60 @@ namespace go get { return data; } - set { + set { + if (loadingInProgress) { + thread.Join (); + Interface.LoadingLists.Remove (this); + pendingChildrenAddition = null; + loadingInProgress = false; + } + data = value; - foreach (GraphicObject c in _list.Children) { - c.ClearBinding (); - } - _list.Children.Clear (); - _list.registerForGraphicUpdate (); + _list.ClearChildren (); + if (data == null) return; pendingChildrenAddition = new Queue (); threadedLoadingFinished = false; + Interface.LoadingLists.Add (this); - Thread t = new Thread (loadingThread); - t.Start (); - t.Join (); - + thread = new Thread(loadingThread); + loadingInProgress = true; + thread.Start (); } } - public override void UpdateLayout (LayoutingType layoutType) - { - CheckPendingChildrenAddition (); - base.UpdateLayout (layoutType); - } +// public override void UpdateLayout (LayoutingType layoutType) +// { +// CheckPendingChildrenAddition (); +// base.UpdateLayout (layoutType); +// } internal void CheckPendingChildrenAddition() { - if (pendingChildrenAddition == null) + if (!loadingInProgress) return; lock (pendingChildrenAddition) { if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50) return; - while (pendingChildrenAddition.Count > 0) - _list.addChild (pendingChildrenAddition.Dequeue ()); + while (pendingChildrenAddition.Count > 0) { + GraphicObject tmp = pendingChildrenAddition.Dequeue (); + tmp.DataSource = tmp.Tag; + tmp.Tag = null; + _list.addChild (tmp); + } + if (threadedLoadingFinished) { + Interface.LoadingLists.Remove (this); + pendingChildrenAddition = null; + loadingInProgress = false; + } } } - volatile Queue pendingChildrenAddition; + Queue pendingChildrenAddition; volatile bool threadedLoadingFinished = false; + volatile bool loadingInProgress = false; + Thread thread; void loadingThread() { @@ -133,9 +148,8 @@ namespace go foreach (var item in data) { ms.Seek(0,SeekOrigin.Begin); GraphicObject g = Interface.Load (ms, t); - g.DataSource = item; + g.Tag = item; g.MouseClick += itemClick; - lock (pendingChildrenAddition) { pendingChildrenAddition.Enqueue (g); } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index d6c7243d..de688d2c 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -116,9 +116,10 @@ namespace go if (template == null) { DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault(); this.SetChild (Interface.Load (dt.Path, this)); - this.child.ResolveBindings (); }else this.SetChild (template); + + this.child.ResolveBindings (); } #region IXmlSerializable diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index f9e3a54b..0af4c762 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -219,7 +219,12 @@ namespace go TopContainer.DeleteWidget (parent as GraphicObject); } - + public override void ResolveBindings () + { + base.ResolveBindings (); + if (Content != null) + Content.ResolveBindings (); + } } } diff --git a/src/Interface.cs b/src/Interface.cs index ddd2a008..1b6f2437 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -49,6 +49,7 @@ namespace go /// public static List References = new List (); public static Queue FreeRefIndices = new Queue (); + public static List LoadingLists= new List(); public static void Unreference (Object o) { diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index fc6f9916..6b16f157 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -254,6 +254,12 @@ namespace go surf = new ImageSurface(bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height,ClientRectangle.Width*4); ctx = new Context(surf); + if (Interface.LoadingLists.Count > 0) { + ListBox[] loadings = new ListBox[Interface.LoadingLists.Count]; + Interface.LoadingLists.CopyTo (loadings, 0); + for (int i = 0; i < loadings.Length; i++) + loadings [i].CheckPendingChildrenAddition (); + } GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count]; GraphicObjects.CopyTo (invGOList,0); -- 2.47.3