Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Question about creating custom shapes (Read 465 times)
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Question about creating custom shapes
Dec 9th, 2022 at 6:30pm
Print Post  
I have a question about designing custom shapes for nodes.

I've attached an image that should appear at the bottom of this post. The image demonstrates that shape I am attempting to achieve, and what I have been able to get so far with my code.

Here is my code for my custom node:
Code (C++)
Select All
public class AddNode : MindFusion.Diagramming.ShapeNode
{
    public AddNode(Diagram parent_diagram) : base(parent_diagram)
    {
        AnchorPoint input_x = new AnchorPoint(0, 33, true, false);
        AnchorPoint input_y = new AnchorPoint(0, 66, true, false);
        AnchorPoint output = new AnchorPoint(100, 50, false, true);

        AnchorPattern = new AnchorPattern()
        {
            Points = new AnchorPointCollection()
            {
                input_x,
                input_y,
                output
            }
        };

        Shape = new Shape(

            new MindFusion.Diagramming.ElementTemplate[]
            {
                new LineTemplate(0, 0, 0, 100),
                new LineTemplate(0, 100, 100, 50),
                new LineTemplate(100, 50, 0, 0)
            },

            FillMode.Winding

        );
    }
}
 



This code creates a triangle that is too elongated in the horizontal direction. If I replace the shape code with this:

Code (C++)
Select All
Shape = new Shape(

    new MindFusion.Diagramming.ElementTemplate[]
    {
        new LineTemplate(0, 0, 0, 100),
        new LineTemplate(0, 100, 75, 50),
        new LineTemplate(75, 50, 0, 0)
    },

    FillMode.Winding

);
 



Then the triangle is about the right shape, but the AnchorPoint is offset.

What are the units being used here? Why does "100" in the vertical direction equate to 3 grid boxes on the diagram, whereas "100" in the horizontal direction equates to 4 grid boxes on the diagram?

For what it's worth, on my diagram I set GridSizeX and GridSizeY to both be 10, if that is important.
  

shapenode.png ( 42 KB | 51 Downloads )
shapenode.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Question about creating custom shapes
Reply #1 - Dec 12th, 2022 at 10:22am
Print Post  
Shape coordinates are specified as percentage of node size, and later mapped to actual node.Bounds, similar to anchor points. So if you want the triangle vertex to match the anchor point, use the first Shape definition where X extends to 100. Then set Bounds to a rectangle with smaller width to prevent the elongation.

E.g. set width = height to make it easier to calculate the coordinates of the embedded plus sign, or set width = sqrt(3) / 2 * height to make it equilateral triangle.

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