I have GoSimpleNodes that I allow the user to resize and reshape. I need to force the result of the resize to be integer values. I have tried in several places but to no avail. What is the preferred method to accomplish this?
Do you want the node size to be integer, or the shape? The Shape gets resized, but a label outside the shape will add some non-integer factor.
Are you using grids?
The shape needs to be an integer value. I am not using a grid, but I am open to using one if it makes life easier.
Well, limited testing, but this seems to work:
[Serializable]
class GoSimpleInt: GoSimpleNode {
public override void LayoutChildren(GoObject childchanged) {
if (childchanged == this.Icon) {
this.Icon.Width = (float)Math.Round(this.Icon.Width);
this.Icon.Height = (float)Math.Round(this.Icon.Height);
}
base.LayoutChildren(childchanged);
}
}
Note it doesn’t help to override DoResize on the node, as the object getting the DoResize is the Icon/Image object. You could subclass that object and handle DoResize there, but this is a little quicker to code.
Actually (after our email about this) I was wondering why you just don’t truncate the width/height as your are doing the export to XML…
Jake,
node.Location defaults to SelectionObject.Center.
You could turn on Grid to get rounded off Location, but beware that doesn’t mean all the other parts of the node will also be “integer”.