pointvec/sources/scripts/interface.js

75 lines
3.3 KiB
JavaScript
Raw Normal View History

2017-11-14 21:11:09 +00:00
function Interface()
{
this.el = document.createElement("div");
this.el.id = "interface";
this.start = function()
{
document.getElementById("app").appendChild(this.el);
2017-11-14 21:11:09 +00:00
// Interface
var html = ""
var path_arr = [
2018-01-13 03:03:21 +00:00
["line","line","M60,60 L240,240",""],
["arc_c","arc clockwise","M60,60 A180,180 0 0,1 240,240",""],
["arc_r","arc reverse","M60,60 A180,180 0 0,0 240,240",""],
["bezier","bezier","M60,60 Q60,150 150,150 Q240,150 240,240 ",""],
["close","close","M60,60 A180,180 0 0,1 240,240 M60,60 A180,180 0 0,0 240,240",""],
2017-11-14 21:11:09 +00:00
2018-01-13 03:03:21 +00:00
["thickness","thickness","M60,60 L240,240","stroke-dasharray: 30,15"],
["linecap","linecap","M60,60 L240,240 M240,180 L240,240 M180,240 L240,240"],
2018-02-04 22:45:58 +00:00
["linejoin","linejoin","M60,60 L120,120 L180,120 M120,180 L180,180 L240,240"],
2018-01-13 03:03:21 +00:00
["mirror","mirror","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210 "],
["fill","fill","M60,60 L60,150 L150,150 L240,150 L240,240 Z "],
2017-11-14 21:11:09 +00:00
2018-01-29 20:48:58 +00:00
["export","export","M150,50 L50,150 L150,250 L250,150 L150,50 Z"]
2017-11-14 21:11:09 +00:00
]
path_arr.forEach(function(a) {
2017-12-03 02:46:27 +00:00
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>'
2017-11-14 21:11:09 +00:00
}, this);
this.el.innerHTML = html
}
this.update = function()
{
let prev = dotgrid.segments[dotgrid.segments.length-1]
document.getElementById("line").className.baseVal = !dotgrid.from() || !dotgrid.to() ? "icon inactive" : "icon";
document.getElementById("arc_c").className.baseVal = !dotgrid.from() || !dotgrid.to() ? "icon inactive" : "icon";
document.getElementById("arc_r").className.baseVal = !dotgrid.from() || !dotgrid.to() ? "icon inactive" : "icon";
document.getElementById("bezier").className.baseVal = !dotgrid.from() || !dotgrid.to() || !dotgrid.end() ? "icon inactive" : "icon";
document.getElementById("thickness").className.baseVal = dotgrid.segments.length < 1 ? "icon inactive" : "icon";
document.getElementById("linecap").className.baseVal = dotgrid.segments.length < 1 ? "icon inactive" : "icon";
2018-02-04 22:45:58 +00:00
document.getElementById("linejoin").className.baseVal = dotgrid.segments.length < 1 ? "icon inactive" : "icon";
2017-11-14 21:11:09 +00:00
document.getElementById("mirror").className.baseVal = dotgrid.segments.length < 1 ? "icon inactive" : "icon";
2017-11-27 04:35:53 +00:00
document.getElementById("fill").className.baseVal = dotgrid.segments.length < 1 ? "icon inactive" : "icon";
2017-11-14 21:11:09 +00:00
document.getElementById("close").className.baseVal = dotgrid.segments.length < 1 || (prev && prev.name == "close") ? "icon inactive" : "icon";
document.getElementById("export").className.baseVal = dotgrid.segments.length < 1 ? "icon inactive" : "icon";
}
2017-11-14 21:57:17 +00:00
2018-01-08 07:53:54 +00:00
this.update_size = function()
{
var size = this.zoom ? {width:600,height:600} : {width:300,height:300};
dotgrid.set_size(size,this.is_visible);
}
this.is_visible = true;
this.zoom = false;
2017-11-14 21:57:17 +00:00
this.toggle = function()
{
this.is_visible = this.is_visible ? false : true;
this.el.className = this.is_visible ? "visible" : "hidden";
2018-01-08 07:53:54 +00:00
this.update_size();
}
this.toggle_zoom = function()
{
this.zoom = this.zoom ? false : true;
this.update_size();
2017-11-14 21:57:17 +00:00
}
}