Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Some troubles migrating form v3.3 to 3.5 (Read 2734 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Some troubles migrating form v3.3 to 3.5
Oct 8th, 2018 at 12:26am
Print Post  
Hello!!
Im back, hoppe Stoyo and Slavcho remember to me lol Smiley
Here some troubles:

protected override InteractionState StartDrawCommon(Point point, MindFusion.Diagramming.Wpf.MouseButton button)
     {
           var state = base.StartDrawCommon(point, button);
Resizing = state != null &&
state.Action == MindFusion.Diagramming.Wpf.Action.Modify && state.AdjustmentHandle < 8;
           return state;
     }

Operator '<' cannot be applied to operands of type 'AdjustmentHandle' and 'int'


private void form_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{




var node = e.Item as DiagramNode;
var size = new Size(20, 20);

Rect r = e.Item.GetBounds();
if (r.Contains(e.MousePosition))
e.HitResult = 8; //error here




if (node != null)
{
var x = e.MousePosition.X;
var y = e.MousePosition.Y;
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; //error here

localPoint = localPoint - diagOffset;
for (int i = 0; i < 8; i++)
{
var point = CustomHandlePosition(i, node.Bounds, size);
var rect = new Rect(point, size);
if (rect.Contains(localPoint))
{
e.HitResult = i; //error here

var std = StdHandlePosition(i, node.Bounds);
MyBehavior.MouseDX = std.X - localPoint.X;
MyBehavior.MouseDY = std.Y - localPoint.Y;

break;
}
}
}
}

Cannot implicitly convert type 'int' to 'MindFusion.Diagramming.Wpf.AdjustmentHandle'      


I testing with the trial version.
How much cost update?



  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Some troubles migrating form v3.3 to 3.5
Reply #1 - Oct 8th, 2018 at 9:29am
Print Post  
Pablo, that you? Tongue Adjustment handles are now represented using classes and enums instead of integer values. Try this for the StartDrawCommon override -

Code
Select All
protected override InteractionState StartDrawCommon(Point point, MouseButton button)
{
	var state = base.StartDrawCommon(point, button);
	Resizing =
		state != null && state.Action == Action.Modify &&
		!state.AdjustmentHandle.IsMoveHandle();
	return state;
} 



Code
Select All
e.HitResult = NodeAdjustmentHandle.Move;
//instead of e.HitResult = 8
 



Try replacing the i < 8 loop with this one -
Code
Select All
foreach (NodeHandleType handleType in Enum.GetValues(typeof(NodeHandleType)))

//and then

e.HitResult = new NodeAdjustmentHandle(handleType);
 



Also replace parameters of your CustomHandlePosition and StdHandlePosition functions with NodeHandleType instead of int.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Some troubles migrating form v3.3 to 3.5
Reply #2 - Oct 8th, 2018 at 11:00am
Print Post  
Yes its me, and I can prove, Im lost with the loop part and after.  Cheesy

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

       Rect r = e.Item.GetBounds();
       if (r.Contains(e.MousePosition))
                e.HitResult = NodeAdjustmentHandle.Move;

            if (node != null)
       {
           var x = e.MousePosition.X;
           var y = e.MousePosition.Y;
           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 = NodeAdjustmentHandle.Move;

                localPoint = localPoint - diagOffset;
           for (int i = 0; i < 8; i++)
           {
               var point = CustomHandlePosition(i, node.Bounds, size);
               var rect = new Rect(point, size);
               if (rect.Contains(localPoint))
               {
                   e.HitResult = i;

                   var std = StdHandlePosition(i, node.Bounds);
                   MyBehavior.MouseDX = std.X - localPoint.X;
                   MyBehavior.MouseDY = std.Y - localPoint.Y;

                   break;
               }
           }
       }
   }

   Point CustomHandlePosition(int handleId, Rect nodeBounds, Size size)
   {
       if (handleId == 0)
           return new Point(0, 0);

       if (handleId == 4)
           return new Point(nodeBounds.Width / 2 - size.Width / 2, 0);

       if (handleId == 1)
           return new Point(nodeBounds.Width - size.Width, 0);

       if (handleId == 7)
           return new Point(0, nodeBounds.Height / 2 - size.Height / 2);

       if (handleId == 5)
           return new Point(nodeBounds.Width - size.Width, nodeBounds.Height / 2 - size.Height / 2);

       if (handleId == 3)
           return new Point(0, nodeBounds.Height - size.Height);

       if (handleId == 6)
           return new Point(nodeBounds.Width / 2 - size.Width / 2, nodeBounds.Height - size.Height);

       if (handleId == 2)
           return new Point(nodeBounds.Width - size.Width, nodeBounds.Height - size.Height);

       return new Point();
   }

   Point StdHandlePosition(int handleId, Rect nodeBounds)
   {
       if (handleId == 0)
           return new Point(0, 0);

       if (handleId == 4)
           return new Point(nodeBounds.Width / 2, 0);

       if (handleId == 1)
           return new Point(nodeBounds.Width, 0);

       if (handleId == 7)
           return new Point(0, nodeBounds.Height / 2);

       if (handleId == 5)
           return new Point(nodeBounds.Width, nodeBounds.Height / 2);

       if (handleId == 3)
           return new Point(0, nodeBounds.Height);

       if (handleId == 6)
           return new Point(nodeBounds.Width / 2, nodeBounds.Height);

       if (handleId == 2)
           return new Point(nodeBounds.Width, nodeBounds.Height);

       return new Point();
   }


   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(handlersize, handlersize);


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


       }
   }

   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 sent a private message later Smiley
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Some troubles migrating form v3.3 to 3.5
Reply #3 - Oct 9th, 2018 at 10:47am
Print Post  
So change your methods to

Code
Select All
Point CustomHandlePosition(NodeHandleType handleId, Rect nodeBounds, Size size)
{
	if (handleId == NodeHandleType.ResizeTopLeft)
		return new Point(0, 0);

	if (handleId == NodeHandleType.ResizeTopCenter)
		return new Point(nodeBounds.Width / 2 - size.Width / 2, 0);

	if (handleId == NodeHandleType.ResizeTopRight)
		return new Point(nodeBounds.Width - size.Width, 0);

	if (handleId == NodeHandleType.ResizeMiddleLeft)
		return new Point(0, nodeBounds.Height / 2 - size.Height / 2);

	if (handleId == NodeHandleType.ResizeMiddleRight)
		return new Point(nodeBounds.Width - size.Width, nodeBounds.Height / 2 - size.Height / 2);

	if (handleId == NodeHandleType.ResizeBottomLeft)
		return new Point(0, nodeBounds.Height - size.Height);

	if (handleId == NodeHandleType.ResizeBottomCenter)
		return new Point(nodeBounds.Width / 2 - size.Width / 2, nodeBounds.Height - size.Height);

	if (handleId == NodeHandleType.ResizeBottomRight)
		return new Point(nodeBounds.Width - size.Width, nodeBounds.Height - size.Height);

	return new Point();
}

Point StdHandlePosition(NodeHandleType handleId, Rect nodeBounds)
{
	if (handleId == NodeHandleType.ResizeTopLeft)
		return new Point(0, 0);

	if (handleId == NodeHandleType.ResizeTopCenter)
		return new Point(nodeBounds.Width / 2, 0);

	if (handleId == NodeHandleType.ResizeTopRight)
		return new Point(nodeBounds.Width, 0);

	if (handleId == NodeHandleType.ResizeMiddleLeft)
		return new Point(0, nodeBounds.Height / 2);

	if (handleId == NodeHandleType.ResizeMiddleRight)
		return new Point(nodeBounds.Width, nodeBounds.Height / 2);

	if (handleId == NodeHandleType.ResizeBottomLeft)
		return new Point(0, nodeBounds.Height);

	if (handleId == NodeHandleType.ResizeBottomCenter)
		return new Point(nodeBounds.Width / 2, nodeBounds.Height);

	if (handleId == NodeHandleType.ResizeBottomRight)
		return new Point(nodeBounds.Width, nodeBounds.Height);

	return new Point();
} 



and the loop becomes

Code
Select All
foreach (NodeHandleType handleType in Enum.GetValues(typeof(NodeHandleType)))
{
	var point = CustomHandlePosition(handleType, node.Bounds, size);
	var rect = new Rect(point, size);
	if (rect.Contains(localPoint))
	{
		e.HitResult = new NodeAdjustmentHandle(handleType);

		var std = StdHandlePosition(handleType, node.Bounds);
		MyBehavior.MouseDX = std.X - localPoint.X;
		MyBehavior.MouseDY = std.Y - localPoint.Y;

		break;
	}
} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Some troubles migrating form v3.3 to 3.5
Reply #4 - Jan 19th, 2019 at 3:27am
Print Post  
OK, thanks finally working.
But there is 2 troubles:

1: If I rotate the node, example 90 degrees, when try resize....the node do rare jumps constraining a little bit in size. This is a older bug I have and never be able to solve.

2:  This not happen before, and start with this change.
If I select multiple objects, before this change I can resize all selected nodes.
For sure I can do now, but the mouse pointer instead to show resize pointer when resize all selected nodes, show cross move pointer. Not  a big issue, just is a little ugly.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Some troubles migrating form v3.3 to 3.5
Reply #5 - Jan 23rd, 2019 at 4:49am
Print Post  
Please need some help with  this issues.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Some troubles migrating form v3.3 to 3.5
Reply #6 - Jan 23rd, 2019 at 12:21pm
Print Post  
I can't see any problems while resizing rotated node, please attach a test project reproducing that.

Add this to your behavior class to show resize cursors -

Code
Select All
public override CursorHint SetMouseCursor(Point point, out bool startInteraction)
{
    if (Diagram.AllowMultipleResize)
    {
        AdjustmentHandle handle = Diagram.Selection.HitTestHandle(point);
        if (handle != null)
        {
            startInteraction = true;
            return SetModfCursor(point, handle, true, false);
        }
    }
    return base.SetMouseCursor(point, out startInteraction);
} 



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