]> O.S.I.I.S - jp/crow.git/commitdiff
debug and test 2 way binding, working ok.
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 21 Oct 2016 22:04:35 +0000 (00:04 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 21 Oct 2016 22:04:35 +0000 (00:04 +0200)
12 files changed:
CrowIDE/src/MembersView.cs
CrowIDE/ui/imlEditor.crow
Templates/ColorPicker.template
Tests/BasicTests.cs
Tests/Interfaces/Divers/colorPicker.crow
Tests/Interfaces/Divers/test2WayBinding.crow [new file with mode: 0755]
Tests/Interfaces/GraphicObject/2.crow
Tests/Tests.csproj
src/CompilerServices/CompilerServices.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/HueSelector.cs
src/GraphicObjects/SaturationValueSelector.cs

index 3f250dd96229adc2769cd4fb8b9fe909b59ae169..d8a76951949bf7bd254903489c326ebe290975a0 100644 (file)
@@ -27,24 +27,29 @@ using System.Collections.Generic;
 
 namespace CrowIDE
 {
-       public class PropertyContainer : IBindable
+       public class PropertyContainer : IBindable, IValueChange
        {
+               #region IBindable implementation
                public object DataSource {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return null; }
                        set {
                                throw new NotImplementedException ();
                        }
                }
-
-               #region IBindable implementation
                List<Binding> bindings = new List<Binding> ();
                public List<Binding> Bindings {
                        get { return bindings; }
                }
                #endregion
 
+               #region IValueChange implementation
+               public event EventHandler<ValueChangeEventArgs> ValueChanged;
+               public virtual void NotifyValueChanged(string MemberName, object _value)
+               {
+                       ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));
+               }
+               #endregion
+
                PropertyInfo pi;
                object instance;
 
@@ -53,7 +58,7 @@ namespace CrowIDE
                        get { return pi.GetValue(instance); }
                        set {
                                try {
-                                       if (pi.PropertyType != value.GetType() && pi.PropertyType != typeof(string)){
+                                       if (!pi.PropertyType.IsAssignableFrom(value.GetType()) && pi.PropertyType != typeof(string)){
                                                if (pi.PropertyType.IsEnum) {
                                                        pi.SetValue (instance, value);
                                                } else {
@@ -67,7 +72,7 @@ namespace CrowIDE
                                } catch (Exception ex) {
                                        System.Diagnostics.Debug.WriteLine ("Error setting property:"+ ex.ToString());
                                }
-
+                               NotifyValueChanged ("Value", value);
                        }
                }
                public string Type { get { return pi.PropertyType.IsEnum ?
@@ -86,7 +91,7 @@ namespace CrowIDE
 
        }
        public class MembersView : ListBox
-       {
+       {               
                object instance;
 
                [XmlAttributeAttribute][DefaultValue(null)]
index d84fa6a8701f3387053ec6e9d5e2f3169a11f45a..ce4911684f5645001f41e4d4af413468acb60151 100644 (file)
                                                        MouseEnter="{Background=UnitedNationsBlue}"
                                                        MouseLeave="{Background=Transparent}" >
                                                <Label Margin="1" Text="{Name}" Height="Fit" Width="50%"/>
-                                               <Popper Foreground="{²Value}" Background="White" Margin="1" Caption="{²Value}">
+                                               <Popper Background="White" Margin="1" Caption="{Value}">
                                                        <Template>
                                                                <HorizontalStack Spacing="3" Height="Fit" Background="{./Background}">
                                                                        <Border Foreground="Black" Width="16" Height="10" CornerRadius="3"
-                                                                               Background="{./Foreground}">
+                                                                               Background="{Value}">
                                                                        </Border>
                                                                        <Label Text="{./Caption}" Foreground="Black"/>
                                                                </HorizontalStack>
index 5bf21131286998ee3cf9708205395610ecc8c6f4..e128ff718774eaae47545bb82252b16cf33cbb1f 100755 (executable)
                                        </VerticalStack>
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Red:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²./R}" Width="50"  />
+                                       <Label Text="Red:" Width="40"/>
+                                       <Spinner Style="ColorSpinner" Value="{²./R}" Width="60"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Green:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²./G}" Width="50"  />
+                                       <Label Text="Green:" Width="40"/>
+                                       <Spinner Style="ColorSpinner" Value="{²./G}" Width="60"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Blue:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²./B}" Width="50"  />
+                                       <Label Text="Blue:" Width="40"/>
+                                       <Spinner Style="ColorSpinner" Value="{²./B}" Width="60"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Alpha:" Width="50"/>
-                                       <Spinner Style="ColorSpinner" Value="{²./A}" Width="50"  />
+                                       <Label Text="Alpha:" Width="40"/>
+                                       <Spinner Style="ColorSpinner" Value="{²./A}" Width="60"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Hue:" Width="50"/>
-                                       <Spinner Style="HSVSpinner" Value="{²../../../hueSelector.Hue}" Width="150"  />
+                                       <Label Text="Hue:" Width="40"/>
+                                       <Spinner Style="HSVSpinner" Value="{²../../../hueSelector.Hue}" Width="60"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Sat:" Width="50"/>
-                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.S}" Width="150"  />
+                                       <Label Text="Sat:" Width="40"/>
+                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.S}" Width="60"  />
                                </HorizontalStack>
                                <HorizontalStack Height="Fit">
-                                       <Label Text="Val:" Width="50"/>
-                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.V}" Width="150"  />
+                                       <Label Text="Val:" Width="40"/>
+                                       <Spinner Style="HSVSpinner" Value="{²../../../colorSelector.V}" Width="60"  />
                                </HorizontalStack>
                        </VerticalStack>
                </HorizontalStack>
index cd9e3ba37175d6b36df4686c814f905060d6383d..e8ba10b115176eff1f0e51c9028c9a79058d3371 100644 (file)
@@ -10,8 +10,21 @@ using System.Diagnostics;
 
 namespace Tests
 {
-       class BasicTests : OpenTKGameWindow
+       class BasicTests : OpenTKGameWindow, IBindable
        {
+               #region IBindable implementation
+               public object DataSource {
+                       get { return null; }
+                       set {
+                               throw new NotImplementedException ();
+                       }
+               }
+               List<Binding> bindings = new List<Binding> ();
+               public List<Binding> Bindings {
+                       get { return bindings; }
+               }
+               #endregion
+
                public BasicTests ()
                        : base(800, 600,"test: press <F3> to toogle test files")
                {
@@ -82,6 +95,17 @@ namespace Tests
                                NotifyValueChanged ("CurSources", curSources);
                        }
                }
+               bool boolVal = true;
+               public bool BoolVal {
+                       get { return boolVal; }
+                       set {
+                               if (boolVal == value)
+                                       return;
+                               boolVal = value;
+                               NotifyValueChanged ("BoolVal", boolVal);
+                       }
+               }
+
                #endregion
 
                void OnClear (object sender, MouseButtonEventArgs e) => TestList = null;
@@ -94,7 +118,8 @@ namespace Tests
 
                        this.KeyDown += KeyboardKeyDown1;
 
-                       testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
+                       //testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
+                       testFiles = new string [] { @"Interfaces/Divers/test2WayBinding.crow" };
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
@@ -108,6 +133,7 @@ namespace Tests
 
                        this.Title = testFiles [idx] + ". Press <F3> to switch example.";
                        CrowInterface.LoadInterface(testFiles[idx]).DataSource = this;
+                       CompilerServices.ResolveBindings (this.Bindings);
                }
                void KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e)
                {
index 17700afb665339e32dabd13b87bcbba6d451c07a..7a0f2801e0e2410139c23989be2e8d764c61bb82 100755 (executable)
@@ -1,5 +1,7 @@
 <?xml version="1.0"?>
 <VerticalStack>
-       <ColorPicker SelectedColor="DarkBlue" Name="colorPicker" Background="Onyx" Margin="5" Fit="True" />
-       <GraphicObject Width="100" Height="60" Background="{../colorPicker.SelectedColor}"/>
+       <ColorPicker SelectedColor="{²../go.Background}" Name="colorPicker" Background="Onyx" Margin="5" Fit="True" />
+       <GraphicObject Name="go" Width="100" Height="60" Background="DarkBlue"/>
+       <GraphicObject Name="go" Width="100" Height="60" Background="{../colorPicker.SelectedColor}"/>
+
 </VerticalStack>
\ No newline at end of file
diff --git a/Tests/Interfaces/Divers/test2WayBinding.crow b/Tests/Interfaces/Divers/test2WayBinding.crow
new file mode 100755 (executable)
index 0000000..cf76f72
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<VerticalStack Fit="true">
+       <CheckBox IsChecked="{²BoolVal}"/>
+       <CheckBox Caption="second" IsChecked="{²BoolVal}"/>
+</VerticalStack>
\ No newline at end of file
index 74075b288f02501889badabe614f7db5e57a34df..696cd44f32e4e6f8bdb20016d243856fda0133b7 100755 (executable)
@@ -1,3 +1,4 @@
 <?xml version="1.0"?>
-<GraphicObject Margin="10" Width="50%" Height="50%" Background="Mantis"
+<GraphicObject Margin="10" Width="50%" Height="50%"
+               Background="hgradient|0:Red|0.25:Blue|0.5:Green|0.75:Yellow|1:Red"
                MinimumSize="50,50"/>
\ No newline at end of file
index e1b8e182cf4061bc624e5950a010c9d8fa86aa2c..82fe60b07c495506ad6a24d33b8402b27e96d99c 100644 (file)
     <None Include="Interfaces\Divers\colorPicker.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\Divers\test2WayBinding.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
index 77666af28b59d6ab14022cf67d37ddc3506ce987..384e6765547be4beb6e27bd322834c5c1e6f9aa6 100644 (file)
@@ -381,8 +381,13 @@ namespace Crow
                                il.Emit (OpCodes.Pop);
                                il.Emit (OpCodes.Ret);
 
-                               Delegate del = dm.CreateDelegate (eiValueChange.EventHandlerType, Bindings [0].Source.Instance);
-                               miValueChangeAdd.Invoke (grouped [0].Target.Instance, new object [] { del });
+                               try {
+                                       Delegate del = dm.CreateDelegate (eiValueChange.EventHandlerType, Bindings [0].Source.Instance);
+                                       miValueChangeAdd.Invoke (grouped [0].Target.Instance, new object [] { del });
+
+                               } catch (Exception ex) {                                        
+                                       Debug.WriteLine ("Binding Delegate error for {0}: \n{1}", Bindings [0].Source.Instance, ex.ToString ());
+                               }
                        }
                }
 
index d182f54ae15385444fefd55e64832d9210046e2c..277e3d48c4d9d8ad9d7efb91f1bf6cfbbf607f92 100644 (file)
@@ -27,7 +27,7 @@ namespace Crow
 
                Interface currentInterface = null;
 
-               public Interface CurrentInterface {
+               [XmlIgnore]public Interface CurrentInterface {
                        get {
                                if (currentInterface == null) {
                                        currentInterface = Interface.CurrentInterface;
@@ -47,6 +47,7 @@ namespace Crow
                public event EventHandler<ValueChangeEventArgs> ValueChanged;
                public virtual void NotifyValueChanged(string MemberName, object _value)
                {
+                       //Debug.WriteLine ("Value changed: {0}->{1} = {2}", this, MemberName, _value);
                        ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));
                }
                #endregion
index 11aee383dae48ba0c5573ecc950fe2e0c307749f..7afd6f7ac61a921cf95fe801d552d5aa407c78d8 100644 (file)
@@ -104,7 +104,7 @@ namespace Crow
 
                        CairoHelpers.CairoRectangle (ctx, r, 2);
                        ctx.SetSourceColor (Color.White);
-                       ctx.LineWidth = 1.0;
+                       ctx.LineWidth = 2.0;
                        ctx.Stroke();
                        ctx.Restore ();
                }
index 54a765b8de0a423a77cdc9182e517906dbc1e27b..b71fa7ef8dc4fae19fe77beed7a37e292ff8cd68 100644 (file)
@@ -65,9 +65,11 @@ namespace Crow
                        Rectangle rGrad = r;
                        rGrad.Inflate (-1);
 
-                       Foreground.SetAsSource (gr, r);
-                       CairoHelpers.CairoRectangle (gr, r, CornerRadius);
-                       gr.Fill();
+                       if (Foreground != null) {//TODO:test if null should be removed
+                               Foreground.SetAsSource (gr, r);
+                               CairoHelpers.CairoRectangle (gr, r, CornerRadius);
+                               gr.Fill ();
+                       }
 
                        Crow.Gradient grad = new Gradient (Gradient.Type.Horizontal);
                        grad.Stops.Add (new Gradient.ColorStop (0, new Color (1, 1, 1, 1)));