Commit bfd07e0f authored by Christian Winter's avatar Christian Winter

measure state introduced. linemanipulator file renamed. previewlinecolor removed

parent 9348f86a
Pipeline #4746998 passed with stage
in 1 minute and 21 seconds
......@@ -32,6 +32,7 @@
<script src="scripts/states/RotateState.js"></script>
<script src="scripts/states/ScaleState.js"></script>
<script src="scripts/states/EditPrefabState.js"></script>
<script src="scripts/states/MeasureState.js"></script>
<script src="scripts/managers/Camera.js"></script>
<script src="scripts/input/MouseHandler.js"></script>
......@@ -55,7 +56,7 @@
<script src="scripts/saving/Exporter.js"></script>
<script src="scripts/Settings.js"></script>
<script src="scripts/ButtonActions.js"></script>
<script src="scripts/LineManipulator.js"></script>
<script src="scripts/Color.js"></script>
<script src="scripts/managers/Logic.js"></script>
<script src="scripts/managers/Selection.js"></script>
......
......@@ -9,8 +9,6 @@ class Settings {
this.canvasColor = "#666";
this.previewLineColor = "#090";
this.crossHairColor = "#f90";
this.crossHairLineWidth = 1;
......
......@@ -8,8 +8,8 @@
this.prefabDict = new PrefabDict();
}
addLine(line) {
if (Input.isKeyDown(Key.Space)) {
addLine(line, guideLine) {
if (guideLine) {
let done = false;
for (let layer of File.layers) {
......
......@@ -6,7 +6,10 @@
static keyDown(keyCode) {
switch (keyCode) {
case Key.Space:
Renderer.redraw();
if (Logic.currentState instanceof IdleState) {
Logic.setState(new MeasureState());
Renderer.redraw();
}
break;
case Key.G:
if (!Selection.noSelection()) {
......@@ -88,7 +91,8 @@
static keyUp(keyCode) {
switch (keyCode) {
case Key.Space:
Renderer.redraw();
if (Logic.currentState instanceof MeasureState)
Logic.setState(new IdleState());
break;
case Key.Tab:
......
......@@ -47,11 +47,14 @@ class MouseHandler {
}
} else if (Logic.currentState instanceof BrushSelectionState) {
Logic.currentState.update();
} else if (Logic.currentState instanceof MeasureState) {
Logic.currentState.update();
}
if (Logic.currentState instanceof IdleState ||
Logic.currentState instanceof DrawingState ||
Logic.currentState instanceof ContinousDrawingState) {
Logic.currentState instanceof ContinousDrawingState ||
Logic.currentState instanceof MeasureState) {
GUI.writeToStatusbarLeft(currentPosition.toString());
}
}
......@@ -110,6 +113,9 @@ class MouseHandler {
else if (Logic.currentState instanceof PrefabBrushState) {
Logic.currentState.place();
}
else if (Logic.currentState instanceof MeasureState) {
Logic.currentState.mouseDown(0);
}
}
else if (e.button == 2) // RMB
{
......@@ -194,6 +200,9 @@ class MouseHandler {
else if (Logic.currentState instanceof PrefabBrushState) {
Logic.currentState.cancel();
}
else if (Logic.currentState instanceof MeasureState) {
Logic.currentState.mouseDown(2);
}
Renderer.redraw();
}
......@@ -208,8 +217,7 @@ class MouseHandler {
}
else if (e.ctrlKey) {
Logic.setState(new ZoomState());
}
else {
} else {
var screenPos = Utilities.getMousePos(e);
Logic.setState(new PanState());
}
......@@ -298,6 +306,8 @@ class MouseHandler {
}
else if (Logic.currentState instanceof ContinousDrawingState) {
Logic.currentState.oldPos = undefined;
} else if (Logic.currentState instanceof MeasureState) {
Logic.currentState.mouseUp(0);
}
}
......@@ -328,6 +338,8 @@ class MouseHandler {
Logic.currentState.execute();
Logic.setState(new IdleState());
}
} else if (Logic.currentState instanceof MeasureState) {
Logic.currentState.mouseUp(2);
}
}
}
......
......@@ -266,9 +266,6 @@
this.drawArtbounds();
this.drawGrid();
//if (Input.isKeyDown(Key.Space))
//this.drawCrosshair();
if (Logic.currentState instanceof BoxSelectionState) {
// TODO if next line is removed, axis gets drawn in orange? somewhere this.currentContext.stroke missing or sth like that? but i cant find it...
this.drawCrosshair(true);
......@@ -295,10 +292,12 @@
this.drawPrefabPreview();
}
if (Logic.currentState instanceof MeasureState) {
if (!Logic.isPreviewing() || Preferences.renderGuideLayers)
if (Logic.currentState.startPosRMB)
this.drawMeasure(Logic.currentState.startPosRMB, Logic.currentState.currentPosRMB);
}
if (!Logic.isPreviewing() || Preferences.renderGuideLayers)
if (Input.isKeyDown(Key.Space))
this.drawMeasure(pivot, currentPosition);
this.fps = 1000 / (step - this.oldStep);
this.oldStep = step;
......@@ -367,12 +366,9 @@
this.renderBatchedLines(1, 'yellow', false, false);
if (Logic.currentState instanceof DrawingState)
this.drawPreviewLine();
this.drawPreviewLine();
if (!(Logic.currentState instanceof DrawingState)
&& !Input.isKeyDown(Key.Space)
&& this.showCursor == true
)
this.drawCursor();
......@@ -489,7 +485,7 @@
if (!(layer.visible))
continue;
if (layer.hideInRenderPreview==true)
if (layer.hideInRenderPreview == true)
this.drawRenderHiddenLayer(layer);
else
this.drawLayer(layer);
......@@ -533,11 +529,9 @@
}
}
if (Logic.currentState instanceof DrawingState)
this.drawPreviewLine();
this.drawPreviewLine();
if (!(Logic.currentState instanceof DrawingState)
&& !Input.isKeyDown(Key.Space)
&& this.showCursor == true
)
this.drawCursor();
......@@ -735,11 +729,15 @@
if (Logic.currentState instanceof DrawingState) {
let start = Logic.currentState.startPos;
let end = currentPosition;
this.drawLineFromTo(start, end, currentLineThickness, Settings.previewLineColor, false);
//this.drawRealCircle(currentPosition, currentLineThickness * 0.5, 1, Settings.previewLineColor, false, true, true);
//this.drawRealCircle(start, currentLineThickness * 0.5, 1, Settings.previewLineColor, false, true, true);
this.drawLineFromTo(start, end, currentLineThickness, currentLineColor, false);
} else if (Logic.currentState instanceof MeasureState) {
if (Logic.currentState.startPosLMB && !Logic.currentState.stoppedLMB) {
let start = Logic.currentState.startPosLMB;
let end = Logic.currentState.currentPosLMB;
this.currentContext.setLineDash([Settings.guideDashSize * Camera.zoom, Settings.guideDashSize * Camera.zoom]);
this.drawLineFromTo(start, end, currentLineThickness, 'black', false);
this.currentContext.setLineDash([]);
}
}
}
......@@ -920,8 +918,9 @@
// angle
pos = p1.addVector(size.normalized().multiply(33 / Camera.zoom));
pos = LineManipulator.rotatePositionByAngle(pos, p1, 180);
pos = Camera.canvasSpaceToScreenSpace(pos);
let num = +(Math.atan2(size.y, size.x) * (180/Math.PI)).toFixed(2);
let num = +(Math.atan2(size.y, size.x) * (180 / Math.PI)).toFixed(2);
this.currentContext.fillText(num + "°", pos.x, pos.y);
// crosshair line end
......
class MeasureState extends State {
constructor() {
super();
}
enter() {
}
exit() {
}
mouseDown(button) {
if (button == 0) {
this.startPosLMB = currentPosition.copy();
this.currentPosLMB = currentPosition.copy();
this.stoppedLMB = false;
} else if (button == 1) {
this.startPosMMB = currentPosition.copy();
this.currentPosMMB = currentPosition.copy();
this.stoppedMMB = false;
} else if (button == 2) {
this.startPosRMB = currentPosition.copy();
this.currentPosRMB = currentPosition.copy();
this.stoppedRMB = false;
}
}
mouseUp(button) {
if (button == 0) {
this.stoppedLMB = true;
File.currentLayer.addLine(new Line(this.startPosLMB, this.currentPosLMB), true);
} else if (button == 1) {
this.stoppedMMB = true;
} else if (button == 2) {
this.stoppedRMB = true;
}
}
top() {
this.stopped = true;
if (this.initWithLMB)
this.locked = false;
}
update() {
if (this.startPosLMB && !this.stoppedLMB)
this.currentPosLMB = currentPosition.copy();
else if (this.startPosMMB && !this.stoppedMMB)
this.currentPosMMB = currentPosition.copy();
else if (this.startPosRMB && !this.stoppedRMB)
this.currentPosRMB = currentPosition.copy();
}
keyDown(keycode) {
}
keyUp(keycode) {
}
toString() {
return "Measure State";
}
}
\ No newline at end of file
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