소스 검색

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 년 전
부모
커밋
085e732488
1개의 변경된 파일27개의 추가작업 그리고 1개의 파일을 삭제
  1. +27
    -1
      app/js/ctrls/CTRLPainter.js

+ 27
- 1
app/js/ctrls/CTRLPainter.js 파일 보기

this.__surface = null; this.__surface = null;
this.__palette = null; this.__palette = null;



this.__snapshotTriggered = false;

// var self = this; // var self = this;


var RenderD = Utils.throttle((function(){ var RenderD = Utils.throttle((function(){
var sx = (e.isCombo) ? Math.floor((this.__brushLastPos[0] - this.__offset[0]) * (1.0 / this.__scale)) : x; 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; 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 (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); LineToSurface(sx, sy, x, y, this.__brushColor, this.__brushPalette);
//RenderD();
} }
} }
} }
input.listen("mouseclick", handle_draw); input.listen("mouseclick", handle_draw);
input.listen("mouseleft+mousemove", 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){ var handle_offset = (function(e){
this.__offset[0] += e.x - e.lastX; this.__offset[0] += e.x - e.lastX;
this.__offset[1] += e.y - e.lastY; this.__offset[1] += e.y - e.lastY;
context.imageSmoothingEnabled = false; context.imageSmoothingEnabled = false;
ResizeCanvasImg(canvas.clientWidth, canvas.clientHeight); // A forced "resize". ResizeCanvasImg(canvas.clientWidth, canvas.clientHeight); // A forced "resize".
input.enableMouseInput(true, canvas); input.enableMouseInput(true, canvas);
input.enableKeyboardInput(true);
//input.mouseTargetElement = canvas; //input.mouseTargetElement = canvas;


this.scale_to_fit(); this.scale_to_fit();

Loading…
취소
저장