Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom DragEvent (Read 5029 times)
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Custom DragEvent
Oct 8th, 2013 at 7:31am
Print Post  
Hi There,

At the moment I'm working on DragPreview thingy. See example below.



Basically i have a NodeListView on the left from where i want to drag the nodes on the diagramfield(Which works). While I'm doing this i want to get a preview of the node before i drop it on the field. Comparable with function ModificationEffect.MoveShades does when i move a node in the diagram only.

What I've tried so far is in the example code below.

Code
Select All
   protected override void OnGiveFeedback(GiveFeedbackEventArgs e)
        {
            base.OnGiveFeedback(e);

            if (e.Effects.HasFlag(DragDropEffects.Copy))
            {
                Mouse.SetCursor(Cursors.Wait);
            }
            else if (e.Effects.HasFlag(DragDropEffects.Move))
            {
                Mouse.SetCursor(Cursors.Cross);
            }
            else
            {
                Mouse.SetCursor(Cursors.Hand);
            }
        } 



I tried overriding several GiveFeedbackEvents, dragevents and mouseevents in my NodeListView class. To see if it was working i kept the logic simple, just for testing purposes, hence the cursors.wait setting, i know this doesn't give me a preview. But it didnt give me a wait icon or cross icon either.

Could anyone give me any insight?

Thanks in advance.

Greets,

Sander
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom DragEvent
Reply #1 - Oct 8th, 2013 at 9:08am
Print Post  
Hi,

Try also setting these properties:

Code
Select All
e.UseDefaultCursors = false;
e.Handled = true; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Custom DragEvent
Reply #2 - Oct 8th, 2013 at 9:29am
Print Post  

Hi,

Thanks, that worked somewhat.

Does Mindfusion have a standard property that gives me the possibility to have a preview of the node under my cursor?

Greets,

Sander
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom DragEvent
Reply #3 - Oct 8th, 2013 at 10:07am
Print Post  
Hi,

There's no such property. You could create an actual node from DragEnter and update its position from DragOver event handlers.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Custom DragEvent
Reply #4 - Oct 8th, 2013 at 10:44am
Print Post  
Hmmm.

Do you happen to have an code-example?

Greets,

Sander
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Custom DragEvent
Reply #5 - Oct 8th, 2013 at 10:50am
Print Post  
Something like this perhaps?

Code
Select All
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        // Package the data.
        DataObject data = new DataObject();
        data.SetData(DataFormats.StringFormat, circleUI.Fill.ToString());
        data.SetData("Double", circleUI.Height);
        data.SetData("Object", this);

        // Inititate the drag-and-drop operation.
        DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move);
    } 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom DragEvent
Reply #6 - Oct 8th, 2013 at 11:09am
Print Post  
Nothing like that, more like this:

Code
Select All
DiagramNode dragIndicator = null;

private void OnDiagramDragEnter(object sender, DragEventArgs e)
{
	if (dragIndicator == null &&
		e.Data.GetDataPresent(typeof(DraggedNode)))
	{
		var data = (DraggedNode)e.Data.GetData(typeof(DraggedNode));
		var position = e.GetPosition(diagram.DocumentPlane);
		dragIndicator = (DiagramNode)data.Node.Clone(false);
		dragIndicator.Move(position.X, position.Y);
		dragIndicator.Opacity = 0.5;
		diagram.Nodes.Add(dragIndicator);
		e.Effects = DragDropEffects.Copy;
		e.Handled = true;
	}
}

void OnDiagramDragOver(object sender, DragEventArgs e)
{
	if (dragIndicator != null)
	{
		var position = e.GetPosition(diagram.DocumentPlane);
		dragIndicator.Move(position.X, position.Y);
		e.Effects = DragDropEffects.Copy;
		e.Handled = true;
	}
}

private void OnNodeCreated(object sender, NodeEventArgs e)
{
	// NodeListView creates an instance automatically, so remove the indicator
	if (dragIndicator != null)
	{
		diagram.Nodes.Remove(dragIndicator);
		dragIndicator = null;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Waterfiets
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Sep 27th, 2013
Re: Custom DragEvent
Reply #7 - Oct 8th, 2013 at 11:52am
Print Post  
Stoyan you're a Genius, it works!. If you'd be living in The Netherlands i would have given you a chocolate bar.  Grin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom DragEvent
Reply #8 - Oct 8th, 2013 at 12:13pm
Print Post  
You can always post it to address from http://mindfusion.eu/contacts.html Cool
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint