Commit 3ea14a95 authored by Christian Winter's avatar Christian Winter

moveSelectionBy() now part of selection class

parent c66354a0
......@@ -29,7 +29,7 @@ class LineManipulator {
if (Preferences.usePivot)
rotationCenter = pivot;
else
rotationCenter = Utilities.calculateCenterOfMass(selection.getAllPositions());
rotationCenter = Utilities.calculateCenterOfMass(selection.data.getAllPositions());
}
for (let p of selAsPoints)
......@@ -74,7 +74,7 @@ class LineManipulator {
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateBBCenter(selection.getAllPositions());
center = Utilities.calculateBBCenter(selection.data.getAllPositions());
let selectionAsPoints = selection.getAllSelectedPoints();
for (let p of selectionAsPoints)
......
......@@ -13,19 +13,7 @@ Utilities = new class {
points[i].position = points[i].position.addVector(delta);
}
}
moveSelectionBy(delta) {
let selection = Application.currentView.selection;
let points = selection.getAllSelectedPoints();
for (let instance of selection.data.instances)
points.push(instance.transform);
if (delta.x != 0 || delta.y != 0) {
ActionHistory.pushAction(new MoveAction(points, delta));
}
}
calculateBBCenter(points) {
let min = new Vector2(Infinity, Infinity);
let max = new Vector2(-Infinity, -Infinity);
......@@ -63,7 +51,7 @@ Utilities = new class {
let selection = Application.currentView.selection;
let selPoints = selection.getAllPositions();
let selPoints = selection.data.getAllPositions();
for (let i = 0; i < selPoints.length; ++i)
selPoints[i].position = GridManager.grid.getNearestPointFor(selPoints[i].position);
......
......@@ -162,4 +162,11 @@
return lines;
}
getAllPositions() {
let instancesPositions = [];
for (let instance of this.instances)
instancesPositions.push(instance.transform);
return Utilities.linesToLineEndings(this.lines).concat(this.points).concat(instancesPositions);
}
}
\ No newline at end of file
......@@ -691,7 +691,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(this.view.selection.getAllPositions());
center = Utilities.calculateCenterOfMass(this.view.selection.data.getAllPositions());
// selected lines
for (let line of this.view.selection.data.lines)
......@@ -721,7 +721,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateBBCenter(this.view.selection.getAllPositions());
center = Utilities.calculateBBCenter(this.view.selection.data.getAllPositions());
// selected lines
for (let line of this.view.selection.data.lines)
......
......@@ -141,13 +141,6 @@
return newSelData;
}
getAllPositions() {
let instancesPositions = [];
for (let instance of this.data.instances)
instancesPositions.push(instance.transform);
return Utilities.linesToLineEndings(this.data.lines).concat(this.data.points).concat(instancesPositions);
}
selectAllToggle() {
if (this.isEmpty())
this.selectEverything();
......@@ -171,4 +164,16 @@
return false;
}
moveBy(delta) {
let points = this.data.getAllPositions();
if (delta.x != 0 || delta.y != 0) {
ActionHistory.pushAction(new MoveAction(points, delta));
}
}
rotate() {
}
}
\ No newline at end of file
......@@ -135,7 +135,7 @@
stepSize = 100;
let delta = new Vector2(x * stepSize, y * stepSize);
Utilities.moveSelectionBy(delta);
Application.currentView.selection.moveBy(delta);
Application.redrawAllViews();
}
}
......
......@@ -24,7 +24,7 @@
}
execute() {
Utilities.moveSelectionBy(this.getDelta());
Application.currentView.selection.moveBy(this.getDelta());
}
cancel() {
......@@ -56,14 +56,14 @@
switch (keycode) {
case Key.D:
Utilities.movePointsBy(Application.currentView.selection.getAllPositions(), this.getDelta());
Utilities.movePointsBy(Application.currentView.selection.data.getAllPositions(), this.getDelta());
Application.currentView.selection.duplicate();
Utilities.movePointsBy(Application.currentView.selection.getAllPositions(), this.getDelta().flipped());
Utilities.movePointsBy(Application.currentView.selection.data.getAllPositions(), this.getDelta().flipped());
break;
case Key.K:
Utilities.movePointsBy(Application.currentView.selection.getAllPositions(), this.getDelta());
Utilities.movePointsBy(Application.currentView.selection.data.getAllPositions(), this.getDelta());
Utilities.cutWithSelection();
Utilities.movePointsBy(Application.currentView.selection.getAllPositions(), this.getDelta().flipped());
Utilities.movePointsBy(Application.currentView.selection.data.getAllPositions(), this.getDelta().flipped());
break;
}
}
......
......@@ -34,7 +34,7 @@
if (Preferences.usePivot)
rotationCenter = pivot;
else
rotationCenter = Utilities.calculateCenterOfMass(Application.currentView.selection.getAllPositions());
rotationCenter = Utilities.calculateCenterOfMass(Application.currentView.selection.data.getAllPositions());
let p1 = Application.currentView.logic.currentState.startPos.subtractVector(rotationCenter);
let p2 = Application.currentView.logic.currentState.currentPos.subtractVector(rotationCenter);
......
......@@ -38,7 +38,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateBBCenter(Application.currentView.selection.getAllPositions());
center = Utilities.calculateBBCenter(Application.currentView.selection.data.getAllPositions());
let p1 = Application.currentView.logic.currentState.startPos.subtractVector(center);
let p2 = Application.currentView.logic.currentState.currentPos.subtractVector(center);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment