Improved shortcuts and drag/drop

This commit is contained in:
Devine Lu Linvega
2017-11-14 07:52:53 +13:00
parent 66a34a6814
commit 16ddcfb27a
7 changed files with 50 additions and 28 deletions

View File

@@ -123,7 +123,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
var pos = this.position_in_grid(new Pos(e.clientX,e.clientY));
pos = this.position_on_grid(pos);
if(e.ctrlKey){ dotgrid.translation = {from:pos,to:pos}; }
if(e.altKey){ dotgrid.delete_at(pos); return; }
if(dotgrid.handle_at(pos)){ dotgrid.translation = {from:pos,to:pos}; return; }
if(!o){ return; }
@@ -141,7 +143,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
var pos = this.position_in_grid(new Pos(e.clientX,e.clientY));
pos = this.position_on_grid(pos);
if(e.ctrlKey && dotgrid.translation){ dotgrid.translation.to = pos; }
if(dotgrid.translation){ dotgrid.translation.to = pos; }
this.cursor.style.left = Math.floor(-(pos.x-this.grid_width));
this.cursor.style.top = Math.floor(pos.y+this.grid_height);
@@ -156,12 +158,13 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
var pos = this.position_in_grid(new Pos(e.clientX,e.clientY));
pos = this.position_on_grid(pos);
if(e.altKey){ return; }
if(dotgrid.translation){
dotgrid.translate(dotgrid.translation);
return;
}
if(e.altKey){ dotgrid.delete_at(pos); return; }
if(pos.x>0) return;
if(from === null){ this.set_from(pos.scale(1/this.scale)); }
@@ -170,6 +173,17 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.draw();
}
this.handle_at = function(pos)
{
for(id in dotgrid.segments){
var segment = dotgrid.segments[id];
if(segment.from && segment.from.is_equal(pos)){ return true; }
if(segment.to && segment.to.is_equal(pos)){ return true; }
if(segment.end && segment.end.is_equal(pos)){ return true; }
}
return false;
}
this.translate = function(t)
{
for(id in dotgrid.segments){

View File

@@ -29,7 +29,7 @@ function Guide()
this.clear = function()
{
this.widgets.getContext('2d').clearRect(0, 0, 600, 600);
this.widgets.getContext('2d').clearRect(0, 0, 1280, 1280);
}
this.update = function()

View File

@@ -28,24 +28,19 @@ function Keyboard()
}
switch (e.keyCode) {
case 83 : dotgrid.draw_arc(e.shiftKey ? "1,1" : "0,1"); break; // 'S'
case 65 : dotgrid.draw_arc(e.shiftKey ? "1,0" : "0,0"); break; // '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 68 : dotgrid.draw_line(); break; // 'd'
case 70 : dotgrid.draw_bezier(); break; // 'f'
case 82 : dotgrid.draw_close(); break; // 'r'
case 187 : dotgrid.mod_thickness(1); break; // '+'
case 189 : dotgrid.mod_thickness(-1); break; // '-'
case 71 : dotgrid.draw_close(); break; // 'g'
case 221 : dotgrid.mod_thickness(1); break; // ']'
case 219 : dotgrid.mod_thickness(-1); break; // '['
case 191 : dotgrid.mod_linecap(1); break; // '/'
case 32 : dotgrid.mod_mirror(); break; // 'space'
case 81 : dotgrid.reset(); break; // 'Q'
case 27 : dotgrid.reset(); break; // 'ESC'
case 87 : dotgrid.erase(); break; // 'W'
case 8 : dotgrid.erase(); break; // 'Backspace'
case 69 : dotgrid.export(); break; // 'e'
case 13 : dotgrid.export(); break; // 'Enter'
case 9 : dotgrid.toggle_fill(); e.preventDefault(); break; // 'tab'

View File

@@ -6,4 +6,9 @@ function Path_Close()
{
return "Z ";
}
this.handles = function()
{
return [];
}
}

View File

@@ -12,7 +12,7 @@ function Render()
var b64Start = 'data:image/svg+xml;base64,';
var image64 = b64Start + svg64;
this.img.src = image64;
this.el.getContext('2d').clearRect(0, 0, 512, 512);
this.el.getContext('2d').clearRect(0, 0, 1280, 1280);
this.el.getContext('2d').drawImage(this.img, 0, 0, 512, 512);
}