I want to allow the user to resize a link anywhere on a segment of an orthogonal link (which would use the resize behaviour of the nearest point) when they hover over the link. So when the user moved their cursor over the link they would automatically get the appropriate cursor of the nearest point and be able to start resizing. Can this be done?
Yes, you could do that. But first I’m wondering what would happen when the user does a mouse down. If the nearest resize handle allowed resizing in any direction, should that point jump directly to where the mouse is? That wouldn’t feel smooth.
Good point. The behaviour that I want is that if the nearest handle allowed resizing in any direction then the resizing would depend on the direction of the segment. If the segment is horizontal then the resize should only allow movement up and down, and if the segment is vertical then the resize should only allow movement right and left. So if the user hovered in the middle of a line the cursor would not become the cross, but rather the appropriate horizontal or vertical one. When the user triggered the mouse down then entire segment would then be moved in the appropriate direction.
This sounds familiar–I think someone else in this forum was looking to do something similar.
Did you still want to allow people to select these links by clicking on them?
If so, then perhaps the easiest thing to do would be to override AddSelectionHandles to call the base method and then add some more GoHandles that extend along most of the length of each movable segment. I suppose you could have the GoHandle.Style be GoHandleStyle.None, so that nothing is drawn. And of course you would set the GoHandle.CursorName to be “col-resize” or “row-resize” as appropriate. The GoHandle.HandleID would need to be something unique so that the DoResize method can figure out what to do – perhaps the segment number plus 100000.
Then an override of DoResize would need to look at the HandleID to see if it’s greater than 100000. If not, call the base method; if so, call SetPoint on the two segment points to follow the mouse.
If I have time I should work on this as a future example. In the meantime you can look at overrides of AddSelectionHandles and DoResize in the samples.
Actually, no I wouldn’t want the user to select them since they would always in a sort of resize mode when the cursor moved over any part of the link.
I’ve been playing around with the Demo1 code and trying to implement this for the GraphLink, but the best I’ve done is created some bizarre behavior.
Were you intending for all the overrides to be done on the GoStroke rather than the link (I’m not able to trap the DoResize on the GraphLink and I’m not sure how to determine the segment direction, so that’s what led me to think that)? If yes, how can I override the stroke methods?
Basically, if your GraphLink class is a GoLabeledLink, you need to make sure its .RealLink is a GoLink-inheriting class that overrides those two methods (AddSelectionHandles and DoResize). A number of example link classes do this, by overriding GoLabeledLink.CreateRealLink to return an instance of the GoLink-inheriting class.
Send me e-mail.