Page Index Toggle Pages: [1] 2  Send TopicPrint
Very Hot Topic (More than 25 Replies) Custom handles issue (Read 12224 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Custom handles issue
Jul 8th, 2014 at 5:01pm
Print Post  
Hello
I woring with custom handles.
I found2 troubles.

1- when i select multiple circular shapes, the 4 handles of corners not resize, work as move.
Only gandlers of the middle act as resize.
Something i missing on the code?

2- Kike can observ the handles are 20x20 pixels.
I note handler act like if point of control is the top border near to bounds of node.
If i catch the handler in any point position not near to border, when i resize is see a Little jumps in the size of the objject.
In this way resize object with presicion is a big problema.

I mniss something in the coe or is related to mindfusion diagram component?

I note this also happen with non custom handlers.
For reproduce this, just use this handlers and try resize any node selectinng the handler from near to internal corner of handler.

How can correct this?




Code
Select All
 private void form_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
   {
       var node = e.Item as DiagramNode;
       var size2 = new Size(form.AdjustmentHandlesSize, form.AdjustmentHandlesSize);
       var size = new Size( 20,20);

       Rect r = e.Item.GetBounds();

       if (r.Contains(e.MousePosition))

           e.HitResult = 8;



       if (node != null)
       {
           var location = node.Bounds.Location;
           var diagOffset = new Vector(location.X, location.Y);

           double rotationAngle = node.RotationAngle;
           Point localPoint = RotatePointAt(e.MousePosition, node.GetCenter(), -rotationAngle);

           if (r.Contains(localPoint))
           {
               e.HitResult = 8;

           }




           localPoint = localPoint - diagOffset;



           var TopLeft = new Point(0, 0);
           var TopLeftRect = new Rect(TopLeft, size);
           if (TopLeftRect.Contains(localPoint))
               e.HitResult = 0;

           var TopMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2, 0);
           var TopMiddleRect = new Rect(TopMiddle, size);
           if (TopMiddleRect.Contains(localPoint))
               e.HitResult = 4;

           var TopRight = new Point(node.Bounds.Width - size.Width, 0);
           var TopRightRect = new Rect(TopRight, size);
           if (TopRightRect.Contains(localPoint))
               e.HitResult = 1;

           var MiddleLeft = new Point(0, node.Bounds.Height / 2 - size.Height / 2);
           var MiddleLeftRect = new Rect(MiddleLeft, size);
           if (MiddleLeftRect.Contains(localPoint))
               e.HitResult = 7;

           var MiddleRight = new Point(node.Bounds.Width - size.Width, node.Bounds.Height / 2 - size.Height / 2);
           var MiddleRightRect = new Rect(MiddleRight, size);
           if (MiddleRightRect.Contains(localPoint))
               e.HitResult = 5;

           var bottomLeft = new Point(0, node.Bounds.Height - size.Height);
           var bottomLeftRect = new Rect(bottomLeft, size);
           if (bottomLeftRect.Contains(localPoint))
               e.HitResult = 3;

           var bottomMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2, node.Bounds.Height - size.Height);
           var bottomMiddleRect = new Rect(bottomMiddle, size);
           if (bottomMiddleRect.Contains(localPoint))
               e.HitResult = 6;

           var bottomRight = new Point(node.Bounds.Width - size.Width, node.Bounds.Height - size.Height);
           var bottomRightRect = new Rect(bottomRight, size);
           if (bottomRightRect.Contains(localPoint))
               e.HitResult = 2;
       }
   }






void form_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{
	var node = e.Item as DiagramNode;
	var size2 = new Size(form.AdjustmentHandlesSize,form.AdjustmentHandlesSize);
    var size = new Size(20, 20);


	if (node != null)
	{

           var TopLeft = new Point(0, 0);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(TopLeft, size));


           var TopMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2, 0);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(TopMiddle, size));

           var TopRight = new Point(node.Bounds.Width  - size.Width , 0);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(TopRight, size));


           var MiddleTop = new Point(0, node.Bounds.Height /2 - size.Height /2);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(MiddleTop, size));

           var MiddleBott = new Point(node.Bounds.Width - size.Width, node.Bounds.Height / 2 - size.Height / 2);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(MiddleBott, size));

           var bottomLeft = new Point(0, node.Bounds.Height - size.Height);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(bottomLeft, size));


		    var bottomMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2,	node.Bounds.Height - size.Height);
            e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(bottomMiddle, size));

            var bottomRight = new Point(node.Bounds.Width  - size.Width ,node.Bounds.Height - size.Height);
            e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.PatternBrush, form.SelectedItemHandlesStyle.DashPen, new Rect(bottomRight, size));


	}
}




 





« Last Edit: Jul 8th, 2014 at 9:37pm by PDM. »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #1 - Jul 9th, 2014 at 10:44am
Print Post  
1. This happens with standard handles too. Override the behavior class you are using to work around it, e.g.:

Code
Select All
diagram.CustomBehavior = new CustomBehavior(diagram);

class CustomBehavior : LinkShapesBehavior
{
	protected internal CustomBehavior(Diagram diagram) : base(diagram)
	{
	}

	protected override InteractionState StartDrawCommon(Point point, MouseButton button)
	{
		if (Diagram.Selection.Nodes.Count > 1)
		{
			foreach (var node in Diagram.Selection.Nodes)
			{
				int handle = -1;
				if (node.HitTestHandle(point, ref handle))
					return new InteractionState(Diagram.Selection, handle, Action.Modify);
			}
		}
		return base.StartDrawCommon(point, button);
	}

	public override CursorHint SetMouseCursor(Point point, out bool startInteraction)
	{
		if (Diagram.Selection.Nodes.Count > 1)
		{
			foreach (var node in Diagram.Selection.Nodes)
			{
				int handle = -1;
				if (node.HitTestHandle(point, ref handle))
				{
					startInteraction = true;
					return SetModfCursor(point, handle, false, false);
				}
			}
		}
		return base.SetMouseCursor(point, out startInteraction);
	}
} 



2. This is by design to align the node borders exactly to the position of mouse cursor, which should make it easier to resize than if the borders follow the cursor at some distance.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handles issue
Reply #2 - Jul 9th, 2014 at 7:56pm
Print Post  
Thankyou for your repply.
Always apreciated the great support.

Honesty no understand how use the code: Undecided


I have some errors, by example


return base.StartDrawCommon(point, button);

Error      14      'MindFusion.Diagramming.Wpf.Behaviors.LinkShapesBehavior' does not contain a definition for 'StartDrawCommon'      


node.HitTestHandle

Error      11      'object' does not contain a definition for 'HitTestHandle' and no extension method 'HitTestHandle' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?

Anyway after fix this, no idea how use.
Please can provide complete working example?



« Last Edit: Jul 9th, 2014 at 9:01pm by PDM. »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #3 - Jul 10th, 2014 at 5:47am
Print Post  
StartDrawCommon is available since version 3 of the control, which is a couple of years old now. See if you don't have it on your account at http://clientsarea.eu if you had active maintenance at that time.

Quote:
'object' does not contain a definition for 'HitTestHandle'


In older versions the Nodes collection wasn't implementing IEnumerable<DiagramNode> so foreach (var node in selection.Nodes) cannot infer the type and the node variable has an object type. Use foreach (DiagramNode node in selection.Nodes) instead.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handles issue
Reply #4 - Jul 10th, 2014 at 6:00am
Print Post  
How much cost update?

The versión available is 2.8

Some special price for update?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #5 - Jul 10th, 2014 at 6:12am
Print Post  
It depends on what license you have. You can ask for upgrade price at sales@mindfusion.eu.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handles issue
Reply #6 - Jul 14th, 2014 at 11:43pm
Print Post  
Ok, all ready ia back to the future with versión 3.1 : )


In the attach you can find a simple example code where i can expose some issues.
Run the example, click on the form screen that make shape node apear with custom handlers.

1- when drag mouse of hendle the object jump to position of mouse.
Can please correct the code with your solution.

2- resize the node, you can see is very frequent when you finish size change some times x or y size + - 1 pixel.

I think is related to my custom handler but no, happen with all handlers.
For check this drag your mouse over form, that créate a default object with non custom handler.
You can see the same behaviour in size.


3 - Edit code enable now

form.AlignToGrid = true;
form.ShowGrid = true;
form.GridStyle = GridStyle.Lines;

Click on form that create shape node with my custom handles, then press control + c, copy then paste control +v

Now you have 2 nodes, align the nodes to grid.

Now, pres control, click on both nodes for select, and press control +c for copy, and contol +v for paste. Without unselect, try align that to new nodes created from copy. Both selected at same time, you can see is imposible align to grid, you have to select object one by one for realign.
Why?

I test with hjandlers provided by mindfusion, the default, and same happen.

I really apreciated if can return with a complete code with the fix.
Thk Wink



  

FormEditor.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #7 - Jul 15th, 2014 at 8:58am
Print Post  
Quote:
when drag mouse of hendle the object jump to position of mouse. Can please correct the code with your solution.


Aligning resized node borders to mouse pointer is by design. If you prefer keeping the original distance between border and pointer from when you start resizing, you could add the difference when calling base methods in a custom behavior class as in attached file.

I hope that helps,
Stoyan
« Last Edit: Jul 15th, 2014 at 11:08am by Stoyo »  

Window1_xaml.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #8 - Jul 15th, 2014 at 9:58am
Print Post  
Quote:
2- resize the node, you can see is very frequent when you finish size change some times x or y size + - 1 pixel.


NodeModifying is validation event raised before the node size is updated, so you are showing values from previous mouse move event. From what I can see the node size does not actually change from last move when you release the mouse button, so I think that's false alarm.
« Last Edit: Jul 15th, 2014 at 11:07am by Stoyo »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #9 - Jul 15th, 2014 at 10:09am
Print Post  
Quote:
Now, pres control, click on both nodes for select, and press control +c for copy, and contol +v for paste. Without unselect, try align that to new nodes created from copy. Both selected at same time, you can see is imposible align to grid, you have to select object one by one for realign.


Moving multiple items only offsets them by grid size, so it's relying that nodes have already being aligned to the grid. You could create nodes at grid points using AlignPointToGrid method, and also pass offsets divisible by grid size to PasteFromClipboard to ensure they remain aligned after pasting.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handles issue
Reply #10 - Jul 16th, 2014 at 8:52am
Print Post  
Thankyou stoyo
Handlers work now how i wnat but i have few troubles.

Before aply this code, for edit my diagrams i use form.Behavior = Behavior.Modify;

For stop edition mode I use: form.Behavior = Behavior.donothing;


With the solution you provide to me, I cant use more Behavior.Modify and i replace for form.CustomBehavior = new MyBehavior(form);


The problem I found is using form.CustomBehavior = new MyBehavior(form); when i drag over the diagram, that draw now a default node, instead draw a selection tool.

Really sorry for annoying to you with tonz of questions. How can mantain my older behaviour?
I no wnat that node be draw when drag mouse over the diagram, the selection tool shoudl appear.

Some code snipet please or guide to do this?


A second trouble i found, is after resize node, if i try move the node, the node jump few pixels. ; (
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handles issue
Reply #11 - Jul 16th, 2014 at 9:42am
Print Post  
About the resize + - pixel issue.
I doing this now.
The same happen, I asume theOnNodeModified is event sent after modification of node finish.
Is that right?
If yes i continue with same trouble.Why?

Code
Select All
    private void form_NodeModifying(object sender, NodeValidationEventArgs e)
        {
              var nodew = Convert.ToInt16(e.Node.RenderSize.Width);
              var nodeh = Convert.ToInt16(e.Node.RenderSize.Height);
              sizeobject.Text = nodew.ToString() + "x" + nodeh.ToString();

        }

void OnNodeModified(object sender, NodeEventArgs e)
  {
      var nodew = Convert.ToInt16(e.Node.RenderSize.Width);
      var nodeh = Convert.ToInt16(e.Node.RenderSize.Height);
      sizeobject.Text = nodew.ToString() + "x" + nodeh.ToString();

  }

 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #12 - Jul 16th, 2014 at 10:36am
Print Post  
Quote:
Before aply this code, for edit my diagrams i use form.Behavior = Behavior.Modify;


Derive MyBehavior from the ModifyBehavior class instead of LinkShapesBehavior.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handles issue
Reply #13 - Jul 16th, 2014 at 10:40am
Print Post  
Quote:
The same happen, I asume theOnNodeModified is event sent after modification of node finish. Is that right? If yes i continue with same trouble.Why?


Problem is you are seeing older value when printing from NodeModifying. The order in which code is executed is:

- MoveMove raised
- NodeModifying raised
- new node size set

So when you show the size from NodeModifying, you are seeing the one set from previous MouseMove, not the one that will be set from current one and shown on screen.

If you want to show current size for node being modified, try doing that from the custom Behavior class again, after calling base.MouseMove.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handles issue
Reply #14 - Jul 16th, 2014 at 10:53am
Print Post  
Stoyo wrote on Jul 16th, 2014 at 10:36am:
Quote:
Before aply this code, for edit my diagrams i use form.Behavior = Behavior.Modify;


Derive MyBehavior from the ModifyBehavior class instead of LinkShapesBehavior.

I hope that helps,
Stoyan



Yep this help, thank you very easy, what about node Jump after resize and try move the node?
If i move the ndoe work ok, but when rsize the node, some times when inmediatly try move the node, the ndoe jump of position few pixels.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint