- Welcome, Guest. Please Login or Register
MindFusion  
  Version 2 of our Xamarin Calendar component adds Resource view and support for Universal Windows Platform. Now beta testing spreadsheet component for Java Swing.  
  HomeHelpSearchLoginRegister   
     
     
   
 
Pages: 1 2  Send Topic Print  
move selected node using arrow keys
Read 1444 times

Slavcho   Offline
God Member
*****
Posts: 979
Gender: male
tech.support


   
     
 
Re: move selected node using arrow keys
Reply #15 - Apr 20th, 2017 at 11:11am
 
Modify the FindOverlaps method to take bounds argument -

Code:
List<DiagramNode> FindOverlaps(
	DiagramNode modifiedNode, Rect bounds, double minDist)
{
	bounds.Inflate(minDist - 1, minDist - 1);

	var overlaps = new List<DiagramNode>();
	.... 



Older places where you call it such as OnNodeModifying, also pass node.Bounds like FindOverlaps(e.Node, e.Node.Bounds, 5). In arrow-key movements methods add an if statement that checks whether new rect leads to overlaps before assigning it -

Code:
var rect = node.Bounds;
rect.X = rect.Left - 10;
if (FindOverlaps(node, rect, 5).Count == 0)
    node.Move(node.Bounds.Left - 10, node.Bounds.Top); 

 
 
 
IP Logged    
 
     

kelum   Offline
Full Member
***
Posts: 100
I Love MindFusion!


   
     
 
Re: move selected node using arrow keys
Reply #16 - Apr 20th, 2017 at 6:47pm
 
so as you mentioned I changed code

Code:
        List<DiagramNode> FindOverlaps(DiagramNode modifiedNode, Rect bounds, double minDist)
        {
            
            bounds.Inflate(minDist - 1, minDist - 1);

            var overlaps = new List<DiagramNode>();
            foreach (var node in flowchart.Nodes)
            {
                if (modifiedNode == node)
                    continue;
                if (bounds.IntersectsWith(node.Bounds))
                    overlaps.Add(node);
            }
            return overlaps;
        } 



and all the arrow key operations changed as follows

Code:
            // left arrow handler
            flowchart.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateLeft, (sender, args) =>
                {
                    foreach (var node in flowchart.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left - 10;

                        if (node != null && node.Bounds.Left - 10 >= flowchart.Bounds.Left && (FindOverlaps(node, rect, 5).Count == 0))
                        {
                            node.Move(node.Bounds.Left - 10, node.Bounds.Top);
                        }

                    }
                }));

            // right arrow handler
            flowchart.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateRight, (sender, args) =>
                {                  
                    foreach (var node in flowchart.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left - 10;

                        if (node != null && node.Bounds.Right + 10 <= flowchart.Bounds.Right && (FindOverlaps(node, rect, 5).Count == 0))
                        {
                            node.Move(node.Bounds.Left + 10, node.Bounds.Top);
                        }
                    }
                }));

            // up arrow handler
            flowchart.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateUp, (sender, args) =>
                {
                    foreach (var node in flowchart.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left - 10;

                        if (node != null && node.Bounds.Top - 10 >= flowchart.Bounds.Top && (FindOverlaps(node, rect, 5).Count == 0))
                        {
                            node.Move(node.Bounds.Left, node.Bounds.Top - 10);
                        }
                    }


                }));

            // down arrow handler
            flowchart.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateDown, (sender, args) =>
                {
                    foreach (var node in flowchart.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left - 10;

                        if (node != null && node.Bounds.Bottom + 10 <= flowchart.Bounds.Bottom && (FindOverlaps(node, rect, 5).Count == 0))
                        {
                            node.Move(node.Bounds.Left, node.Bounds.Top + 10);
                        }
                    }
                })); 



this is compiling without errors, but in here once move one node over other node (overlap) then its locking each other, by selecting one of that overlapped node I can't move node away using arrow keys
 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 979
Gender: male
tech.support


   
     
 
Re: move selected node using arrow keys
Reply #17 - Apr 21st, 2017 at 6:40am
 
rect.X = rect.Left - 10 is only valid when you move to the left, you'll need to alter this expression for other directions.

If you allow nodes to overlap at any point, than offsetting by just 10 pixels might not find a non-overlapping position so it won't accept the movement. You might want to change the logic so that it always accepts movement if the moved node currently overlaps with another one.
 
 
 
IP Logged    
 
     

kelum   Offline
Full Member
***
Posts: 100
I Love MindFusion!


   
     
 
Re: move selected node using arrow keys
Reply #18 - Apr 21st, 2017 at 10:04am
 
so as you mentioned I'updated code,

then Left Arrow Key and Up Arrow Key started to working properly (which is i can close up to 5 pixels, then those are not overlap)

Code:
            // left arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateLeft, (sender, args) =>
                {                   
                    foreach (var node in diagram.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left - 10;

                        if (node != null && node.Bounds.Left - 10 >= diagram.Bounds.Left && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left - 10, node.Bounds.Top);
                        }

                    }
                }));

		   // up arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateUp, (sender, args) =>
                {                  

                    foreach (var node in diagram.Selection.Nodes)
                    {

                        var rect = node.Bounds;
                        rect.Y = rect.Top - 10;

                        if (node != null && node.Bounds.Top - 10 >= diagram.Bounds.Top && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left, node.Bounds.Top - 10);
                        }
                    }


                })); 



Left Arrow Key Operation with proper distance
...

Up Arrow Key Operation with proper distance
...

but Right arrow key and Bottom Arrow key not working like Left Arrow Key and Up Arrow Key , which is can't close up to 5 pixels they are locating with different spaces
Code:
            // right arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateRight, (sender, args) =>
                {
                  
                    foreach (var node in diagram.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Right + 10;

                        if (node != null && node.Bounds.Right + 10 <= diagram.Bounds.Right && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left + 10, node.Bounds.Top);
                        }
                    }
                }));



            // down arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateDown, (sender, args) =>
                {
                   
                    foreach (var node in diagram.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.Y = rect.Bottom + 10;

                        if (node != null && node.Bounds.Bottom + 10 <= diagram.Bounds.Bottom && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left, node.Bounds.Top + 10);
                        }
                    }
                }));  



Bottom Arrow Key Operation with wide distance

...

Right Arrow Key Operation with wide distance

...

How can I reduce more spaces in right and down arrow handlers like up and left handlers
 
 
 
IP Logged    
 
     

kelum   Offline
Full Member
***
Posts: 100
I Love MindFusion!


   
     
 
Re: move selected node using arrow keys
Reply #19 - Apr 21st, 2017 at 10:17am
 
Anyway I found the solution like this,


Code:
            // left arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateLeft, (sender, args) =>
                {
                    foreach (var node in diagram.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left - 10;

                        if (node != null && node.Bounds.Left - 10 >= diagram.Bounds.Left && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left - 10, node.Bounds.Top);
                        }

                    }
                }));



            // up arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateUp, (sender, args) =>
                {

                    foreach (var node in diagram.Selection.Nodes)
                    {

                        var rect = node.Bounds;
                        rect.Y = rect.Top - 10;

                        if (node != null && node.Bounds.Top - 10 >= diagram.Bounds.Top && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left, node.Bounds.Top - 10);
                        }
                    }


                }));

		    // right arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateRight, (sender, args) =>
                {

                    foreach (var node in diagram.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.X = rect.Left + 10;

                        if (node != null && node.Bounds.Right + 10 <= diagram.Bounds.Right && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left + 10, node.Bounds.Top);
                        }
                    }
                }));

            // down arrow handler
            diagram.CommandBindings.Add(
                new CommandBinding(Diagram.NavigateDown, (sender, args) =>
                {

                    foreach (var node in diagram.Selection.Nodes)
                    {
                        var rect = node.Bounds;
                        rect.Y = rect.Top + 10;

                        if (node != null && node.Bounds.Bottom + 10 <= diagram.Bounds.Bottom && (FindOverlaps(node, rect, 2).Count == 0))
                        {
                            node.Move(node.Bounds.Left, node.Bounds.Top + 10);
                        }
                    }
                })); 



let me know if you have suggestion
 
 
 
IP Logged    
 
     

Slavcho   Offline
God Member
*****
Posts: 979
Gender: male
tech.support


   
     
 
Re: move selected node using arrow keys
Reply #20 - Apr 21st, 2017 at 11:05am
 
It should look like this as you've found, otherwise it didn't match the positions where you are moving the node on next line -

// right
rect.X = rect.Left + 10;

// down
rect.Y = rect.Top + 10;
 
 
 
IP Logged    
 
     
Pages: 1 2  Send Topic Print