Commit dec1f183 authored by Christian Winter's avatar Christian Winter

canvaskeyhandler not needed any more. now in view class

parent 76c4b423
......@@ -431,11 +431,11 @@
}
activate() {
this.canvas.style.background = 'green';
this.canvas.style.background = Settings.canvasColor;
}
deactivate() {
this.canvas.style.background = 'grey';
this.canvas.style.background = 'darkred';
}
_updateCurrentPosition() {
......@@ -458,4 +458,131 @@
GUI.writeToStats("RMB down", this.RMBDown);
}
keyDown(keyCode) {
switch (keyCode) {
case Key.Space:
if (Logic.currentState instanceof IdleState) {
Logic.setState(new MeasureState());
Application.redrawAllViews();
}
break;
case Key.G:
if (!Selection.noSelection()) {
if (Input.isKeyDown(Key.Alt))
LineManipulator.resetPosition();
else
Logic.setState(new MoveLinesState());
Application.redrawAllViews();
}
break;
case Key.R:
if (!Selection.noSelection()) {
if (Input.isKeyDown(Key.Shift))
LineManipulator.rotateSelectionBy(90);
else if (Input.isKeyDown(Key.Control))
LineManipulator.rotateSelectionBy(-90);
else if (Input.isKeyDown(Key.Alt))
LineManipulator.resetRotation();
else
Logic.setState(new RotateState());
Application.redrawAllViews();
}
break;
case Key.S:
if (!Input.isKeyDown(Key.Control) && !Input.isKeyDown(Key.Shift))
if (!Selection.noSelection()) {
if (Input.isKeyDown(Key.Alt))
LineManipulator.resetScale();
else
Logic.setState(new ScaleState());
Application.redrawAllViews();
}
break;
case Key.D:
if (Input.isKeyDown(Key.Shift)) {
if (Logic.currentState instanceof IdleState || Logic.currentState instanceof MoveLinesState) {
if (!Selection.noSelection()) {
Selection.duplicate();
Logic.setState(new MoveLinesState());
}
}
}
else {
if (Logic.currentState instanceof IdleState) {
Logic.setState(new ContinousDrawingState());
}
}
break;
case Key.Tab:
if (!Logic.isPreviewing()) {
Logic.isRenderPreviewing = true;
Renderer.setQualitySetting("quality");
Application.redrawAllViews();
}
break;
case Key.K:
if (Logic.currentState instanceof IdleState)
Utilities.cutWithSelection();
break;
case Key.Escape:
Logic._clearStates();
break;
case Key.Control:
MouseHandler.updateCurrentPosition();
Application.redrawAllViews();
break;
case Key.E:
Utilities.extrudeSelection();
break;
}
}
keyUp(keyCode) {
switch (keyCode) {
case Key.Space:
if (Logic.currentState instanceof MeasureState)
Logic.setState(new IdleState());
break;
case Key.Tab:
if (Logic.isPreviewing()) {
Logic.isRenderPreviewing = false;
Renderer.setQualitySetting(Preferences.qualitySetting);
Application.redrawAllViews();
}
break;
case Key.Shift:
if (Logic.currentState instanceof DrawingState) {
if (drawPolyLine) {
Logic.currentState.cancel();
Application.redrawAllViews();
}
}
drawPolyLine = false;
break;
case Key.D:
if (Logic.currentState instanceof ContinousDrawingState) {
if (!Logic.currentState.used && !Selection.noSelection()) {
Selection.duplicate();
Logic.setState(new MoveLinesState());
}
else
Logic.setState(Logic.previousState);
}
break;
case Key.Control:
MouseHandler.updateCurrentPosition();
Application.redrawAllViews();
break;
}
}
}
\ No newline at end of file
class CanvasKeyHandler {
constructor() {
console.log("CanvasKeyHandler created.");
}
static keyDown(keyCode) {
switch (keyCode) {
case Key.Space:
if (Logic.currentState instanceof IdleState) {
Logic.setState(new MeasureState());
Application.redrawAllViews();
}
break;
case Key.G:
if (!Selection.noSelection()) {
if (Input.isKeyDown(Key.Alt))
LineManipulator.resetPosition();
else
Logic.setState(new MoveLinesState());
Application.redrawAllViews();
}
break;
case Key.R:
if (!Selection.noSelection()) {
if (Input.isKeyDown(Key.Shift))
LineManipulator.rotateSelectionBy(90);
else if (Input.isKeyDown(Key.Control))
LineManipulator.rotateSelectionBy(-90);
else if (Input.isKeyDown(Key.Alt))
LineManipulator.resetRotation();
else
Logic.setState(new RotateState());
Application.redrawAllViews();
}
break;
case Key.S:
if (!Input.isKeyDown(Key.Control) && !Input.isKeyDown(Key.Shift))
if (!Selection.noSelection()) {
if (Input.isKeyDown(Key.Alt))
LineManipulator.resetScale();
else
Logic.setState(new ScaleState());
Application.redrawAllViews();
}
break;
case Key.D:
if (Input.isKeyDown(Key.Shift)) {
if (Logic.currentState instanceof IdleState || Logic.currentState instanceof MoveLinesState) {
if (!Selection.noSelection()) {
Selection.duplicate();
Logic.setState(new MoveLinesState());
}
}
}
else {
if (Logic.currentState instanceof IdleState) {
Logic.setState(new ContinousDrawingState());
}
}
break;
case Key.Tab:
if (!Logic.isPreviewing()) {
Logic.isRenderPreviewing = true;
Renderer.setQualitySetting("quality");
Application.redrawAllViews();
}
break;
case Key.K:
if (Logic.currentState instanceof IdleState)
Utilities.cutWithSelection();
break;
case Key.Escape:
Logic._clearStates();
break;
case Key.Control:
MouseHandler.updateCurrentPosition();
Application.redrawAllViews();
break;
case Key.E:
Utilities.extrudeSelection();
break;
}
}
static keyUp(keyCode) {
switch (keyCode) {
case Key.Space:
if (Logic.currentState instanceof MeasureState)
Logic.setState(new IdleState());
break;
case Key.Tab:
if (Logic.isPreviewing()) {
Logic.isRenderPreviewing = false;
Renderer.setQualitySetting(Preferences.qualitySetting);
Application.redrawAllViews();
}
break;
case Key.Shift:
if (Logic.currentState instanceof DrawingState) {
if (drawPolyLine) {
Logic.currentState.cancel();
Application.redrawAllViews();
}
}
drawPolyLine = false;
break;
case Key.D:
if (Logic.currentState instanceof ContinousDrawingState) {
if (!Logic.currentState.used && !Selection.noSelection()) {
Selection.duplicate();
Logic.setState(new MoveLinesState());
}
else
Logic.setState(Logic.previousState);
}
break;
case Key.Control:
MouseHandler.updateCurrentPosition();
Application.redrawAllViews();
break;
}
}
}
\ No newline at end of file
......@@ -39,11 +39,12 @@ class Input {
default:
break;
}
// WIP new structure --> always false
if (MouseHandler.canvasFocused)
Logic.currentState.keyDown(e.keyCode);
if (MouseHandler.canvasFocused)
CanvasKeyHandler.keyDown(e.keyCode);
Application.currentView.keyDown(e.keyCode);
if (!MouseHandler.canvasFocused) {
if (e.keyCode == Key.Enter) {
......@@ -78,11 +79,11 @@ class Input {
switch (e.keyCode) {
default:
// WIP new structure --> always false
if (MouseHandler.canvasFocused)
Logic.currentState.keyUp(e.keyCode);
if (MouseHandler.canvasFocused)
CanvasKeyHandler.keyUp(e.keyCode);
Application.currentView.keyDown(e.keyCode);
break;
}
......
......@@ -236,8 +236,6 @@
}
tmpRedraw() {
console.log("tmpRedraw")
this.currentContext.clearRect(0, 0, this.view.canvas.width, this.view.canvas.height);
this.screenBounds = this.view.camera.getVisibleBounds();
......
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