Move transformation not as inline function

This commit is contained in:
ziajka 2018-03-19 11:24:40 +01:00
parent 3d25633a38
commit 65b491e54e
2 changed files with 10 additions and 9 deletions

View File

@ -9,7 +9,6 @@ class OnSelectedListenerMock {
public constructor(public nodes: Node[] = []) {}
public listen(nodes: Node[]) {
console.log(this);
this.nodes = nodes;
}
}

View File

@ -25,17 +25,12 @@ export class SelectionTool {
public activate() {
const self = this;
const transformation = (p) => {
const transformation_point = this.context.getZeroZeroTransformationPoint();
return [p[0] - transformation_point.x, p[1] - transformation_point.y];
};
this.selection.on("mousedown", function() {
const subject = select(window);
const parent = this.parentElement;
const start = transformation(mouse(parent));
const start = self.transformation(mouse(parent));
self.startSelection(start);
// clear selection
@ -45,10 +40,10 @@ export class SelectionTool {
subject
.on("mousemove.selection", function() {
const end = transformation(mouse(parent));
const end = self.transformation(mouse(parent));
self.moveSelection(start, end);
}).on("mouseup.selection", function() {
const end = transformation(mouse(parent));
const end = self.transformation(mouse(parent));
self.endSelection(start, end);
subject
.on("mousemove.selection", null)
@ -116,4 +111,11 @@ export class SelectionTool {
private rect(x: number, y: number, w: number, h: number) {
return "M" + [x, y] + " l" + [w, 0] + " l" + [0, h] + " l" + [-w, 0] + "z";
}
private transformation(point) {
const transformation_point = this.context.getZeroZeroTransformationPoint();
return [point[0] - transformation_point.x, point[1] - transformation_point.y];
}
}