Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom handle, resize problem ! (Read 5715 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Custom handle, resize problem !
May 20th, 2011 at 11:45am
Print Post  
I working with custom nodes, and custom handles.

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


The foudn a problem with custom handles.
When i rotate node, cant resize.

If i use some default handles provided work ok, but with custom handles no.

Why this happen?
Have some workaround fro fix this?

Best regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handle, resize problem !
Reply #1 - May 20th, 2011 at 1:40pm
Print Post  
What does your HitTestAdjustmentHandles handler look like?
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handle, resize problem !
Reply #2 - May 21st, 2011 at 9:43am
Print Post  
private void form_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
   {
      var node = e.Item as DiagramNode;
      var size = new Size(
          form.AdjustmentHandlesSize,
          form.AdjustmentHandlesSize);

      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);

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



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


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

         
          var MiddleLeft = new Point(0, node.Bounds.Height / 2 - size.Height / 2);
          var MiddleLeftRect = new Rect(MiddleLeft, size);
          if (MiddleLeftRect.Contains(e.MousePosition - diagOffset))
              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(e.MousePosition - diagOffset))
              e.HitResult = 5;


          var bottomLeft = new Point(0, node.Bounds.Height - size.Height);
          var bottomLeftRect = new Rect(bottomLeft, size);
          if (bottomLeftRect.Contains(e.MousePosition - diagOffset))
              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(e.MousePosition - diagOffset))
              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(e.MousePosition - diagOffset))
              e.HitResult = 2;
      }
   }






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

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));

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handle, resize problem !
Reply #3 - May 23rd, 2011 at 5:48am
Print Post  
Add this code to the front of your handler and then use localPoint when calling Rect.Contains:

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

Point RotatePointAt(Point point, Point pivot, double angle)
{
	Matrix rotation = new Matrix();
	rotation.RotateAt(angle, pivot.X, pivot.Y);
	Point res = rotation.Transform(point);
	return res;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handle, resize problem !
Reply #4 - May 23rd, 2011 at 1:11pm
Print Post  
Really sorry but not understand how this work.
Can rotate correclty what cant do is RESIZE node rotated.
M rotating my nodes in this way:
node.RotationAngle = 90;

I not understand your solution and how apply.
Please can put complete example?
Best regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handle, resize problem !
Reply #5 - May 24th, 2011 at 6:29am
Print Post  
Code
Select All
Point RotatePointAt(Point point, Point pivot, double angle)
{
	Matrix rotation = new Matrix();
	rotation.RotateAt(angle, pivot.X, pivot.Y);
	Point res = rotation.Transform(point);
	return res;
}

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

	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);
		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;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handle, resize problem !
Reply #6 - Sep 6th, 2011 at 5:34pm
Print Post  
Stoyo, after roatte i can resize, but see a new problem.
Only can drag and move the object selecting form the center only.

Why this happen and how can fix this, when object is rotated is very hard move the node, can drag, only can drag form the center.

A simple example for ilustrate thsi stiaution is create a simple large vertical shape, then rotate, and try drag, you cna see can drag and move only if drag the object form the center.

If shape is perfect square, or perfect circle not have any problem to drag selecting te node form any palce and the drag andmove.
Only happen when is a large rectangle shape.

Hoppe can help to me with this.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom handle, resize problem !
Reply #7 - Sep 7th, 2011 at 8:21am
Print Post  
Hi Pablo,

Move the code that calls r.Contains so that it tests with the rotated point:

Code
Select All
Rect r = e.Item.GetBounds();
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;
		return;
	}

	localPoint = localPoint - diagOffset;
	... 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Custom handle, resize problem !
Reply #8 - Sep 7th, 2011 at 12:17pm
Print Post  
Thankyiu fixed now!
Return comented.

Code
Select All
Rect r = e.Item.GetBounds();
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;
//return;
}

localPoint = localPoint - diagOffset;
...


 

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint