public override void RectangleUpdating(ref RectangleF newRect, bool dragAll, bool dragLeft, bool dragTop, bool dragRight, bool dragBottom)
{
float left = newRect.Left, right = newRect.Right, top = newRect.Top, bottom = newRect.Bottom;
bool aspectAdjustWidth = false, aspectAdjustHeight = false;
if (!dragAll) {
if (!dragTop && !dragBottom)
aspectAdjustHeight = true;
else if (!dragLeft && !dragRight)
aspectAdjustWidth = true;
// Update the coordinates to preserve aspect.
float newAspect = (bottom != top) ? Math.Abs(right - left) / Math.Abs(bottom - top) : 1;
if (!aspectAdjustWidth && !aspectAdjustHeight) {
// Determine if width or height aspect should be adjusted.
if (newAspect < aspect)
aspectAdjustWidth = true;
else if (newAspect > aspect)
aspectAdjustHeight = true;
}
if (aspectAdjustHeight && aspect != 0) {
// Adjust the height to match the width.
float newHeight = Math.Abs(right - left) / aspect;
if (dragBottom) {
if (bottom > top)
bottom = top + newHeight;
else
bottom = top - newHeight;
}
else {
if (top < bottom)
top = bottom - newHeight;
else
top = bottom + newHeight;
}
}
else if (aspectAdjustWidth) {
// Adjust the width to match the height
float newWidth = Math.Abs(bottom - top) * aspect;
if (dragLeft) {
if (left < right)
left = right - newWidth;
else
left = right + newWidth;
}
else {
if (right > left)
right = left + newWidth;
else
right = left - newWidth;
}
}
newRect = Geometry.RectFromPoints(left, top, right, bottom);
}
}