pointvec/desktop/sources/scripts/interface.js

79 lines
3.6 KiB
JavaScript
Raw Normal View History

2017-11-14 16:11:09 -05:00
function Interface()
{
this.el = document.createElement("div");
this.el.id = "interface";
2018-03-06 19:50:41 -05:00
this.el.appendChild(this.menu_el = document.createElement("div"));
this.menu_el.id = "menu";
this.is_visible = true;
this.zoom = false;
2017-11-14 16:11:09 -05:00
this.start = function()
{
document.getElementById("app").appendChild(this.el);
2018-03-06 19:50:41 -05:00
this.el.appendChild(dotgrid.picker.el);
2017-11-14 16:11:09 -05:00
var html = ""
2018-02-06 14:04:25 -05:00
var tools = {
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",""],
2018-03-06 17:02:43 -05:00
linecap: ["linecap","M60,60 L60,60 L180,180 L240,180 L240,240 L180,240 L180,180"],
2018-02-06 14:04:25 -05:00
linejoin: ["linejoin","M60,60 L120,120 L180,120 M120,180 L180,180 L240,240"],
2018-03-06 17:08:53 -05:00
thickness: ["thickness","M120,90 L120,90 L90,120 L180,210 L210,180 Z M105,105 L105,105 L60,60 M195,195 L195,195 L240,240","stroke-dasharray: 30,15"],
2018-02-06 14:04:25 -05:00
mirror: ["mirror","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210"],
2018-03-07 00:51:29 -05:00
fill: ["fill","M60,60 L60,150 L150,150 L240,150 L240,240 Z"],
2018-03-06 18:17:44 -05:00
color: ["color","M150,60 A90,90 0 0,1 240,150 A-90,90 0 0,1 150,240 A-90,-90 0 0,1 60,150 A90,-90 0 0,1 150,60"],
2018-02-06 14:04:25 -05:00
}
2018-02-05 20:14:23 -05:00
for(id in tools){
var tool = tools[id];
2018-03-06 17:02:43 -05:00
html += `<svg id="${id}" ar="${id}" title="${tool[0]}" viewBox="0 0 300 300" class="icon"><path class="icon_path" d="${tool[1]}"/>${id == "depth" ? `<path class="icon_path inactive" d=""/>` : ""}<rect ar="${id}" width="300" height="300" opacity="0"><title>${id}</title></rect></svg>`
}
2018-03-06 19:50:41 -05:00
this.menu_el.innerHTML = html
2017-11-14 16:11:09 -05:00
}
this.update = function()
{
2018-02-05 22:27:48 -05:00
document.getElementById("line").className.baseVal = !dotgrid.tool.can_cast("line") ? "icon inactive" : "icon";
document.getElementById("arc_c").className.baseVal = !dotgrid.tool.can_cast("arc_c") ? "icon inactive" : "icon";
document.getElementById("arc_r").className.baseVal = !dotgrid.tool.can_cast("arc_r") ? "icon inactive" : "icon";
document.getElementById("bezier").className.baseVal = !dotgrid.tool.can_cast("bezier") ? "icon inactive" : "icon";
2018-02-06 01:51:09 -05:00
document.getElementById("close").className.baseVal = !dotgrid.tool.can_cast("close") ? "icon inactive" : "icon";
2017-11-14 16:11:09 -05:00
2018-03-06 17:08:53 -05:00
document.getElementById("thickness").className.baseVal = dotgrid.tool.layer().length < 1 ? "icon inactive" : "icon";
2018-02-05 20:14:23 -05:00
document.getElementById("linecap").className.baseVal = dotgrid.tool.layer().length < 1 ? "icon inactive" : "icon";
document.getElementById("linejoin").className.baseVal = dotgrid.tool.layer().length < 1 ? "icon inactive" : "icon";
document.getElementById("mirror").className.baseVal = dotgrid.tool.layer().length < 1 ? "icon inactive" : "icon";
2018-03-07 00:51:29 -05:00
document.getElementById("fill").className.baseVal = dotgrid.tool.layer().length < 1 ? "icon inactive" : "icon";
2018-03-06 18:17:44 -05:00
document.getElementById("color").children[0].style.fill = dotgrid.tool.style().color;
document.getElementById("color").children[0].style.stroke = dotgrid.tool.style().color;
document.getElementById("color").className.baseVal = "icon";
2017-11-14 16:11:09 -05:00
}
2017-11-14 16:57:17 -05:00
2018-01-08 02:53:54 -05:00
this.update_size = function()
{
var size = this.zoom ? {width:600,height:600} : {width:300,height:300};
dotgrid.set_size(size,this.is_visible);
}
2017-11-14 16:57:17 -05:00
this.toggle = function()
{
this.is_visible = this.is_visible ? false : true;
this.el.className = this.is_visible ? "visible" : "hidden";
2018-01-08 02:53:54 -05:00
this.update_size();
}
this.toggle_zoom = function()
{
this.zoom = this.zoom ? false : true;
this.update_size();
2017-11-14 16:57:17 -05:00
}
}