Added clear method and removed edge of screen bug

This commit is contained in:
Lewis Hemens 2014-01-22 22:57:33 +00:00
parent bc79014d0b
commit 1c3c668247
5 changed files with 21 additions and 20 deletions

View File

@ -46,10 +46,11 @@ button.active {
background: #D0E0FF; background: #D0E0FF;
} }
#export-button, #import-button { button.file {
background: #D8D8D8; background: #D8D8D8;
} }
#export-button.active, #import-button.active {
button.file.active {
background: #C8C8C8; background: #C8C8C8;
} }
@ -73,17 +74,7 @@ button.active {
margin: 0px; margin: 0px;
} }
#export-area, #import-area { textarea {
width: 380px;
height: 280px;
overflow: hidden;
resize: none;
margin: 5px;
font-family: monospace;
white-space: pre;
}
#input-area {
width: 380px; width: 380px;
height: 280px; height: 280px;
overflow: hidden; overflow: hidden;
@ -106,8 +97,9 @@ button.active {
</pre></div> </pre></div>
<div id="menu"> <div id="menu">
<div id="buttons"> <div id="buttons">
<button id="export-button" class="tool">Export</button> <button id="export-button" class="file tool">Export</button>
<button id="import-button" class="tool">Import</button> <button id="import-button" class="file tool">Import</button>
<button id="clear-button" class="file tool">Clear</button>
<button id="box-button" class="tool active">Box</button> <button id="box-button" class="tool active">Box</button>
<button id="line-button" class="tool">Line</button> <button id="line-button" class="tool">Line</button>

View File

@ -160,7 +160,7 @@ ascii.Controller.prototype.installBindings = function() {
}.bind(this)); }.bind(this));
$('#import-submit-button').click(function(e) { $('#import-submit-button').click(function(e) {
this.state.clearCanvas(); this.state.clear();
this.state.fromText($('#import-area').val(), this.state.fromText($('#import-area').val(),
this.view.screenToCell(new ascii.Vector( this.view.screenToCell(new ascii.Vector(
this.view.canvas.width / 2, this.view.canvas.width / 2,
@ -211,6 +211,10 @@ ascii.Controller.prototype.updateButtons = function(id) {
if (id == 'export-button') { if (id == 'export-button') {
$('#export-area').val(this.state.outputText()); $('#export-area').val(this.state.outputText());
} }
if (id == 'clear-button') {
this.state.clear();
this.view.dirty = true;
}
}; };
/** /**

View File

@ -135,7 +135,12 @@ ascii.DrawFreeform.prototype.end = function(position) {
ascii.DrawFreeform.prototype.getCursor = function(position) { ascii.DrawFreeform.prototype.getCursor = function(position) {
return 'crosshair'; return 'crosshair';
}; };
ascii.DrawFreeform.prototype.handleKey = function(value) {}; ascii.DrawFreeform.prototype.handleKey = function(value) {
if (value.length == 1) {
// The value is not a special character, so lets use it.
this.value = value;
}
};
/** /**
* @constructor * @constructor

View File

@ -24,7 +24,7 @@ ascii.State = function() {
/** /**
* This clears the entire state, but is undoable. * This clears the entire state, but is undoable.
*/ */
ascii.State.prototype.clearCanvas = function() { ascii.State.prototype.clear = function() {
for (var i = 0; i < this.cells.length; i++) { for (var i = 0; i < this.cells.length; i++) {
for (var j = 0; j < this.cells[i].length; j++) { for (var j = 0; j < this.cells[i].length; j++) {
var position = new ascii.Vector(i, j); var position = new ascii.Vector(i, j);

View File

@ -154,8 +154,8 @@ ascii.View.prototype.frameToScreen = function(vector) {
*/ */
ascii.View.prototype.frameToCell = function(vector) { ascii.View.prototype.frameToCell = function(vector) {
return new ascii.Vector( return new ascii.Vector(
Math.round((vector.x - CHAR_PIXELS_H / 2) / CHAR_PIXELS_H), Math.min(Math.max(0, Math.round((vector.x - CHAR_PIXELS_H / 2) / CHAR_PIXELS_H)), MAX_GRID_SIZE),
Math.round((vector.y + CHAR_PIXELS_V / 2) / CHAR_PIXELS_V)); Math.min(Math.max(0, Math.round((vector.y + CHAR_PIXELS_V / 2) / CHAR_PIXELS_V)), MAX_GRID_SIZE));
}; };
/** /**