summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-11-21 13:50:30 -0500
committerJules Laplace <jules@okfoc.us>2014-11-21 13:50:30 -0500
commite46886c6382bd2517eca07826e9a2cf6cb353962 (patch)
tree73ac7463f82525a568d6baff09473179733f3289 /js
parentfea42b1513e321b6c397c914327a9a4a7d96e331 (diff)
right/left bracket to resize brush
Diffstat (limited to 'js')
-rw-r--r--js/app.js29
-rw-r--r--js/lex.js9
-rw-r--r--js/matrix.js14
-rw-r--r--js/tool.js1
4 files changed, 45 insertions, 8 deletions
diff --git a/js/app.js b/js/app.js
index 480b20c..3d70bcb 100644
--- a/js/app.js
+++ b/js/app.js
@@ -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) {
diff --git a/js/lex.js b/js/lex.js
index 39a47cd..ed4679d 100644
--- a/js/lex.js
+++ b/js/lex.js
@@ -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)
+}
diff --git a/js/tool.js b/js/tool.js
index 3b9b803..43a00bf 100644
--- a/js/tool.js
+++ b/js/tool.js
@@ -1,5 +1,6 @@
function Tool (span) {
this.lex = new Lex (span)
+ this.name = span.innerHTML
this.span = span
}
Tool.prototype.use = function(){}