From 35ac43bbb4450151448344956420526b5290d1c1 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 22 Oct 2016 00:04:35 +0200 Subject: [PATCH] debug and test 2 way binding, working ok. --- Templates/ColorPicker.template | 28 ++++++++--------- Tests/BasicTests.cs | 30 +++++++++++++++++-- Tests/Interfaces/Divers/colorPicker.crow | 6 ++-- Tests/Interfaces/Divers/test2WayBinding.crow | 5 ++++ Tests/Interfaces/GraphicObject/2.crow | 3 +- Tests/Tests.csproj | 3 ++ src/CompilerServices/CompilerServices.cs | 9 ++++-- src/GraphicObjects/GraphicObject.cs | 3 +- src/GraphicObjects/HueSelector.cs | 2 +- src/GraphicObjects/SaturationValueSelector.cs | 8 +++-- 10 files changed, 71 insertions(+), 26 deletions(-) create mode 100755 Tests/Interfaces/Divers/test2WayBinding.crow diff --git a/Templates/ColorPicker.template b/Templates/ColorPicker.template index 5bf21131..e128ff71 100755 --- a/Templates/ColorPicker.template +++ b/Templates/ColorPicker.template @@ -17,32 +17,32 @@ - - - - - - - diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index cd9e3ba3..e8ba10b1 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -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 bindings = new List (); + public List Bindings { + get { return bindings; } + } + #endregion + public BasicTests () : base(800, 600,"test: press 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 to switch example."; CrowInterface.LoadInterface(testFiles[idx]).DataSource = this; + CompilerServices.ResolveBindings (this.Bindings); } void KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e) { diff --git a/Tests/Interfaces/Divers/colorPicker.crow b/Tests/Interfaces/Divers/colorPicker.crow index 17700afb..7a0f2801 100755 --- a/Tests/Interfaces/Divers/colorPicker.crow +++ b/Tests/Interfaces/Divers/colorPicker.crow @@ -1,5 +1,7 @@  - - + + + + \ No newline at end of file diff --git a/Tests/Interfaces/Divers/test2WayBinding.crow b/Tests/Interfaces/Divers/test2WayBinding.crow new file mode 100755 index 00000000..cf76f72b --- /dev/null +++ b/Tests/Interfaces/Divers/test2WayBinding.crow @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/GraphicObject/2.crow b/Tests/Interfaces/GraphicObject/2.crow index 74075b28..696cd44f 100755 --- a/Tests/Interfaces/GraphicObject/2.crow +++ b/Tests/Interfaces/GraphicObject/2.crow @@ -1,3 +1,4 @@ - \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index e1b8e182..82fe60b0 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -304,6 +304,9 @@ PreserveNewest + + PreserveNewest + diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 77666af2..384e6765 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -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 ()); + } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index d182f54a..277e3d48 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -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 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 diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs index 11aee383..7afd6f7a 100644 --- a/src/GraphicObjects/HueSelector.cs +++ b/src/GraphicObjects/HueSelector.cs @@ -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 (); } diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs index 54a765b8..b71fa7ef 100644 --- a/src/GraphicObjects/SaturationValueSelector.cs +++ b/src/GraphicObjects/SaturationValueSelector.cs @@ -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))); -- 2.47.3