Getting more info about the current resize operation

Mar 11, 2013 at 10:18 AM
Hi,

When a shape is being resized, I need to know which exactly control point is used to do that.

Or - instead - it will be enough for me to know how shape's geometry is currently affected. For example, if we're dragging the control point located at the right edge of the shape - then the shape rectangle's Right property is being affected; if this control point is at the bottom left corner of the shape - then properties X and Height are affected; etc.

Is it possible to get this info?

PS: I need this to restrict mouse movement when resizing a "container" shape - in my app this resizing must be limited to the minimal rectangle covering all "child" shapes. In other words, user must be not able to make container smaller than its "contents". To do that, I must calculate the correct cursor clipping rectangle - and this depends upon which exactly resize operation is in progress.
Coordinator
Mar 11, 2013 at 11:48 AM
The shape has to restrict the movement - and the shape usually knows its resize handles.
As far as I know, your shapes are not rotatable which simplifies the calulations a lot:
protected override bool MovePointByCore(ControlPointId pointId, float transformedDeltaX, float transformedDeltaY, float sin, float cos, ResizeModifiers modifiers) {
    // transformedDeltaX/Y contain the movement of the mouse transformed in the coordinate system of the unrotated shape
    // In case of unrotated shapes, transformedDeltaX/Y contain the mouse movement in X/Y direction
    switch (pointId) {
        case TopCenterControlPoint:
            // Calculate the new height
            // Restrict the calculated new height to the desired value
            // Apply the new height and move the shape to the new position
            // Caution: Center point has to be on even coordinates.
            // So if the new height has an odd value, you have to restrict it to an even value.
        break;

        // ...
    }
    // returns true if the control point movement was not restricted at all.
}
Mar 11, 2013 at 12:27 PM
Edited Mar 11, 2013 at 1:18 PM
Thank You for the feedback.
However, I do not like the idea that the shape itself must be responsible for restricting its movement.
I think I'll better fire an event (e.g. PointMoved) from inside the MovePointByCore() method - so that its subscriber can set <event_argument>.Cancel to true; in my app it's a special "service" which handles all stuff related to container/child relations.

[UPDATE] I think that instead of
// Calculate the new height
// Restrict the calculated new height to the desired value
// Apply the new height and move the shape to the new position
I'll simply calculate the cursor clipping rectangle. However, if in future releases you'll decide to allow resizing with keyboard keys - that will be a problem...
Mar 12, 2013 at 1:18 PM
Edited Mar 12, 2013 at 4:01 PM
Seems my idea with PointMoved event (fired from inside the MovePointByCore method) is not the solution.
If I subscribe to this event for every shape added to the diagram - I'll catch this event only when point movement is finished (i.e. when the mouse button is depressed). This is because the subscription is made for the real shape. And if I want to catch this event for every movement "delta" - I must make the subscription for the preview shape as well, and this seems to be a problem. As the result, I cannot calculate the clipping rectangle :((
Mar 13, 2013 at 2:30 PM
Edited Mar 14, 2013 at 6:49 PM
BTW, constant TopCenterControlPoint is private and so it's not accessible from your code :) Why haven't you made it protected, I wonder?!

OK, I think I've found another way to solve my problem. It still uses the MovePointByCore() method but does not use events. I'll post a solution in another (new) thread when it's ready. [UPDATE] Posted solution in this topic.