From: Jean-Philippe Bruyère Date: Fri, 20 Aug 2021 06:35:24 +0000 (+0200) Subject: debug dragNdrop bugs, should be simplified X-Git-Tag: v0.9.5-beta~1 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=36f62cf1ca61cb10c6958787376ae76efb71a1ea;p=jp%2Fcrow.git debug dragNdrop bugs, should be simplified --- diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index 8725a27b..632c9bbf 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -22,8 +22,8 @@ using Path = System.IO.Path; namespace Crow { /// - /// The Interface Class is the root of crow graphic trees. It is thread safe allowing - /// application to run multiple interfaces in different threads. + /// The Interface Class is the root of crow graphic trees. + /// It is thread safe allowing application to run multiple interfaces in different threads. /// It provides the Dirty bitmap and zone of the interface to be drawn on screen. /// /// @@ -486,14 +486,13 @@ namespace Crow { if (disposing) { - // TODO: dispose managed state (managed objects). + disposeContextMenus (); #if VKVG vkCtx.Dispose (); #endif } currentCursor?.Dispose (); - disposeContextMenus (); if (ownWindow) { Glfw3.DestroyWindow (hWin); @@ -503,14 +502,10 @@ namespace Crow disposedValue = true; } } - - // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. ~Interface() { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(false); } - // This code added to correctly implement the disposable pattern. public void Dispose() { Dispose(true); @@ -518,17 +513,6 @@ namespace Crow } #endregion - /*public void ProcessEvents () - { - //if (armedClick != null) { - // if (lastClickTime.ElapsedMilliseconds > DOUBLECLICK_TRESHOLD) { - // //cancel double click and - // armedClick.onMouseClick (armedClick, armedClickEventArgs); - // armedClick = null; - // } - //} - }*/ - #region Static and constants //initial capacity for layouting and clipping queues. const int INIT_QUEUE_CAPACITY = 512; @@ -655,16 +639,16 @@ namespace Crow internal Widget dragndropHover; public Surface DragImage = null; - public Rectangle DragImageBounds; + public Rectangle DragImageBounds, lastDragImageBounds; public bool DragImageFolowMouse;//prevent dragImg to be moved by mouse public void ClearDragImage () { lock (UpdateMutex) { if (DragImage == null) return; - clipping.UnionRectangle (DragImageBounds); + clipping.UnionRectangle (lastDragImageBounds); DragImage.Dispose(); DragImage = null; - DragImageBounds = default; + DragImageBounds = lastDragImageBounds = default; } } public void CreateDragImage (Surface img, Rectangle bounds, bool followMouse = true) { @@ -673,6 +657,7 @@ namespace Crow ClearDragImage (); DragImage = img; DragImageBounds = bounds; + lastDragImageBounds = default; DragImageFolowMouse = followMouse; } } @@ -1110,6 +1095,13 @@ namespace Crow clippingRegistration (); + if (DragAndDropOperation != null && DragImageFolowMouse && DragImage != null) { + lastDragImageBounds = DragImageBounds; + DragImageBounds.X = MousePosition.X - DragImageBounds.Width / 2; + DragImageBounds.Y = MousePosition.Y - DragImageBounds.Height / 2; + if (DragImageBounds != lastDragImageBounds) + clipping.UnionRectangle(lastDragImageBounds); + } if (!clipping.IsEmpty) { if (ctx == null) { @@ -1218,79 +1210,69 @@ namespace Crow /// repainted. If it contains also clip rectangles, its cache will be update, or if not cached a full redraw will take place protected virtual void processDrawing(Context ctx){ DbgLogger.StartEvent (DbgEvtType.ProcessDrawing); - - if (DragImage != null) - clipping.UnionRectangle(DragImageBounds); - - PerformanceMeasure.Begin (PerformanceMeasure.Kind.Drawing); + PerformanceMeasure.Begin (PerformanceMeasure.Kind.Drawing); #if VKVG - clear (ctx); + clear (ctx); #else - ctx.PushGroup (); + ctx.PushGroup (); - if (SolidBackground) - clear (ctx); + if (SolidBackground) + clear (ctx); #endif - - for (int i = GraphicTree.Count -1; i >= 0 ; i--){ - Widget p = GraphicTree[i]; - if (!p.IsVisible) - continue; - if (clipping.OverlapOut (p.Slot)) - continue; - - //ctx.Save (); - p.Paint (ctx); - //ctx.Restore (); - } + + for (int i = GraphicTree.Count -1; i >= 0 ; i--){ + Widget p = GraphicTree[i]; + if (!p.IsVisible) + continue; + if (clipping.OverlapOut (p.Slot)) + continue; + + ctx.Save (); + p.Paint (ctx); + ctx.Restore (); + } - if (DragAndDropOperation != null) { - if (DragImage != null) { - DirtyRect += DragImageBounds; - if (DragImageFolowMouse) { - DragImageBounds.X = MousePosition.X - DragImageBounds.Width / 2; - DragImageBounds.Y = MousePosition.Y - DragImageBounds.Height / 2; - } - ctx.Save (); - ctx.ResetClip (); - ctx.SetSource (DragImage, DragImageBounds.X, DragImageBounds.Y); - ctx.PaintWithAlpha (0.8); - ctx.Restore (); - DirtyRect += DragImageBounds; - IsDirty = true; - } - } + + if (lastDragImageBounds != DragImageBounds) { + DirtyRect += lastDragImageBounds; + ctx.Save (); + ctx.ResetClip (); + ctx.SetSource (DragImage, DragImageBounds.X, DragImageBounds.Y); + ctx.PaintWithAlpha (0.8); + ctx.Restore (); + DirtyRect += DragImageBounds; + IsDirty = true; + } + #if DEBUG_CLIP_RECTANGLE - ctx.LineWidth = 1; - ctx.SetSource(1,1,0,0.5); - for (int i = 0; i < clipping.NumRectangles; i++) - ctx.Rectangle(clipping.GetRectangle(i)); - ctx.Stroke (); - + ctx.LineWidth = 1; + ctx.SetSource(1,1,0,0.5); + for (int i = 0; i < clipping.NumRectangles; i++) + ctx.Rectangle(clipping.GetRectangle(i)); + ctx.Stroke (); + #endif #if VKVG - ctx.Flush(); - //vkCtx.render (); - //vkCtx.WaitIdle(); + ctx.Flush(); #else - ctx.PopGroupToSource (); + ctx.PopGroupToSource (); - if (!SolidBackground) - clear (ctx); + if (!SolidBackground) + clear (ctx); - ctx.Paint (); + ctx.Paint (); - surf.Flush (); + surf.Flush (); #endif - - clipping.Reset (); + + clipping.Reset (); - PerformanceMeasure.End (PerformanceMeasure.Kind.Drawing); - IsDirty = true; + PerformanceMeasure.End (PerformanceMeasure.Kind.Drawing); + IsDirty = true; #if !VKVG drawTextCursor (ctx); diff --git a/Crow/src/Widgets/DockWindow.cs b/Crow/src/Widgets/DockWindow.cs index 0edccaa5..763da1aa 100644 --- a/Crow/src/Widgets/DockWindow.cs +++ b/Crow/src/Widgets/DockWindow.cs @@ -4,6 +4,7 @@ using System; using System.Xml.Serialization; +using Crow.Drawing; using Glfw; @@ -198,7 +199,7 @@ namespace Crow r.Inflate (r.Width / -3, r.Height / -3); break; } - /*Surface dragImg = IFace.surf.CreateSimilar (Content.ColorAlpha, r.Width, r.Height); + Surface dragImg = IFace.CreateSurface (r.Width, r.Height); using (Context gr = new Context(dragImg)) { gr.LineWidth = 1; gr.Rectangle (0,0,r.Width,r.Height); @@ -207,7 +208,7 @@ namespace Crow gr.SetSource (0.1,0.2,1); gr.Stroke (); } - IFace.CreateDragImage (dragImg, r, false);*/ + IFace.CreateDragImage (dragImg, r, false); } } protected override void onDragEnter (object sender, DragDropEventArgs e) { diff --git a/Crow/src/Widgets/Group.cs b/Crow/src/Widgets/Group.cs index 33e1b4c1..f13f335a 100644 --- a/Crow/src/Widgets/Group.cs +++ b/Crow/src/Widgets/Group.cs @@ -49,6 +49,7 @@ namespace Crow searchTallestChild (); this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); + this.RegisterForGraphicUpdate(); } public override void InsertChild (int idx, Widget g) { diff --git a/Directory.Build.props b/Directory.Build.props index 16d2c0c0..b91129b5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,7 +6,7 @@ Jean-Philippe Bruyère 7.3 - 1.0.0 + 0.9.5 $(CrowVersion)-beta