2016-12-31 12:37:10 -05:00
|
|
|
function Keyboard()
|
|
|
|
{
|
2017-11-06 21:41:41 -05:00
|
|
|
this.listen = function(e)
|
2016-12-31 12:37:10 -05:00
|
|
|
{
|
2017-11-21 17:58:07 -05:00
|
|
|
// zoom
|
|
|
|
if(e.key == "~" || e.keyCode == 192){
|
2018-01-08 02:53:54 -05:00
|
|
|
dotgrid.interface.toggle_zoom();
|
|
|
|
e.preventDefault();
|
2017-11-21 17:58:07 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-05 14:53:59 -05:00
|
|
|
// save
|
2017-11-06 21:41:41 -05:00
|
|
|
if(e.key == "s" && (e.ctrlKey || e.metaKey)){
|
2018-01-11 22:22:50 -05:00
|
|
|
e.preventDefault();
|
2017-11-05 14:53:59 -05:00
|
|
|
dotgrid.export();
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 14:38:14 -05:00
|
|
|
|
2017-11-21 16:57:16 -05:00
|
|
|
// open
|
|
|
|
if(e.key == "o" && (e.ctrlKey || e.metaKey)){
|
2018-01-11 22:22:50 -05:00
|
|
|
e.preventDefault();
|
|
|
|
dotgrid.open();
|
2017-11-21 16:57:16 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-05 20:10:37 -05:00
|
|
|
// undo
|
2017-11-06 21:41:41 -05:00
|
|
|
if(e.key == "z" && (e.ctrlKey || e.metaKey)){
|
2018-01-11 22:22:50 -05:00
|
|
|
e.preventDefault();
|
2017-11-05 20:10:37 -05:00
|
|
|
dotgrid.erase();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-07 16:40:13 -05:00
|
|
|
// new
|
|
|
|
if(e.key == "n" && (e.ctrlKey || e.metaKey)){
|
2018-01-11 22:22:50 -05:00
|
|
|
e.preventDefault();
|
2017-11-07 16:40:13 -05:00
|
|
|
dotgrid.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-06 21:41:41 -05:00
|
|
|
// Reset
|
|
|
|
if((e.key == "Backspace" || e.key == "Delete") && e.ctrlKey && e.shiftKey){
|
|
|
|
e.preventDefault();
|
|
|
|
dotgrid.theme.reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-17 01:45:15 -05:00
|
|
|
var numbers = ["0","1","2","3","4","5","6","7","8","9"]
|
|
|
|
if(numbers.indexOf(e.key) > -1 || e.code == "Digit0" || e.keyCode == 48){
|
|
|
|
keyboard.cheatcode(e.key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.code_history = "";
|
2017-11-14 16:57:17 -05:00
|
|
|
}
|
2017-11-17 01:45:15 -05:00
|
|
|
|
2017-11-26 23:35:53 -05:00
|
|
|
switch(e.keyCode || e.key) {
|
2017-11-13 13:52:53 -05:00
|
|
|
case 65 : dotgrid.draw_arc(e.shiftKey ? "1,0" : "0,0"); break; // 'a/A'
|
|
|
|
case 83 : dotgrid.draw_arc(e.shiftKey ? "1,1" : "0,1"); break; // 's/S'
|
2017-11-05 15:51:16 -05:00
|
|
|
case 68 : dotgrid.draw_line(); break; // 'd'
|
|
|
|
case 70 : dotgrid.draw_bezier(); break; // 'f'
|
2017-11-14 16:57:17 -05:00
|
|
|
case "g" : dotgrid.draw_close(); break;
|
2017-11-13 13:52:53 -05:00
|
|
|
case 71 : dotgrid.draw_close(); break; // 'g'
|
2017-11-26 23:35:53 -05:00
|
|
|
case "h" : dotgrid.toggle_fill(); break;
|
|
|
|
case 72 : dotgrid.toggle_fill(); break; // 'g'
|
2017-11-14 16:57:17 -05:00
|
|
|
|
|
|
|
case "[" : dotgrid.mod_thickness(-1); break;
|
2017-11-05 20:10:37 -05:00
|
|
|
case 219 : dotgrid.mod_thickness(-1); break; // '['
|
2017-11-14 16:57:17 -05:00
|
|
|
case "]" : dotgrid.mod_thickness(1); break;
|
|
|
|
case 221 : dotgrid.mod_thickness(1); break; // ']'
|
|
|
|
|
|
|
|
case "+" : dotgrid.mod_thickness(1); break;
|
|
|
|
case "-" : dotgrid.mod_thickness(-1); break;
|
|
|
|
case "<" : dotgrid.mod_thickness(1); break;
|
|
|
|
case ">" : dotgrid.mod_thickness(-1); break;
|
|
|
|
|
|
|
|
case "/" : dotgrid.mod_linecap(1); break; // '/'
|
2017-11-05 15:51:16 -05:00
|
|
|
case 191 : dotgrid.mod_linecap(1); break; // '/'
|
2017-11-05 20:10:37 -05:00
|
|
|
|
2017-11-14 16:57:17 -05:00
|
|
|
case "space" : dotgrid.mod_linecap(1); break; // '/'
|
2017-11-10 14:46:11 -05:00
|
|
|
case 32 : dotgrid.mod_mirror(); break; // 'space'
|
2016-12-31 15:55:35 -05:00
|
|
|
|
2017-11-14 16:57:17 -05:00
|
|
|
case "Escape" : dotgrid.mod_linecap(1); break; // '/'
|
2017-11-05 15:51:16 -05:00
|
|
|
case 27 : dotgrid.reset(); break; // 'ESC'
|
|
|
|
case 8 : dotgrid.erase(); break; // 'Backspace'
|
2017-11-07 02:15:15 -05:00
|
|
|
case 13 : dotgrid.export(); break; // 'Enter'
|
2017-11-05 20:10:37 -05:00
|
|
|
|
2017-11-14 16:57:17 -05:00
|
|
|
case 9 : dotgrid.interface.toggle(); e.preventDefault(); break; // 'tab'
|
2017-01-04 12:48:08 -05:00
|
|
|
|
2017-11-13 14:45:31 -05:00
|
|
|
case 38 : dotgrid.mod_move(new Pos(0,-15)); break; // 'up'
|
|
|
|
case 40 : dotgrid.mod_move(new Pos(0,15)); break; // 'down'
|
|
|
|
case 37 : dotgrid.mod_move(new Pos(-15,0)); break; // 'left'
|
|
|
|
case 39 : dotgrid.mod_move(new Pos(15,0)); break; // 'right'
|
2016-12-31 12:37:10 -05:00
|
|
|
}
|
2017-11-04 19:59:11 -04:00
|
|
|
dotgrid.draw();
|
2016-12-31 12:37:10 -05:00
|
|
|
}
|
2017-11-17 01:45:15 -05:00
|
|
|
|
|
|
|
this.code_history = "";
|
|
|
|
|
|
|
|
this.cheatcode = function(key)
|
|
|
|
{
|
|
|
|
if(key.length != 1){ return; }
|
|
|
|
this.code_history += key;
|
|
|
|
|
|
|
|
if(this.code_history.length == 2){
|
|
|
|
var x = this.code_history.substr(0,2);
|
|
|
|
var y = 15;
|
|
|
|
dotgrid.move_cursor(new Pos(x * -15,y * 15))
|
|
|
|
}
|
|
|
|
if(this.code_history.length > 3){
|
|
|
|
var x = this.code_history.substr(0,2);
|
|
|
|
var y = this.code_history.substr(2,2);
|
|
|
|
dotgrid.add_point(new Pos(x * -15,y * 15))
|
|
|
|
dotgrid.move_cursor(new Pos(x * -15,y * 15))
|
|
|
|
this.code_history = "";
|
|
|
|
}
|
|
|
|
}
|
2016-12-31 12:37:10 -05:00
|
|
|
}
|