summaryrefslogtreecommitdiff
path: root/js/ui
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-12-09 17:13:38 -0500
committerJules Laplace <jules@okfoc.us>2014-12-09 17:37:24 -0500
commit6f151fef14c41ed1c4d65c2013224e0af37b7964 (patch)
tree42842913b43ca21a37d2df1414b0dc11b2a6fca1 /js/ui
parentda3b3feedfe3a928dec6ac615579538a9ab5b582 (diff)
non-destructive resize
Diffstat (limited to 'js/ui')
-rw-r--r--js/ui/controls.js38
-rw-r--r--js/ui/keys.js7
2 files changed, 30 insertions, 15 deletions
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])
}
})