diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-04-30 13:03:33 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-04-30 13:03:33 +0200 |
| commit | 02ac8178673249c2d1af60d7b291d8b40419bcd8 (patch) | |
| tree | 672b1242b2d31ed159916ed32b99147279fcc758 /src | |
| parent | 8771dccd2369447a50485c7649e8a0851b551958 (diff) | |
glfw backend, group measure on change only
Diffstat (limited to 'src')
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 52 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 13 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 91 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 7 | ||||
| -rw-r--r-- | src/GraphicObjects/Splitter.cs | 12 | ||||
| -rw-r--r-- | src/Interface.cs | 5 |
6 files changed, 101 insertions, 79 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index ea46d439..af72a9e0 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -46,11 +46,11 @@ namespace Crow } } public class Binding{ - static int bindingCpt = 0; + static int bindingCpt; string dynMethodId = ""; - bool resolved = false; + bool resolved; - public bool TwoWayBinding = false; + public bool TwoWayBinding; public string NewDynMethodId { get { @@ -150,7 +150,9 @@ namespace Crow } while (ptr < bindingExp.Length - 1) { if (tmp == null) { + #if DEBUG_BINDING Debug.WriteLine ("\tERROR: target not found => " + this.ToString()); + #endif return false; } if (bindingExp [ptr] == "..") @@ -165,7 +167,9 @@ namespace Crow } if (tmp == null) { + #if DEBUG_BINDING Debug.WriteLine ("\tERROR: target not found => " + this.ToString()); + #endif return false; } @@ -190,7 +194,7 @@ namespace Crow if (TwoWayBinding) { IBindable source = Source.Instance as IBindable; if (source == null) - throw new Exception (Target.Instance.ToString() + " does not implement IBindable for 2 way bindings"); + throw new Exception (Target.Instance + " does not implement IBindable for 2 way bindings"); source.Bindings.Add (new Binding (Source, Target)); } return true; @@ -222,9 +226,9 @@ namespace Crow return; if (Bindings.Count == 0) return; - #if DEBUG_BINDING +#if DEBUG_BINDING Debug.WriteLine ("Resolve Bindings => " + this.ToString ()); - #endif +#endif //grouped bindings by Instance of Source Dictionary<object,List<Binding>> resolved = new Dictionary<object, List<Binding>>(); @@ -248,9 +252,9 @@ namespace Crow Delegate del = Delegate.CreateDelegate (b.Target.Event.EventHandlerType, b.Source.Instance, b.Source.Method); addHandler.Invoke (b.Target.Instance, new object[] { del }); - #if DEBUG_BINDING +#if DEBUG_BINDING Debug.WriteLine ("\tHandler binded => " + b.ToString()); - #endif +#endif b.Resolved = true; } catch (Exception ex) { Debug.WriteLine ("\tERROR: " + ex.ToString()); @@ -294,7 +298,7 @@ namespace Crow System.Reflection.Emit.Label[] jumpTable = null; System.Reflection.Emit.Label endMethod = new System.Reflection.Emit.Label(); - #region Retrieve EventHandler parameter type +#region Retrieve EventHandler parameter type //EventInfo ei = targetType.GetEvent ("ValueChanged"); //no dynamic update if ValueChanged interface is not implemented if (source_Type.GetInterfaces().Contains(typeof(IValueChange))){ @@ -328,11 +332,11 @@ namespace Crow il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Brfalse, endMethod); } - #endregion +#endregion i = 0; foreach (Binding b in grouped) { - #region initialize target with actual value +#region initialize target with actual value object targetValue = null; if (b.Source.Member != null){ if (b.Source.Member.MemberType == MemberTypes.Property) @@ -363,7 +367,7 @@ namespace Crow else b.Target.Property.GetSetMethod ().Invoke (b.Target.Instance, new object[] { targetValue }); - #endregion +#endregion //if no dyn update, skip jump table if (il == null) @@ -437,17 +441,17 @@ namespace Crow /// <param name="es">Event binding details</param> public static void CompileEventSource(Binding binding) { - #if DEBUG_BINDING +#if DEBUG_BINDING Debug.WriteLine ("\tCompile Event Source => " + binding.ToString()); - #endif +#endif Type target_type = binding.Target.Instance.GetType(); - #region Retrieve EventHandler parameter type +#region Retrieve EventHandler parameter type MethodInfo evtInvoke = binding.Target.Event.EventHandlerType.GetMethod ("Invoke"); ParameterInfo[] evtParams = evtInvoke.GetParameters (); Type handlerArgsType = evtParams [1].ParameterType; - #endregion +#endregion Type[] args = {typeof(object), typeof(object),handlerArgsType}; DynamicMethod dm = new DynamicMethod(binding.NewDynMethodId, @@ -456,7 +460,7 @@ namespace Crow target_type); - #region IL generation +#region IL generation ILGenerator il = dm.GetILGenerator(256); string src = binding.Expression.Trim(); @@ -478,7 +482,7 @@ namespace Crow string lop = operandes [0].Trim (); string rop = operandes [operandes.Length-1].Trim (); - #region LEFT OPERANDES +#region LEFT OPERANDES GraphicObject lopObj = binding.Target.Instance as GraphicObject; //default left operand base object is //the first arg (object sender) of the event handler @@ -520,9 +524,9 @@ namespace Crow default: throw new Exception (string.Format("GOML:member type not handle: {0}", lopParts[i])); } - #endregion +#endregion - #region RIGHT OPERANDES +#region RIGHT OPERANDES if (rop.StartsWith("\'")){ if (!rop.EndsWith("\'")) throw new Exception (string.Format @@ -544,7 +548,7 @@ namespace Crow il.Emit(OpCodes.Unbox_Any, lopT); } - #endregion +#endregion //emit left operand assignment il.Emit(lopSetOC, lopSetMbi); @@ -552,7 +556,7 @@ namespace Crow il.Emit(OpCodes.Ret); - #endregion +#endregion Delegate del = dm.CreateDelegate(binding.Target.Event.EventHandlerType, binding.Target.Instance); MethodInfo addHandler = binding.Target.Event.GetAddMethod (); @@ -561,7 +565,7 @@ namespace Crow binding.Resolved = true; } - #region conversions +#region conversions internal static MethodInfo GetConvertMethod( Type targetType ) { @@ -588,7 +592,7 @@ namespace Crow return typeof( Convert ).GetMethod( name, BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof( object ) }, null ); } - #endregion +#endregion public static FieldInfo GetEventHandlerField(Type type, string eventName) { diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index d5ff81c6..adf428c5 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -50,11 +50,18 @@ namespace Crow } protected override int measureRawSize (LayoutingType lt) { + int totSpace = 0; + for (int i = 0; i < Children.Count; i++) { + if (Children [i].Visible) + totSpace += Spacing; + } + if (totSpace > 0) + totSpace -= Spacing; if (lt == LayoutingType.Width) { if (Orientation == Orientation.Horizontal) - return contentSize.Width + (Children.Count - 1) * Spacing + 2 * Margin; + return contentSize.Width + totSpace + 2 * Margin; }else if (Orientation == Orientation.Vertical) - return contentSize.Height + (Children.Count - 1) * Spacing + 2 * Margin; + return contentSize.Height + totSpace + 2 * Margin; return base.measureRawSize (lt); } @@ -103,7 +110,7 @@ namespace Crow public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { GraphicObject go = sender as GraphicObject; - Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); + //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); switch (arg.LayoutType) { case LayoutingType.Width: if (Orientation == Orientation.Horizontal) { diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 30aa4a95..549f9a91 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -672,7 +672,6 @@ namespace Crow } /// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary> public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){ - } public virtual bool ArrangeChildren { get { return false; } } public virtual void RegisterForLayouting(LayoutingType layoutType){ @@ -680,9 +679,9 @@ namespace Crow return; lock (Interface.CurrentInterface.LayoutMutex) { //dont set position for stretched item - if (Width == 0) + if (Width == Measure.Stretched) layoutType &= (~LayoutingType.X); - if (Height == 0) + if (Height == Measure.Stretched) layoutType &= (~LayoutingType.Y); if (!ArrangeChildren) @@ -786,52 +785,58 @@ namespace Crow Slot.Y = Top; break; case LayoutingType.Width: - if (Width.IsFixed) - Slot.Width = Width; - else if (Width == Measure.Fit) { - Slot.Width = measureRawSize (LayoutingType.Width); - } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width)) - return false; - else if (Width == Measure.Stretched) - Slot.Width = Parent.ClientRectangle.Width; - else - Slot.Width = (int)Math.Round ((double)(Parent.ClientRectangle.Width * Width) / 100.0); + if (Visible) { + if (Width.IsFixed) + Slot.Width = Width; + else if (Width == Measure.Fit) { + Slot.Width = measureRawSize (LayoutingType.Width); + } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width)) + return false; + else if (Width == Measure.Stretched) + Slot.Width = Parent.ClientRectangle.Width; + else + Slot.Width = (int)Math.Round ((double)(Parent.ClientRectangle.Width * Width) / 100.0); - if (Slot.Width < 0) - return false; + if (Slot.Width < 0) + return false; - //size constrain - if (Slot.Width < MinimumSize.Width) { - Slot.Width = MinimumSize.Width; - NotifyValueChanged ("WidthPolicy", Measure.Stretched); - } else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) { - Slot.Width = MaximumSize.Width; - NotifyValueChanged ("WidthPolicy", Measure.Stretched); - } + //size constrain + if (Slot.Width < MinimumSize.Width) { + Slot.Width = MinimumSize.Width; + NotifyValueChanged ("WidthPolicy", Measure.Stretched); + } else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) { + Slot.Width = MaximumSize.Width; + NotifyValueChanged ("WidthPolicy", Measure.Stretched); + } + } else + Slot.Width = 0; break; case LayoutingType.Height: - if (Height.IsFixed) - Slot.Height = Height; - else if (Height == Measure.Fit) { - Slot.Height = measureRawSize (LayoutingType.Height); - } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height)) - return false; - else if (Height == Measure.Stretched) - Slot.Height = Parent.ClientRectangle.Height; - else - Slot.Height = (int)Math.Round ((double)(Parent.ClientRectangle.Height * Height) / 100.0); + if (Visible) { + if (Height.IsFixed) + Slot.Height = Height; + else if (Height == Measure.Fit) { + Slot.Height = measureRawSize (LayoutingType.Height); + } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height)) + return false; + else if (Height == Measure.Stretched) + Slot.Height = Parent.ClientRectangle.Height; + else + Slot.Height = (int)Math.Round ((double)(Parent.ClientRectangle.Height * Height) / 100.0); - if (Slot.Height < 0) - return false; + if (Slot.Height < 0) + return false; - //size constrain - if (Slot.Height < MinimumSize.Height) { - Slot.Height = MinimumSize.Height; - NotifyValueChanged ("HeightPolicy", Measure.Stretched); - } else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) { - Slot.Height = MaximumSize.Height; - NotifyValueChanged ("HeightPolicy", Measure.Stretched); - } + //size constrain + if (Slot.Height < MinimumSize.Height) { + Slot.Height = MinimumSize.Height; + NotifyValueChanged ("HeightPolicy", Measure.Stretched); + } else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) { + Slot.Height = MaximumSize.Height; + NotifyValueChanged ("HeightPolicy", Measure.Stretched); + } + } else + Slot.Height = 0; break; } diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 0ff4beca..16a797d7 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -92,6 +92,13 @@ namespace Crow return child == goToFind ? true : child == null ? false : child.Contains(goToFind); } + public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) + { + if (Width == Measure.Fit) + layoutType &= (~LayoutingType.X); + if (Height == Measure.Fit) + layoutType &= (~LayoutingType.Y); + } public override bool UpdateLayout (LayoutingType layoutType) { if (child != null) { diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs index 6a1f2254..527b4084 100644 --- a/src/GraphicObjects/Splitter.cs +++ b/src/GraphicObjects/Splitter.cs @@ -83,14 +83,14 @@ namespace Crow if (gs.Orientation == Orientation.Horizontal) { if (ptrThis >= 0) - gs.Children [ptrThis - 1].Width = Math.Max(gs.Children [ptrThis - 1].Slot.Width + e.XDelta*2, 1); + gs.Children [ptrThis - 1].Width = Math.Max(gs.Children [ptrThis - 1].Slot.Width + e.XDelta, 1); if (ptrThis < gs.Children.Count - 1) - gs.Children [ptrThis + 1].Width = Math.Max(gs.Children [ptrThis + 1].Slot.Width - e.XDelta*2, 1); + gs.Children [ptrThis + 1].Width = Math.Max(gs.Children [ptrThis + 1].Slot.Width - e.XDelta, 1); } else { if (ptrThis >= 0) - gs.Children [ptrThis - 1].Height = Math.Max(gs.Children [ptrThis - 1].Slot.Height + e.YDelta*2, 1); + gs.Children [ptrThis - 1].Height = Math.Max(gs.Children [ptrThis - 1].Slot.Height + e.YDelta, 1); if (ptrThis < gs.Children.Count - 1) - gs.Children [ptrThis + 1].Height = Math.Max(gs.Children [ptrThis + 1].Slot.Height - e.YDelta*2, 1); + gs.Children [ptrThis + 1].Height = Math.Max(gs.Children [ptrThis + 1].Slot.Height - e.YDelta, 1); } } public override bool UpdateLayout (LayoutingType layoutType) @@ -100,12 +100,12 @@ namespace Crow if (gs.Orientation == Orientation.Horizontal) Width = thickness; else - Width = 0; + Width = Measure.Stretched; } else if (layoutType == LayoutingType.Height){ if (gs.Orientation == Orientation.Vertical) Height = thickness; else - Height = 0; + Height = Measure.Stretched; } return base.UpdateLayout (layoutType); } diff --git a/src/Interface.cs b/src/Interface.cs index 063a34de..2e145bff 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -655,6 +655,7 @@ namespace Crow if (!FocusedWidget.MouseRepeat) return true; mouseRepeatThread = new Thread (mouseRepeatThreadFunc); + mouseRepeatThread.IsBackground = true; mouseRepeatThread.Start (); return true; } @@ -685,8 +686,7 @@ namespace Crow #endregion #region Keyboard - public bool ProcessKeyDown(int Key){ - Keyboard.SetKeyState ((Crow.Key)Key, true); + public bool ProcessKeyDown(int Key){ if (_focusedWidget == null) return false; KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); @@ -694,7 +694,6 @@ namespace Crow return true; } public bool ProcessKeyUp(int Key){ - Keyboard.SetKeyState ((Crow.Key)Key, false); if (_activeWidget == null) return false; //KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); |