From b4d19e469b3de98778002ac97814c6b647cba113 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Nov 2014 14:47:43 -0500 Subject: better chara input --- js/app.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'js/app.js') diff --git a/js/app.js b/js/app.js index 9cd9cf8..a5e3aea 100644 --- a/js/app.js +++ b/js/app.js @@ -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') }) } -- cgit v1.2.3-70-g09d2