Check for positions before drawing.

This commit is contained in:
Devine Lu Linvega 2016-12-31 11:29:31 -07:00
parent d14b375d53
commit 608d75c005
2 changed files with 10 additions and 14 deletions

View File

@ -65,12 +65,6 @@ function Dotgrid(width,height,grid_x,grid_y)
this.mouse_down = function(e) this.mouse_down = function(e)
{ {
var pos = this.position_in_grid(e.clientX,e.clientY);
pos = this.position_on_grid(pos[0],pos[1]);
if(from === null){ this.set_from(pos); }
else if(to === null){ this.set_to(pos); }
else{ }
} }
this.mouse_move = function(e) this.mouse_move = function(e)
@ -84,6 +78,12 @@ function Dotgrid(width,height,grid_x,grid_y)
this.mouse_up = function(e) this.mouse_up = function(e)
{ {
var pos = this.position_in_grid(e.clientX,e.clientY);
pos = this.position_on_grid(pos[0],pos[1]);
if(from === null){ this.set_from(pos); }
else if(to === null){ this.set_to(pos); }
else{ }
} }
@ -106,15 +106,9 @@ function Dotgrid(width,height,grid_x,grid_y)
} }
// Draw // Draw
this.draw_line = function() this.draw_line = function()
{ {
draw_line(); if(from === null || to === null){ return; }
}
function draw_line()
{
console.log(vector_element);
var s = document.createElementNS('http://www.w3.org/2000/svg', 'line'); var s = document.createElementNS('http://www.w3.org/2000/svg', 'line');
s.setAttribute('x1', -from[0]); s.setAttribute('x1', -from[0]);
@ -132,6 +126,8 @@ function Dotgrid(width,height,grid_x,grid_y)
this.draw_arc = function(orientation) this.draw_arc = function(orientation)
{ {
if(from === null || to === null){ return; }
var s = document.createElementNS("http://www.w3.org/2000/svg", "path"); var s = document.createElementNS("http://www.w3.org/2000/svg", "path");
s.setAttribute("d","M"+(-from[0])+","+(from[1])+" A15,15 0 "+orientation+" "+(-to[0])+","+(to[1])+""); s.setAttribute("d","M"+(-from[0])+","+(from[1])+" A15,15 0 "+orientation+" "+(-to[0])+","+(to[1])+"");
s.setAttribute('stroke', "#000000"); s.setAttribute('stroke', "#000000");

View File

@ -1,4 +1,4 @@
dotgrid = new Dotgrid(300,300,20,20); dotgrid = new Dotgrid(300,300,21,21);
dotgrid.install(); dotgrid.install();
var keyboard = new Keyboard(); var keyboard = new Keyboard();