diff options
| author | Julie Lala <jules@okfoc.us> | 2015-05-01 02:14:59 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2015-05-01 02:14:59 -0400 |
| commit | 41c77a3357596c566d5b89283980e8d06f84c778 (patch) | |
| tree | 7f6c54c0c08eafbd097c12000f6b5453b86e18fb /js | |
| parent | 8b83fb2bafcf11b1981535f6dbc364db15153d87 (diff) | |
save custom brushes
Diffstat (limited to 'js')
| -rw-r--r-- | js/blit.js | 8 | ||||
| -rw-r--r-- | js/draw.js | 4 | ||||
| -rw-r--r-- | js/lex.js | 7 | ||||
| -rw-r--r-- | js/matrix.js | 33 | ||||
| -rw-r--r-- | js/ui/controls.js | 5 | ||||
| -rw-r--r-- | js/ui/custom.js | 24 |
6 files changed, 67 insertions, 14 deletions
@@ -5,7 +5,7 @@ var blit = (function(){ B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell && lex.opacity > 0) { - cell.clone(lex) + cell.assign(lex) } }) } @@ -14,7 +14,7 @@ var blit = (function(){ B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell && cell.opacity == 0) { - cell.clone(lex) + cell.assign(lex) } }) } @@ -24,7 +24,7 @@ var blit = (function(){ B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell) { - lex.clone(cell) + lex.assign(cell) } }) } @@ -33,7 +33,7 @@ var blit = (function(){ B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell) { - cell.clone(lex) + cell.assign(lex) } }) } @@ -55,7 +55,7 @@ var draw = (function(){ function fill (lex, x, y) { var q = [ [x,y] ] - var target = canvas.aa[y][x].copy() + var target = canvas.aa[y][x].clone() var n, w = 0, e = 0, j = 0 var kk = 0 // gets into a weird infinite loop if we don't break here.. :\ @@ -84,7 +84,7 @@ var draw = (function(){ } } for (var i = w; i <= e; i++) { - canvas.aa[j][i].clone(lex) + canvas.aa[j][i].assign(lex) if (j > 0 && canvas.aa[j-1][i].eq(target)) { q.push([ i, j-1 ]) } @@ -51,8 +51,7 @@ Lex.prototype.mirc = function(){ return "\x03" + (this.fg&15) + "," + (this.bg&15) + char } } -Lex.prototype.clone = function (lex){ - if (lex.opacity == 0) return +Lex.prototype.assign = function (lex){ this.fg = lex.fg this.bg = lex.bg this.char = lex.char @@ -67,9 +66,9 @@ Lex.prototype.paint = function (lex){ this.opacity = 1 this.build() } -Lex.prototype.copy = function () { +Lex.prototype.clone = function () { var lex = new Lex (0,0) - lex.clone(this) + lex.assign(this) return lex } Lex.prototype.erase = function (){ diff --git a/js/matrix.js b/js/matrix.js index 732820e..b1d80f6 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -6,8 +6,8 @@ function Matrix (w,h,f){ this.f = f this.initialize() } -Matrix.prototype.initialize = function(){ - var w = this.w || 1, h = this.h || 1, f = this.f +Matrix.prototype.initialize = function(f){ + var w = this.w || 1, h = this.h || 1, f = f || this.f var aa = new Array (h) for (var y = 0; y < h; y++) { aa[y] = new Array (w) @@ -23,9 +23,34 @@ Matrix.prototype.rebuild = function (){ this.append() this.bind() this.generate && this.generate() - // the focused character might disappear after resizing + // the focused character might disappear after resizing.. focused = canvas.aa[0][0] } +Matrix.prototype.clone = function () { + var base = this + var clone = new Matrix(this.w, this.h, function(x,y){ + return base.getCell(x,y).clone() + }) + clone.f = this.f + return clone +} +Matrix.prototype.assign = function (mat) { + var base = this + this.demolish() + this.w = mat.w + this.h = mat.h + this.f = function(){} + this.initialize(function(x,y){ + var el = mat.getCell(x,y).clone() + el.build() + return el + }) + this.append() + this.bind() + focused = canvas.aa[0][0] + return this +} + Matrix.prototype.bind = function () {} Matrix.prototype.demolish = function (){ this.forEach(function(lex){ @@ -94,7 +119,7 @@ Matrix.prototype.region = function(w,h,x,y) { return mat } Matrix.prototype.setCell = function(lex,x,y){ - this.aa[y] && this.aa[y][x] && this.aa[y][x].clone(lex) + this.aa[y] && this.aa[y][x] && this.aa[y][x].assign(lex) } Matrix.prototype.getCell = function(x,y){ if (this.aa[y] && this.aa[y][x]) return this.aa[y][x] diff --git a/js/ui/controls.js b/js/ui/controls.js index 661f881..9ea58f5 100644 --- a/js/ui/controls.js +++ b/js/ui/controls.js @@ -254,6 +254,11 @@ var controls = (function(){ controls.canvas_height.build() canvas.resize(canvas.w, h) } + + add_custom_el.addEventListener("click", function(){ + custom.clone() + }) + } function int_key (f) { diff --git a/js/ui/custom.js b/js/ui/custom.js new file mode 100644 index 0000000..a758d48 --- /dev/null +++ b/js/ui/custom.js @@ -0,0 +1,24 @@ +var custom = (function(){ + + var exports = {} + + exports.clone = function (){ + var new_brush = brush.clone() + var rapper = document.createElement("div") + rapper.className = "custom" + new_brush.append(rapper) + custom_rapper.appendChild(rapper) + // store in localstorage? + rapper.addEventListener("click", function(){ + // load this brush + exports.load(new_brush) + }) + } + + exports.load = function(new_brush){ + brush.assign( new_brush ) + } + + return exports + +})() |
