Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic The handle-style and the handle-size of these ShapeNodes (Read 2301 times)
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
The handle-style and the handle-size of these ShapeNodes
Sep 21st, 2020 at 3:00am
Print Post  
Hi, there. Smiley

At present, my program realizes that hold down Ctrl and double click the left mouse button to generate a ShapeNode with a green frame, and hold down Ctrl while holding down the left mouse button, and drag the diagram to generate a ShapeNode with a white frame. But there is a strange phenomenon. After I select the ShapeNode with the green border, the black handle that appears is very large, completely covering the entire range of the ShapeNode, as shown in the screenshot 9_21_8.
1. How to solve it?
2. And because the black-filled handle style will obscure the image of ShapeNode underneath. How can I change the handle style of ShapeNode to the same effect as the screenshot 9_21_4?

ShapeNode that generates a green border:
private void diagram_NodeDoubleClicked(object sender, NodeEventArgs e)
{
var node = e.Node;

if (node.MasterGroup != null)
node = node.MasterGroup.MainItem as DiagramNode;

var posX = e.MousePosition.X - (diagram.Viewport.X + diagram.Viewport.Width / 2);
var posY = e.MousePosition.Y - (diagram.Viewport.Y + diagram.Viewport.Height / 2);

diagram.ScrollX += posX;
diagram.ScrollY += posY;

if (Keyboard.Modifiers == ModifierKeys.Control)
{
var cx = e.MousePosition.X;
var cy = e.MousePosition.Y;
var myImage = new BitmapImage(new Uri("../../Resources/Images/Menu/Tranger.png", UriKind.Relative));

rectangle1 = diagram.Factory.CreateShapeNode(cx - 1, cy - 1, 2, 2, Shapes.Rectangle);
rectangle1.Brush = Brushes.Transparent;
rectangle1.Image = myImage;
rectangle1.Stroke = Brushes.Green;
//rectangle1.Text = "R405";
rectangle1.RotateText = true;

double newValue;
double angleValue = 0;
if (double.TryParse(angle.Text, out newValue))
angleValue = newValue;

rectangle1.RotationAngle = angleValue;
rectangle1.StrokeThickness = 0.2;


}
}

ShapeNode that generates a white border:
void OnDiagramDoubleClicked(object sender, DiagramEventArgs e)
{
// hold down the Ctrl key + double-click
if (Keyboard.Modifiers == ModifierKeys.Control)
{
var cx = e.MousePosition.X;
var cy = e.MousePosition.Y;

var rectangle1 = Diagram.Factory.CreateShapeNode(
cx - 50, cy - 50, 100, 100, Shapes.Rectangle);

rectangle1.Brush = Brushes.Transparent;
rectangle1.Stroke = Brushes.Green;
}
}

Any assistance would be appreciated.

Cheers,

Jack
« Last Edit: Sep 21st, 2020 at 10:08am by JackPan »  

9_21_7_0.png ( 239 KB | 99 Downloads )
9_21_7_0.png
9_21_8.png ( 784 KB | 97 Downloads )
9_21_8.png
9_21_4.png ( 7 KB | 92 Downloads )
9_21_4.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: The handle-style and the handle-size of these ShapeNodes
Reply #1 - Sep 23rd, 2020 at 7:39am
Print Post  
Hi,

You can use the Diagram.AdjustmentHandlesSize property to control the size of the handles, and the various Diagram *HandlesStyle properties to customize the look.

Alternatively you can set nodes' HandlesStyle to Custom and customdraw the handles yourself via the Diagram.DrawAdjustmentHandles event.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: The handle-style and the handle-size of these ShapeNodes
Reply #2 - Sep 23rd, 2020 at 8:13am
Print Post  
Hi, Lyubo. Smiley

Please don't mind if I continue to ask this question.
My current program creates a behavior class RectanglesBehavior inherited from PanBehavior. How to use the code in this class to implement the Diagram.AdjustmentHandlesSize property to control the size of the handle, and use various Diagram * HandlesStyle to achieve the effect of screenshot 9_21_4.png?

class RectanglesBehavior : PanBehavior
    {
        public RectanglesBehavior(Diagram diagram) : base(diagram, false, true)
        {
            diagram.DoubleClicked += OnDiagramDoubleClicked;
        }

        void OnDiagramDoubleClicked(object sender, DiagramEventArgs e)
        {
            // hold down the Ctrl key + double-click
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                var cx = e.MousePosition.X;
                var cy = e.MousePosition.Y;

                var rectangle1 = Diagram.Factory.CreateShapeNode(
                    cx - 50, cy - 50, 100, 100, Shapes.Rectangle);

                rectangle1.Brush = Brushes.Transparent;
                rectangle1.Stroke = Brushes.Green;
            }
        }

        public override InteractionState StartDraw(Point point)
        {
            Diagram.ModifierKeyActions.Control = ModifierKeyAction.None;
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                //return new InteractionState(new ShapeNode(Diagram), null, MindFusion.Diagramming.Wpf.Action.Create);
                var node = new ShapeNode(Diagram);
                node.Brush = Brushes.Transparent;
                node.Shape = Shapes.Rectangle;
                node.Stroke = Brushes.AliceBlue;
                node.StrokeThickness = 0.06;
                return new InteractionState(node, null, MindFusion.Diagramming.Wpf.Action.Create);
            }

            var selected = Diagram.ActiveItem as ShapeNode;
            if (selected != null)
            {
                var handle = selected.HitTestHandle(point);
                if (handle != null)
                    return new InteractionState(selected, handle, MindFusion.Diagramming.Wpf.Action.Modify);
            }

            /*
           var rect = NearestRect(point);
           if (rect != null)
           {
                 var handlesStyle = rect.HandlesStyle;
                 rect.HandlesStyle = HandlesStyle.SquareHandles2;
                 var handle = rect.HitTestHandle(point);
                 rect.HandlesStyle = handlesStyle;
                 if (handle != null)
                       return new InteractionState(rect, handle, Action.Modify);
           }*/

            // return base.StartDraw(point);
            return null;
        }

        /*public override CursorHint SetMouseCursor(Point point, out bool startInteraction)
     {
           return base.SetMouseCursor(point, out startInteraction);
     }*/

        /*protected override void OnMouseUp(Point mousePosition, MindFusion.Diagramming.Wpf.MouseButton mouseButton)
           {
                 base.OnMouseUp(mousePosition, mouseButton);
           }*/


        DiagramNode NearestRect(Point point)
        {
            DiagramNode nearest = null;
            double minDist = double.MaxValue;
            foreach (var node in Diagram.Nodes)
            {
                if (node.Locked)
                    continue;
                var dist = DistToRect(point, node.Bounds);
                if (dist < minDist)
                {
                    minDist = dist;
                    nearest = node;
                }
            }
            return nearest;
        }

        double DistToRect(Point point, Rect rect)
        {
            var v = new[]
            {
            new Point(rect.Left, rect.Top),
            new Point(rect.Right, rect.Top),
            new Point(rect.Right, rect.Bottom),
            new Point(rect.Left, rect.Bottom),
        };
            double minDist = double.MaxValue;
            for (var i = 0; i < 4; i++)
            {
                var v1 = v[i];
                var v2 = v[(i + 1) % 4];
                var dist = MindFusion.Utilities.DistToLineSegment(point, v1, v2);
                if (dist < minDist)
                    minDist = dist;
            }
            return minDist;
        }
    }

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


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: The handle-style and the handle-size of these ShapeNodes
Reply #3 - Sep 23rd, 2020 at 9:21am
Print Post  
Hi,

You don't need to do that from the behavior class, just set the properties of your Diagram instance. For example:
Code
Select All
            diagram.AdjustmentHandlesSize = 1;
            diagram.ActiveItemHandlesStyle.HandleBrush = diagram.SelectedItemHandlesStyle.HandleBrush = Brushes.Transparent;
            diagram.ActiveItemHandlesStyle.HandlePen = diagram.SelectedItemHandlesStyle.HandlePen = new Pen(Brushes.Cyan, 0.1); 



Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: The handle-style and the handle-size of these ShapeNodes
Reply #4 - Sep 28th, 2020 at 7:18am
Print Post  
Thanks very much, Lyubo. Smiley

Smiley Smiley Smiley

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