The MindFusion Forums
https://mindfusion.eu/Forum/YaBB.pl
Flow Diagramming Components >> WPF >> Some troubles migrating form v3.3 to 3.5
https://mindfusion.eu/Forum/YaBB.pl?num=1538958403

Message started by PDM on Oct 8th, 2018 at 1:26am

Title: Some troubles migrating form v3.3 to 3.5
Post by PDM on Oct 8th, 2018 at 1:26am
Hello!!
Im back, hoppe Stoyo and Slavcho remember to me lol :)
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?




Title: Re: Some troubles migrating form v3.3 to 3.5
Post by Slavcho on Oct 8th, 2018 at 10:29am
Pablo, that you? :P Adjustment handles are now represented using classes and enums instead of integer values. Try this for the StartDrawCommon override -


Code:
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:
e.HitResult = NodeAdjustmentHandle.Move;
//instead of e.HitResult = 8


Try replacing the i < 8 loop with this one -

Code:
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

Title: Re: Some troubles migrating form v3.3 to 3.5
Post by PDM on Oct 8th, 2018 at 12:00pm
Yes its me, and I can prove, Im lost with the loop part and after.  :D


Code:
  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 :)

Title: Re: Some troubles migrating form v3.3 to 3.5
Post by Slavcho on Oct 9th, 2018 at 11:47am
So change your methods to


Code:
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:
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

Title: Re: Some troubles migrating form v3.3 to 3.5
Post by PDM on Jan 19th, 2019 at 3:27am
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.

Title: Re: Some troubles migrating form v3.3 to 3.5
Post by PDM on Jan 23rd, 2019 at 4:49am
Please need some help with  this issues.

Title: Re: Some troubles migrating form v3.3 to 3.5
Post by Slavcho on Jan 23rd, 2019 at 12:21pm
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:
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

The MindFusion Forums » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.