]> O.S.I.I.S - jp/crow.git/commitdiff
Simple bindings
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 18 May 2015 16:13:48 +0000 (18:13 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 18 May 2015 16:13:48 +0000 (18:13 +0200)
demonstration in testFps

23 files changed:
GOLib.csproj
GOLib.sln
Images/Icons/updown.svg [new file with mode: 0644]
Tests/GOLIBTest_1.cs
Tests/GOLIBTest_4.cs
Tests/GOLIBTest_fps.cs
Tests/IValueChange.cs [new file with mode: 0644]
Tests/Interfaces/fps.goml
Tests/Interfaces/log.xml [new file with mode: 0755]
Tests/Tests.csproj
src/CompilerServices/CompilerServices.cs
src/DynAttribute.cs [new file with mode: 0755]
src/EventSource.cs [deleted file]
src/GraphicObjects/Checkbox.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/IValueChange.cs [new file with mode: 0644]
src/GraphicObjects/Image.cs
src/GraphicObjects/NumericControl.cs
src/GraphicObjects/Spinner.cs [new file with mode: 0644]
src/GraphicObjects/TextBox.cs
src/Interface.cs
src/TextChangeEventArgs.cs

index 567b61c51ed4f9b93d94987d7d0dd9e6c7ef27c4..3cc7e7e2a2f95101da35ba0cc90ed1a479f341ff 100644 (file)
@@ -38,6 +38,9 @@
     <DebugType>None</DebugType>\r
     <BaseAddress>4194304</BaseAddress>\r
   </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DefineConstants>__linux__</DefineConstants>\r
+  </PropertyGroup>\r
   <!--  <PropertyGroup Condition=" '$(Platform)' == 'Linux_x86' ">\r
     <DefineConstants>__linux__</DefineConstants>\r
     <PlatformTarget>x86</PlatformTarget>\r
     <PlatformTarget>anycpu</PlatformTarget>\r
   </PropertyGroup>-->\r
   <ItemGroup>\r
-    <Compile Include="src\EventSource.cs">\r
-      <LogicalName>\r
-      </LogicalName>\r
-    </Compile>\r
     <Compile Include="src\Colors.cs">\r
       <LogicalName>\r
       </LogicalName>\r
       <LogicalName>\r
       </LogicalName>\r
     </Compile>\r
+    <Compile Include="src\GraphicObjects\Spinner.cs">\r
+      <LogicalName>\r
+      </LogicalName>\r
+    </Compile>\r
+    <Compile Include="src\DynAttribute.cs">\r
+      <LogicalName>\r
+      </LogicalName>\r
+    </Compile>\r
+    <Compile Include="src\GraphicObjects\IValueChange.cs">\r
+      <LogicalName>\r
+      </LogicalName>\r
+    </Compile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
       </LogicalName>\r
     </Folder>\r
   </ItemGroup>\r
-  <ItemGroup>\r
-    <None Include="Images\Icons\icon_alert.gif">\r
-      <LogicalName>\r
-      </LogicalName>\r
-    </None>\r
-  </ItemGroup>\r
   <ItemGroup>\r
     <EmbeddedResource Include="Images\Icons\question_mark.svg">\r
       <LogicalName>go.image.icons.question_mark</LogicalName>\r
     </EmbeddedResource>\r
+    <EmbeddedResource Include="Images\Icons\icon_alert.gif" />\r
+    <EmbeddedResource Include="Images\Icons\updown.svg" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ProjectReference Include="OpenTK\Source\OpenTK\OpenTK.csproj">\r
index 7b897639a710cc23443779d81ea5689dc52a6916..98b5962cbf5a84080a93c7cda96b76b0bf1cc7c4 100644 (file)
--- a/GOLib.sln
+++ b/GOLib.sln
@@ -24,16 +24,15 @@ Global
                {232716B4-D19D-4FD7-B310-94A98FD926F0}.Documentation|Any CPU.Build.0 = Debug|Any CPU\r
                {232716B4-D19D-4FD7-B310-94A98FD926F0}.Nsis|Any CPU.ActiveCfg = Debug|Any CPU\r
                {232716B4-D19D-4FD7-B310-94A98FD926F0}.Nsis|Any CPU.Build.0 = Debug|Any CPU\r
-               {232716B4-D19D-4FD7-B310-94A98FD926F0}.Release|Linux_x86.ActiveCfg = Release|Linux_x86\r
-               {232716B4-D19D-4FD7-B310-94A98FD926F0}.Release|Linux_x86.Build.0 = Release|Linux_x86\r
+               {232716B4-D19D-4FD7-B310-94A98FD926F0}.Release|Linux_x86.ActiveCfg = Debug|Any CPU\r
                {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU\r
                {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Linux_x86.Build.0 = Debug|Any CPU\r
                {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU\r
                {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Documentation|Any CPU.Build.0 = Debug|Any CPU\r
                {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Nsis|Any CPU.ActiveCfg = Debug|Any CPU\r
                {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Nsis|Any CPU.Build.0 = Debug|Any CPU\r
-               {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Linux_x86.ActiveCfg = Release|Linux_x86\r
-               {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Linux_x86.Build.0 = Release|Linux_x86\r
+               {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
+               {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Linux_x86.Build.0 = Release|Any CPU\r
                {A37A7E14-0000-0000-0000-000000000000}.Debug|Linux_x86.ActiveCfg = Release|Any CPU\r
                {A37A7E14-0000-0000-0000-000000000000}.Debug|Linux_x86.Build.0 = Release|Any CPU\r
                {A37A7E14-0000-0000-0000-000000000000}.Documentation|Any CPU.ActiveCfg = Documentation|Any CPU\r
@@ -48,14 +47,13 @@ Global
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Documentation|Any CPU.Build.0 = Debug|Any CPU\r
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Nsis|Any CPU.ActiveCfg = Debug|Any CPU\r
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Nsis|Any CPU.Build.0 = Debug|Any CPU\r
-               {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.ActiveCfg = Release|Linux_x86\r
-               {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.Build.0 = Release|Linux_x86\r
+               {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
+               {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.Build.0 = Release|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Documentation|Any CPU.Build.0 = Debug|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Nsis|Any CPU.ActiveCfg = Debug|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Nsis|Any CPU.Build.0 = Debug|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
-               {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Release|Linux_x86.Build.0 = Release|Any CPU\r
        EndGlobalSection\r
 EndGlobal\r
diff --git a/Images/Icons/updown.svg b/Images/Icons/updown.svg
new file mode 100644 (file)
index 0000000..df22a28
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   viewBox="0 0 65.480012 51.479989"
+   height="51.479988"
+   width="65.480011">
+
+  <defs
+     id="defs4">
+    <filter
+       height="1.4299999"
+       y="-0.215"
+       width="1.3096"
+       x="-0.1548"
+       id="filter4391"
+       style="color-interpolation-filters:sRGB">
+      <feGaussianBlur
+         id="feGaussianBlur4393"
+         stdDeviation="3.225" />
+    </filter>
+  </defs>
+
+  <g
+     id="up">
+    <path
+       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter4391)"
+       d="M 32,9 7,44 57,44 Z"
+       id="path4144"
+       inkscape:connector-curvature="0"
+       sodipodi:nodetypes="cccc" />
+  </g>
+  <g
+     id="down"
+     transform="matrix(-1,0,0,-1,64,53)">
+    <path
+       sodipodi:nodetypes="cccc"
+       inkscape:connector-curvature="0"
+       id="path4142"
+       d="M 32,9 7,44 57,44 Z"
+       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter4391)" />
+  </g>
+</svg>
index f92cd16c9f3d3c2d05d70b18e0cfec0f379b5585..1f3760475dfd473030cc1cec0d100e2f16d30b27 100644 (file)
@@ -27,7 +27,7 @@ namespace test
                protected override void OnLoad (EventArgs e)\r
                {\r
                        base.OnLoad (e);\r
-                       LoadInterface("Interfaces/test1.goml", out g);\r
+                       LoadInterface("Interfaces/log.xml", out g);\r
 \r
                }\r
                protected override void OnRenderFrame (FrameEventArgs e)\r
index 5ee286b690f72f249ca520322b06e2242013c4ce..1f244e16599b43975c171b799308c94402eb9199 100644 (file)
@@ -82,9 +82,9 @@ namespace test
 \r
 \r
                        c.MouseMove += pFps_mousemove;\r
-                       slTest.ValueChanged += (object sender, ValueChangeEventArgs vce) => {\r
-                               labV.Text = vce.NewValue.ToString ("00.00");\r
-                       };\r
+//                     slTest.ValueChanged += (object sender, ValueChangeEventArgs vce) => {\r
+//                             labV.Text = vce.NewValue.ToString ("00.00");\r
+//                     };\r
 \r
 \r
                        int i = 0;\r
index 946eb5e11ea9fdf6236022f7083406ee94936385..aaf5631e21c734076250aa6c7776fa2f5d52a055 100644 (file)
@@ -16,27 +16,49 @@ using System.Threading;
 \r
 namespace test\r
 {\r
-       class GOLIBTest_fps : OpenTKGameWindow\r
+       class GOLIBTest_fps : OpenTKGameWindow , IValueChange\r
        {\r
                #region FPS\r
-               static int _fps = 0;\r
+               int _fps = 0;\r
 \r
-               public static int fps {\r
+               public int fps {\r
                        get { return _fps; }\r
                        set {\r
+                               if (_fps == value)\r
+                                       return;\r
+                               \r
+                               int oldVal = _fps;\r
                                _fps = value;\r
-                               if (_fps > fpsMax)\r
+\r
+                               if (_fps > fpsMax) {\r
                                        fpsMax = _fps;\r
-                               else if (_fps < fpsMin)\r
+                                       ValueChanged(this, new ValueChangeEventArgs ("fpsMax", fpsMax, _fps));\r
+                               } else if (_fps < fpsMin) {\r
+                                       ValueChanged(this, new ValueChangeEventArgs ("fpsMin", fpsMin, _fps));\r
                                        fpsMin = _fps;\r
+                               }\r
+\r
+                               if (ValueChanged != null)\r
+                                       ValueChanged(this, new ValueChangeEventArgs ("fps", oldVal, _fps));\r
+\r
+                               //ValueChanged.Raise (this, new ValueChangeEventArgs ("fps", oldVal, _fps));\r
                        }\r
+               }\r
+               string name = "testName";\r
 \r
+               public string Name {\r
+                       get {\r
+                               return name;\r
+                       }\r
+                       set {\r
+                               name = value;\r
+                       }\r
                }\r
 \r
-               public static int fpsMin = int.MaxValue;\r
-               public static int fpsMax = 0;\r
+               public int fpsMin = int.MaxValue;\r
+               public int fpsMax = 0;\r
 \r
-               static void resetFps ()\r
+               void resetFps ()\r
                {\r
                        fpsMin = int.MaxValue;\r
                        fpsMax = 0;\r
@@ -61,6 +83,9 @@ namespace test
                        labFpsMax = g.FindByName ("labFpsMax") as Label;\r
                        labUpdate = g.FindByName ("labUpdate") as Label;\r
 \r
+                       //ValueChanged += (object sender, ValueChangeEventArgs vce) => labFps.Text = vce.NewValue.ToString ();\r
+       \r
+\r
                }\r
                protected override void OnRenderFrame (FrameEventArgs e)\r
                {\r
@@ -76,11 +101,12 @@ namespace test
 \r
                        fps = (int)RenderFrequency;\r
 \r
-                       labFps.Text = fps.ToString();\r
+                       //labFps.Text = fps.ToString();\r
                        labUpdate.Text = this.updateTime.ElapsedMilliseconds.ToString() + " ms";\r
+\r
                        if (frameCpt > 200) {\r
-                               labFpsMin.Text = fpsMin.ToString();\r
-                               labFpsMax.Text = fpsMax.ToString();\r
+//                             labFpsMin.Text = fpsMin.ToString();\r
+//                             labFpsMax.Text = fpsMax.ToString();\r
                                resetFps ();\r
                                frameCpt = 0;\r
 \r
@@ -88,6 +114,12 @@ namespace test
                        frameCpt++;\r
                }\r
 \r
+               #region IValueChange implementation\r
+\r
+               public event EventHandler<ValueChangeEventArgs> ValueChanged;\r
+\r
+               #endregion\r
+\r
                [STAThread]\r
                static void Main ()\r
                {\r
diff --git a/Tests/IValueChange.cs b/Tests/IValueChange.cs
new file mode 100644 (file)
index 0000000..9449913
--- /dev/null
@@ -0,0 +1,23 @@
+#define MONO_CAIRO_DEBUG_DISPOSE\r
+\r
+\r
+using System;\r
+using System.Runtime.InteropServices;\r
+using OpenTK;\r
+using OpenTK.Graphics.OpenGL;\r
+using OpenTK.Input;\r
+\r
+using System.Diagnostics;\r
+\r
+//using GGL;\r
+using go;\r
+using System.Threading;\r
+\r
+\r
+namespace test\r
+{\r
+       interface IValueChange\r
+       {
+       }
+\r
+}
\ No newline at end of file
index 85b60afd8077a233895ccd390fd05660ac57da1c..7c18d4ce0649ed9d923c16099f97b6c496919256 100755 (executable)
                        </HorizontalStack>\r
                        <HorizontalStack>\r
                                <Label Text="Fps:" Width = "30" VerticalAlignment="Center"  TextAlignment="LeftCenter"/>\r
-                               <Label Name="labFps" Text="xxxx" Font="droid bold, 12"\r
+                               <Label Name="labFps" Text="{fps}" Font="droid bold, 12"\r
                                        TextAlignment="Center" Background="AoEnglish"/>\r
                        </HorizontalStack>\r
                        <HorizontalStack>\r
                                <Label Text="Min:" Width = "30" />\r
-                               <Label Name="labFpsMin" Text="xxxx" Font="droid bold, 12"\r
+                               <Label Name="labFpsMin" Text="{fpsMin}" Font="droid bold, 12"\r
                                        TextAlignment="Center" Background="AoEnglish"/>\r
                        </HorizontalStack>\r
                        <HorizontalStack>\r
                                <Label Text="Max:" Width = "30"/>\r
-                               <Label Name="labFpsMax" Text="xxxx" Font="droid bold, 12"\r
+                               <Label Name="labFpsMax" Text="{fpsMax}" Font="droid bold, 12"\r
                                        TextAlignment="Center" Background="AoEnglish"/>\r
                        </HorizontalStack>\r
                </VerticalStack>                                \r
diff --git a/Tests/Interfaces/log.xml b/Tests/Interfaces/log.xml
new file mode 100755 (executable)
index 0000000..1039f7b
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<Container Name="topContainer" HorizontalAlignment="Center" VerticalAlignment="Top"
+       Margin="2"
+       Width="600" Height="-1">
+       <Border Margin="2" BorderWidth="1" Background="0,6;0,6;0,6;0,6" Height="-1">
+               <Group Width="0" Name="logs">
+                       <VerticalStack Name="VerticalStack" Width="0" Focusable="False">
+                               <Label Name="line1" Width="0" Text="Line1" Margin="0"/>
+                               <Label Name="line2" Width="0" Text="Line2" Margin="0"/>
+                               <Label Name="line3" Width="0" Text="Line3" Margin="0"/>
+                               <Label Name="line4" Width="0" Text="Line4" Margin="0"/>
+                       </VerticalStack>
+                       <Button Name="btOk" Background="Gray" Fit="True"
+                               HorizontalAlignment="Right" VerticalAlignment="Bottom"
+                               MouseClick="BtOk_MouseClick">
+                               <Label Text="Ok" Margin="3" Foreground="White" />
+                       </Button>
+               </Group>
+       </Border>
+</Container>
+
index 02a190058ea8566bd8ca5b858d6f7122f8be515c..d80400f0968037b96684423a771ca7a5a517cf10 100644 (file)
@@ -8,7 +8,7 @@
     <OutputType>Exe</OutputType>
     <RootNamespace>Tests</RootNamespace>
     <AssemblyName>Tests</AssemblyName>
-    <StartupObject>test.GOLIBTest_4</StartupObject>
+    <StartupObject>test.GOLIBTest_fps</StartupObject>
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <OutputPath>..\bin\$(configuration)</OutputPath>
     <IntermediateOutputPath>obj\$(configuration)</IntermediateOutputPath>
       </LogicalName>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\log.xml">
+      <LogicalName>
+      </LogicalName>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\">
index 034180d157a7828a87b922b2eba5d84378876593..36c88030b2eef36edf1be79807845cf95bc1ef5e 100644 (file)
@@ -1,6 +1,10 @@
 using System;
 using System.Reflection.Emit;
 using System.Reflection;
+using System.Collections;
+using System.Diagnostics;
+using System.Linq;
+
 
 namespace go
 {
@@ -33,12 +37,12 @@ namespace go
 
                }
                static int dynHandleCpt = 0;
-               public static void CompileEventSource(EventSource es)
+               public static void CompileEventSource(DynAttribute es)
                {
                        Type srcType = es.Source.GetType ();
 
                        #region Retrieve EventHandler parameter type
-                       EventInfo ei = srcType.GetEvent (es.EventName);
+                       EventInfo ei = srcType.GetEvent (es.MemberName);
                        MethodInfo invoke = ei.EventHandlerType.GetMethod ("Invoke");
                        ParameterInfo[] pars = invoke.GetParameters ();
 
@@ -54,10 +58,10 @@ namespace go
                        #region IL generation
                        ILGenerator il = dm.GetILGenerator(256);
 
-                       string src = es.Handler.Trim();
+                       string src = es.Value.Trim();
 
                        if (! (src.StartsWith("{") || src.EndsWith ("}"))) 
-                               throw new Exception (string.Format("GOML:Malformed {0} Event handler: {1}", es.EventName, es.Handler));
+                               throw new Exception (string.Format("GOML:Malformed {0} Event handler: {1}", es.MemberName, es.Value));
 
                        src = src.Substring (1, src.Length - 2);
                        string[] srcLines = src.Split (new char[] { ';' });
@@ -145,11 +149,109 @@ namespace go
 
                        #endregion
 
-                       FieldInfo evtFi = getEventHandlerField (srcType, es.EventName);
+                       FieldInfo evtFi = getEventHandlerField (srcType, es.MemberName);
                        Delegate del = dm.CreateDelegate(evtFi.FieldType);
                        evtFi.SetValue(es.Source, del);
                }
 
+               public static void CreateBinding(DynAttribute binding, object _source)
+               {
+                       
+                       Type srcType = _source.GetType ();
+                       Type dstType = binding.Source.GetType ();
+
+                       MemberInfo miSrc = srcType.GetMember (binding.Value).FirstOrDefault();
+                       Type srcValueType = null;
+                       if (miSrc.MemberType == MemberTypes.Property)
+                               srcValueType = (miSrc as PropertyInfo).PropertyType;
+                       else if (miSrc.MemberType == MemberTypes.Field) 
+                               srcValueType = (miSrc as FieldInfo).FieldType;
+                       else
+                               throw new Exception("unandled source type for binding");
+
+                       #region Retrieve EventHandler parameter type
+                       EventInfo ei = srcType.GetEvent ("ValueChanged");
+                       MethodInfo evtInvoke = ei.EventHandlerType.GetMethod ("Invoke");
+                       ParameterInfo[] evtParams = evtInvoke.GetParameters ();
+
+                       Type handlerArgsType = evtParams [1].ParameterType;
+                       #endregion
+
+                       Type[] args = {typeof(object), handlerArgsType};
+                       DynamicMethod dm = new DynamicMethod("dynHandle_" + dynHandleCpt,
+                               typeof(void), 
+                               args, 
+                               srcType.Module, true);
+
+                       //register target object reference
+                       int dstIdx = Interface.References.IndexOf(binding.Source);
+
+                       if (dstIdx < 0) {
+                               dstIdx = Interface.References.Count;
+                               Interface.References.Add (binding.Source);
+                       }
+
+
+
+                       #region IL generation
+                       ILGenerator il = dm.GetILGenerator(256);
+
+                       System.Reflection.Emit.Label labFailed = il.DefineLabel();
+                       System.Reflection.Emit.Label labContinue = il.DefineLabel();
+
+                       #region test if valueChange event is the correct one
+                       il.Emit (OpCodes.Ldstr, binding.Value);
+                       //push name from arg
+                       il.Emit(OpCodes.Ldarg_1);
+                       FieldInfo fiMbName = typeof(ValueChangeEventArgs).GetField("MemberName");
+                       il.Emit(OpCodes.Ldfld, fiMbName);
+                       MethodInfo miStrEqu = typeof(string).GetMethod("op_Inequality", new Type[] {typeof(string),typeof(string)});
+                       il.Emit(OpCodes.Call, miStrEqu);
+                       il.Emit(OpCodes.Brfalse_S, labContinue);
+                       il.Emit(OpCodes.Br_S, labFailed);
+                       il.MarkLabel(labContinue);
+                       #endregion
+
+                       string[] srcLines = binding.Value.Trim().Split (new char[] { ';' });
+                       foreach (string srcLine in srcLines) {
+                               MethodInfo infoWriteLine = typeof(System.Diagnostics.Debug).GetMethod("WriteLine", new Type[] { typeof(string) });
+
+                               string statement = srcLine.Trim ();
+
+                               //load target ref onto the stack
+                               FieldInfo fiRefs = typeof(Interface).GetField("References");
+                               il.Emit(OpCodes.Ldsfld, fiRefs);
+                               il.Emit(OpCodes.Ldc_I4, dstIdx);
+
+                               MethodInfo miGetRef = Interface.References.GetType().GetMethod("get_Item");
+                               il.Emit(OpCodes.Callvirt, miGetRef);
+                               il.Emit(OpCodes.Isinst, dstType);
+
+                               //push new value
+                               il.Emit(OpCodes.Ldarg_1);
+                               FieldInfo fiNewValue = typeof(ValueChangeEventArgs).GetField("NewValue");
+                               il.Emit(OpCodes.Ldfld, fiNewValue);
+
+                               PropertyInfo piTarget = dstType.GetProperty(binding.MemberName);
+                               MethodInfo miToStr = typeof(object).GetMethod("ToString",Type.EmptyTypes);
+
+                               if (!srcValueType.IsValueType)
+                                       il.Emit(OpCodes.Castclass, srcValueType);
+                               il.Emit(OpCodes.Callvirt, miToStr);
+                               il.Emit(OpCodes.Callvirt, piTarget.GetSetMethod());
+                       }
+                       il.MarkLabel(labFailed);
+                       il.Emit(OpCodes.Ret);
+
+                       #endregion
+
+                       Delegate del = dm.CreateDelegate(ei.EventHandlerType);
+                       MethodInfo addHandler = ei.GetAddMethod ();
+                       //Delegate del = dm.CreateDelegate(typeof(System.EventHandler));
+                       addHandler.Invoke(_source, new object[] {del});
+               }
+
+
                public static FieldInfo getEventHandlerField(Type type, string eventName)
                {
                        FieldInfo fi;
diff --git a/src/DynAttribute.cs b/src/DynAttribute.cs
new file mode 100755 (executable)
index 0000000..db2be2b
--- /dev/null
@@ -0,0 +1,14 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+\r
+namespace go\r
+{\r
+       public class DynAttribute\r
+    {\r
+        public GraphicObject Source;\r
+        public string MemberName;\r
+        public String Value;\r
+    }\r
+}\r
diff --git a/src/EventSource.cs b/src/EventSource.cs
deleted file mode 100755 (executable)
index d8065cd..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace go\r
-{\r
-       public class EventSource\r
-    {\r
-        public GraphicObject Source;\r
-        public string EventName;\r
-        public String Handler;\r
-    }\r
-}\r
index 3c25c741a7c79d0ab472145979127ff67959bb1e..586855d9edec584103812c7d8e4403f6a71a49e7 100644 (file)
@@ -242,11 +242,11 @@ namespace go
         public override void ReadXml(System.Xml.XmlReader reader)\r
         {\r
             string handler = reader.GetAttribute("OnClick");\r
-                       Interface.EventsToResolve.Add(new EventSourc\r
+                       Interface.EventsToResolve.Add(new DynAttribut\r
             { \r
                 Source = this, \r
-                Handler = handler,\r
-                EventName = "OnClick"\r
+                Value = handler,\r
+                MemberName = "OnClick"\r
             });\r
 \r
             //Container c = this as Container;\r
index a7b9e93e6cd4c5ac5dcab35bb23d04dbe43bb2fe..683e88f3266f73d5c700ca50a35773b80a5719d1 100644 (file)
@@ -108,6 +108,7 @@ namespace go
                public event EventHandler<KeyboardKeyEventArgs> KeyUp;\r
                public event EventHandler Focused;\r
                public event EventHandler Unfocused;\r
+\r
                #endregion\r
 \r
                #region public properties\r
@@ -641,11 +642,11 @@ namespace go
                                if (string.IsNullOrEmpty (handler))\r
                                        continue;\r
                                        \r
-                               Interface.EventsToResolve.Add(new EventSourc\r
+                               Interface.EventsToResolve.Add(new DynAttribut\r
                                        { \r
                                                Source = this, \r
-                                               Handler = handler,\r
-                                               EventName = ei.Name\r
+                                               Value = handler,\r
+                                               MemberName = ei.Name\r
                                        });\r
                        }\r
                        foreach (PropertyInfo pi in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {\r
@@ -713,6 +714,19 @@ namespace go
                                                else\r
                                                        pi.SetValue (this, defaultValue, null);\r
                                        } else {\r
+                                               if (v.StartsWith("{")) {\r
+                                                       //binding\r
+                                                       if (!v.EndsWith("}"))\r
+                                                               throw new Exception (string.Format("GOML:Malformed binding: {0}", v));\r
+                                                       \r
+                                                       string strBinding = v.Substring (1, v.Length - 2);\r
+                                                       Interface.Bindings.Add (new DynAttribute () {\r
+                                                               Source = this,\r
+                                                               MemberName = name,\r
+                                                               Value = strBinding\r
+                                                       });\r
+                                               }\r
+\r
                                                if (pi.PropertyType == typeof(string)) {\r
                                                        pi.SetValue (this, v, null);\r
                                                        continue;\r
index 7b63156fcd0cbed6e6349257677dfc89d27d7b8f..a2a04e0b37a8dfc39917ad6a9a1ed0e8d73ea3ec 100644 (file)
@@ -120,7 +120,10 @@ namespace go
                        return tmp;\r
                }\r
 \r
-\r
+               public override void RegisterForLayouting (int layoutType)\r
+               {\r
+                       base.RegisterForLayouting (layoutType);\r
+               }\r
 \r
                public override Rectangle ContextCoordinates(Rectangle r){\r
                        return r + ClientRectangle.Position;\r
diff --git a/src/GraphicObjects/IValueChange.cs b/src/GraphicObjects/IValueChange.cs
new file mode 100644 (file)
index 0000000..4dc886b
--- /dev/null
@@ -0,0 +1,30 @@
+//
+//  IValueChange.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2015 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+
+namespace go
+{
+       public interface IValueChange
+       {
+               event EventHandler<ValueChangeEventArgs> ValueChanged;
+       }
+}
+
index aa3ea56d78b8563bce1d47b69ad87d4e3b162e4e..3858aebc22c1505694a9f6739775dfac585af731 100755 (executable)
@@ -71,7 +71,6 @@ namespace go
                                hSVG = new Rsvg.Handle (ms.ToArray ());\r
                                imgSize = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);\r
                                _imgPath = resId;\r
-                               //loadImage (@"Images/Icons/question_mark.svg");\r
                        }\r
                }\r
                //load image via System.Drawing.Bitmap, cairo load png only\r
index 93aadc84885a46e02fac74a60d939041aafb0857..2eb54bca822e0f5b0b877cada779ce5fcb162d58 100644 (file)
@@ -13,10 +13,10 @@ namespace go
                public NumericControl(double minimum, double maximum, double step)
                        : base()
                {
-                       _minValue = minimum;
-                       _maxValue = maximum;
-                       _smallStep = step;
-                       _bigStep = step * 5;
+                       minValue = minimum;
+                       maxValue = maximum;
+                       smallStep = step;
+                       bigStep = step * 5;
                }
                #endregion
 
@@ -30,54 +30,54 @@ namespace go
                #endregion
 
                #region private fields
-               double _actualValue, _minValue, _maxValue, _smallStep, _bigStep;
+               double _actualValue, minValue, maxValue, smallStep, bigStep;
                #endregion
 
                #region public properties
                [XmlAttributeAttribute()][DefaultValue(0)]
                public virtual double Minimum {
-                       get { return _minValue; }
+                       get { return minValue; }
                        set {
-                               if (_minValue == value)
+                               if (minValue == value)
                                        return;
 
-                               _minValue = value;
+                               minValue = value;
 
                        }
                }
                [XmlAttributeAttribute()][DefaultValue(10.0)]
                public virtual double Maximum
                {
-                       get { return _maxValue; }
+                       get { return maxValue; }
                        set {
-                               if (_maxValue == value)
+                               if (maxValue == value)
                                        return;
 
-                               _maxValue = value;
+                               maxValue = value;
 
                        }
                }
                [XmlAttributeAttribute()][DefaultValue(0.5)]
                public virtual double SmallIncrement
                {
-                       get { return _smallStep; }
+                       get { return smallStep; }
                        set {
-                               if (_smallStep == value)
+                               if (smallStep == value)
                                        return;
 
-                               _smallStep = value;
+                               smallStep = value;
 
                        }
                }
                [XmlAttributeAttribute()][DefaultValue(2.0)]
                public virtual double LargeIncrement
                {
-                       get { return _bigStep; }
+                       get { return bigStep; }
                        set {
-                               if (_bigStep == value)
+                               if (bigStep == value)
                                        return;
 
-                               _bigStep = value;
+                               bigStep = value;
 
                        }
                }
@@ -90,16 +90,16 @@ namespace go
                                if (value == _actualValue)
                                        return;
 
-                               Decimal oldV = (Decimal)_actualValue;
+                               int oldV = Convert.ToInt32(_actualValue);
 
-                               if (value < _minValue)
-                                       _actualValue = _minValue;
-                               else if (value > _maxValue)
-                                       _actualValue = _maxValue;
+                               if (value < minValue)
+                                       _actualValue = minValue;
+                               else if (value > maxValue)
+                                       _actualValue = maxValue;
                                else                    
                                        _actualValue = value;
 
-                               onValueChanged(this,new ValueChangeEventArgs(oldV,(Decimal)_actualValue));
+                               onValueChanged(this,new ValueChangeEventArgs("Value", oldV, Convert.ToInt32( _actualValue)));
                                registerForGraphicUpdate();
                        }
                }
diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs
new file mode 100644 (file)
index 0000000..dcf0d3d
--- /dev/null
@@ -0,0 +1,43 @@
+//
+//  Spinner.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2015 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+
+namespace go
+{
+       public class Spinner : NumericControl
+       {
+               public Spinner (double minimum, double maximum, double step) : 
+               base (minimum, maximum, step)
+               {
+                       butUp = new Button ();
+                       butUp.setChild (new Image ("go.Image.Icons.updown.svg"));
+               }
+               public Spinner () : base()
+               {
+               }
+       
+               Button butUp;
+               Button butDown;
+               Label labCpt;
+
+       }
+}
+
index 2040378919aba1ec81d4cc4804f48abc71173f43..28e7c74cd16232ddeeb9fa98e9d6a3a4f2bc98e2 100644 (file)
@@ -15,7 +15,7 @@ namespace go
     public class TextBoxWidget : Label\r
     {\r
                #region CTOR\r
-               public TextBoxWidget(string _initialValue, GOEvent _onTextChanged = null)\r
+               public TextBoxWidget(string _initialValue)\r
                        : base(_initialValue)\r
                {\r
 \r
@@ -25,19 +25,6 @@ namespace go
                { }\r
                #endregion\r
 \r
-               static bool _capitalOn = false; //????????????????\r
-               [XmlIgnore]public static bool capitalOn\r
-               {\r
-                       get\r
-                       {\r
-                               return _capitalOn;\r
-                                       //Keyboard[Key.ShiftLeft] || Keyboard[Key.ShiftRight] ?\r
-                                       //!_capitalOn : _capitalOn;\r
-                       }\r
-                       set { _capitalOn = value; }\r
-               }\r
-\r
-\r
                #region GraphicObject overrides\r
                [XmlIgnore]public override bool HasFocus   //trigger update when lost focus to errase text beam\r
         {\r
@@ -71,23 +58,7 @@ namespace go
                protected override void onDraw (Context gr)\r
                {\r
                        base.onDraw (gr);\r
-                       //                      gr.FontOptions.Antialias = Antialias.Subpixel;\r
-                       //                      gr.FontOptions.HintMetrics = HintMetrics.On;\r
-//                     gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
-//                     gr.SetFontSize (Font.Size);\r
-\r
                        FontExtents fe = gr.FontExtents;\r
-\r
-\r
-\r
-//                     gr.MoveTo(rText.X, rText.Y + fe.Ascent);\r
-//                     #if _WIN32 || _WIN64\r
-//                     gr.ShowText(txt);\r
-//                     #elif __linux__\r
-//                     gr.ShowText(Text);\r
-//                     #endif\r
-//                     gr.Fill();\r
-\r
                }\r
                #endregion\r
 \r
index 8684d8517e4766bef187329f2d70b4fe95588d41..776dd9a6562e39413a95b11f5790adbc637abeae 100644 (file)
@@ -25,6 +25,7 @@ using System.Reflection;
 using System.Diagnostics;
 using System.Collections.Generic;
 using System.Xml;
+using System.Linq;
 
 namespace go
 {
@@ -35,11 +36,17 @@ namespace go
                public static bool ReplaceTabsWithSpace = false;
                public static bool DesignerMode = false;
 
+               /// <summary>
+               /// Graphic objects References use in dynamic delegates for binding
+               /// </summary>
+               public static List<object> References = new List<object>();
+
                public static LayoutingQueue LayoutingQueue = new LayoutingQueue();
 
                #region Load/Save
 
-               internal static List<EventSource> EventsToResolve;
+               internal static List<DynAttribute> EventsToResolve;
+               internal static List<DynAttribute> Bindings;
 
                public static void Save<T>(string file, T graphicObject)
                {            
@@ -68,12 +75,13 @@ namespace go
                                }
                        }
                        Type t = Type.GetType("go." + root);
-                       var go = Activator.CreateInstance(t);
+                       //var go = Activator.CreateInstance(t);
                        return Load(path, t);
                }
                public static void Load<T>(string file, out T result, object ClassContainingHandlers = null)
                {
-                       EventsToResolve = new List<EventSource>();
+                       EventsToResolve = new List<DynAttribute>();
+                       Bindings = new List<DynAttribute> ();
 
                        XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
                        xn.Add("", "");
@@ -87,32 +95,42 @@ namespace go
                        if (ClassContainingHandlers == null)
                                return;
 
-                       foreach (EventSource es in EventsToResolve)
+                       foreach (DynAttribute es in EventsToResolve)
                        {
-                               if (string.IsNullOrEmpty(es.Handler))
+                               if (string.IsNullOrEmpty(es.Value))
                                        continue;
 
-                               if (es.Handler.StartsWith ("{")) {
+                               if (es.Value.StartsWith ("{")) {
                                        CompilerServices.CompileEventSource (es);
                                } else {                                        
-                                       MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Handler, BindingFlags.NonPublic | BindingFlags.Public
+                                       MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public
                                                | BindingFlags.Instance);
 
                                        if (mi == null) {
-                                               Debug.WriteLine ("Handler Method not found: " + es.Handler);
+                                               Debug.WriteLine ("Handler Method not found: " + es.Value);
                                                continue;
                                        }
 
-                                       FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.EventName);
+                                       FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.MemberName);
                                        Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);
                                        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);
+                               CompilerServices.CreateBinding (binding, ClassContainingHandlers);
+                       }
                }
                public static GraphicObject Load(string file, Type type, object ClassContainingHandlers = null)
                {
                        GraphicObject result;
-                       EventsToResolve = new List<EventSource>();
+                       EventsToResolve = new List<DynAttribute>();
 
                        XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
                        xn.Add("", "");
@@ -126,23 +144,23 @@ namespace go
                        if (ClassContainingHandlers == null)
                                return result;
 
-                       foreach (EventSource es in EventsToResolve)
+                       foreach (DynAttribute es in EventsToResolve)
                        {
-                               if (string.IsNullOrEmpty(es.Handler))
+                               if (string.IsNullOrEmpty(es.Value))
                                        continue;
 
-                               if (es.Handler.StartsWith ("{")) {
+                               if (es.Value.StartsWith ("{")) {
                                        CompilerServices.CompileEventSource (es);
                                } else {                                        
-                                       MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Handler, BindingFlags.NonPublic | BindingFlags.Public
+                                       MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public
                                                | BindingFlags.Instance);
 
                                        if (mi == null) {
-                                               Debug.WriteLine ("Handler Method not found: " + es.Handler);
+                                               Debug.WriteLine ("Handler Method not found: " + es.Value);
                                                continue;
                                        }
 
-                                       FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.EventName);
+                                       FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.MemberName);
                                        Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);
                                        fi.SetValue(es.Source, del);
                                }
index b826fe4a66ba4684ca27f40462703acc36c5fcc7..726c9ae9ad3127973d1732a37f8b7cfac7a70340 100644 (file)
@@ -4,11 +4,14 @@ namespace go
 {
        public class ValueChangeEventArgs: EventArgs
        {
-               public Decimal OldValue;
-               public Decimal NewValue;
+               public string MemberName;
+               public object OldValue;
+               public object NewValue;
 
-               public ValueChangeEventArgs (Decimal _oldValue, Decimal _newValue) : base()
+
+               public ValueChangeEventArgs (string _memberName, object _oldValue, object _newValue) : base()
                {
+                       MemberName = _memberName;
                        OldValue = _oldValue;
                        NewValue = _newValue;
                }