pointvec/sources/scripts/dotgrid.js

536 lines
15 KiB
JavaScript
Raw Normal View History

2016-12-31 21:35:14 +00:00
function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,linecap = "round", color = "#000000")
2016-12-31 15:00:57 +00:00
{
2017-11-07 02:10:09 +00:00
this.theme = new Theme();
2016-12-31 15:00:57 +00:00
this.width = width;
this.height = height;
2016-12-31 17:18:01 +00:00
this.grid_x = grid_x;
this.grid_y = grid_y;
2016-12-31 20:37:13 +00:00
this.block_x = block_x;
this.block_y = block_y;
2016-12-31 21:35:14 +00:00
this.thickness = thickness;
this.linecap = linecap;
this.color = color;
2017-11-06 00:18:57 +00:00
this.offset = new Pos(0,0);
2016-12-31 21:35:14 +00:00
2017-11-06 01:10:37 +00:00
// Dotgrid
this.element = document.createElement("div");
this.element.id = "dotgrid";
this.element.style.width = this.width;
this.element.style.height = this.height;
2016-12-31 15:00:57 +00:00
2017-11-12 21:47:34 +00:00
this.wrapper = document.createElement("div");
this.wrapper.id = "wrapper";
2016-12-31 17:18:01 +00:00
this.grid_width = this.width/this.grid_x;
this.grid_height = this.height/this.grid_y;
2016-12-31 17:37:10 +00:00
var cursor = null;
var cursor_from = null;
var cursor_to = null;
2017-11-04 23:59:11 +00:00
var cursor_end = null;
2016-12-31 17:18:01 +00:00
var from = null;
var to = null;
2017-11-04 23:59:11 +00:00
var end = null;
this.svg_el = null;
2017-11-05 19:53:59 +00:00
this.mirror_el = null;
this.mirror = false;
2017-11-06 01:10:37 +00:00
this.fill = false;
2017-11-04 23:59:11 +00:00
2017-11-09 19:47:06 +00:00
this.guide = new Guide();
this.render = new Render();
2017-11-04 23:59:11 +00:00
this.path = document.createElementNS("http://www.w3.org/2000/svg", "path");
this.segments = [];
this.interface = document.createElement("div");
this.interface.id = "interface";
2017-11-12 21:47:34 +00:00
this.scale = 1
2016-12-31 17:18:01 +00:00
2016-12-31 15:00:57 +00:00
this.install = function()
{
2017-11-12 21:47:34 +00:00
document.body.appendChild(this.wrapper);
this.wrapper.appendChild(this.element);
this.wrapper.appendChild(this.interface);
this.element.appendChild(this.guide.el);
this.wrapper.appendChild(this.render.el);
2016-12-31 17:18:01 +00:00
// Cursors
this.cursor = document.createElement("div");
this.cursor.id = "cursor";
this.element.appendChild(this.cursor);
2017-11-10 19:46:11 +00:00
this.cursor_coord = document.createElement("div");
this.cursor_coord.id = "cursor_coord";
this.cursor_coord.className = "fl"
this.cursor.appendChild(this.cursor_coord);
2016-12-31 17:37:10 +00:00
cursor_from = document.createElement("div");
cursor_from.id = "cursor_from";
this.element.appendChild(cursor_from);
2016-12-31 17:18:01 +00:00
2016-12-31 17:37:10 +00:00
cursor_to = document.createElement("div");
cursor_to.id = "cursor_to";
this.element.appendChild(cursor_to);
2016-12-31 17:18:01 +00:00
2017-11-04 23:59:11 +00:00
cursor_end = document.createElement("div");
cursor_end.id = "cursor_end";
this.element.appendChild(cursor_end);
2017-11-06 00:18:57 +00:00
this.offset_el = document.createElementNS("http://www.w3.org/2000/svg", "g");
2017-11-05 19:53:59 +00:00
this.mirror_el = document.createElementNS("http://www.w3.org/2000/svg", "g");
this.mirror_path = document.createElementNS("http://www.w3.org/2000/svg", "path");
2016-12-31 17:18:01 +00:00
// Vector
2017-11-04 23:59:11 +00:00
this.svg_el = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2017-11-07 02:10:09 +00:00
this.svg_el.setAttribute("class","vector fh");
2017-11-04 23:59:11 +00:00
this.svg_el.setAttribute("width",this.width+"px");
this.svg_el.setAttribute("height",this.height+"px");
this.svg_el.setAttribute("xmlns","http://www.w3.org/2000/svg");
this.svg_el.setAttribute("baseProfile","full");
this.svg_el.setAttribute("version","1.1");
this.svg_el.style.width = this.width;
this.svg_el.style.height = this.height;
this.svg_el.style.stroke = this.color;
this.svg_el.style.strokeWidth = this.thickness;
2017-11-07 02:41:41 +00:00
this.svg_el.style.fill = this.fill ? "black" : "none !important";
2017-11-04 23:59:11 +00:00
this.svg_el.style.strokeLinecap = this.linecap;
this.element.appendChild(this.svg_el);
2017-11-06 00:18:57 +00:00
2017-11-06 04:35:29 +00:00
this.offset_el.appendChild(this.path)
2017-11-06 00:18:57 +00:00
this.svg_el.appendChild(this.offset_el);
2017-11-05 19:53:59 +00:00
this.svg_el.appendChild(this.mirror_el);
this.mirror_el.appendChild(this.mirror_path);
2017-11-05 00:52:05 +00:00
2017-11-07 02:10:09 +00:00
this.theme.start();
2017-11-09 19:47:06 +00:00
this.guide.start();
2017-11-12 20:26:23 +00:00
this.resize();
this.draw();
2016-12-31 17:18:01 +00:00
}
// Cursor
this.mouse_down = function(e)
{
2017-11-05 00:52:05 +00:00
var o = e.target.getAttribute("data-operation");
if(!o){ return; }
if(o == "line"){ this.draw_line(); }
if(o == "arc_c"){ this.draw_arc("0,1"); }
2017-11-05 04:58:53 +00:00
if(o == "arc_r"){ this.draw_arc("0,0"); }
if(o == "bezier"){ this.draw_bezier(); }
2017-11-05 19:38:14 +00:00
if(o == "close"){ this.draw_close(); }
2017-11-10 19:46:11 +00:00
if(o == "mirror"){ this.mod_mirror(); }
2017-11-05 00:52:05 +00:00
if(o == "export"){ this.export(); }
2016-12-31 17:18:01 +00:00
}
this.mouse_move = function(e)
{
2017-11-07 11:04:47 +00:00
var pos = this.position_in_grid(new Pos(e.clientX,e.clientY));
pos = this.position_on_grid(pos);
2016-12-31 17:18:01 +00:00
2017-11-12 21:47:34 +00:00
this.cursor.style.left = Math.floor(-(pos.x-this.grid_width));
this.cursor.style.top = Math.floor(pos.y+this.grid_height);
2017-11-12 21:50:25 +00:00
this.cursor_coord.className = -pos.x > this.width/2 ? "fl left" : "fl"
2017-11-12 21:47:34 +00:00
this.cursor_coord.textContent = parseInt(-pos.x/this.grid_width)+","+parseInt(pos.y/this.grid_height);
2016-12-31 17:18:01 +00:00
}
this.mouse_up = function(e)
{
2017-11-07 11:04:47 +00:00
var pos = this.position_in_grid(new Pos(e.clientX,e.clientY));
pos = this.position_on_grid(pos);
2017-11-07 21:40:13 +00:00
if(e.altKey){ dotgrid.delete_at(pos); return; }
2017-11-07 11:04:47 +00:00
if(pos.x>0) return;
2017-11-06 04:35:29 +00:00
2017-11-12 21:47:34 +00:00
if(from === null){ this.set_from(pos.scale(1/this.scale)); }
else if(to === null){ this.set_to(pos.scale(1/this.scale)); }
else{ this.set_end(pos.scale(1/this.scale)); }
2017-11-04 23:59:11 +00:00
this.draw();
2016-12-31 17:18:01 +00:00
}
// Setters
this.set_from = function(pos)
{
from = pos;
2017-11-12 21:47:34 +00:00
cursor_from.style.left = Math.floor(-pos.x*this.scale + this.grid_width);
cursor_from.style.top = Math.floor(pos.y*this.scale + this.grid_height);
2016-12-31 17:18:01 +00:00
}
this.set_to = function(pos)
{
2017-11-12 21:47:34 +00:00
cursor_to.style.left = Math.floor(-pos.x*this.scale + this.grid_width);
cursor_to.style.top = Math.floor(pos.y*this.scale + this.grid_height);
2016-12-31 17:18:01 +00:00
to = pos;
}
2017-11-04 23:59:11 +00:00
this.set_end = function(pos)
{
2017-11-12 21:47:34 +00:00
cursor_end.style.left = Math.floor(-pos.x*this.scale + this.grid_width);
cursor_end.style.top = Math.floor(pos.y*this.scale + this.grid_height);
2017-11-04 23:59:11 +00:00
end = pos;
}
2017-11-07 21:40:13 +00:00
this.delete_at = function(pos)
{
var segs = [];
for(id in this.segments){
var s = this.segments[id];
if(s.from && s.from.is_equal(pos)){ continue; }
if(s.to && s.to.is_equal(pos)){ continue; }
if(s.end && s.end.is_equal(pos)){ continue; }
segs.push(s);
}
this.segments = segs;
this.draw();
}
2017-11-04 23:59:11 +00:00
this.mod_thickness = function(mod)
{
2017-11-07 06:59:45 +00:00
this.thickness = Math.max(this.thickness+mod,0);
2017-11-10 19:46:11 +00:00
this.cursor_coord.textContent = this.thickness;
2017-11-04 23:59:11 +00:00
this.draw();
}
this.mod_linecap_index = 1;
this.mod_linecap = function(mod)
{
var a = ["butt","square","round"];
this.mod_linecap_index += 1;
this.linecap = a[this.mod_linecap_index % a.length];
this.draw();
}
2017-11-07 11:04:47 +00:00
this.mod_move = function(move)
2017-11-04 23:59:11 +00:00
{
2017-11-06 00:18:57 +00:00
if(!to && !end && from){
2017-11-07 11:04:47 +00:00
this.set_from(new Pos(from.x-(move.x),from.y+(move.y)))
2017-11-05 00:52:05 +00:00
this.draw();
return;
}
2017-11-06 00:18:57 +00:00
if(!end && to){
2017-11-07 11:04:47 +00:00
this.set_to(new Pos(to.x-(move.x),to.y+(move.y)))
2017-11-05 00:52:05 +00:00
this.draw();
return;
2017-11-04 23:59:11 +00:00
}
2017-11-06 00:18:57 +00:00
if(end){
2017-11-07 11:04:47 +00:00
this.set_end(new Pos(end.x-(move.x),end.y+(move.y)))
2017-11-06 00:18:57 +00:00
this.draw();
2017-11-06 04:35:29 +00:00
return;
2017-11-06 00:18:57 +00:00
}
// Move offset
2017-11-07 11:04:47 +00:00
this.offset = this.offset.add(new Pos(move.x,move.y));
2017-11-04 23:59:11 +00:00
this.draw();
}
2017-11-10 19:46:11 +00:00
this.mirror_index = 0;
this.mod_mirror = function()
{
this.mirror_index += 1;
this.mirror_index = this.mirror_index > 3 ? 0 : this.mirror_index;
this.draw();
}
2017-11-06 01:10:37 +00:00
this.toggle_fill = function()
{
dotgrid.fill = dotgrid.fill ? false : true;
this.draw();
}
2017-11-12 21:47:34 +00:00
this.draw = function(exp = false)
2017-11-04 23:59:11 +00:00
{
var d = "";
var prev = "";
for(id in this.segments){
var segment = this.segments[id];
d += segment.to_segment(prev)+" ";
prev = segment;
}
this.path.setAttribute("d",d);
this.svg_el.style.width = this.width;
this.svg_el.style.height = this.height;
this.svg_el.style.stroke = this.color;
this.svg_el.style.strokeLinecap = this.linecap;
2017-11-12 21:47:34 +00:00
this.svg_el.style.strokeWidth = this.thickness*this.scale;
2017-11-06 01:10:37 +00:00
this.svg_el.style.fill = this.fill ? "black" : "none";
2017-11-04 23:59:11 +00:00
2017-11-12 21:47:34 +00:00
//console.log(this.svg_el)
2017-11-10 19:46:11 +00:00
// Draw Mirror
if(this.mirror_index == 1){
this.mirror_path.setAttribute("d",d);
2017-11-12 21:47:34 +00:00
this.mirror_path.setAttribute("transform","translate("+(this.width - (this.offset.x*this.scale))+","+(this.offset.y*this.scale)+"),scale(-1,1)")
2017-11-10 19:46:11 +00:00
}
else if(this.mirror_index == 2){
this.mirror_path.setAttribute("d",d);
2017-11-12 21:47:34 +00:00
this.mirror_path.setAttribute("transform","translate("+((this.offset.x*this.scale))+","+(this.height - (this.offset.y*this.scale))+"),scale(1,-1)")
2017-11-10 19:46:11 +00:00
}
else if(this.mirror_index == 3){
this.mirror_path.setAttribute("d",d);
2017-11-12 21:47:34 +00:00
this.mirror_path.setAttribute("transform","translate("+(this.width -(this.offset.x*this.scale))+","+(this.height - (this.offset.y*this.scale))+"),scale(-1,-1)")
2017-11-10 19:46:11 +00:00
}
else{
this.mirror_path.setAttribute("d",'M0,0');
this.mirror_path.setAttribute("transform","")
}
2017-11-06 00:18:57 +00:00
2017-11-12 21:47:34 +00:00
this.offset_el.setAttribute("transform","translate("+(this.offset.x*this.scale)+","+(this.offset.y*this.scale)+")")
2017-11-05 19:53:59 +00:00
2017-11-09 19:47:06 +00:00
this.render.draw();
2017-11-04 23:59:11 +00:00
this.update_interface();
}
2016-12-31 17:18:01 +00:00
// Draw
2017-11-05 00:52:05 +00:00
this.draw_line = function()
2016-12-31 17:37:10 +00:00
{
2017-11-07 02:41:41 +00:00
if(from === null || to === null){ return; }
2017-11-06 00:18:57 +00:00
2017-11-07 11:04:47 +00:00
to = new Pos(to.x * -1, to.y).sub(this.offset)
from = new Pos(from.x * -1,from.y).sub(this.offset)
end = end ? new Pos(end.x * -1,end.y).sub(this.offset) : null;
2017-11-06 00:18:57 +00:00
2017-11-07 02:41:41 +00:00
this.segments.push(new Path_Line(from,to,end));
2016-12-31 17:18:01 +00:00
2017-11-07 02:41:41 +00:00
this.draw();
2017-11-07 21:40:13 +00:00
this.reset();
2016-12-31 17:18:01 +00:00
}
2016-12-31 18:16:00 +00:00
this.draw_arc = function(orientation)
2016-12-31 17:18:01 +00:00
{
2016-12-31 18:29:31 +00:00
if(from === null || to === null){ return; }
2017-11-07 11:04:47 +00:00
to = new Pos(to.x * -1, to.y).sub(this.offset)
from = new Pos(from.x * -1,from.y).sub(this.offset)
2017-11-07 11:25:14 +00:00
end = end ? new Pos(end.x * -1,end.y).sub(this.offset) : null;
2017-11-06 05:45:41 +00:00
2017-11-07 02:41:41 +00:00
this.segments.push(new Path_Arc(from,to,orientation,end));
2017-11-04 23:59:11 +00:00
this.draw();
2017-11-07 21:40:13 +00:00
this.reset();
2017-11-04 23:59:11 +00:00
}
this.draw_bezier = function()
{
2017-11-06 05:45:41 +00:00
if(from === null || to === null || end === null){ return; }
2017-11-04 23:59:11 +00:00
2017-11-07 11:04:47 +00:00
to = new Pos(to.x * -1, to.y).sub(this.offset)
from = new Pos(from.x * -1,from.y).sub(this.offset)
end = new Pos(end.x * -1,end.y).sub(this.offset)
2017-11-07 02:41:41 +00:00
this.segments.push(new Path_Bezier(from,to,end));
2017-01-04 17:48:08 +00:00
2017-11-04 23:59:11 +00:00
this.draw();
2017-11-07 21:40:13 +00:00
this.reset();
2017-01-04 17:48:08 +00:00
}
2017-11-05 04:33:04 +00:00
this.draw_close = function()
{
if(this.segments.length == 0){ return; }
2017-11-05 19:38:14 +00:00
if(this.segments[this.segments.length-1].name == "close"){ return; }
2017-11-05 04:33:04 +00:00
this.segments.push(new Path_Close());
2017-11-06 04:35:29 +00:00
2017-11-05 04:33:04 +00:00
this.draw();
2017-11-07 21:40:13 +00:00
this.reset();
2017-11-05 04:33:04 +00:00
}
2016-12-31 17:37:10 +00:00
this.reset = function()
2016-12-31 17:18:01 +00:00
{
from = null;
to = null;
2017-11-04 23:59:11 +00:00
end = null;
2016-12-31 17:37:10 +00:00
cursor_from.style.left = -100;
cursor_from.style.top = -100;
cursor_to.style.left = -100;
cursor_to.style.top = -100;
2017-11-04 23:59:11 +00:00
cursor_end.style.left = -100;
cursor_end.style.top = -100;
2016-12-31 17:18:01 +00:00
}
2017-11-07 21:40:13 +00:00
this.clear = function()
{
this.reset();
this.segments = [];
this.thickness = 10
this.linecap = "square"
this.color = "#000000"
this.draw();
}
2016-12-31 17:47:37 +00:00
this.erase = function()
{
2017-11-05 19:15:31 +00:00
if(from || to || end){
this.reset();
}
else{
2017-11-06 04:35:29 +00:00
this.segments.pop();
2017-11-05 19:15:31 +00:00
}
2017-11-04 23:59:11 +00:00
this.draw();
2016-12-31 17:47:37 +00:00
}
2016-12-31 20:47:40 +00:00
this.export = function()
{
2017-11-05 04:33:04 +00:00
if(this.segments.length == 0){ return; }
2017-11-12 21:47:34 +00:00
this.scale = 1
this.width = 300
this.height = 300
this.draw()
var svg = this.svg_el.outerHTML
2017-11-06 04:35:29 +00:00
2017-11-12 21:47:34 +00:00
dotgrid.resize()
2017-11-05 01:06:00 +00:00
dialog.showSaveDialog((fileName) => {
2017-11-12 21:47:34 +00:00
dotgrid.resize()
2017-11-05 01:06:00 +00:00
if (fileName === undefined){ return; }
2017-11-12 21:47:34 +00:00
fs.writeFile(fileName+".svg", svg, (err) => {
2017-11-05 01:06:00 +00:00
if(err){ alert("An error ocurred creating the file "+ err.message); return; }
});
2017-11-09 19:47:06 +00:00
fs.writeFile(fileName+'.png', dotgrid.render.buffer());
2017-11-06 04:35:29 +00:00
});
2017-11-04 23:59:11 +00:00
}
this.update_interface = function()
{
var html = "";
2017-11-05 00:52:05 +00:00
if(from && to){
2017-11-06 01:10:37 +00:00
html += "<img data-operation='line' title='line (d)' src='media/icons/line.svg' class='icon'/>";
html += "<img data-operation='arc_c' title='arc clockwise (s)' src='media/icons/arc_clockwise.svg' class='icon'/>";
html += "<img data-operation='arc_r' title='arc reverse (a)' src='media/icons/arc_reverse.svg' class='icon'/>";
2017-11-05 00:52:05 +00:00
}
else{
2017-11-06 01:10:37 +00:00
html += "<img title='line (d)' src='media/icons/line.svg' class='icon inactive'/>";
html += "<img title='arc clockwise (s)' src='media/icons/arc_clockwise.svg' class='icon inactive'/>";
html += "<img title='arc reverse (a)' src='media/icons/arc_reverse.svg' class='icon inactive'/>";
2017-11-05 00:52:05 +00:00
}
2017-11-04 23:59:11 +00:00
2017-11-05 00:52:05 +00:00
if(from && to && end){
2017-11-06 04:35:29 +00:00
html += "<img data-operation='bezier' title='bezier (f)' src='media/icons/bezier.svg' class='icon'/>";
2017-11-05 00:52:05 +00:00
}
else{
2017-11-06 01:10:37 +00:00
html += "<img title='bezier (f)' src='media/icons/bezier.svg' class='icon inactive'/>";
2017-11-05 00:52:05 +00:00
}
2017-11-04 23:59:11 +00:00
2017-11-05 19:38:14 +00:00
if(this.segments.length > 0 && this.segments[this.segments.length-1].name != "close"){
2017-11-06 01:10:37 +00:00
html += "<img data-operation='close (r)' title='close' src='media/icons/close.svg' class='icon'/>";
2017-11-05 19:38:14 +00:00
}
else{
2017-11-06 01:10:37 +00:00
html += "<img title='close (r)' src='media/icons/close.svg' class='icon inactive'/>";
2017-11-05 19:38:14 +00:00
}
2017-11-10 19:46:11 +00:00
if(this.segments.length > 0 && this.mirror_index != 0){
2017-11-06 01:10:37 +00:00
html += "<img data-operation='mirror' title='mirror (space)' src='media/icons/mirror.svg' class='icon' style='margin-left:35px'/>";
2017-11-05 19:53:59 +00:00
}
else{
2017-11-06 01:10:37 +00:00
html += "<img data-operation='mirror' title='mirror (space)' src='media/icons/mirror.svg' class='icon inactive' style='margin-left:35px'/>";
2017-11-05 19:53:59 +00:00
}
2017-11-05 00:52:05 +00:00
if(this.segments.length > 0){
2017-11-06 01:10:37 +00:00
html += "<img data-operation='export' title='export (e)' src='media/icons/export.svg' class='icon right'/>";
2017-11-05 00:52:05 +00:00
}
else{
2017-11-06 01:10:37 +00:00
html += "<img title='export (e)' src='media/icons/export.svg' class='icon right inactive'/>";
2017-11-05 00:52:05 +00:00
}
2017-11-06 04:35:29 +00:00
2017-11-04 23:59:11 +00:00
this.interface.innerHTML = html;
2016-12-31 20:47:40 +00:00
}
2016-12-31 17:18:01 +00:00
// Normalizers
2017-11-07 11:04:47 +00:00
this.position_in_grid = function(pos)
2016-12-31 17:18:01 +00:00
{
2017-11-12 21:47:34 +00:00
return new Pos((window.innerWidth/2) - (this.width/2) - pos.x,pos.y - (30+10*(this.scale)))
2016-12-31 17:18:01 +00:00
}
2017-11-07 11:04:47 +00:00
this.position_on_grid = function(pos) // rounds the mouse position to the nearest cell, and limits the coords to within the box
2016-12-31 17:18:01 +00:00
{
2017-11-07 11:04:47 +00:00
x = Math.round(pos.x/this.grid_width)*this.grid_width
2017-11-12 21:47:34 +00:00
y = Math.round(pos.y/this.grid_height)*this.grid_height
2017-11-07 06:55:51 +00:00
off = (x<-this.width || x>0 || y>this.height || y<0)
if(off) { // change position so the cursor will not be seen
x = 50
y = -50
}
2017-11-07 11:04:47 +00:00
return new Pos(x,y);
2016-12-31 15:00:57 +00:00
}
2017-11-12 21:47:34 +00:00
this.resize = function()
{
this.scale = Math.min((window.innerWidth-90)/300,(window.innerHeight-100)/320)
this.width = dotgrid.scale*300
this.height = dotgrid.scale*300
this.element.style.width = this.width
this.element.style.height = this.height
this.element.style.padding = Math.floor(10*this.scale)+"px"
this.svg_el.setAttribute("width",this.width+"px");
this.svg_el.setAttribute("height",this.height+"px");
this.grid_width = dotgrid.width/dotgrid.grid_x;
this.grid_height = dotgrid.height/dotgrid.grid_y;
this.guide.update()
//cursor updates
if(from) {
cursor_from.style.left = Math.floor(-from.x*this.scale + this.grid_width);
cursor_from.style.top = Math.floor(from.y*this.scale + this.grid_height);
}
if(to) {
cursor_to.style.left = Math.floor(-to.x*this.scale + this.grid_width);
cursor_to.style.top = Math.floor(to.y*this.scale + this.grid_height);
}
if(end) {
cursor_end.style.left = Math.floor(-end.x*this.scale + this.grid_width);
cursor_end.style.top = Math.floor(end.y*this.scale + this.grid_height);
}
}
2017-11-06 04:35:29 +00:00
}
2017-11-07 02:10:09 +00:00
window.addEventListener('dragover',function(e)
{
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = 'copy';
});
2017-11-12 21:47:34 +00:00
window.addEventListener('resize', function(e)
{
dotgrid.resize()
dotgrid.draw()
}, false);
2017-11-07 02:10:09 +00:00
window.addEventListener('drop', function(e)
{
e.preventDefault();
e.stopPropagation();
var files = e.dataTransfer.files;
for(file_id in files){
var file = files[file_id];
if(file.name.indexOf(".thm") == -1){ console.log("skipped",file); continue; }
var path = file.path;
var reader = new FileReader();
reader.onload = function(e){
var o = JSON.parse(e.target.result);
dotgrid.theme.install(o);
};
reader.readAsText(file);
return;
}
});