Keyboard operations
This commit is contained in:
parent
bdfabc4c06
commit
d506abbda3
@ -147,22 +147,8 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
|
|
||||||
if(dotgrid.translation){ dotgrid.translation.to = pos; }
|
if(dotgrid.translation){ dotgrid.translation.to = pos; }
|
||||||
|
|
||||||
if(pos.x>0) {
|
dotgrid.move_cursor(pos)
|
||||||
this.cursor.style.visibility = "hidden"
|
|
||||||
} else {
|
|
||||||
if(this.cursor.style.visibility == "hidden") {
|
|
||||||
this.cursor.style.transition = "initial"
|
|
||||||
}
|
|
||||||
this.cursor.style.visibility = "visible"
|
|
||||||
this.cursor.style.left = Math.floor(-(pos.x-this.grid_width));
|
|
||||||
this.cursor.style.top = Math.floor(pos.y+this.grid_height);
|
|
||||||
this.cursor_coord.className = -pos.x > this.width/2 ? "fl left" : "fl"
|
|
||||||
this.cursor_coord.textContent = parseInt(-pos.x/this.grid_width)+","+parseInt(pos.y/this.grid_height);
|
|
||||||
window.setTimeout(() => dotgrid.cursor.style.transition = "all 50ms", 17 /*one frame*/)
|
|
||||||
}
|
|
||||||
|
|
||||||
dotgrid.guide.update();
|
dotgrid.guide.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mouse_up = function(e)
|
this.mouse_up = function(e)
|
||||||
@ -181,10 +167,32 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
|
|
||||||
dotgrid.translation = null;
|
dotgrid.translation = null;
|
||||||
|
|
||||||
|
this.add_point(pos)
|
||||||
|
this.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.move_cursor = function(pos)
|
||||||
|
{
|
||||||
|
if(pos.x>0) {
|
||||||
|
this.cursor.style.visibility = "hidden"
|
||||||
|
} else {
|
||||||
|
if(this.cursor.style.visibility == "hidden") {
|
||||||
|
this.cursor.style.transition = "initial"
|
||||||
|
}
|
||||||
|
this.cursor.style.visibility = "visible"
|
||||||
|
this.cursor.style.left = Math.floor(-(pos.x-this.grid_width));
|
||||||
|
this.cursor.style.top = Math.floor(pos.y+this.grid_height);
|
||||||
|
this.cursor_coord.className = -pos.x > this.width/2 ? "fl left" : "fl"
|
||||||
|
this.cursor_coord.textContent = parseInt(-pos.x/this.grid_width)+","+parseInt(pos.y/this.grid_height);
|
||||||
|
window.setTimeout(() => dotgrid.cursor.style.transition = "all 50ms", 17 /*one frame*/)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.add_point = function(pos)
|
||||||
|
{
|
||||||
if(from === null){ this.set_from(pos.scale(1/this.scale)); }
|
if(from === null){ this.set_from(pos.scale(1/this.scale)); }
|
||||||
else if(to === null){ this.set_to(pos.scale(1/this.scale)); }
|
else if(to === null){ this.set_to(pos.scale(1/this.scale)); }
|
||||||
else{ this.set_end(pos.scale(1/this.scale)); }
|
else{ this.set_end(pos.scale(1/this.scale)); }
|
||||||
this.draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handle_at = function(pos)
|
this.handle_at = function(pos)
|
||||||
@ -276,17 +284,23 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
this.mod_move = function(move)
|
this.mod_move = function(move)
|
||||||
{
|
{
|
||||||
if(!to && !end && from){
|
if(!to && !end && from){
|
||||||
this.set_from(new Pos(from.x-(move.x),from.y+(move.y)))
|
var pos = new Pos(from.x-(move.x),from.y+(move.y))
|
||||||
|
this.set_from(pos)
|
||||||
|
this.move_cursor(pos)
|
||||||
this.draw();
|
this.draw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!end && to){
|
if(!end && to){
|
||||||
this.set_to(new Pos(to.x-(move.x),to.y+(move.y)))
|
var pos = new Pos(to.x-(move.x),to.y+(move.y))
|
||||||
|
this.set_to(pos)
|
||||||
|
this.move_cursor(pos)
|
||||||
this.draw();
|
this.draw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(end){
|
if(end){
|
||||||
this.set_end(new Pos(end.x-(move.x),end.y+(move.y)))
|
var pos = new Pos(end.x-(move.x),end.y+(move.y))
|
||||||
|
this.set_end(pos)
|
||||||
|
this.move_cursor(pos)
|
||||||
this.draw();
|
this.draw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,15 @@ function Keyboard()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(e.key){
|
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 = "";
|
||||||
|
}
|
||||||
|
|
||||||
switch(e.keyCode) {
|
switch(e.keyCode) {
|
||||||
case 65 : dotgrid.draw_arc(e.shiftKey ? "1,0" : "0,0"); break; // 'a/A'
|
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'
|
case 83 : dotgrid.draw_arc(e.shiftKey ? "1,1" : "0,1"); break; // 's/S'
|
||||||
@ -68,4 +74,25 @@ function Keyboard()
|
|||||||
}
|
}
|
||||||
dotgrid.draw();
|
dotgrid.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user