Simplistic Node

Hi,
I need a very simple node type but was wondering if there was a stock GoNode child class that might fit the bill. I need a node with a resizable image, a label at the bottom of the image, and allow me to add ports anywhere on the image. I cannot seem to find the one I need in the Reference Manual. Help?

I suppose it can be hard to find things in the API reference when you don’t know exactly what term to look for.
Reading through the “Nodes” chapter of the User Guide would be much more enlightening, because it skips a lot of details and includes screen shots.
Basically you want to use GoIconicNode.
There’s a MultiPortNode example class that you can adapt. It does some things you might not want to do, such as set DraggableLabel to true, and make use of the MultiPortNodePort example port class which limits how many links the user can connect to each port. And of course you’ll need to make it (actually the Icon) Resizable. You’ll probably also want to set it to be ResizesRealtime. And you might possibly want to set it to be Reshapable.
The biggest issue for you is to decide what to do with the positions of the ports when the Icon is resized by the user. I suspect the definition of MultiPortNode.OnChildBoundsChanged might not be what you want. Try this instead:
protected override void OnChildBoundsChanged(GoObject child, RectangleF old) {
if (child != null && child == this.Icon && old.Width > 0 && old.Height > 0) {
RectangleF thisRect = this.Icon.Bounds;
float scaleFactorX = thisRect.Width / old.Width;
float scaleFactorY = thisRect.Height / old.Height;
foreach (GoObject obj in this) {
if (obj == this.Icon) continue;
RectangleF childRect = obj.Bounds;
float newRectx = thisRect.X + ((childRect.X - old.X) * scaleFactorX);
float newRecty = thisRect.Y + ((childRect.Y - old.Y) * scaleFactorY);
float newRectwidth = childRect.Width;
float newRectheight = childRect.Height;
if (obj.AutoRescales) {
newRectwidth *= scaleFactorX;
newRectheight *= scaleFactorY;
}
obj.Bounds = new RectangleF(newRectx, newRecty, newRectwidth, newRectheight);
}
}
base.OnChildBoundsChanged(child, old); // this will call LayoutChildren
}
and make sure the ports that you use have the GoObject.AutoRescales property set to false. You can do that either in the constructor for MultiPortNodePort, or in the override MultiPortNode.CreatePort method.
Maybe we should change the example class to do this, since the current example class doesn’t handle resizing the Icon.