From e90ba4585159f0183586b6ac82358b927c709a7e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 11 May 2016 01:45:36 -0400 Subject: left/right keys work in no/paint mode --- js/ui/keys.js | 21 +++++++++++++++++++++ js/ui/nopaint.js | 14 ++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'js/ui') diff --git a/js/ui/keys.js b/js/ui/keys.js index ba63fa7..a83ac55 100644 --- a/js/ui/keys.js +++ b/js/ui/keys.js @@ -159,6 +159,27 @@ var keys = (function(){ } } } + keys.left_right_key = function (fn) { + return function (e){ + console.log(e.keyCode) + switch (e.keyCode) { + case 39: // right + e.preventDefault() + fn(1) + break + case 38: // up + case 40: // down + e.preventDefault() + fn(0) + break + case 37: // left + e.preventDefault() + fn(-1) + break + } + } + } + keys.single_numeral_key = function (lex, fn) { return keys.int_key(function(n, keyCode){ if (n == 0) n = 10 diff --git a/js/ui/nopaint.js b/js/ui/nopaint.js index 4528cbf..292e83e 100644 --- a/js/ui/nopaint.js +++ b/js/ui/nopaint.js @@ -12,12 +12,14 @@ var nopaint = (function(){ controls.paint.use = function(state){ nopaint.play() nopaint_pause_el.classList.toggle("hidden", false) + focused = controls.paint.lex } controls.nopaint_pause = new Tool (nopaint_pause_el) controls.nopaint_pause.use = function(state){ nopaint.pause() nopaint_pause_el.classList.toggle("hidden", true) + focused = canvas.aa[0][0] } // use own stepwise clock to drive tweens @@ -42,7 +44,13 @@ var nopaint = (function(){ nopaint.undo = function(){ undo.undo() } - nopaint.pause = function(){ + controls.paint.lex.raw_key = nopaint.raw_key = keys.left_right_key(function(n){ + if (! nopaint.timeout) return + if (n > 0) nopaint.play() + else if (n < 0) nopaint.undo() + else nopaint.pause() + }) + nopaint.pause = nopaint.blur = function(){ clearTimeout(nopaint.timeout) nopaint.timeout = 0 nopaint.step = 0 @@ -60,7 +68,8 @@ var nopaint = (function(){ nopaint.step += 1 } nopaint.switch_tool = function(){ - undo.new() + var state = undo.new() + delete state.focus last_tool = nopaint.tool last_tool && last_tool.finish() nopaint.tool = nopaint.get_random_tool() @@ -403,5 +412,6 @@ var nopaint = (function(){ nopaint.regenerate_weights() nopaint.toggle(true) + return nopaint })() -- cgit v1.2.3-70-g09d2