diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/app.js | 29 | ||||
| -rw-r--r-- | js/lex.js | 9 | ||||
| -rw-r--r-- | js/matrix.js | 14 | ||||
| -rw-r--r-- | js/tool.js | 1 |
4 files changed, 45 insertions, 8 deletions
@@ -101,11 +101,14 @@ function build () { } function bind () { canvas.forEach(function(lex, x, y){ + lex.span.addEventListener('contextmenu', function(e){ + e.preventDefault() + }) lex.span.addEventListener('mousedown', function(e){ e.preventDefault() dragging = true if (drawing) { - erasing = e.which == "3" + erasing = (e.which == "3" || e.ctrlKey) draw(lex, x, y, erasing) } else { @@ -173,10 +176,21 @@ function bind () { if (! e.metaKey && ! e.ctrlKey && ! e.altKey) { e.preventDefault() } + console.log(e.keyCode) switch (e.keyCode) { case 27: // esc if (focused) focused.blur() break + case 219: // [ + if (! focused && current_tool.name != "text") { + brush.contract(1) + break + } + case 221: // ] + if (! focused && current_tool.name != "text") { + brush.expand(1) + break + } default: if (focused) focused.key(String.fromCharCode(e.keyCode), e.keyCode) break @@ -191,7 +205,6 @@ function int_key (f) { } - function draw (lex, x, y, erasing) { stamp (canvas, brush, x, y, erasing) } @@ -201,13 +214,17 @@ function stamp (canvas, brush, x, y, erasing) { s += x-hh t += y-hh if (s >= 0 && s < canvas.w && t >= 0 && t < canvas.h) { - canvas.aa[t][s].clone(lex) + if (erasing) { + canvas.aa[t][s].erase(lex) + } + else { + canvas.aa[t][s].clone(lex) + } } }) } -function mod (i,n) { - return i - n * Math.floor(i / n) -} +function clamp (n,a,b){ return n < a ? a : n < b ? n : b } +function mod (i,n) { return i - n * Math.floor(i / n) } document.body.addEventListener('copy', function (e) { if (e.clipboardData) { @@ -31,12 +31,19 @@ Lex.prototype.irc = function(){ } } Lex.prototype.clone = function (lex){ - if (! erasing && lex.isClear()) return + if (lex.isClear()) return this.fg = lex.fg this.bg = lex.bg this.char = lex.char this.build() } +Lex.prototype.erase = function (lex){ + if (lex.isClear()) return + this.fg = colors.white + this.bg = colors.black + this.char = " " + this.build() +} Lex.prototype.fill = function(fg,bg){ this.fg = fg this.bg = bg diff --git a/js/matrix.js b/js/matrix.js index ff734bf..8108568 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -87,4 +87,16 @@ Matrix.prototype.ascii = function () { }).filter(function(line){ return line.length > 0 }) var txt = '/exec -out printf "' + lines.join("\\n") + '"\n' return txt -}
\ No newline at end of file +} +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){ + brush.expand(-i) +} @@ -1,5 +1,6 @@ function Tool (span) { this.lex = new Lex (span) + this.name = span.innerHTML this.span = span } Tool.prototype.use = function(){} |
