Fixed off the edge of the screen bug

This commit is contained in:
Lewis Hemens 2014-03-25 22:32:44 +00:00
parent 45052b42f8
commit 671d527a59
2 changed files with 14 additions and 2 deletions

View File

@ -58,7 +58,7 @@ function ea(a, b) {
this.canvas = document.getElementById("ascii-canvas"); this.canvas = document.getElementById("ascii-canvas");
this.context = this.canvas.getContext("2d"); this.context = this.canvas.getContext("2d");
this.zoom = 1; this.zoom = 1;
this.offset = new l(7500, 7500); this.offset = new l(9E3, 5100);
this.d = !0; this.d = !0;
this.s = !1; this.s = !1;
A(this); A(this);
@ -84,6 +84,10 @@ function fa(a) {
b.scale(a.zoom, a.zoom); b.scale(a.zoom, a.zoom);
b.translate(a.canvas.width / 2 / a.zoom, a.canvas.height / 2 / a.zoom); b.translate(a.canvas.width / 2 / a.zoom, a.canvas.height / 2 / a.zoom);
var c = n(B(a, new l(0, 0)), new l(3, 3)), d = B(a, new l(a.canvas.width, a.canvas.height)).add(new l(3, 3)); var c = n(B(a, new l(0, 0)), new l(3, 3)), d = B(a, new l(a.canvas.width, a.canvas.height)).add(new l(3, 3));
c.x = Math.max(0, Math.min(c.x, 2E3));
d.x = Math.max(0, Math.min(d.x, 2E3));
c.y = Math.max(0, Math.min(c.y, 600));
d.y = Math.max(0, Math.min(d.y, 600));
b.lineWidth = "1"; b.lineWidth = "1";
b.strokeStyle = "#EEEEEE"; b.strokeStyle = "#EEEEEE";
b.beginPath(); b.beginPath();

View File

@ -11,7 +11,10 @@ ascii.View = function(state) {
/** @type {Object} */ this.context = this.canvas.getContext('2d'); /** @type {Object} */ this.context = this.canvas.getContext('2d');
/** @type {number} */ this.zoom = 1; /** @type {number} */ this.zoom = 1;
/** @type {ascii.Vector} */ this.offset = new ascii.Vector(7500, 7500); /** @type {ascii.Vector} */ this.offset = new ascii.Vector(
MAX_GRID_WIDTH * CHAR_PIXELS_H / 2,
MAX_GRID_HEIGHT * CHAR_PIXELS_V / 2);
/** @type {boolean} */ this.dirty = true; /** @type {boolean} */ this.dirty = true;
// TODO: Should probably save this setting in a cookie or something. // TODO: Should probably save this setting in a cookie or something.
/** @type {boolean} */ this.useLines = false; /** @type {boolean} */ this.useLines = false;
@ -70,6 +73,11 @@ ascii.View.prototype.render = function() {
.add(new ascii.Vector( .add(new ascii.Vector(
RENDER_PADDING_CELLS, RENDER_PADDING_CELLS)); RENDER_PADDING_CELLS, RENDER_PADDING_CELLS));
startOffset.x = Math.max(0, Math.min(startOffset.x, MAX_GRID_WIDTH));
endOffset.x = Math.max(0, Math.min(endOffset.x, MAX_GRID_WIDTH));
startOffset.y = Math.max(0, Math.min(startOffset.y, MAX_GRID_HEIGHT));
endOffset.y = Math.max(0, Math.min(endOffset.y, MAX_GRID_HEIGHT));
// Render the grid. // Render the grid.
context.lineWidth = '1'; context.lineWidth = '1';
context.strokeStyle = '#EEEEEE'; context.strokeStyle = '#EEEEEE';