summaryrefslogtreecommitdiff
path: root/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/app.js')
-rw-r--r--js/app.js29
1 files changed, 23 insertions, 6 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) {