From: jpbruyere Date: Tue, 2 Jun 2015 10:28:36 +0000 (+0200) Subject: listbox update X-Git-Tag: 0.2~92 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=c54c8b8e7e369dbba890efdb35a015740d1d95ea;p=jp%2Fcrow.git listbox update --- diff --git a/Templates/Listbox.goml b/Templates/Listbox.goml index 0746d24e..43f8425b 100755 --- a/Templates/Listbox.goml +++ b/Templates/Listbox.goml @@ -1,3 +1,5 @@  - - \ No newline at end of file + + + + \ No newline at end of file diff --git a/Tests/GOLIBTest_4.cs b/Tests/GOLIBTest_4.cs index 9b189a92..096d249e 100644 --- a/Tests/GOLIBTest_4.cs +++ b/Tests/GOLIBTest_4.cs @@ -17,15 +17,7 @@ using System.Collections.Generic; namespace test { - public class ClsItem - { - public string Field; - public ClsItem(){ - } - public ClsItem(string str){ - Field = str; - } - } + class GOLIBTest_4 : OpenTKGameWindow, IValueChange { #region IValueChange implementation diff --git a/Tests/GOLIBTest_Listbox.cs b/Tests/GOLIBTest_Listbox.cs new file mode 100644 index 00000000..cd7cd83a --- /dev/null +++ b/Tests/GOLIBTest_Listbox.cs @@ -0,0 +1,97 @@ +#define MONO_CAIRO_DEBUG_DISPOSE + + +using System; +using System.Runtime.InteropServices; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +using System.Diagnostics; + +//using GGL; +using go; +using System.Threading; +using System.Collections.Generic; + + +namespace test +{ + public class ClsItem : IValueChange + { + #region IValueChange implementation + + public event EventHandler ValueChanged; + + #endregion + + public string field; + + public string Field { + get { + return field; + } + set { + field = value; + ValueChanged.Raise(this, new ValueChangeEventArgs ("Field", null, field)); + } + } + + public ClsItem(){ + } + public ClsItem(string str){ + Field = str; + } + } + + class GOLIBTest_Listbox : OpenTKGameWindow, IValueChange + { + #region IValueChange implementation + + public event EventHandler ValueChanged; + + #endregion + + public GOLIBTest_Listbox () + : base(1024, 600,"test") + {} + + public List TestList = new List(new ClsItem[] + { + new ClsItem("string 1"), + new ClsItem("string 2"), + new ClsItem("string 3") + }); + ListBox g; + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + LoadInterface("Interfaces/test_Listbox.goml", out g); + + ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", null, TestList)); + TestList [1].Field = "test string"; + } + protected override void OnRenderFrame (FrameEventArgs e) + { + GL.Clear (ClearBufferMask.ColorBufferBit); + base.OnRenderFrame (e); + SwapBuffers (); + } + + protected override void OnUpdateFrame (FrameEventArgs e) + { + base.OnUpdateFrame (e); + } + + [STAThread] + static void Main () + { + Console.WriteLine ("starting example"); + + using (GOLIBTest_Listbox win = new GOLIBTest_Listbox( )) { + win.Run (30.0); + } + } + } +} \ No newline at end of file diff --git a/Tests/Interfaces/test_Listbox.goml b/Tests/Interfaces/test_Listbox.goml new file mode 100755 index 00000000..d336ae3c --- /dev/null +++ b/Tests/Interfaces/test_Listbox.goml @@ -0,0 +1,3 @@ + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 2efca8ef..d19fb844 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - test.GOLIBTest_4 + test.GOLIBTest_Listbox v4.5 ..\bin\$(configuration) obj\$(configuration) @@ -83,6 +83,10 @@ + + + + @@ -150,6 +154,11 @@ PreserveNewest + + PreserveNewest + + + diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 36c88030..f8bbcdf0 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -237,8 +237,18 @@ namespace go if (!srcValueType.IsValueType) il.Emit(OpCodes.Castclass, srcValueType); - il.Emit(OpCodes.Callvirt, miToStr); + if (piTarget.PropertyType == typeof(string)) + il.Emit(OpCodes.Callvirt, miToStr); il.Emit(OpCodes.Callvirt, piTarget.GetSetMethod()); + + //initialize target with actual value + if (miSrc.MemberType == MemberTypes.Property) + piTarget.GetSetMethod().Invoke(binding.Source, new object[] { (miSrc as PropertyInfo).GetGetMethod().Invoke(_source,null)}); + else if (miSrc.MemberType == MemberTypes.Field){ + MethodInfo miSetTarget = piTarget.GetSetMethod(); + FieldInfo fiSource = miSrc as FieldInfo; + miSetTarget.Invoke(binding.Source, new object[] { fiSource.GetValue(_source)}); + } } il.MarkLabel(labFailed); il.Emit(OpCodes.Ret); diff --git a/src/Interface.cs b/src/Interface.cs index a9da051a..0d0425ed 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -139,16 +139,21 @@ namespace go fi.SetValue(es.Source, del); } } - - foreach (DynAttribute binding in Bindings) { -// Type tSource = binding.Source.GetType (); -// if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ -// Debug.WriteLine ("Binding source does not implement IValueChange."); -// continue; -// } - //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); + while (Bindings.Count > 0) { + DynAttribute binding = Bindings [0]; + Bindings.RemoveAt (0); CompilerServices.CreateBinding (binding, hostClass); } +// foreach (DynAttribute binding in Bindings) { +//// Type tSource = binding.Source.GetType (); +//// if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ +//// Debug.WriteLine ("Binding source does not implement IValueChange."); +//// continue; +//// } +// //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); +// CompilerServices.CreateBinding (binding, hostClass); +// } +// Bindings.Clear (); } public static GraphicObject Load(Stream stream, Type type, object hostClass = null) { @@ -185,17 +190,22 @@ namespace go fi.SetValue(es.Source, del); } } - - foreach (DynAttribute binding in Bindings) { - // Type tSource = binding.Source.GetType (); - // if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ - // Debug.WriteLine ("Binding source does not implement IValueChange."); - // continue; - // } - //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); + while (Bindings.Count > 0) { + DynAttribute binding = Bindings [0]; + Bindings.RemoveAt (0); CompilerServices.CreateBinding (binding, hostClass); } +// foreach (DynAttribute binding in Bindings) { +// // Type tSource = binding.Source.GetType (); +// // if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ +// // Debug.WriteLine ("Binding source does not implement IValueChange."); +// // continue; +// // } +// //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); +// CompilerServices.CreateBinding (binding, hostClass); +// } +// Bindings.Clear (); return result; }