diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-11-22 14:47:43 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-11-22 14:47:43 -0500 |
| commit | b4d19e469b3de98778002ac97814c6b647cba113 (patch) | |
| tree | ab4d0f8ad5d33588a8287530971880f1889da5cd /js/app.js | |
| parent | dd8a053f9845d4adeb8540f24d1e8d46def35ad3 (diff) | |
better chara input
Diffstat (limited to 'js/app.js')
| -rw-r--r-- | js/app.js | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -29,6 +29,7 @@ function build () { }) shader.init() shader.run(canvas) + shader.animate() brush = new Matrix (5, 5, function(x,y){ var lex = new Lex (x,y) @@ -39,6 +40,7 @@ function build () { var lex = new Lex (x,y) lex.bg = colors[color_hue_order[y>>1]] lex.build() + console.log(lex.bg, lex.css()) return lex }) canvas.append(canvas_rapper) @@ -98,7 +100,8 @@ function build () { controls.shader = new Tool (shader_el) controls.shader.use = function(){ shader_textarea.style.display = "block" - setTimeout(function(){ shader_textarea.focus() }) + // setTimeout(function(){ shader_textarea.focus() }) + shader_textarea.focus() } controls.shader.blur = function(){ Tool.prototype.blur.call(this) @@ -116,6 +119,7 @@ function build () { controls.canvas_height = new Lex (canvas_height_el) controls.circle.focus() +// controls.shader.focus() brush.bg = colors.red brush.generate() @@ -162,6 +166,7 @@ function bind () { }) window.addEventListener('mouseup', function(){ dragging = erasing = false + if (current_tool.name != 'shader') { cursor_input.focus() } }); [controls.width, controls.height, controls.canvas_width, controls.canvas_height].forEach(function(lex){ @@ -214,15 +219,26 @@ function bind () { canvas.build() }) - window.addEventListener('keydown', function(e){ + window.addEventListener('mousedown', function(e){ + if (current_tool.name == "shader") { return } + cursor_input.focus() + }) + cursor_input.addEventListener('keydown', function(e){ + if (focused) { focused.key(undefined, e.keyCode) } + }) + cursor_input.addEventListener('input', function(e){ if (current_tool.name == "shader") { + cursor_input.value = "" return } if (! e.metaKey && ! e.ctrlKey && ! e.altKey) { e.preventDefault() } + var char = cursor_input.value + cursor_input.value = "" - // console.log(e.keyCode) + // var charFromKeyCode = String.fromCharCode(e.keyCode) + switch (e.keyCode) { case 27: // esc if (focused) focused.blur() @@ -238,12 +254,14 @@ function bind () { break } default: - if (focused) focused.key(String.fromCharCode(e.keyCode), e.keyCode) + if (focused) focused.key(char, e.keyCode) break } }) - + + document.addEventListener('DOMContentLoaded', function(){ + if (current_tool.name != 'shader') { cursor_input.focus() } document.body.classList.remove('loading') }) } |
