Browse Source

CTRLPainter now listens for keyboard shortcuts 'ctrl+z' and 'ctrl+y' to undo and redo (respectively) any drawing on active surfaces.

dev
Bryan Miller 5 years ago
parent
commit
085e732488
1 changed files with 27 additions and 1 deletions
  1. +27
    -1
      app/js/ctrls/CTRLPainter.js

+ 27
- 1
app/js/ctrls/CTRLPainter.js View File

@@ -70,6 +70,9 @@ class CTRLPainter {
this.__surface = null;
this.__palette = null;


this.__snapshotTriggered = false;

// var self = this;

var RenderD = Utils.throttle((function(){
@@ -195,8 +198,11 @@ class CTRLPainter {
var sx = (e.isCombo) ? Math.floor((this.__brushLastPos[0] - this.__offset[0]) * (1.0 / this.__scale)) : x;
var sy = (e.isCombo) ? Math.floor((this.__brushLastPos[1] - this.__offset[1]) * (1.0 / this.__scale)) : y;
if (x >= 0 && x < this.__surface.width && y >= 0 && y < this.__surface.height){
if (!this.__snapshotTriggered){
this.__snapshotTriggered = true;
this.__surface.snapshot();
}
LineToSurface(sx, sy, x, y, this.__brushColor, this.__brushPalette);
//RenderD();
}
}
}
@@ -204,6 +210,25 @@ class CTRLPainter {
input.listen("mouseclick", handle_draw);
input.listen("mouseleft+mousemove", handle_draw);

var handle_mouseup = (function(e){
this.__snapshotTriggered = false;
}).bind(this);
input.listen("mouseup", handle_mouseup);

var handle_undo = (function(e){
if (this.__surface !== null){
this.__surface.undo();
}
}).bind(this);
input.listen("ctrl+z", handle_undo);

var handle_redo = (function(e){
if (this.__surface !== null){
this.__surface.redo();
}
}).bind(this);
input.listen("ctrl+y", handle_redo);

var handle_offset = (function(e){
this.__offset[0] += e.x - e.lastX;
this.__offset[1] += e.y - e.lastY;
@@ -313,6 +338,7 @@ class CTRLPainter {
context.imageSmoothingEnabled = false;
ResizeCanvasImg(canvas.clientWidth, canvas.clientHeight); // A forced "resize".
input.enableMouseInput(true, canvas);
input.enableKeyboardInput(true);
//input.mouseTargetElement = canvas;

this.scale_to_fit();

Loading…
Cancel
Save