aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-18 23:26:23 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-18 23:26:23 +0100
commit0e44a661c488b012b9fc0eb56fec23ac8786436c (patch)
treeb8d815c971bb47254c9973e15b87aecb100144c2 /src
parentac3e60a3c49a2a1175564fbc994d3aed47c6bfb4 (diff)
drag and drop operations
Diffstat (limited to 'src')
-rw-r--r--src/DragDropEventArgs.cs55
-rw-r--r--src/GraphicObjects/GraphicObject.cs83
-rw-r--r--src/Input/MouseState.cs2
-rw-r--r--src/Interface.cs7
4 files changed, 113 insertions, 34 deletions
diff --git a/src/DragDropEventArgs.cs b/src/DragDropEventArgs.cs
new file mode 100644
index 00000000..428a7363
--- /dev/null
+++ b/src/DragDropEventArgs.cs
@@ -0,0 +1,55 @@
+//
+// LayoutingEventArgs.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2013-2017 Jean-Philippe Bruyère
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+namespace Crow
+{
+ public class DragDropEventArgs: EventArgs
+ {
+ /// <summary>
+ /// Source of the drag and drop operation
+ /// </summary>
+ public GraphicObject DragSource;
+ /// <summary>
+ /// Target of the drag and drop operation
+ /// </summary>
+ public GraphicObject DropTarget;
+
+ //public DragDropEventArgs (GraphicObject source, GraphicObject target = null) : base()
+ public DragDropEventArgs (GraphicObject source = null, GraphicObject target = null) : base()
+ {
+ DragSource = source;
+ DropTarget = target;
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("{0} => {1}", DragSource,DropTarget);
+ }
+ }
+}
+
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index ef2e0197..65f8ed26 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -318,8 +318,10 @@ namespace Crow
/// <summary>Occurs when the enabled state this object is set to false</summary>
public event EventHandler Disabled;
public event EventHandler StartDrag;
+ public event EventHandler DragEnter;
+ public event EventHandler DragLeave;
public event EventHandler EndDrag;
- public event EventHandler Dropped;
+ public event EventHandler Drop;
/// <summary>Occurs when one part of the rendering slot changed</summary>
public event EventHandler<LayoutingEventArgs> LayoutChanged;
/// <summary>Occurs when DataSource changed</summary>
@@ -1088,37 +1090,42 @@ namespace Crow
return;
isDragged = value;
- if (isDragged) {
- CurrentInterface.HoverWidget = null;
- onStartDrag (this, null);
- }
-
- NotifyValueChanged ("IsDrag", IsDragged);
+ NotifyValueChanged ("IsDragged", IsDragged);
}
}
/// <summary>
- /// start dragging
+ /// fired when drag and drop operation start
/// </summary>
- protected virtual void onStartDrag (object sender, EventArgs e){
- Debug.WriteLine("DRAG => " + this.ToString());
- StartDrag.Raise (this, null);
+ protected virtual void onStartDrag (object sender, DragDropEventArgs e){
+ CurrentInterface.HoverWidget = this.focusParent;
+ IsDragged = true;
+ StartDrag.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : START DRAG => " + e.ToString());
}
/// <summary>
/// Occured when dragging ends without dropping
/// </summary>
- protected virtual void onEndDrag (object sender, EventArgs e){
+ protected virtual void onEndDrag (object sender, DragDropEventArgs e){
IsDragged = false;
- EndDrag.Raise (this, null);
- Debug.WriteLine("END DRAG => " + this.ToString());
+ EndDrag.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : END DRAG => " + e.ToString());
}
- /// <summary>
- /// Dragging end with a dropping
- /// </summary>
- protected virtual void onDrop (object sender, EventArgs e){
+ protected virtual void onDragEnter (object sender, DragDropEventArgs e){
+ e.DropTarget = this;
+ DragEnter.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : DRAG Enter => " + e.ToString());
+ }
+ protected virtual void onDragLeave (object sender, DragDropEventArgs e){
+ e.DropTarget = null;
+ DragLeave.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : DRAG Leave => " + e.ToString());
+ }
+ protected virtual void onDrop (object sender, DragDropEventArgs e){
IsDragged = false;
- Debug.WriteLine("DROPPED => " + this.ToString());
- Dropped.Raise (this, null);
+ Drop.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : DROP => " + e.ToString());
}
+
#endregion
#region Queuing
@@ -1544,8 +1551,12 @@ namespace Crow
}
public virtual void onMouseMove(object sender, MouseMoveEventArgs e)
{
- if (AllowDrag & !IsDragged & IsActive)
- IsDragged = true;
+ if (AllowDrag & HasFocus & e.Mouse.LeftButton == ButtonState.Pressed) {
+ if (CurrentInterface.DragAndDropOperation == null) {
+ CurrentInterface.DragAndDropOperation = new DragDropEventArgs (this);
+ onStartDrag (this, CurrentInterface.DragAndDropOperation);
+ }
+ }
//bubble event to the top
GraphicObject p = focusParent;
@@ -1582,16 +1593,14 @@ namespace Crow
Debug.WriteLine("MOUSE UP => " + this.ToString());
#endif
- if (IsDragged){
- bool dropOK = false;
- if (CurrentInterface.HoverWidget!=null) {
- if (CurrentInterface.HoverWidget.AllowDrop)
- dropOK = true;
+ if (CurrentInterface.DragAndDropOperation != null){
+ if (CurrentInterface.DragAndDropOperation.DragSource == this) {
+ if (CurrentInterface.DragAndDropOperation.DropTarget != null)
+ onDrop (this, CurrentInterface.DragAndDropOperation);
+ else
+ onEndDrag (this, CurrentInterface.DragAndDropOperation);
+ CurrentInterface.DragAndDropOperation = null;
}
- if (dropOK)
- onDrop (this, null);
- else
- onEndDrag (this, null);
}
//bubble event to the top
@@ -1631,6 +1640,14 @@ namespace Crow
#if DEBUG_FOCUS
Debug.WriteLine("MouseEnter => " + this.ToString());
#endif
+
+ if (CurrentInterface.DragAndDropOperation != null) {
+ if (this.AllowDrop) {
+ if (CurrentInterface.DragAndDropOperation.DragSource != this && CurrentInterface.DragAndDropOperation.DropTarget != this)
+ onDragEnter (this, CurrentInterface.DragAndDropOperation);
+ }
+ }
+
MouseEnter.Raise (this, e);
}
public virtual void onMouseLeave(object sender, MouseMoveEventArgs e)
@@ -1638,6 +1655,10 @@ namespace Crow
#if DEBUG_FOCUS
Debug.WriteLine("MouseLeave => " + this.ToString());
#endif
+ if (CurrentInterface.DragAndDropOperation != null) {
+ if (CurrentInterface.DragAndDropOperation.DropTarget == this)
+ onDragLeave (this, CurrentInterface.DragAndDropOperation);
+ }
MouseLeave.Raise (this, e);
}
#endregion
diff --git a/src/Input/MouseState.cs b/src/Input/MouseState.cs
index 594619ac..f6db21ea 100644
--- a/src/Input/MouseState.cs
+++ b/src/Input/MouseState.cs
@@ -46,6 +46,8 @@ namespace Crow
#endregion
+
+
#region Public Members
/// <summary>
diff --git a/src/Interface.cs b/src/Interface.cs
index e1bd7533..becd37ce 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -206,6 +206,8 @@ namespace Crow
/// </summary>
public static Dictionary<String, Instantiator> Instantiators = new Dictionary<string, Instantiator>();
public List<CrowThread> CrowThreads = new List<CrowThread>();//used to monitor thread finished
+
+ public DragDropEventArgs DragAndDropOperation = null;
#endregion
#region Private Fields
@@ -824,12 +826,11 @@ namespace Crow
MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY);
e.Mouse = Mouse;
- if (ActiveWidget != null) {
+ if (ActiveWidget != null&& DragAndDropOperation == null) {
//TODO, ensure object is still in the graphic tree
//send move evt even if mouse move outside bounds
ActiveWidget.onMouseMove (this, e);
- if (!ActiveWidget.IsDragged)//if active is dragged, process mouse move as it was not visible.
- return true;
+ return true;
}
if (HoverWidget != null) {