diff --git a/js-lib/common.js b/js-lib/common.js index 3139efe..a8eeb99 100644 --- a/js-lib/common.js +++ b/js-lib/common.js @@ -4,12 +4,14 @@ goog.provide('ascii'); -/** @const */ var MAX_GRID_SIZE = 1000; +/** @const */ var MAX_GRID_WIDTH = 2000; +/** @const */ var MAX_GRID_HEIGHT = 600; + /** @const */ var SPECIAL_VALUE = '+'; /** @const */ var MAX_UNDO = 50; -/** @const */ var SPECIAL_LINE_H = '\u2014'; +/** @const */ var SPECIAL_LINE_H = '\u2013'; /** @const */ var SPECIAL_LINE_V = '|'; /** @const */ var ERASE_CHAR = '\u2009'; @@ -17,8 +19,8 @@ goog.provide('ascii'); /** @const */ var DRAG_LATENCY = 130; // Milliseconds. /** @const */ var DRAG_ACCURACY = 3; // Pixels. -/** @const */ var CHAR_PIXELS_H = 11; -/** @const */ var CHAR_PIXELS_V = 15; +/** @const */ var CHAR_PIXELS_H = 9; +/** @const */ var CHAR_PIXELS_V = 17; /** @const */ var RENDER_PADDING = 70; diff --git a/js-lib/controller.js b/js-lib/controller.js index 816ad74..4620709 100644 --- a/js-lib/controller.js +++ b/js-lib/controller.js @@ -163,8 +163,8 @@ ascii.Controller.prototype.installBindings = function() { this.state.clear(); this.state.fromText($('#import-area').val(), this.view.screenToCell(new ascii.Vector( - this.view.canvas.width / 2, - this.view.canvas.height / 3))); + this.view.canvas.width / 4, + this.view.canvas.height / 4))); $('#import-area').val(''); this.view.dirty = true; }.bind(this)); diff --git a/js-lib/state.js b/js-lib/state.js index fa3bdd5..9090336 100644 --- a/js-lib/state.js +++ b/js-lib/state.js @@ -6,7 +6,7 @@ */ ascii.State = function() { /** @type {Array.>} */ - this.cells = new Array(MAX_GRID_SIZE); + this.cells = new Array(MAX_GRID_WIDTH); /** @type {Array.} */ this.scratchCells = new Array(); @@ -14,7 +14,7 @@ ascii.State = function() { this.undoStates = new Array(); for (var i = 0; i < this.cells.length; i++) { - this.cells[i] = new Array(MAX_GRID_SIZE); + this.cells[i] = new Array(MAX_GRID_HEIGHT); for (var j = 0; j < this.cells[i].length; j++) { this.cells[i][j] = new ascii.Cell(); } @@ -217,7 +217,14 @@ ascii.State.prototype.fromText = function(value, offset) { for (var j = 0; j < lines.length; j++) { var line = lines[j]; for (var i = 0; i < line.length; i++) { - this.drawValue(new ascii.Vector(i, j).add(offset), line.charAt(i)); + var char = line.charAt(i); + // Convert special output back to special chars. + // TODO: This is a horrible hack, need to handle multiple special chars + // correctly and preserve them through line drawing etc. + if (char == SPECIAL_LINE_H || char == SPECIAL_LINE_V) { + char = SPECIAL_VALUE; + } + this.drawValue(new ascii.Vector(i, j).add(offset), char); } } this.commitDraw(); diff --git a/js-lib/view.js b/js-lib/view.js index 836f975..628d882 100644 --- a/js-lib/view.js +++ b/js-lib/view.js @@ -102,7 +102,7 @@ ascii.View.prototype.render = function() { if (cellValue != null) { this.context.fillStyle = '#000000'; context.fillText(cellValue, - i * CHAR_PIXELS_H - this.offset.x + 1, + i * CHAR_PIXELS_H - this.offset.x, j * CHAR_PIXELS_V - this.offset.y - 3); } } @@ -153,9 +153,10 @@ ascii.View.prototype.frameToScreen = function(vector) { * @return {ascii.Vector} */ ascii.View.prototype.frameToCell = function(vector) { + // We limit the edges in a bit, as most drawing needs a full context to work. return new ascii.Vector( - Math.min(Math.max(0, Math.round((vector.x - CHAR_PIXELS_H / 2) / CHAR_PIXELS_H)), MAX_GRID_SIZE), - Math.min(Math.max(0, Math.round((vector.y + CHAR_PIXELS_V / 2) / CHAR_PIXELS_V)), MAX_GRID_SIZE)); + Math.min(Math.max(1, Math.round((vector.x - CHAR_PIXELS_H / 2) / CHAR_PIXELS_H)), MAX_GRID_WIDTH - 2), + Math.min(Math.max(1, Math.round((vector.y + CHAR_PIXELS_V / 2) / CHAR_PIXELS_V)), MAX_GRID_HEIGHT - 2)); }; /**