From da3b3feedfe3a928dec6ac615579538a9ab5b582 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 9 Dec 2014 16:15:37 -0500 Subject: less-destructive resize; stub out selection --- js/matrix.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'js/matrix.js') diff --git a/js/matrix.js b/js/matrix.js index fd4ee4f..79f3d9f 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -98,6 +98,59 @@ Matrix.prototype.getCell = function(x,y){ if (this.aa[y] && this.aa[y][x]) return this.aa[y][x] else return null } +Matrix.prototype.resize = function(w,h){ + var div, row, lex + var f = this.f, old_h = this.h, old_w = this.w + var rapper = this.rapper + w = max(w, 1) + h = max(h, 1) + if (h < old_h) { + for (var y = old_h; y > h; y--) { + row = this.aa.pop() + div = row[0].span.parentNode + row.forEach(function(lex, x){ + lex.demolish() + }) + div.parentNode.removeChild(div) + } + } + else if (h > old_h) { + for (var y = old_h; y < h; y++) { + div = document.createElement("div") + rapper.appendChild( div ) + this.aa[y] = new Array (w) + for (var x = 0; x < w; x++) { + lex = this.aa[y][x] = f(x,y) + div.appendChild(lex.span) + } + } + } + + if (w < old_w) { + this.aa.forEach(function(row, y){ + while (row.length > w) { + lex = row.pop() + lex.demolish() + } + }) + } + else if (w > old_w) { + this.aa.forEach(function(row, y){ + div = row[0].span.parentNode + for (var x = row.length; x < w; x++) { + lex = row[x] = f(x,y) + div.appendChild(lex.span) + } + }) + } + + this.w = w + this.h = h + this.bind && this.bind() +} + +// + Matrix.prototype.ascii = function () { var lines = this.aa.map(function(row, y){ var last, line = "" @@ -160,15 +213,3 @@ Matrix.prototype.irssi = function(){ } return '/exec -out printf "' + escaped_txt + '"\n' } -Matrix.prototype.expand = function(i){ - var w = this.w = clamp(this.w+i, 1, 9), h = this.h = clamp(this.h+i, 1, 9) - console.log(w,h) - controls.width.char = ""+w - controls.width.build() - controls.height.char = ""+h - controls.height.build() - this.rebuild() -} -Matrix.prototype.contract = function(i){ - this.expand(-i) -} -- cgit v1.2.3-70-g09d2