]> O.S.I.I.S - jp/crow.git/commitdiff
debug threaded listbox
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 14 Oct 2015 13:06:07 +0000 (15:06 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 14 Oct 2015 13:06:07 +0000 (15:06 +0200)
debug new binding system

Templates/ComboboxOverlay.goml
Templates/Scrollbar.goml
Tests/GOLIBTests.cs
Tests/Interfaces/testCombobox.goml
src/GraphicObjects/Combobox.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/ListBox.cs
src/GraphicObjects/TemplatedControl.cs
src/GraphicObjects/Window.cs
src/Interface.cs
src/OpenTKGameWindow.cs

index 4665846fc09e51a51cbc71dae233d60ab5b2e04b..cab4953159e03dcb12e7a89a38c3e1cdcb73204b 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>\r
 <Border BorderWidth="1" Margin="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}" >\r
-       <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"\r
-               Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">\r
+<!--   <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"\r
+               Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">-->\r
                <VerticalStack Height="-1" Width="{../../../TemplatedWidth}" Name="List" Margin="0" VerticalAlignment="Top"/>\r
-       </Scroller>\r
+<!--   </Scroller>-->\r
 </Border>
\ No newline at end of file
index 8dcadc64926096500782a1de241d445ecc65848d..08d33a95e339bb07e956534722ea171908d37d18 100755 (executable)
@@ -2,13 +2,13 @@
 <Border BorderWidth="1" BorderColor="LightGray">\r
        <GenericStack Orientation="{../../Orientation}" Width="0" Height="0">\r
                <Button Width="12" Height="12" MouseClick="../../../onScrollBack">\r
-                       <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="../../../../up"/>\r
+                       <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="up"/>\r
                </Button>\r
                <Slider Name="Slider" Value="{../../../Scroll}" Maximum="{../../../MaximumScroll}" \r
                        Width="{../../../Width}" Height="{../../../Height}" Orientation="{../../../Orientation}"\r
                        ValueChanged="../../../onSliderValueChange"/>\r
                <Button Width="12" Height="12" MouseClick="../../../onScrollForth">\r
-                       <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="../../../../down"/>\r
+                       <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="down"/>\r
                </Button>\r
        </GenericStack>\r
 </Border>
\ No newline at end of file
index 5fcbbc386358a2a8ca2aad6645d260e4c2748e81..83fe00a1a221a8589ebaab3cd30e89c65cccc22e 100644 (file)
@@ -20,13 +20,15 @@ namespace test
        class GOLIBTests : OpenTKGameWindow, IValueChange\r
        {\r
                #region IValueChange implementation\r
-\r
                public event EventHandler<ValueChangeEventArgs> ValueChanged;\r
-\r
+               public virtual void NotifyValueChanged(string MemberName, object _value)\r
+               {\r
+                       ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));                 \r
+               }\r
                #endregion\r
 \r
                public GOLIBTests ()\r
-                       : base(600, 400,"test: press spacebar to toogle test files")\r
+                       : base(600, 500,"test: press spacebar to toogle test files")\r
                {\r
                        VSync = VSyncMode.Off;\r
                }\r
@@ -124,6 +126,11 @@ namespace test
                        base.OnKeyDown (e);\r
                        if (e.Key == Key.Escape) {\r
                                this.Quit ();\r
+                               return;\r
+                       }else if (e.Key == Key.L) {\r
+                               TestList.Add ("new string");\r
+                               NotifyValueChanged ("TestList", TestList);\r
+                               return;\r
                        }\r
                        ClearInterface ();\r
                        idx++;\r
index c022d22c87c83a3d2aff3be420f4ae62da7f9c1e..ddd92aa5029b70bb3be3593274236fa0e4a17d22 100755 (executable)
@@ -1,2 +1,2 @@
 <?xml version="1.0"?>\r
-<Combobox Height="-1" Data="{TestList}"/>
\ No newline at end of file
+<Combobox Height="-1" Data="{TestList}" SelectedIndex="0"/>
\ No newline at end of file
index 3e841793e3e80223abe69e69e08c1b72880456bf..bed9f131c878516cfe96d0eb42dd7f89d2ec1006 100644 (file)
@@ -22,7 +22,7 @@ namespace go
 {\r
        [DefaultTemplate("#go.Templates.Combobox.goml")]\r
        [DefaultOverlayTemplate("#go.Templates.ComboboxOverlay.goml")]\r
-       public class Combobox : TemplatedControl\r
+       public class Combobox : TemplatedContainer\r
     {          \r
                #region CTOR\r
                public Combobox() : base(){     }       \r
@@ -48,14 +48,14 @@ namespace go
                        base.loadTemplate (template);\r
                        loadOverlayTemplate (null);\r
                }\r
-//             public override GraphicObject Content {\r
-//                     get {\r
-//                             throw new NotImplementedException ();\r
-//                     }\r
-//                     set {\r
-//                             throw new NotImplementedException ();\r
-//                     }\r
-//             }\r
+               public override GraphicObject Content {\r
+                       get {\r
+                               throw new NotImplementedException ();\r
+                       }\r
+                       set {\r
+                               throw new NotImplementedException ();\r
+                       }\r
+               }\r
                #endregion\r
 \r
                protected virtual void loadOverlayTemplate(GraphicObject overlayTemplate)\r
@@ -84,7 +84,8 @@ namespace go
                                //TODO:reload list with new template?\r
                                _overlayTemplate = value; \r
 \r
-                               Overlay = Interface.Load (_overlayTemplate, this, !Interface.DontResoveGOML);\r
+                               Overlay = Interface.Load (_overlayTemplate);\r
+                               Overlay.ResolveBindings ();\r
                                _list = Overlay.FindByName ("List") as Group;\r
                        }\r
                }\r
@@ -111,7 +112,7 @@ namespace go
                                        Text = "";\r
                                else\r
                                        Text = _selectedItem.ToString ();\r
-                       }\r
+                               }\r
                }\r
                public object SelectedItem{\r
                        set {\r
@@ -159,6 +160,7 @@ namespace go
 \r
                                Thread t = new Thread (loadingThread);\r
                                t.Start ();\r
+                               t.Join ();\r
 \r
                        }\r
                }\r
@@ -226,6 +228,7 @@ namespace go
                                if (_overlay != null) {\r
                                        _overlay.LayoutChanged -= _overlay_LayoutChanged;\r
                                        _overlay.MouseLeave -= _overlay_MouseLeave;\r
+                                       _overlay.LogicalParent = null;\r
                                }\r
 \r
                                _overlay = value; \r
@@ -233,6 +236,7 @@ namespace go
                                if (_overlay == null)\r
                                        return;\r
 \r
+                               _overlay.LogicalParent = this;\r
                                _overlay.Focusable = true;\r
                                _overlay.LayoutChanged += _overlay_LayoutChanged;\r
                                _overlay.MouseLeave += _overlay_MouseLeave;\r
@@ -351,6 +355,11 @@ namespace go
                        base.ClearBinding ();\r
 \r
                }\r
-\r
+               public override void ResolveBindings ()\r
+               {\r
+                       base.ResolveBindings ();\r
+                       if (Overlay != null)\r
+                               Overlay.ResolveBindings ();\r
+               }\r
        }\r
 }\r
index 5c2b7df27bcdbc08ab677d448d52ea812ef1dcf4..78378aa8642897cefffbf17170e1f8a8e2f5ca99 100644 (file)
@@ -53,7 +53,17 @@ namespace go
             Children.Remove(child);\r
                        this.RegisterForLayouting ((int)LayoutingType.Sizing);\r
         }\r
-\r
+               public virtual void ClearChildren()\r
+               {\r
+                       int lim = children.Count;\r
+                       for (int i = 0; i < lim; i++) {\r
+                               GraphicObject g = Children [0];\r
+                               g.ClearBinding ();\r
+                               g.Parent = null;\r
+                               Children.Remove(g);                             \r
+                       }\r
+                       this.RegisterForLayouting ((int)LayoutingType.Sizing);\r
+               }\r
                public void putWidgetOnTop(GraphicObject w)\r
                {\r
                        if (Children.Contains(w))\r
index 15752f8001bddd0490817cf5fe0323e26a1f581e..5f2e5454c4135d22a9cddc699a15aef1a259955a 100644 (file)
@@ -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<GraphicObject> ();
                                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<GraphicObject> pendingChildrenAddition;
+               Queue<GraphicObject> 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);
                                }
index d6c7243d0d45537fe4359ff7e1ecd6a04fb1f428..de688d2cf0bbb639d9961e0116535b889d5fb518 100644 (file)
@@ -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
index f9e3a54b428bce78f0a23353078710b0eb9630db..0af4c7626edfa5ea81404e0ab64650a475954653 100644 (file)
@@ -219,7 +219,12 @@ namespace go
                        TopContainer.DeleteWidget (parent as GraphicObject);
                }
 
-
+               public override void ResolveBindings ()
+               {
+                       base.ResolveBindings ();
+                       if (Content != null)
+                               Content.ResolveBindings ();
+               }
        }
 }
 
index ddd2a0085004d51dc3994d27e7c932cfbb892ad4..1b6f24374948ef21de2647f652f1520e4da446fa 100644 (file)
@@ -49,6 +49,7 @@ namespace go
                /// </summary>
                public static List<object> References = new List<object> ();
                public static Queue<int> FreeRefIndices = new Queue<int> ();
+               public static List<ListBox> LoadingLists= new List<ListBox>();
 
                public static void Unreference (Object o)
                {
index fc6f9916f11d87ed3e9b3574ee5af72363ef01aa..6b16f1576dd4eff79dac16e150c95a9dad99fbdc 100755 (executable)
@@ -254,6 +254,12 @@ namespace go
                        surf = new ImageSurface(bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height,ClientRectangle.Width*4);\r
                        ctx = new Context(surf);\r
 \r
+                       if (Interface.LoadingLists.Count > 0) {\r
+                               ListBox[] loadings = new ListBox[Interface.LoadingLists.Count];\r
+                               Interface.LoadingLists.CopyTo (loadings, 0);\r
+                               for (int i = 0; i < loadings.Length; i++)\r
+                                       loadings [i].CheckPendingChildrenAddition ();                           \r
+                       }\r
 \r
                        GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count];\r
                        GraphicObjects.CopyTo (invGOList,0);\r