aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-06-02 12:28:36 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-06-02 12:28:36 +0200
commitc54c8b8e7e369dbba890efdb35a015740d1d95ea (patch)
treef2b7ed73e93c4170e22e3713d4c66e02eeb40d76
parentb56c22ad826a49b7ea0013c1ca78cf64169fc326 (diff)
listbox update
-rwxr-xr-xTemplates/Listbox.goml6
-rw-r--r--Tests/GOLIBTest_4.cs10
-rw-r--r--Tests/GOLIBTest_Listbox.cs97
-rwxr-xr-xTests/Interfaces/test_Listbox.goml3
-rw-r--r--Tests/Tests.csproj11
-rw-r--r--src/CompilerServices/CompilerServices.cs12
-rw-r--r--src/Interface.cs42
7 files changed, 152 insertions, 29 deletions
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 @@
<?xml version="1.0"?>
-<VerticalStack Name="List">
-</VerticalStack> \ No newline at end of file
+<Border Fit="True" Background="Gray">
+ <VerticalStack Name="List" Margin="5">
+ </VerticalStack>
+</Border> \ 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<ValueChangeEventArgs> 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<ValueChangeEventArgs> ValueChanged;
+
+ #endregion
+
+ public GOLIBTest_Listbox ()
+ : base(1024, 600,"test")
+ {}
+
+ public List<ClsItem> TestList = new List<ClsItem>(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 @@
+<?xml version="1.0"?>
+ <ListBox Data="{TestList}">
+ </ListBox>
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 @@
<OutputType>Exe</OutputType>
<RootNamespace>Tests</RootNamespace>
<AssemblyName>Tests</AssemblyName>
- <StartupObject>test.GOLIBTest_4</StartupObject>
+ <StartupObject>test.GOLIBTest_Listbox</StartupObject>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputPath>..\bin\$(configuration)</OutputPath>
<IntermediateOutputPath>obj\$(configuration)</IntermediateOutputPath>
@@ -83,6 +83,10 @@
<LogicalName>
</LogicalName>
</Compile>
+ <Compile Include="GOLIBTest_Listbox.cs">
+ <LogicalName>
+ </LogicalName>
+ </Compile>
</ItemGroup>
<ItemGroup>
<None Include="image\u.svg">
@@ -150,6 +154,11 @@
</LogicalName>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Include="Interfaces\test_Listbox.goml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <LogicalName>
+ </LogicalName>
+ </None>
</ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\">
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;
}