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

Make notes scale from the center when using the mouse #663

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 19 additions & 14 deletions client/js/controls/post_notes_overlay_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ class ScalingNoteState extends ActiveState {
}));
this._originalMousePoint = mousePoint;
this._originalSize = _getNoteSize(note);
this._origin = _getNoteCentroid(this._note);
this._scaleDirection = new Point(
mousePoint.x > this._origin.x ? 1 : -1,
mousePoint.y > this._origin.y ? 1 : -1
);
}

evtCanvasKeyDown(e) {
Expand All @@ -417,22 +422,22 @@ class ScalingNoteState extends ActiveState {
evtCanvasMouseMove(e) {
const mousePoint = this._getPointFromEvent(e);
const originalMousePoint = this._originalMousePoint;
const origin = this._origin;
const originalSize = this._originalSize;
const scaleDirection = this._scaleDirection;
const scale = new Point(
1 +
((mousePoint.x - originalMousePoint.x) / originalSize.x) *
scaleDirection.x,
1 +
((mousePoint.y - originalMousePoint.y) / originalSize.y) *
scaleDirection.y
);
for (let i of misc.range(this._note.polygon.length)) {
const polygonPoint = this._note.polygon.at(i);
const originalPolygonPoint = this._originalPolygon[i];
polygonPoint.x =
originalMousePoint.x +
(originalPolygonPoint.x - originalMousePoint.x) *
(1 +
(mousePoint.x - originalMousePoint.x) /
originalSize.x);
polygonPoint.y =
originalMousePoint.y +
(originalPolygonPoint.y - originalMousePoint.y) *
(1 +
(mousePoint.y - originalMousePoint.y) /
originalSize.y);
const point = this._note.polygon.at(i);
const originalPoint = this._originalPolygon[i];
point.x = origin.x + (originalPoint.x - origin.x) * scale.x;
point.y = origin.y + (originalPoint.y - origin.y) * scale.y;
}
}

Expand Down