diff options
| author | Julie Lala <jules@okfoc.us> | 2014-12-08 01:54:19 -0500 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-12-08 01:54:19 -0500 |
| commit | dddd544a566ce53a70351b9fc1391af5034ae09e (patch) | |
| tree | 2cd31db279eb9855c9f78955f44c98f5d0ccdb9a /js/ui/keys.js | |
| parent | 2377b7795ce2a428fd34bee7ee228f17923dfb0c (diff) | |
splitting out keys
Diffstat (limited to 'js/ui/keys.js')
| -rw-r--r-- | js/ui/keys.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/js/ui/keys.js b/js/ui/keys.js new file mode 100644 index 0000000..7711e9d --- /dev/null +++ b/js/ui/keys.js @@ -0,0 +1,83 @@ +var keys = (function(){ + + var keys = {} + var direction = [0,1] + keys.bind = function(){ + cursor_input.addEventListener('keydown', function(e){ + + console.log("keycode:", e.keyCode) + + switch (e.keyCode) { + case 27: // esc + if (focused) focused.blur() + break + case 219: // [ + if (current_tool.name != "text") { + e.preventDefault() + brush.contract(1) + brush.modified = false + break + } + case 221: // ] + if (current_tool.name != "text") { + e.preventDefault() + brush.expand(1) + brush.modified = false + break + } + case 8: + e.preventDefault() + current_canvas.focusLex(focused.y-1, focused.x) + focused.char = " " + focused.build() + return + case 13: // return + e.preventDefault() + current_canvas.focusLex(focused.y, focused.x+1) + return + case 38: // up + e.preventDefault() + current_canvas.focusLex(focused.y - 1, focused.x + 0) + break + case 40: // down + e.preventDefault() + current_canvas.focusLex(focused.y + 1, focused.x + 0) + break + case 37: // left + e.preventDefault() + current_canvas.focusLex(focused.y + 0, focused.x - 1) + break + case 39: // right + e.preventDefault() + current_canvas.focusLex(focused.y + 0, focused.x + 1) + break + // default: + // if (focused) { focused.key(undefined, e.keyCode) } + } + }) + + cursor_input.addEventListener('input', function(e){ + /* + if (! e.metaKey && ! e.ctrlKey && ! e.altKey) { + e.preventDefault() + } + */ + if (current_tool.name == "shader") { + cursor_input.value = "" + return + } + var char = cursor_input.value + cursor_input.value = "" + + console.log("input:", char) + + if (focused && char) { + var y = focused.y, x = focused.x + focused.key(char, e.keyCode) + current_canvas.focusLex(y + direction[0], focused.x + direction[1]) + } + }) + } + + return keys +})() |
