Added line previews

This commit is contained in:
Devine Lu Linvega 2017-12-03 15:46:27 +13:00
parent 8ae565cb74
commit 897e93a541
4 changed files with 49 additions and 1 deletions

View File

@ -31,3 +31,5 @@ svg.vector { z-index: 1000;position: relative; left:10px; top:10px; width:300px;
#interface.hidden { display: none;opacity: 0 }
#interface.visible { display: block; opacity: 1 }
#preview { position: absolute; top:20px; left:20px; stroke-dasharray: 4,4 }

View File

@ -99,6 +99,22 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.svg_el.style.fill = "none";
this.svg_el.style.strokeLinecap = this.linecap;
this.element.appendChild(this.svg_el);
// Preview
this.preview_el = document.createElementNS("http://www.w3.org/2000/svg", "svg");
this.preview_el.id = "preview"
this.preview_el.setAttribute("class","vector fh");
this.preview_el.setAttribute("width",this.width+"px");
this.preview_el.setAttribute("height",this.height+"px");
this.preview_el.setAttribute("xmlns","http://www.w3.org/2000/svg");
this.preview_el.setAttribute("baseProfile","full");
this.preview_el.setAttribute("version","1.1");
this.preview_el.style.width = this.width;
this.preview_el.style.height = this.height;
this.preview_el.style.stroke = "#72dec2";
this.preview_el.style.strokeWidth = 2;
this.preview_el.style.fill = "none";
this.preview_el.style.strokeLinecap = "round";
this.element.appendChild(this.preview_el);
this.offset_el.appendChild(this.path)
this.svg_el.appendChild(this.offset_el);
@ -149,6 +165,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
if(dotgrid.translation){ dotgrid.translation.to = pos; }
var o = e.target.getAttribute("ar");
dotgrid.preview(o);
dotgrid.move_cursor(pos)
dotgrid.guide.update();
}
@ -223,6 +242,32 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
dotgrid.draw();
}
this.preview = function(operation)
{
if(from && to && operation == "line"){
var d = new Path_Line(from.mirror(),to.mirror(),end.mirror()).to_segment();
this.preview_el.innerHTML = "<path d='"+d+"'></path>"
console.log(d);
return;
}
if(from && to && operation == "arc_c"){
var d = new Path_Arc(from.mirror(),to.mirror(),"0,1",end.mirror()).to_segment();
this.preview_el.innerHTML = "<path d='"+d+"'></path>"
return;
}
if(from && to && operation == "arc_r"){
var d = new Path_Arc(from.mirror(),to.mirror(),"0,0",end.mirror()).to_segment();
this.preview_el.innerHTML = "<path d='"+d+"'></path>"
return;
}
if(from && to && operation == "bezier"){
var d = new Path_Bezier(from.mirror(),to.mirror(),end.mirror()).to_segment();
this.preview_el.innerHTML = "<path d='"+d+"'></path>"
return;
}
this.preview_el.innerHTML = "";
}
// Setters
this.set_from = function(pos)

View File

@ -25,7 +25,7 @@ function Interface()
["export","export (ctrl s)","M150,50 L50,150 L150,250 L250,150 L150,50 Z"]
]
path_arr.forEach(function(a) {
html+='<svg id="'+a[0]+'" ar="'+a[0]+'" title="hello" viewBox="0 0 300 300" class="icon" style="'+a[3]+'"><path class="icon_path" d="'+a[2]+'" stroke-linecap: round; stroke-width="12px" fill="none" /><rect ar="'+a[0]+'" width="300" height="300" opacity="0"><title>'+a[1]+'</title></rect></svg>'
html += '<svg id="'+a[0]+'" ar="'+a[0]+'" title="hello" viewBox="0 0 300 300" class="icon" style="'+a[3]+'"><path class="icon_path" d="'+a[2]+'" stroke-linecap: round; stroke-width="12px" fill="none" /><rect ar="'+a[0]+'" width="300" height="300" opacity="0"><title>'+a[1]+'</title></rect></svg>'
}, this);
this.el.innerHTML = html
}

View File

@ -57,6 +57,7 @@ function Theme()
html += ".icon { color:"+theme.f_high+" !important; stroke:"+theme.f_high+" !important }\n";
html += "#dotgrid svg.vector { fill:"+theme.f_high+" }\n";
html += "#dotgrid #preview { stroke:"+theme.f_low+" !important} \n";
html += "#dotgrid #cursor { border-color:"+theme.f_med+"}\n";
html += "#dotgrid #cursor_from { background:"+theme.f_low+"; border-color:"+theme.f_low+"}\n";
html += "#dotgrid #cursor_to { background:"+theme.f_low+"; border-color:"+theme.f_low+"}\n";