Tweaked char dimensions, added in a hack for importing specil chars
This commit is contained in:
parent
1c3c668247
commit
360b9d255d
|
@ -4,12 +4,14 @@
|
||||||
|
|
||||||
goog.provide('ascii');
|
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 SPECIAL_VALUE = '+';
|
||||||
|
|
||||||
/** @const */ var MAX_UNDO = 50;
|
/** @const */ var MAX_UNDO = 50;
|
||||||
|
|
||||||
/** @const */ var SPECIAL_LINE_H = '\u2014';
|
/** @const */ var SPECIAL_LINE_H = '\u2013';
|
||||||
/** @const */ var SPECIAL_LINE_V = '|';
|
/** @const */ var SPECIAL_LINE_V = '|';
|
||||||
|
|
||||||
/** @const */ var ERASE_CHAR = '\u2009';
|
/** @const */ var ERASE_CHAR = '\u2009';
|
||||||
|
@ -17,8 +19,8 @@ goog.provide('ascii');
|
||||||
/** @const */ var DRAG_LATENCY = 130; // Milliseconds.
|
/** @const */ var DRAG_LATENCY = 130; // Milliseconds.
|
||||||
/** @const */ var DRAG_ACCURACY = 3; // Pixels.
|
/** @const */ var DRAG_ACCURACY = 3; // Pixels.
|
||||||
|
|
||||||
/** @const */ var CHAR_PIXELS_H = 11;
|
/** @const */ var CHAR_PIXELS_H = 9;
|
||||||
/** @const */ var CHAR_PIXELS_V = 15;
|
/** @const */ var CHAR_PIXELS_V = 17;
|
||||||
|
|
||||||
/** @const */ var RENDER_PADDING = 70;
|
/** @const */ var RENDER_PADDING = 70;
|
||||||
|
|
||||||
|
|
|
@ -163,8 +163,8 @@ ascii.Controller.prototype.installBindings = function() {
|
||||||
this.state.clear();
|
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 / 4,
|
||||||
this.view.canvas.height / 3)));
|
this.view.canvas.height / 4)));
|
||||||
$('#import-area').val('');
|
$('#import-area').val('');
|
||||||
this.view.dirty = true;
|
this.view.dirty = true;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
ascii.State = function() {
|
ascii.State = function() {
|
||||||
/** @type {Array.<Array.<ascii.Cell>>} */
|
/** @type {Array.<Array.<ascii.Cell>>} */
|
||||||
this.cells = new Array(MAX_GRID_SIZE);
|
this.cells = new Array(MAX_GRID_WIDTH);
|
||||||
/** @type {Array.<ascii.MappedCell>} */
|
/** @type {Array.<ascii.MappedCell>} */
|
||||||
this.scratchCells = new Array();
|
this.scratchCells = new Array();
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ ascii.State = function() {
|
||||||
this.undoStates = new Array();
|
this.undoStates = new Array();
|
||||||
|
|
||||||
for (var i = 0; i < this.cells.length; i++) {
|
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++) {
|
for (var j = 0; j < this.cells[i].length; j++) {
|
||||||
this.cells[i][j] = new ascii.Cell();
|
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++) {
|
for (var j = 0; j < lines.length; j++) {
|
||||||
var line = lines[j];
|
var line = lines[j];
|
||||||
for (var i = 0; i < line.length; i++) {
|
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();
|
this.commitDraw();
|
||||||
|
|
|
@ -102,7 +102,7 @@ ascii.View.prototype.render = function() {
|
||||||
if (cellValue != null) {
|
if (cellValue != null) {
|
||||||
this.context.fillStyle = '#000000';
|
this.context.fillStyle = '#000000';
|
||||||
context.fillText(cellValue,
|
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);
|
j * CHAR_PIXELS_V - this.offset.y - 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,9 +153,10 @@ ascii.View.prototype.frameToScreen = function(vector) {
|
||||||
* @return {ascii.Vector}
|
* @return {ascii.Vector}
|
||||||
*/
|
*/
|
||||||
ascii.View.prototype.frameToCell = function(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(
|
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(1, Math.round((vector.x - CHAR_PIXELS_H / 2) / CHAR_PIXELS_H)), MAX_GRID_WIDTH - 2),
|
||||||
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.y + CHAR_PIXELS_V / 2) / CHAR_PIXELS_V)), MAX_GRID_HEIGHT - 2));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue