Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Custom rendering on ports

Last post 05-29-2008 8:08 AM by Mathy. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-28-2008 1:17 PM

    • Mathy
    • Top 10 Contributor
    • Joined on 07-16-2007
    • Posts 19

    Custom rendering on ports

    Hi,

    I am doing some custom rendering in a class inherited from Port. I can't figure out however how I can shift the area of the port a bit so that the center is not on the border of the shape. I fiddled with Offset and InternalRectangle already but that doesn't give the wanted results. Any tips?

    thx,

    Mathy
     

    • 194.7.161.130
  • 05-28-2008 11:07 PM In reply to

    Re: Custom rendering on ports

    There are 3 routes you can go down here

    1. Adjust the position as your render by using graphics.Transform(), but then the mouseover code etc would fail OR

    2. Actually locate the port as you wish by overding the Shape.LocatePort function OR

    3. Overriding the way the port offset is calculatedin Port.CalculateOffset

    I include the code for the overriden methods

     

    //Locate a port based on the orientation(side) of the parent and the percentage

    public virtual void LocatePort(Port port)

    {

    RectangleF shapeRect = TransformRectangle; PointF start = new PointF();

    float ratio = port.Percent / 100;

    switch (port.Orientation)

    {

    case PortOrientation.Top:

       start = new PointF(shapeRect.X +(shapeRect.Width * ratio),shapeRect.Y-1);

       break;

    case PortOrientation.Bottom:

       start = new PointF(shapeRect.X +(shapeRect.Width * ratio),shapeRect.Y+shapeRect.Height+1);

       break;

    case PortOrientation.Left:

       start = new PointF(shapeRect.X-1,shapeRect.Y +(shapeRect.Height * ratio));

       break;

    case PortOrientation.Right:

       start = new PointF(shapeRect.X + shapeRect.Width +1,shapeRect.Y +(shapeRect.Height * ratio));

       break;

    default:

       break;

    }

     

    port.Validate =
    false;

    port.Location = Intercept(start);

    port.Validate =
    true;

    }

    protected internal PointF CalculateOffset()

    {

       float width = Rectangle.Width;

       float height = Rectangle.Height;

       float halfwidth = width / 2;

       float halfheight = height / 2;

       if (Alignment == PortAlignment.Center || Parent ==null) return new PointF(- halfwidth, - halfheight);

       //Return outset or inset values

       if (Alignment == PortAlignment.Outset)

       {

          if (mOrientation == PortOrientation.Top) return new PointF(- halfwidth,-height);

          if (mOrientation == PortOrientation.Bottom) return new PointF(- halfwidth,0);

          if (mOrientation == PortOrientation.Left) return new PointF(-width,-halfheight);      return new PointF(0,-halfheight);

       }

       else

       {

          if (mOrientation == PortOrientation.Top) return new PointF(- halfwidth,0);

          if (mOrientation == PortOrientation.Bottom) return new PointF(- halfwidth,-height);

          if (mOrientation == PortOrientation.Left) return new PointF(0,-halfheight);      return new PointF(-width,-halfheight);

       }

    }

    • 86.130.74.248
  • 05-29-2008 8:08 AM In reply to

    • Mathy
    • Top 10 Contributor
    • Joined on 07-16-2007
    • Posts 19

    Re: Custom rendering on ports

     I solved it by setting alignment to Outset, I missed that property when looking for a solution.

    • 194.7.161.130
Page 1 of 1 (3 items)