Moved dirty bit into the state
This commit is contained in:
parent
c36ef787d3
commit
2b8368d63b
|
@ -31,7 +31,6 @@ ascii.Controller.prototype.handlePress = function(position) {
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
if (this.dragOrigin == null && this.pressVector != null) {
|
if (this.dragOrigin == null && this.pressVector != null) {
|
||||||
this.drawFunction.start(this.view.screenToCell(position));
|
this.drawFunction.start(this.view.screenToCell(position));
|
||||||
this.view.dirty = true;
|
|
||||||
}
|
}
|
||||||
// TODO: Skip this if release happens before timeout.
|
// TODO: Skip this if release happens before timeout.
|
||||||
}.bind(this), DRAG_LATENCY);
|
}.bind(this), DRAG_LATENCY);
|
||||||
|
@ -62,7 +61,6 @@ ascii.Controller.prototype.handleMove = function(position) {
|
||||||
!this.view.screenToCell(position)
|
!this.view.screenToCell(position)
|
||||||
.equals(this.view.screenToCell(this.lastMoveCell)))) {
|
.equals(this.view.screenToCell(this.lastMoveCell)))) {
|
||||||
this.drawFunction.move(this.view.screenToCell(position));
|
this.drawFunction.move(this.view.screenToCell(position));
|
||||||
this.view.dirty = true;
|
|
||||||
this.lastMoveCell = position;
|
this.lastMoveCell = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +81,6 @@ ascii.Controller.prototype.handleRelease = function(position) {
|
||||||
if (this.dragOrigin == null &&
|
if (this.dragOrigin == null &&
|
||||||
($.now() - this.pressTimestamp) >= DRAG_LATENCY) {
|
($.now() - this.pressTimestamp) >= DRAG_LATENCY) {
|
||||||
this.drawFunction.end(this.view.screenToCell(position));
|
this.drawFunction.end(this.view.screenToCell(position));
|
||||||
this.view.dirty = true;
|
|
||||||
}
|
}
|
||||||
this.pressVector = null;
|
this.pressVector = null;
|
||||||
this.pressTimestamp = 0;
|
this.pressTimestamp = 0;
|
||||||
|
@ -156,7 +153,6 @@ ascii.Controller.prototype.installBindings = function() {
|
||||||
|
|
||||||
$('#undo-button').click(function(e) {
|
$('#undo-button').click(function(e) {
|
||||||
this.state.undo();
|
this.state.undo();
|
||||||
this.view.dirty = true;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
$('#import-submit-button').click(function(e) {
|
$('#import-submit-button').click(function(e) {
|
||||||
|
@ -166,7 +162,6 @@ ascii.Controller.prototype.installBindings = function() {
|
||||||
this.view.canvas.width / 4,
|
this.view.canvas.width / 4,
|
||||||
this.view.canvas.height / 4)));
|
this.view.canvas.height / 4)));
|
||||||
$('#import-area').val('');
|
$('#import-area').val('');
|
||||||
this.view.dirty = true;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
$(window).keypress(function(e) {
|
$(window).keypress(function(e) {
|
||||||
|
@ -213,7 +208,6 @@ ascii.Controller.prototype.updateButtons = function(id) {
|
||||||
}
|
}
|
||||||
if (id == 'clear-button') {
|
if (id == 'clear-button') {
|
||||||
this.state.clear();
|
this.state.clear();
|
||||||
this.view.dirty = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -224,7 +218,6 @@ ascii.Controller.prototype.updateButtons = function(id) {
|
||||||
ascii.Controller.prototype.handleKeyPress = function(event) {
|
ascii.Controller.prototype.handleKeyPress = function(event) {
|
||||||
if (!event.ctrlKey && !event.metaKey && event.keyCode != 13) {
|
if (!event.ctrlKey && !event.metaKey && event.keyCode != 13) {
|
||||||
this.drawFunction.handleKey(String.fromCharCode(event.keyCode));
|
this.drawFunction.handleKey(String.fromCharCode(event.keyCode));
|
||||||
this.view.dirty = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -239,7 +232,7 @@ ascii.Controller.prototype.handleKeyDown = function(event) {
|
||||||
if (event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
if (event.keyCode == 67) { specialKeyCode = KEY_COPY; }
|
if (event.keyCode == 67) { specialKeyCode = KEY_COPY; }
|
||||||
if (event.keyCode == 86) { specialKeyCode = KEY_PASTE; }
|
if (event.keyCode == 86) { specialKeyCode = KEY_PASTE; }
|
||||||
if (event.keyCode == 90) { this.state.undo(); this.view.dirty = true; }
|
if (event.keyCode == 90) { this.state.undo(); }
|
||||||
// if (event.keyCode == 89) { this.state.redo(); }
|
// if (event.keyCode == 89) { this.state.redo(); }
|
||||||
if (event.keyCode == 88) { specialKeyCode = KEY_CUT; }
|
if (event.keyCode == 88) { specialKeyCode = KEY_CUT; }
|
||||||
}
|
}
|
||||||
|
@ -255,7 +248,6 @@ ascii.Controller.prototype.handleKeyDown = function(event) {
|
||||||
//event.preventDefault();
|
//event.preventDefault();
|
||||||
//event.stopPropagation();
|
//event.stopPropagation();
|
||||||
this.drawFunction.handleKey(specialKeyCode);
|
this.drawFunction.handleKey(specialKeyCode);
|
||||||
this.view.dirty = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ ascii.State = function() {
|
||||||
this.cells = new Array(MAX_GRID_WIDTH);
|
this.cells = new Array(MAX_GRID_WIDTH);
|
||||||
/** @type {Array.<ascii.MappedCell>} */
|
/** @type {Array.<ascii.MappedCell>} */
|
||||||
this.scratchCells = new Array();
|
this.scratchCells = new Array();
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.dirty = true;
|
||||||
|
|
||||||
/** @type {Array.<Array.<ascii.MappedValue>>} */
|
/** @type {Array.<Array.<ascii.MappedValue>>} */
|
||||||
this.undoStates = new Array();
|
this.undoStates = new Array();
|
||||||
|
@ -46,17 +48,6 @@ ascii.State.prototype.getCell = function(vector) {
|
||||||
return this.cells[vector.x][vector.y];
|
return this.cells[vector.x][vector.y];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the cells value at the given position. Probably shouldn't
|
|
||||||
* be used directly in many cases. Used drawValue instead.
|
|
||||||
*
|
|
||||||
* @param {ascii.Vector} position
|
|
||||||
* @param {?string} value
|
|
||||||
*/
|
|
||||||
ascii.State.prototype.setValue = function(position, value) {
|
|
||||||
this.getCell(position).value = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the cells scratch (uncommitted) value at the given position.
|
* Sets the cells scratch (uncommitted) value at the given position.
|
||||||
*
|
*
|
||||||
|
@ -67,6 +58,7 @@ ascii.State.prototype.drawValue = function(position, value) {
|
||||||
var cell = this.getCell(position);
|
var cell = this.getCell(position);
|
||||||
this.scratchCells.push(new ascii.MappedCell(position, cell));
|
this.scratchCells.push(new ascii.MappedCell(position, cell));
|
||||||
cell.scratchValue = value;
|
cell.scratchValue = value;
|
||||||
|
this.dirty = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,6 +164,7 @@ ascii.State.prototype.commitDraw = function(opt_skipSave) {
|
||||||
}
|
}
|
||||||
this.undoStates.push(oldValues);
|
this.undoStates.push(oldValues);
|
||||||
}
|
}
|
||||||
|
this.dirty = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,8 +30,9 @@ ascii.View.prototype.resizeCanvas = function() {
|
||||||
* Starts the animation loop for the canvas. Should only be called once.
|
* Starts the animation loop for the canvas. Should only be called once.
|
||||||
*/
|
*/
|
||||||
ascii.View.prototype.animate = function() {
|
ascii.View.prototype.animate = function() {
|
||||||
if (this.dirty) {
|
if (this.dirty || this.state.dirty) {
|
||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
|
this.state.dirty = false;
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
var view = this;
|
var view = this;
|
||||||
|
|
Loading…
Reference in New Issue