aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-08-20 08:35:24 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-08-20 08:35:24 +0200
commit36f62cf1ca61cb10c6958787376ae76efb71a1ea (patch)
treec6c19417da16744eb2ba1dae7d1bdc2559ed137a
parent950104a8d304ebc9e4499186bc4cac8e6721b6ff (diff)
debug dragNdrop bugs, should be simplified
-rw-r--r--Crow/src/Interface.cs134
-rw-r--r--Crow/src/Widgets/DockWindow.cs5
-rw-r--r--Crow/src/Widgets/Group.cs1
-rw-r--r--Directory.Build.props2
-rw-r--r--Samples/BasicTests/BasicTests.cs2
-rw-r--r--Samples/dragNdrop/dragNdrop.cs9
-rw-r--r--Samples/dragNdrop/ui/test.crow10
7 files changed, 77 insertions, 86 deletions
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
{
/// <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;
+
+ 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 ();
- }
+ 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 @@
<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
diff --git a/Samples/BasicTests/BasicTests.cs b/Samples/BasicTests/BasicTests.cs
index 7e704916..3b4e6bb2 100644
--- a/Samples/BasicTests/BasicTests.cs
+++ b/Samples/BasicTests/BasicTests.cs
@@ -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;
}
diff --git a/Samples/dragNdrop/dragNdrop.cs b/Samples/dragNdrop/dragNdrop.cs
index 4b063263..29c22f28 100644
--- a/Samples/dragNdrop/dragNdrop.cs
+++ b/Samples/dragNdrop/dragNdrop.cs
@@ -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 ();
}
diff --git a/Samples/dragNdrop/ui/test.crow b/Samples/dragNdrop/ui/test.crow
index ce49ea71..026cb482 100644
--- a/Samples/dragNdrop/ui/test.crow
+++ b/Samples/dragNdrop/ui/test.crow
@@ -15,11 +15,11 @@
</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">