]> O.S.I.I.S - jp/crow.git/commitdiff
debug dragNdrop bugs, should be simplified
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 20 Aug 2021 06:35:24 +0000 (08:35 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 20 Aug 2021 06:35:24 +0000 (08:35 +0200)
Crow/src/Interface.cs
Crow/src/Widgets/DockWindow.cs
Crow/src/Widgets/Group.cs
Directory.Build.props
Samples/BasicTests/BasicTests.cs
Samples/dragNdrop/dragNdrop.cs
Samples/dragNdrop/ui/test.crow

index 8725a27bdc07894b8abf45071e7401f57d861f05..632c9bbf66cd58c428cbc76868ee5d2ed1cbe2f7 100644 (file)
@@ -22,8 +22,8 @@ using Path = System.IO.Path;
 namespace Crow
 {
        /// <summary>
-       /// 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.
        /// </summary>
        /// <remarks>
@@ -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</summary>
                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);
index 0edccaa534cda77c0dfa410fa9ad2b91981f6f00..763da1aa63f0e96af8cabe079ed7be64497d3e88 100644 (file)
@@ -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) {
index 33e1b4c1601680478d9e76c0a15409ee26df8f1c..f13f335ae833ca3f492dd36d2f62d12913d2a7a9 100644 (file)
@@ -49,6 +49,7 @@ namespace Crow
                                searchTallestChild ();
 
                        this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
+                       this.RegisterForGraphicUpdate();
 
                }
                public override void InsertChild (int idx, Widget g) {
index 16d2c0c0446374e8f1a022600a75524f99217bae..b91129b568c797253d643891c3abc5c15d63d063 100644 (file)
@@ -6,7 +6,7 @@
                <Authors>Jean-Philippe Bruyère</Authors>           
                <LangVersion>7.3</LangVersion>
                
-               <CrowVersion>1.0.0</CrowVersion>
+               <CrowVersion>0.9.5</CrowVersion>
                <CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
 
                <!-- If you dont have a native libstb on your system, enable the managed version of stb here
index 7e70491601546addd49628d46c60aac03faea6b5..3b4e6bb2ceccbd1991536f92200be48f7194f709 100644 (file)
@@ -94,7 +94,7 @@ namespace Samples
                        } catch (Exception ex) {
                                //(LoadIMLFragment ($"<Label Background='Red' Foreground='White' Height='Fit' Width='Stretched' Multiline='true' VerticalAlignment='Bottom' Margin='5' />") as OldLabel).Text = ex.ToString();
                                Console.WriteLine (ex);
-                                                                                                                                                                                                                                                //MessageBox.Show (CurrentInterface, MessageBox.Type.Error, ex.Message + "\n" + ex.InnerException.Message).Modal = true;
+                               //MessageBox.Show (CurrentInterface, MessageBox.Type.Error, ex.Message + "\n" + ex.InnerException.Message).Modal = true;
                        }
                        return false;
                }
index 4b06326344e9f280a9edcb7c47a9de1fc655bee5..29c22f28616e54e69b707bb2eb51ac918192aa29 100644 (file)
@@ -1,3 +1,4 @@
+using System;
 using Crow;
 using Samples;
 using Crow.Drawing;
@@ -29,6 +30,10 @@ namespace tests
         private void W_StartDrag (object sender, DragDropEventArgs e) {
                        Rectangle r = e.DragSource.LastPaintedSlot;
             startGroup = e.DragSource.Parent as Group;
+                       if (e.DragSource.bmp == null) {
+                               Console.WriteLine ($"DragSource surface is null: {e.DragSource}");
+                               return;
+                       }
 
             Surface dragImg = CreateSurface (ref r);
             using (Context gr = new Context(dragImg)) {
@@ -41,7 +46,8 @@ namespace tests
         }
         private void W_EndDrag (object sender, DragDropEventArgs e) {
             lock (UpdateMutex)
-                startGroup.AddChild (e.DragSource);            
+                startGroup.AddChild (e.DragSource);
+                       ClearDragImage ();
         }
 
         private void W_DragEnter (object sender, DragDropEventArgs e) {
@@ -54,6 +60,7 @@ namespace tests
         }
         private void W_Drop (object sender, DragDropEventArgs e) {
             //(e.DropTarget as Group).AddChild (e.DragSource);            
+                       ClearDragImage ();
         }
 
 
index ce49ea71d035b1eac010396c232297eb8b7dd035..026cb482fa5eff3c6553143afd637e40ff95fcb3 100644 (file)
                </HorizontalStack>
        </VerticalStack>
        <HorizontalStack Margin="20" Name="zone1" Height="100" Width="Stretched" Background="Grey" AllowDrop="true" DragEnter="W_DragEnter" DragLeave="W_DragLeave">
-               <Widget Name="w1" Background="Blue" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>
-               <Widget Name="w2" Background="Red" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
-               <Widget Name="w3" Background="Green" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
-               <Widget Name="w4" Background="Yellow" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
-               <Widget Name="w5" Background="DimGrey" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
+               <Widget CacheEnabled="True" Name="w1" Background="Blue" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>
+               <Widget CacheEnabled="True" Name="w2" Background="Red" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
+               <Widget CacheEnabled="True" Name="w3" Background="Green" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
+               <Widget CacheEnabled="True" Name="w4" Background="Yellow" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
+               <Widget CacheEnabled="True" Name="w5" Background="DimGrey" Focusable="true" Width="50" Height="Stretched" AllowDrag="true" StartDrag="W_StartDrag" EndDrag="W_EndDrag" Drop="W_Drop"/>/>
        </HorizontalStack>
        <Widget Height="20" Focusable="true"/>
        <HorizontalStack Margin="20" Name="zone2" Height="150" Width="Stretched" Background="Grey" AllowDrop="true" DragEnter="W_DragEnter" DragLeave="W_DragLeave">