summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/app.js8
-rw-r--r--js/lex.js1
-rw-r--r--js/ui/controls.js38
-rw-r--r--js/ui/keys.js7
4 files changed, 31 insertions, 23 deletions
diff --git a/js/app.js b/js/app.js
index fd375cf..de399bc 100644
--- a/js/app.js
+++ b/js/app.js
@@ -49,12 +49,4 @@ function bind () {
})
}
-
-function int_key (f) {
- return function (key, keyCode) {
- var n = parseInt(key)
- ! isNaN(n) && f(n)
- }
-}
-
init()
diff --git a/js/lex.js b/js/lex.js
index 18ca4c5..2dc1dd5 100644
--- a/js/lex.js
+++ b/js/lex.js
@@ -91,6 +91,7 @@ Lex.prototype.focus = function(){
Lex.prototype.blur = function(){
this.span.classList.remove('focused')
focused = null
+ this.onBlur && this.onBlur()
}
Lex.prototype.demolish = function(){
if (this.span.parentNode) { this.span.parentNode.removeChild(this.span) }
diff --git a/js/ui/controls.js b/js/ui/controls.js
index aadd3c9..e8c9abd 100644
--- a/js/ui/controls.js
+++ b/js/ui/controls.js
@@ -110,7 +110,12 @@ var controls = (function(){
// bind
controls.bind = function(){
- [controls.width, controls.height, controls.canvas_width, controls.canvas_height].forEach(function(lex){
+ [
+ controls.width,
+ controls.height,
+ controls.canvas_width,
+ controls.canvas_height
+ ].forEach(function(lex){
lex.span.addEventListener('mousedown', function(e){
lex.focus()
})
@@ -133,14 +138,14 @@ var controls = (function(){
})
controls.width.key = int_key(function(n, keyCode){
- controls.width.blur()
+ controls.width.blur()
controls.width.char = ""+n
controls.width.build()
brush.w = n
brush.rebuild()
})
controls.height.key = int_key(function(n, keyCode){
- controls.height.blur()
+ controls.height.blur()
controls.height.char = ""+n
controls.height.build()
brush.h = n
@@ -154,11 +159,20 @@ var controls = (function(){
}
controls.canvas_width.char = ""+n
controls.canvas_width.build()
- canvas.resize(n, canvas.h)
- // canvas.w = n
- // canvas.rebuild()
- // canvas.build()
})
+ controls.canvas_width.onBlur = function(){
+ var w = parseInt(controls.canvas_width.char) || 1
+ controls.canvas_width.char = w+""
+ controls.canvas_width.build()
+ canvas.resize(w, canvas.h)
+ }
+ controls.canvas_height.onBlur = function(){
+ var h = parseInt(controls.canvas_height.char) || 1
+ controls.canvas_height.char = h+""
+ controls.canvas_height.build()
+ canvas.resize(canvas.w, h)
+ }
+
controls.canvas_height.key = int_key(function(n, keyCode){
controls.canvas_height.read()
if (controls.canvas_height.char.length == 1) {
@@ -167,11 +181,15 @@ var controls = (function(){
controls.canvas_height.char = ""+n
controls.canvas_height.build()
canvas.resize(canvas.w, n)
- // canvas.h = n
- // canvas.rebuild()
- // canvas.build()
})
}
+ function int_key (f) {
+ return function (key, keyCode) {
+ var n = parseInt(key)
+ ! isNaN(n) && f(n)
+ }
+ }
+
return controls
})() \ No newline at end of file
diff --git a/js/ui/keys.js b/js/ui/keys.js
index d1badf6..0070dff 100644
--- a/js/ui/keys.js
+++ b/js/ui/keys.js
@@ -74,11 +74,8 @@ var keys = (function(){
if (focused && char) {
var y = focused.y, x = focused.x
focused.key(char, e.keyCode)
- if (! ('y' in focused && 'x' in focused) ) {
- return
- }
- console.log(focused)
- console.log(y, direction[0], x, direction[1])
+ if (! ('y' in focused && 'x' in focused) ) { return }
+ // console.log(y, direction[0], x, direction[1])
current_canvas.focusLex(y + direction[0], x + direction[1])
}
})