summaryrefslogtreecommitdiff
path: root/js/matrix.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/matrix.js')
-rw-r--r--js/matrix.js73
1 files changed, 61 insertions, 12 deletions
diff --git a/js/matrix.js b/js/matrix.js
index 0bb2492..79f3d9f 100644
--- a/js/matrix.js
+++ b/js/matrix.js
@@ -89,7 +89,68 @@ Matrix.prototype.region = function(w,h,x,y) {
return parent.aa[y][x]
})
mat.f = this.f
+ return mat
}
+Matrix.prototype.setCell = function(lex,x,y){
+ this.aa[y] && this.aa[y][x] && this.aa[y][x].clone(lex)
+}
+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 = ""
@@ -152,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)
-}