Hi,
Here’s a complete TransitionLink that you can drop into StateCharter, starting with your code posted earlier:
public class TransitionLink : GoLink {
public TransitionLink() {}
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint,
int whichHandle, GoInputState evttype, SizeF min, SizeF max) {
(this.ResizesRealtime || evttype == GoInputState.Start|| evttype == GoInputState.Finish || evttype == GoInputState.Cancel)) {
origPoint = newPoint;
} else {
float gap = origPoint.X - newPoint.X;
this.Curviness = gap;
this.AdjustingStyle = GoLinkAdjustingStyle.Calculate;
this.CalculateRoute();
}
} else {
base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
this.AdjustingStyle = GoLinkAdjustingStyle.Scale;
}
}
base.AddSelectionHandles(sel, selectedObj);
PointF handlePoint = this.GetSpotLocation(GoObject.MiddleRight);
IGoHandle handle = sel.CreateResizeHandle(this, selectedObj, handlePoint, SharpnessID, true);
GoHandle goh = handle.GoObject as GoHandle;
if (goh != null) {
goh.Style = GoHandleStyle.Diamond;
goh.BrushColor = Color.Yellow;
RectangleF bounds = goh.Bounds;
bounds.Inflate(1, 1);
goh.Bounds = bounds;
}
}
[NonSerialized]
PointF origPoint;
[/code]
New and Improved: uses view.FirstInput.DocPoint and handles X/Y movement of mouse.
public class TransitionLink : GoLink {
public TransitionLink() {}
int whichHandle, GoInputState evttype, SizeF min, SizeF max) {
(this.ResizesRealtime || evttype == GoInputState.Finish || evttype == GoInputState.Cancel)) {
float gap = view.FirstInput.DocPoint.X - newPoint.X;
float gapY = view.FirstInput.DocPoint.Y - newPoint.Y;
if (Math.Abs(gapY) > Math.Abs(gap)) gap = gapY;
this.Curviness = gap;
this.AdjustingStyle = GoLinkAdjustingStyle.Calculate;
this.CalculateRoute();
} else {
base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
this.AdjustingStyle = GoLinkAdjustingStyle.Scale;
}
}
base.AddSelectionHandles(sel, selectedObj);
PointF handlePoint = this.GetSpotLocation(GoObject.MiddleRight);
IGoHandle handle = sel.CreateResizeHandle(this, selectedObj, handlePoint, SharpnessID, true);
GoHandle goh = handle.GoObject as GoHandle;
if (goh != null) {
goh.Style = GoHandleStyle.Diamond;
goh.BrushColor = Color.Yellow;
RectangleF bounds = goh.Bounds;
bounds.Inflate(1, 1);
goh.Bounds = bounds;
}
}
Thanks a lot Jake!
As usual your support is great!!
In case you’re intereseted i post the final calculation which works perfect. It looks like you have to copy the curviness before the resizing process begins and add it to the gap otherwise it doesn’t behave correctly.
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint,int whichHandle, GoInputState evttype, SizeF min, SizeF max)
GoObject uses TopLeft, MiddleTop, etc for resize handle ids… GoStroke and GoLink are a little different because they don’t have “spots” like that. So what you end up with is mostly an “enum” sort of an input that has situations where a static enum isn’t enough.
OK, I understand.