Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve extensibility of change bounds tool #32

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions src/features/tools/change-bounds-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
toElementAndBounds,
toElementAndRoutingPoints
} from "../../utils/smodel-util";
import { isBoundsAwareMoveable, isResizable, ResizeHandleLocation, SResizeHandle } from "../change-bounds/model";
import { isBoundsAwareMoveable, isResizable, Resizable, ResizeHandleLocation, SResizeHandle } from "../change-bounds/model";
import {
createMovementRestrictionFeedback,
IMovementRestrictor,
Expand Down Expand Up @@ -286,45 +286,52 @@ export class ChangeBoundsListener extends DragAwareMouseListener implements Sele
return [];
}

const actions: Action[] = [];
const resizeElement = findParentByFeature(this.activeResizeHandle, isResizable);
if (this.isActiveResizeElement(resizeElement)) {
switch (this.activeResizeHandle.location) {
case ResizeHandleLocation.TopLeft:
this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x + this.positionDelta.x,
resizeElement.bounds.y + this.positionDelta.y,
resizeElement.bounds.width - this.positionDelta.x,
resizeElement.bounds.height - this.positionDelta.y)
.forEach(action => actions.push(action));
break;
return this.handleTopLeftResize(resizeElement);
case ResizeHandleLocation.TopRight:
this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x,
resizeElement.bounds.y + this.positionDelta.y,
resizeElement.bounds.width + this.positionDelta.x,
resizeElement.bounds.height - this.positionDelta.y)
.forEach(action => actions.push(action));
break;
return this.handleTopRightResize(resizeElement);
case ResizeHandleLocation.BottomLeft:
this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x + this.positionDelta.x,
resizeElement.bounds.y,
resizeElement.bounds.width - this.positionDelta.x,
resizeElement.bounds.height + this.positionDelta.y)
.forEach(action => actions.push(action));
break;
return this.handleBottomLeftResize(resizeElement);
case ResizeHandleLocation.BottomRight:
this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x,
resizeElement.bounds.y,
resizeElement.bounds.width + this.positionDelta.x,
resizeElement.bounds.height + this.positionDelta.y)
.forEach(action => actions.push(action));
break;
return this.handleBottomRightResize(resizeElement);
}
}
return actions;
return [];
}

protected handleTopLeftResize(resizeElement: SParentElement & Resizable): Action[] {
return this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x + this.positionDelta.x,
resizeElement.bounds.y + this.positionDelta.y,
resizeElement.bounds.width - this.positionDelta.x,
resizeElement.bounds.height - this.positionDelta.y);
}

protected handleTopRightResize(resizeElement: SParentElement & Resizable): Action[] {
return this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x,
resizeElement.bounds.y + this.positionDelta.y,
resizeElement.bounds.width + this.positionDelta.x,
resizeElement.bounds.height - this.positionDelta.y);
}

protected handleBottomLeftResize(resizeElement: SParentElement & Resizable): Action[] {
return this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x + this.positionDelta.x,
resizeElement.bounds.y,
resizeElement.bounds.width - this.positionDelta.x,
resizeElement.bounds.height + this.positionDelta.y);
}

protected handleBottomRightResize(resizeElement: SParentElement & Resizable): Action[] {
return this.createSetBoundsAction(resizeElement,
resizeElement.bounds.x,
resizeElement.bounds.y,
resizeElement.bounds.width + this.positionDelta.x,
resizeElement.bounds.height + this.positionDelta.y);
}

protected createChangeBoundsAction(element: SModelElement & BoundsAware): Action[] {
Expand Down