diff --git a/js/Keyboard.js b/js/Keyboard.js index 92ab870..f08b6b6 100644 --- a/js/Keyboard.js +++ b/js/Keyboard.js @@ -1,10 +1,21 @@ var keyboardShortcutsEnabled = true; +var wordBuffer = ""; + +var wordFuncs = { + "idbeholdl": function() { + alert("Light!"); + }, + "idspispopd": function() { + drawTextOnCanvas("Im in ur kanvas drawin' ur stuffz."); + } +}; function initKeyboard() { $(document).keypress(function(event) { if (!keyboardShortcutsEnabled) return; + if (event.ctrlKey && event.altKey && ! event.metaKey) processWords(event); if (event.altKey || event.ctrlKey || event.metaKey) return; //ignore key presses with modifier keys except shift var ch = String.fromCharCode(event.which); @@ -40,4 +51,24 @@ function initKeyboard() { event.preventDefault(); //prevents the character to end up in a focussed textfield }) -} \ No newline at end of file +} + +function processWords(e) { + wordBuffer += String.fromCharCode(e.which); + + var match = false; + for (var k in wordFuncs) { + if (k.indexOf(wordBuffer) == 0) { + if (k.length == wordBuffer.length) match = wordFuncs[k]; + else match = true; + break; + } + } + + if (typeof(match) == 'function') { + match(); + wordBuffer = ""; + } else if (!match) { + wordBuffer = ""; + } +} diff --git a/js/WordArt.js b/js/WordArt.js index ea67c48..cbf4b02 100644 --- a/js/WordArt.js +++ b/js/WordArt.js @@ -22,24 +22,27 @@ function onWordArtOk() { hidePopup(popupWordArt); var s = $("#txtWordArt").val(); + drawTextOnCanvas(s); +} - if (s!=undefined) { - var points = getStringAsPoints(s); - - var bounds = getBounds(points); - var scaleX = (canvasWidth-50) / bounds.width; - var scaleY = (canvasHeight-50) / bounds.height; +function drawTextOnCanvas(text) { + if (typeof(text) == 'string') { + var points = getStringAsPoints(text); - var scale = Math.min(scaleX,scaleY); + var bounds = getBounds(points); + var scaleX = (canvasWidth-50) / bounds.width; + var scaleY = (canvasHeight-50) / bounds.height; - scalePoints(points,scale); - var bounds = getBounds(points); - translatePoints(points,-bounds.x,-bounds.y); //left top of text is (0,0) - translatePoints(points,-bounds.width/2,-bounds.height/2); //anchor point center - translatePoints(points,canvasWidth/2,canvasHeight/2); //center in canvas + var scale = Math.min(scaleX,scaleY); - canvasDrawPoints(canvas,points); - } + scalePoints(points,scale); + var bounds = getBounds(points); + translatePoints(points,-bounds.x,-bounds.y); //left top of text is (0,0) + translatePoints(points,-bounds.width/2,-bounds.height/2); //anchor point center + translatePoints(points,canvasWidth/2,canvasHeight/2); //center in canvas + + canvasDrawPoints(canvas,points); + } } function getStringAsPoints(text) {