diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-08-27 06:51:36 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-08-27 06:51:36 +0200 |
| commit | 6cbe9f9d2a604cdbb74f46f3710ea3dc60a87e55 (patch) | |
| tree | 7e3e675b2f6b14d320b124389b25fde003b63ea6 /src/GraphicObjects/GraphicObject.cs | |
| parent | 3025ab70f5fc51819f5980908a8a98d5d6426b7e (diff) | |
first step in implementing a dispose mechanism for graphic objects
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index aad6e327..8fd9a6e9 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -38,8 +38,27 @@ using System.IO; namespace Crow { - public class GraphicObject : ILayoutable, IValueChange + public class GraphicObject : ILayoutable, IValueChange, IDisposable { + #region IDisposable implementation + + public virtual void Dispose () + { + #if DEBUG_DISPOSE + Debug.WriteLine ("{0} Disposed", this.ToString()); + #endif + + parent = null; + if (IsQueueForRedraw) + Debugger.Break (); + if (!localDataSourceIsNull) + DataSource = null; + Clipping?.Dispose (); + bmp?.Dispose (); + } + + #endregion + internal static ulong currentUid = 0; internal ulong uid = 0; @@ -804,12 +823,27 @@ namespace Crow public virtual bool Contains(GraphicObject goToFind){ return false; } + /// <summary> + /// return true if this is contained inside go + /// </summary> + public bool IsInside(GraphicObject go){ + ILayoutable p = this.Parent; + while (p != null) { + if (p == go) + return true; + p = p.Parent; + } + return false; + } #region Queuing /// <summary> /// Register old and new slot for clipping /// </summary> public virtual void ClippingRegistration(){ + #if DEBUG_UPDATE + Debug.WriteLine (string.Format("ClippingRegistration -> {0}", this.ToString ())); + #endif IsQueueForRedraw = false; if (Parent == null) return; @@ -821,6 +855,9 @@ namespace Crow /// </summary> /// <param name="clip">Clip rectangle</param> public virtual void RegisterClip(Rectangle clip){ + #if DEBUG_UPDATE + Debug.WriteLine (string.Format("RegisterClip -> {1}:{0}", clip, this.ToString ())); + #endif Rectangle r = clip + ClientRectangle.Position; if (CacheEnabled && !IsDirty) Clipping.UnionRectangle (r); @@ -835,6 +872,9 @@ namespace Crow [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForGraphicUpdate () { + #if DEBUG_UPDATE + Debug.WriteLine (string.Format("RegisterForGraphicUpdate -> {0}", this.ToString ())); + #endif IsDirty = true; if (Width.IsFit || Height.IsFit) RegisterForLayouting (LayoutingType.Sizing); @@ -845,6 +885,9 @@ namespace Crow [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForRedraw () { + #if DEBUG_UPDATE + Debug.WriteLine (string.Format("RegisterForRedraw -> {0}", this.ToString ())); + #endif IsDirty = true; if (RegisteredLayoutings == LayoutingType.None) currentInterface.EnqueueForRepaint (this); @@ -1091,6 +1134,9 @@ namespace Crow /// this trigger the effective drawing routine </summary> protected virtual void RecreateCache () { + #if DEBUG_UPDATE + Debug.WriteLine ("RecreateCache -> {0}", this.ToString ()); + #endif IsDirty = false; if (bmp != null) bmp.Dispose (); @@ -1102,6 +1148,9 @@ namespace Crow bmp.Flush (); } protected virtual void UpdateCache(Context ctx){ + #if DEBUG_UPDATE + Debug.WriteLine ("UpdateCache -> {0}", this.ToString ()); + #endif Rectangle rb = Slot + Parent.ClientRectangle.Position; if (clearBackground) { ctx.Save (); @@ -1119,6 +1168,9 @@ namespace Crow /// of the widget </summary> public virtual void Paint (ref Context ctx) { + #if DEBUG_UPDATE + Debug.WriteLine (string.Format("Paint -> {0}", this.ToString ())); + #endif //TODO:this test should not be necessary if (Slot.Height < 0 || Slot.Width < 0 || parent == null) return; @@ -1307,7 +1359,22 @@ namespace Crow protected virtual void onLogicalParentChanged(object sender, DataSourceChangeEventArgs e) { LogicalParentChanged.Raise (this, e); } - + internal void ClearTemplateBinding(){ + #if DEBUG_UPDATE + Debug.WriteLine (string.Format("ClearTemplateBinding: {0}", this.ToString())); + #endif + if (ValueChanged == null) + return; + EventInfo eiEvt = this.GetType().GetEvent ("ValueChanged"); + foreach (Delegate d in ValueChanged.GetInvocationList()) { + if (d.Method.Name == "dyn_tmpValueChanged") { + eiEvt.RemoveEventHandler (this, d); + #if DEBUG_BINDING + Debug.WriteLine ("\t{0} template binding handler removed in {1} for: {2}", d.Method.Name, this, "ValueChanged"); + #endif + } + } + } public override string ToString () { string tmp =""; |