Commit ff584129 authored by Christian Winter's avatar Christian Winter

prefabs can be moved

parent 08538035
Pipeline #4763212 passed with stage
......@@ -21,10 +21,13 @@
class PrefabInstance {
constructor(prefabReference, position, rotation, scale) {
this.transform = {};
this.reference = prefabReference;
this.position = position == undefined ? Vector2.zero : position;
this.rotation = rotation == undefined ? 0 : rotation;
this.scale = scale == undefined ? new Vector2(1, 1) : scale;
this.transform.position = position == undefined ? Vector2.zero : position;
this.transform.rotation = rotation == undefined ? 0 : rotation;
this.transform.scale = scale == undefined ? new Vector2(1, 1) : scale;
this.reference.instances.push(this);
}
......@@ -36,7 +39,7 @@ class PrefabInstance {
selectionHit() {
for (let line of this.reference.lines) {
// prepare line
line = line.copy().move(this.position);
line = line.copy().move(this.transform.position);
// check for hit
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange)
......@@ -50,18 +53,18 @@ class PrefabInstance {
let max = new Vector2(-Infinity, -Infinity);
for (let line of this.lines) {
min.x = Math.min(min.x, line.start.position.x);
min.y = Math.min(min.y, line.start.position.y);
max.x = Math.max(max.x, line.start.position.x);
min.x = Math.min(min.x, line.start.transform.position.x);
min.y = Math.min(min.y, line.start.transform.position.y);
max.x = Math.max(max.x, line.start.transform.position.x);
max.y = Math.max(max.y, line.start.position.y);
min.x = Math.min(min.x, line.end.position.x);
min.y = Math.min(min.y, line.end.position.y);
max.x = Math.max(max.x, line.end.position.x);
max.y = Math.max(max.y, line.end.position.y);
min.x = Math.min(min.x, line.end.transform.position.x);
min.y = Math.min(min.y, line.end.transform.position.y);
max.x = Math.max(max.x, line.end.transform.position.x);
max.y = Math.max(max.y, line.end.transform.position.y);
}
return new Bounds(min.addVector(this.position), max.addVector(this.position));
return new Bounds(min.addVector(this.transform.position), max.addVector(this.transform.position));
}
}
\ No newline at end of file
......@@ -61,13 +61,13 @@
for (let instance of this.prefabs[id].instances) {
for (let line of this.prefabs[id].lines) {
let newLine = line.copy();
newLine.move(instance.position);
newLine.move(instance.transform.position);
newLine.start.position = LineManipulator.rotatePositionByAngle(newLine.start.position, instance.position, instance.rotation);
newLine.end.position = LineManipulator.rotatePositionByAngle(newLine.end.position, instance.position, instance.rotation);
newLine.start.position = LineManipulator.rotatePositionByAngle(newLine.start.position, instance.transform.position, instance.transform.rotation);
newLine.end.position = LineManipulator.rotatePositionByAngle(newLine.end.position, instance.transform.position, instance.transform.rotation);
newLine.start.position = LineManipulator.scalePoint(newLine.start.position, instance.position, instance.scale);
newLine.end.position = LineManipulator.scalePoint(newLine.end.position, instance.position, instance.scale);
newLine.start.position = LineManipulator.scalePoint(newLine.start.position, instance.transform.position, instance.transform.scale);
newLine.end.position = LineManipulator.scalePoint(newLine.end.position, instance.transform.position, instance.transform.scale);
Selection.data.addLine(newLine);
}
......
......@@ -20,6 +20,7 @@ class Settings {
this.guideDashSize = 10;
this.prefabColor = 'green';
this.prefabSelectionColor = 'lightgreen';
this.prefabOutlineSize = 3;
this.measureDashSize = 20;
......
......@@ -25,7 +25,12 @@ class Utilities {
}
}
static moveSelectionBy(points, delta) {
static moveSelectionBy(delta) {
let points = Selection.getAllSelectedPoints();
for (let instance of Selection.data.prefabInstances)
points.push(instance.transform);
if (delta.x != 0 || delta.y != 0) {
ActionHistory.pushAction(new MoveAction(points, delta));
}
......
......@@ -605,6 +605,7 @@
this.drawRealCircle(line.end.position, line.thickness * this.handleSizeFactor, 0, line.color, false, false, true);
}
this.drawPrefabInstances(Settings.prefabSelectionColor);
if (File.currentLayer.hideInRenderPreview)
this.currentContext.setLineDash([]);
......@@ -686,8 +687,8 @@
for (let instance of instances) {
for (let line of prefab.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.position),
line.end.position.addVector(instance.position),
line.start.position.addVector(instance.transform.position),
line.end.position.addVector(instance.transform.position),
line.thickness + Settings.prefabOutlineSize,
Settings.prefabColor
);
......@@ -697,8 +698,8 @@
for (let instance of instances) {
for (let line of prefab.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.position),
line.end.position.addVector(instance.position),
line.start.position.addVector(instance.transform.position),
line.end.position.addVector(instance.transform.position),
line.thickness,
line.color
);
......@@ -742,8 +743,7 @@
}
static drawCursor() {
if (Logic.currentState instanceof MeasureState)
{
if (Logic.currentState instanceof MeasureState) {
let size = cursorRange * Math.PI * 2 / 6 * Camera.zoom;
this.currentContext.setLineDash([size, size]);
}
......@@ -801,8 +801,12 @@
let radius = (!Logic.isPreviewing() && Preferences.showLineHandles) ? p.line.thickness * this.handleSizeFactor : p.line.thickness * 0.5;
this.drawRealCircle(p.position.addVector(delta), radius, 0, p.line.color, false, false, true);
}
// prefab instances
this.drawPrefabInstances(Settings.prefabSelectionColor, delta);
}
static drawRotateLinesPreview() {
let angleDegree = Logic.currentState.getAngle();
let center;
......@@ -983,4 +987,31 @@
);
}
static drawPrefabInstances(outlinecolor, deltaPos, deltaRot, deltaScale) {
deltaPos = deltaPos ? deltaPos : new Vector2(0, 0);
// draw prefab instances
for (let instance of Selection.data.prefabInstances) {
// TODO multibatching? or dont delete batch after rendering to reuse?
// light green outline
if (!Logic.isPreviewing()) {
for (let line of instance.reference.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.transform.position).addVector(deltaPos),
line.end.position.addVector(instance.transform.position).addVector(deltaPos),
line.thickness + Settings.prefabOutlineSize,
outlinecolor
);
}
for (let line of instance.reference.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.transform.position).addVector(deltaPos),
line.end.position.addVector(instance.transform.position).addVector(deltaPos),
line.thickness,
line.color
);
}
}
}
......@@ -169,15 +169,15 @@ class Exporter {
text += indent;
text += "<g prefabReferenceID='" + prefab.id + "'";
text += " positionX='" + instance.position.x + "'";
text += " positionY='" + instance.position.y + "'";
text += " rotation='" + instance.rotation + "'";
text += " scaleX='" + instance.scale.x + "'";
text += " scaleY='" + instance.scale.y + "'";
text += " positionX='" + instance.transform.position.x + "'";
text += " positionY='" + instance.transform.position.y + "'";
text += " rotation='" + instance.transform.rotation + "'";
text += " scaleX='" + instance.transform.scale.x + "'";
text += " scaleY='" + instance.transform.scale.y + "'";
text += "> \n";
for (let line of prefab.lines) {
line = line.copy().move(instance.position);
line = line.copy().move(instance.transform.position);
text +=
indent + "\t" +
'<line ' +
......
......@@ -145,8 +145,7 @@
stepSize = 100;
let delta = new Vector2(x * stepSize, y * stepSize);
let selPoints = Selection.getAllSelectedPoints();
Utilities.moveSelectionBy(selPoints, delta);
Utilities.moveSelectionBy(delta);
Renderer.redraw();
}
}
......
......@@ -24,9 +24,7 @@
}
execute() {
let selPoints = Selection.getAllSelectedPoints();
Utilities.moveSelectionBy(selPoints, this.getDelta());
Utilities.moveSelectionBy(this.getDelta());
File.currentLayer.changed();
}
......
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