From: Jean-Philippe Bruyère Date: Tue, 14 Feb 2017 23:27:39 +0000 (+0100) Subject: Several Lock while debuging for magicCrow, Image Opacity, could be put in GraphicObj X-Git-Tag: v0.9.5-beta~243 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=35555b7988e10acbed258725dcb1021061f74784;p=jp%2Fcrow.git Several Lock while debuging for magicCrow, Image Opacity, could be put in GraphicObj --- diff --git a/Crow.csproj b/Crow.csproj index f5d90aa4..ab9ff58d 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -20,12 +20,9 @@ v4.5 C# Rapid Open Widget 4194304 - 0.5 $(SolutionDir)build\$(Configuration) $(SolutionDir)build\obj\$(Configuration) crow.key - 8.0.30703 - 2.0 true diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 7aac41d7..287edd50 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -135,7 +135,8 @@ namespace Crow if (parent == value) return; DataSourceChangeEventArgs e = new DataSourceChangeEventArgs (parent, value); - parent = value; + lock (this) + parent = value; onParentChanged (this, e); } @@ -1115,34 +1116,35 @@ namespace Crow public virtual void Paint (ref Context ctx) { //TODO:this test should not be necessary - if (Slot.Height < 0 || Slot.Width < 0) + if (Slot.Height < 0 || Slot.Width < 0 || parent == null) return; + lock (this) { + LastPaintedSlot = Slot; - LastPaintedSlot = Slot; + if (cacheEnabled) { + if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize) + cacheEnabled = false; + } - if (cacheEnabled) { - if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize) - cacheEnabled = false; - } + if (cacheEnabled) { + if (IsDirty) + RecreateCache (); - if (cacheEnabled) { - if (IsDirty) - RecreateCache (); + UpdateCache (ctx); + if (!isEnabled) + paintDisabled (ctx, Slot + Parent.ClientRectangle.Position); + } else { + Rectangle rb = Slot + Parent.ClientRectangle.Position; + ctx.Save (); - UpdateCache (ctx); - if (!isEnabled) - paintDisabled (ctx, Slot + Parent.ClientRectangle.Position); - } else { - Rectangle rb = Slot + Parent.ClientRectangle.Position; - ctx.Save (); + ctx.Translate (rb.X, rb.Y); - ctx.Translate (rb.X, rb.Y); + onDraw (ctx); + if (!isEnabled) + paintDisabled (ctx, Slot); - onDraw (ctx); - if (!isEnabled) - paintDisabled (ctx, Slot); - - ctx.Restore (); + ctx.Restore (); + } } } void paintDisabled(Context gr, Rectangle rb){ diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 6e470b95..1e0e7b58 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -61,11 +61,13 @@ namespace Crow } public virtual void ClearChildren() { - while(Children.Count > 0){ - GraphicObject g = Children[Children.Count-1]; - g.LayoutChanged -= OnChildLayoutChanges; - g.Parent = null; - Children.RemoveAt(Children.Count-1); + lock (children) { + while (Children.Count > 0) { + GraphicObject g = Children [Children.Count - 1]; + g.LayoutChanged -= OnChildLayoutChanges; + g.Parent = null; + Children.RemoveAt (Children.Count - 1); + } } resetChildrenMaxSize (); @@ -78,16 +80,20 @@ namespace Crow { if (Children.Contains(w)) { - Children.Remove(w); - Children.Add(w); + lock (children) { + Children.Remove (w); + Children.Add (w); + } } } public void putWidgetOnBottom(GraphicObject w) { if (Children.Contains(w)) { - Children.Remove(w); - Children.Insert(0, w); + lock (children) { + Children.Remove (w); + Children.Insert (0, w); + } } } @@ -95,21 +101,25 @@ namespace Crow public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) { base.OnDataSourceChanged (this, e); - foreach (GraphicObject g in children) - if (g.localDataSourceIsNull & g.localLogicalParentIsNull) - g.OnDataSourceChanged (sender, e); + lock (children) { + foreach (GraphicObject g in children) + if (g.localDataSourceIsNull & g.localLogicalParentIsNull) + g.OnDataSourceChanged (sender, e); + } } public override GraphicObject FindByName (string nameToFind) { if (Name == nameToFind) return this; - - foreach (GraphicObject w in Children) { - GraphicObject r = w.FindByName (nameToFind); - if (r != null) - return r; + GraphicObject tmp = null; + lock (children) { + foreach (GraphicObject w in Children) { + tmp = w.FindByName (nameToFind); + if (tmp != null) + break; + } } - return null; + return tmp; } public override bool Contains (GraphicObject goToFind) { diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index 281011ad..1b32d70d 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -12,6 +12,7 @@ namespace Crow Picture _pic; string _svgSub; bool scaled, keepProps; + double opacity; #region Public properties [XmlAttributeAttribute][DefaultValue(true)] @@ -84,6 +85,17 @@ namespace Crow RegisterForGraphicUpdate (); } } + [XmlAttributeAttribute()][DefaultValue(1.0)] + public virtual double Opacity { + get { return opacity; } + set { + if (opacity == value) + return; + opacity = value; + NotifyValueChanged ("Faded", opacity); + RegisterForRedraw (); + } + } #endregion #region CTOR @@ -129,6 +141,14 @@ namespace Crow return; _pic.Paint (gr, ClientRectangle, _svgSub); + + if (Opacity<1.0) { + gr.SetSourceRGBA (0.0, 0.0, 0.0, 1.0-Opacity); + gr.Operator = Operator.DestOut; + gr.Rectangle (ClientRectangle); + gr.Fill (); + gr.Operator = Operator.Over; + } } #endregion } diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 57e48015..3be86ce4 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -863,6 +863,8 @@ namespace Crow il.Emit(OpCodes.Ldc_I4, dmVC);//load index of dynmathod il.Emit (OpCodes.Call, CompilerServices.miDSChangeEmitHelper); + il.MarkLabel (cancel); + if (bindingDef.TwoWay){ il.Emit (OpCodes.Ldarg_1);//arg1: dataSourceChange source, the origine of the binding il.Emit (OpCodes.Ldstr, bindingDef.SourceMember);//arg2: orig member @@ -872,7 +874,6 @@ namespace Crow il.Emit (OpCodes.Call, CompilerServices.miDSReverseBinding); } - il.MarkLabel (cancel); } il.Emit (OpCodes.Ret); @@ -901,6 +902,9 @@ namespace Crow Debug.WriteLine ("Member '{0}' not found in new DataSource '{1}' of '{2}'", destMember, dest, orig); return; } + #if DEBUG_BINDING + Debug.WriteLine ("DS Reverse binding: Member '{0}' found in new DS '{1}' of '{2}'", destMember, dest, orig); + #endif #region ValueChanged emit DynamicMethod dm = new DynamicMethod ("dyn_valueChanged" + NewId, diff --git a/src/Interface.cs b/src/Interface.cs index 924f092e..e90ae42c 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -472,8 +472,12 @@ namespace Crow lock (DrawingQueue) g = DrawingQueue.Dequeue (); g.IsQueueForRedraw = false; - g.Parent.RegisterClip (g.LastPaintedSlot); - g.Parent.RegisterClip (g.getSlot ()); + if (g.Parent == null) + continue; + lock (g) { + g.Parent.RegisterClip (g.LastPaintedSlot); + g.Parent.RegisterClip (g.getSlot ()); + } } #if MEASURE_TIME