2018-03-06 22:08:34 -05:00
|
|
|
function Dotgrid(width,height,grid_x,grid_y,block_x,block_y)
|
2016-12-31 10:00:57 -05:00
|
|
|
{
|
2018-01-12 03:09:26 -05:00
|
|
|
this.controller = new Controller();
|
2017-11-06 21:10:09 -05:00
|
|
|
this.theme = new Theme();
|
2017-11-14 16:11:09 -05:00
|
|
|
this.interface = new Interface();
|
2018-01-31 04:10:48 -05:00
|
|
|
this.history = new History();
|
2018-02-05 18:39:25 -05:00
|
|
|
this.guide = new Guide();
|
2018-05-10 18:06:03 -04:00
|
|
|
this.renderer = new Renderer();
|
2018-02-05 18:39:25 -05:00
|
|
|
this.tool = new Tool();
|
2018-03-06 19:50:41 -05:00
|
|
|
this.picker = new Picker();
|
2018-08-02 18:57:35 -04:00
|
|
|
this.cursor = new Cursor();
|
2017-11-06 21:10:09 -05:00
|
|
|
|
2016-12-31 12:18:01 -05:00
|
|
|
this.grid_x = grid_x;
|
|
|
|
this.grid_y = grid_y;
|
2016-12-31 15:37:13 -05:00
|
|
|
this.block_x = block_x;
|
|
|
|
this.block_y = block_y;
|
2016-12-31 16:35:14 -05:00
|
|
|
|
2016-12-31 10:00:57 -05:00
|
|
|
this.install = function()
|
2018-07-07 20:15:35 -04:00
|
|
|
{
|
2018-05-08 05:05:19 -04:00
|
|
|
document.getElementById("app").appendChild(this.guide.el);
|
2017-11-04 20:52:05 -04:00
|
|
|
|
2017-11-06 21:10:09 -05:00
|
|
|
this.theme.start();
|
2018-03-06 17:57:52 -05:00
|
|
|
this.tool.start();
|
2017-11-09 14:47:06 -05:00
|
|
|
this.guide.start();
|
2017-11-14 16:11:09 -05:00
|
|
|
this.interface.start();
|
2018-01-12 03:09:26 -05:00
|
|
|
|
2018-01-12 22:24:18 -05:00
|
|
|
this.controller.add("default","*","About",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Dotgrid'); },"CmdOrCtrl+,");
|
|
|
|
this.controller.add("default","*","Fullscreen",() => { app.toggle_fullscreen(); },"CmdOrCtrl+Enter");
|
|
|
|
this.controller.add("default","*","Hide",() => { app.toggle_visible(); },"CmdOrCtrl+H");
|
|
|
|
this.controller.add("default","*","Inspect",() => { app.inspect(); },"CmdOrCtrl+.");
|
|
|
|
this.controller.add("default","*","Documentation",() => { dotgrid.controller.docs(); },"CmdOrCtrl+Esc");
|
2018-01-12 15:00:53 -05:00
|
|
|
this.controller.add("default","*","Reset",() => { dotgrid.reset(); dotgrid.theme.reset(); },"CmdOrCtrl+Backspace");
|
|
|
|
this.controller.add("default","*","Quit",() => { app.exit(); },"CmdOrCtrl+Q");
|
|
|
|
|
2018-01-12 03:46:09 -05:00
|
|
|
this.controller.add("default","File","New",() => { dotgrid.new(); },"CmdOrCtrl+N");
|
|
|
|
this.controller.add("default","File","Open",() => { dotgrid.open(); },"CmdOrCtrl+O");
|
2018-05-10 17:57:14 -04:00
|
|
|
this.controller.add("default","File","Save(.grid)",() => { dotgrid.save(); },"CmdOrCtrl+S");
|
|
|
|
this.controller.add("default","File","Render(.png)",() => { dotgrid.render(); },"CmdOrCtrl+R");
|
|
|
|
this.controller.add("default","File","Export(.svg)",() => { dotgrid.export(); },"CmdOrCtrl+E");
|
2018-01-12 03:46:09 -05:00
|
|
|
|
2018-01-13 15:11:57 -05:00
|
|
|
this.controller.add("default","Edit","Copy",() => { document.execCommand('copy'); },"CmdOrCtrl+C");
|
2018-02-07 01:44:18 -05:00
|
|
|
this.controller.add("default","Edit","Cut",() => { document.execCommand('cut'); },"CmdOrCtrl+X");
|
2018-01-13 15:11:57 -05:00
|
|
|
this.controller.add("default","Edit","Paste",() => { document.execCommand('paste'); },"CmdOrCtrl+V");
|
2018-02-05 22:27:48 -05:00
|
|
|
this.controller.add("default","Edit","Undo",() => { dotgrid.tool.undo(); },"CmdOrCtrl+Z");
|
|
|
|
this.controller.add("default","Edit","Redo",() => { dotgrid.tool.redo(); },"CmdOrCtrl+Shift+Z");
|
2018-02-05 18:39:25 -05:00
|
|
|
this.controller.add("default","Edit","Delete",() => { dotgrid.tool.remove_segment(); },"Backspace");
|
2018-02-05 20:23:25 -05:00
|
|
|
this.controller.add("default","Edit","Deselect",() => { dotgrid.tool.clear(); },"Esc");
|
2018-01-12 03:46:09 -05:00
|
|
|
|
2018-02-05 18:39:25 -05:00
|
|
|
this.controller.add("default","Stroke","Line",() => { dotgrid.tool.cast("line"); },"A");
|
2018-02-05 22:27:48 -05:00
|
|
|
this.controller.add("default","Stroke","Arc",() => { dotgrid.tool.cast("arc_c"); },"S"); // 0,1
|
|
|
|
this.controller.add("default","Stroke","Arc Rev",() => { dotgrid.tool.cast("arc_r")},"D"); // 0,0
|
|
|
|
this.controller.add("default","Stroke","Bezier",() => { dotgrid.tool.cast("bezier") },"F");
|
2018-05-10 17:13:01 -04:00
|
|
|
this.controller.add("default","Stroke","Close",() => { dotgrid.tool.cast("close") },"Z");
|
2018-01-12 03:46:09 -05:00
|
|
|
|
2018-08-02 21:10:57 -04:00
|
|
|
this.controller.add("default","Effect","Linecap",() => { dotgrid.tool.toggle("linecap"); },"Q");
|
|
|
|
this.controller.add("default","Effect","Linejoin",() => { dotgrid.tool.toggle("linejoin"); },"W");
|
|
|
|
this.controller.add("default","Effect","Mirror",() => { dotgrid.tool.toggle("mirror"); },"E");
|
|
|
|
this.controller.add("default","Effect","Fill",() => { dotgrid.tool.toggle("fill"); },"R");
|
2018-03-21 03:10:09 -04:00
|
|
|
this.controller.add("default","Effect","Color",() => { dotgrid.picker.start(); },"G");
|
2018-08-02 21:10:57 -04:00
|
|
|
this.controller.add("default","Effect","Thicker",() => { dotgrid.tool.toggle("thickness",1) },"}");
|
|
|
|
this.controller.add("default","Effect","Thinner",() => { dotgrid.tool.toggle("thickness",-1) },"{");
|
|
|
|
this.controller.add("default","Effect","Thicker +5",() => { dotgrid.tool.toggle("thickness",5) },"]");
|
2018-08-02 21:48:16 -04:00
|
|
|
this.controller.add("default","Effect","Thinner -5",() => { dotgrid.tool.toggle("thickness",-5) },"[");
|
2018-02-06 13:42:34 -05:00
|
|
|
|
2018-05-10 16:46:50 -04:00
|
|
|
this.controller.add("default","Manual","Add Point",() => { dotgrid.tool.add_vertex(dotgrid.cursor.pos); dotgrid.guide.refresh() },"Enter");
|
|
|
|
this.controller.add("default","Manual","Move Up",() => { dotgrid.cursor.pos.y -= 15; dotgrid.guide.refresh() },"Up");
|
|
|
|
this.controller.add("default","Manual","Move Right",() => { dotgrid.cursor.pos.x -= 15; dotgrid.guide.refresh() },"Right");
|
|
|
|
this.controller.add("default","Manual","Move Down",() => { dotgrid.cursor.pos.y += 15; dotgrid.guide.refresh() },"Down");
|
|
|
|
this.controller.add("default","Manual","Move Left",() => { dotgrid.cursor.pos.x += 15; dotgrid.guide.refresh() },"Left");
|
2018-05-07 19:32:00 -04:00
|
|
|
this.controller.add("default","Manual","Remove Point",() => { dotgrid.tool.remove_segments_at(dotgrid.cursor.pos); },"CmdOrCtrl+Backspace");
|
|
|
|
|
2018-03-06 15:32:31 -05:00
|
|
|
this.controller.add("default","Layers","Foreground",() => { dotgrid.tool.select_layer(0) },"CmdOrCtrl+1");
|
|
|
|
this.controller.add("default","Layers","Middleground",() => { dotgrid.tool.select_layer(1) },"CmdOrCtrl+2");
|
|
|
|
this.controller.add("default","Layers","Background",() => { dotgrid.tool.select_layer(2) },"CmdOrCtrl+3");
|
2018-02-06 13:42:34 -05:00
|
|
|
|
2018-01-29 15:48:58 -05:00
|
|
|
this.controller.add("default","View","Tools",() => { dotgrid.interface.toggle(); },"U");
|
2018-01-12 22:24:18 -05:00
|
|
|
this.controller.add("default","View","Grid",() => { dotgrid.guide.toggle(); },"H");
|
2018-02-18 21:29:07 -05:00
|
|
|
|
2018-03-06 19:50:41 -05:00
|
|
|
this.controller.add("picker","*","About",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Dotgrid'); },"CmdOrCtrl+,");
|
|
|
|
this.controller.add("picker","*","Fullscreen",() => { app.toggle_fullscreen(); },"CmdOrCtrl+Enter");
|
|
|
|
this.controller.add("picker","*","Hide",() => { app.toggle_visible(); },"CmdOrCtrl+H");
|
|
|
|
this.controller.add("picker","*","Inspect",() => { app.inspect(); },"CmdOrCtrl+.");
|
|
|
|
this.controller.add("picker","*","Documentation",() => { dotgrid.controller.docs(); },"CmdOrCtrl+Esc");
|
|
|
|
this.controller.add("picker","*","Reset",() => { dotgrid.reset(); dotgrid.theme.reset(); },"CmdOrCtrl+Backspace");
|
|
|
|
this.controller.add("picker","*","Quit",() => { app.exit(); },"CmdOrCtrl+Q");
|
|
|
|
|
|
|
|
this.controller.add_role("picker","Edit","undo");
|
|
|
|
this.controller.add_role("picker","Edit","redo");
|
|
|
|
this.controller.add_role("picker","Edit","cut");
|
|
|
|
this.controller.add_role("picker","Edit","copy");
|
|
|
|
this.controller.add_role("picker","Edit","paste");
|
|
|
|
this.controller.add_role("picker","Edit","delete");
|
|
|
|
this.controller.add_role("picker","Edit","selectall");
|
|
|
|
|
|
|
|
this.controller.add("picker","Mode","Stop Picker Mode",() => { dotgrid.picker.stop(); },"Escape");
|
2018-07-07 20:15:35 -04:00
|
|
|
|
2018-01-12 03:09:26 -05:00
|
|
|
this.controller.commit();
|
2017-11-12 15:26:23 -05:00
|
|
|
|
2018-08-02 18:57:35 -04:00
|
|
|
document.addEventListener('mousedown', function(e){ dotgrid.cursor.down(e); }, false);
|
|
|
|
document.addEventListener('mousemove', function(e){ dotgrid.cursor.move(e); }, false);
|
|
|
|
document.addEventListener('contextmenu', function(e){ dotgrid.cursor.alt(e); }, false);
|
|
|
|
document.addEventListener('mouseup', function(e){ dotgrid.cursor.up(e);}, false);
|
2018-07-26 02:56:06 -04:00
|
|
|
document.addEventListener('copy', function(e){ dotgrid.copy(e); }, false);
|
|
|
|
document.addEventListener('cut', function(e){ dotgrid.cut(e); }, false);
|
|
|
|
document.addEventListener('paste', function(e){ dotgrid.paste(e); }, false);
|
2018-01-11 22:22:50 -05:00
|
|
|
window.addEventListener('drop', dotgrid.drag);
|
2018-07-26 02:56:06 -04:00
|
|
|
|
2018-01-31 04:10:48 -05:00
|
|
|
this.new();
|
2016-12-31 12:18:01 -05:00
|
|
|
}
|
|
|
|
|
2018-05-07 01:03:35 -04:00
|
|
|
// File
|
2018-01-12 03:46:09 -05:00
|
|
|
|
2018-01-12 03:09:26 -05:00
|
|
|
this.new = function()
|
|
|
|
{
|
2018-07-17 20:52:23 -04:00
|
|
|
this.set_zoom(1.0)
|
2018-05-07 00:51:58 -04:00
|
|
|
this.set_size({width:300,height:300})
|
2018-02-05 22:27:48 -05:00
|
|
|
this.history.push(this.tool.layers);
|
2018-05-07 01:03:35 -04:00
|
|
|
this.clear();
|
2018-01-12 03:09:26 -05:00
|
|
|
}
|
|
|
|
|
2018-05-10 17:57:14 -04:00
|
|
|
this.open = function()
|
|
|
|
{
|
|
|
|
var paths = dialog.showOpenDialog({properties: ['openFile'],filters:[{name:"Dotgrid Image",extensions:["dot","grid"]}]});
|
|
|
|
|
|
|
|
if(!paths){ console.log("Nothing to load"); return; }
|
|
|
|
|
|
|
|
fs.readFile(paths[0], 'utf-8', (err, data) => {
|
|
|
|
if(err){ alert("An error ocurred reading the file :" + err.message); return; }
|
2018-05-10 18:06:03 -04:00
|
|
|
this.tool.replace(JSON.parse(data.toString().trim()));
|
|
|
|
this.guide.refresh();
|
2018-05-10 17:57:14 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-10 18:37:10 -04:00
|
|
|
this.save = function(content = this.tool.export())
|
2018-01-12 03:09:26 -05:00
|
|
|
{
|
2018-08-03 23:55:08 -04:00
|
|
|
if(dotgrid.tool.length() < 1){ console.log("Nothing to save"); return; }
|
|
|
|
|
2018-07-07 20:15:35 -04:00
|
|
|
dialog.showSaveDialog({
|
|
|
|
title:"Save to .grid",
|
|
|
|
filters: [{name: "Dotgrid", extensions: ["grid", "dot"]}]
|
|
|
|
},(fileName) => {
|
2018-01-12 03:09:26 -05:00
|
|
|
if (fileName === undefined){ return; }
|
2018-05-16 16:58:31 -04:00
|
|
|
fileName = fileName.substr(-5,5) != ".grid" ? fileName+".grid" : fileName;
|
|
|
|
fs.writeFileSync(fileName, content);
|
2018-05-10 18:06:03 -04:00
|
|
|
this.guide.refresh()
|
2018-01-12 03:09:26 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-16 18:53:29 -04:00
|
|
|
this.render = function(content = this.renderer.to_png({width:dotgrid.tool.settings.size.width*2,height:dotgrid.tool.settings.size.height*2}), ready = null, size = null)
|
2018-01-12 03:09:26 -05:00
|
|
|
{
|
2018-05-10 18:37:10 -04:00
|
|
|
if(!ready){return; }
|
2018-08-03 23:55:08 -04:00
|
|
|
if(dotgrid.tool.length() < 1){ console.log("Nothing to render"); return; }
|
2018-05-10 18:37:10 -04:00
|
|
|
|
2018-05-10 17:57:14 -04:00
|
|
|
dialog.showSaveDialog({title:"Render to .png"},(fileName) => {
|
|
|
|
if (fileName === undefined){ return; }
|
2018-05-16 16:58:31 -04:00
|
|
|
fileName = fileName.substr(-4,4) != ".png" ? fileName+".png" : fileName;
|
2018-05-10 19:08:51 -04:00
|
|
|
console.log(`Rendered ${size.width}x${size.height}`)
|
2018-05-16 16:58:31 -04:00
|
|
|
fs.writeFileSync(fileName, ready);
|
2018-05-10 17:57:14 -04:00
|
|
|
});
|
|
|
|
}
|
2018-01-12 03:09:26 -05:00
|
|
|
|
2018-05-10 18:37:10 -04:00
|
|
|
this.export = function(content = this.renderer.to_svg())
|
2018-05-10 17:57:14 -04:00
|
|
|
{
|
2018-08-03 23:55:08 -04:00
|
|
|
if(dotgrid.tool.length() < 1){ console.log("Nothing to export"); return; }
|
|
|
|
|
2018-05-10 18:06:03 -04:00
|
|
|
dialog.showSaveDialog({title:"Export to .svg"},(fileName) => {
|
2018-05-10 17:57:14 -04:00
|
|
|
if (fileName === undefined){ return; }
|
2018-05-16 16:58:31 -04:00
|
|
|
fileName = fileName.substr(-4,4) != ".svg" ? fileName+".svg" : fileName;
|
|
|
|
fs.writeFileSync(fileName, content);
|
2018-05-10 18:06:03 -04:00
|
|
|
this.guide.refresh()
|
2018-01-12 03:09:26 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-07 01:03:35 -04:00
|
|
|
// Basics
|
2018-07-07 20:15:35 -04:00
|
|
|
|
|
|
|
this.set_size = function(size = {width:300,height:300},interface = true,scale = 1)
|
2017-11-21 17:58:07 -05:00
|
|
|
{
|
2018-08-02 21:48:16 -04:00
|
|
|
size = { width:clamp(step(size.width,15),105,1080),height:clamp(step(size.height,15),120,1080)}
|
2018-05-06 19:15:23 -04:00
|
|
|
|
2018-05-07 18:47:09 -04:00
|
|
|
this.tool.settings.size.width = size.width
|
|
|
|
this.tool.settings.size.height = size.height
|
2018-05-10 04:01:31 -04:00
|
|
|
|
2018-05-12 17:50:19 -04:00
|
|
|
var win = require('electron').remote.getCurrentWindow();
|
|
|
|
win.setSize((size.width+100)*scale,(size.height+100+(interface ? 10 : 0))*scale,true);
|
2018-07-07 20:15:35 -04:00
|
|
|
|
2017-11-21 17:58:07 -05:00
|
|
|
this.grid_x = size.width/15
|
|
|
|
this.grid_y = size.height/15
|
2018-05-07 00:24:01 -04:00
|
|
|
|
2018-05-07 18:47:09 -04:00
|
|
|
this.grid_width = this.tool.settings.size.width/this.grid_x;
|
|
|
|
this.grid_height = this.tool.settings.size.height/this.grid_y;
|
2018-05-07 00:51:58 -04:00
|
|
|
|
2017-11-21 17:58:07 -05:00
|
|
|
dotgrid.guide.resize(size);
|
2018-05-10 17:13:01 -04:00
|
|
|
|
|
|
|
this.interface.refresh();
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2017-11-04 19:59:11 -04:00
|
|
|
}
|
|
|
|
|
2018-05-12 17:50:19 -04:00
|
|
|
this.set_zoom = function(scale)
|
|
|
|
{
|
|
|
|
this.set_size({width:this.tool.settings.size.width,height:this.tool.settings.size.height},true,scale)
|
|
|
|
webFrame.setZoomFactor(scale)
|
|
|
|
}
|
|
|
|
|
2016-12-31 12:18:01 -05:00
|
|
|
// Draw
|
2018-07-07 20:15:35 -04:00
|
|
|
|
2016-12-31 12:37:10 -05:00
|
|
|
this.reset = function()
|
2016-12-31 12:18:01 -05:00
|
|
|
{
|
2018-02-06 14:16:01 -05:00
|
|
|
this.tool.clear();
|
2016-12-31 12:18:01 -05:00
|
|
|
}
|
|
|
|
|
2017-11-07 16:40:13 -05:00
|
|
|
this.clear = function()
|
|
|
|
{
|
2018-02-04 16:09:46 -05:00
|
|
|
this.history.clear();
|
2018-02-06 14:16:01 -05:00
|
|
|
this.tool.reset();
|
2017-11-07 16:40:13 -05:00
|
|
|
this.reset();
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2018-05-10 17:47:09 -04:00
|
|
|
dotgrid.interface.refresh(true);
|
2017-11-07 16:40:13 -05:00
|
|
|
}
|
|
|
|
|
2018-01-11 22:22:50 -05:00
|
|
|
this.drag = function(e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-07-07 20:15:35 -04:00
|
|
|
|
2018-01-11 22:22:50 -05:00
|
|
|
var file = e.dataTransfer.files[0];
|
|
|
|
|
2018-04-09 00:50:52 -04:00
|
|
|
if(!file.path || file.path.indexOf(".dot") < 0 && file.path.indexOf(".grid") < 0){ console.log("Dotgrid","Not a dot file"); return; }
|
2018-01-11 22:22:50 -05:00
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function(e){
|
2018-02-07 15:34:17 -05:00
|
|
|
dotgrid.tool.replace(JSON.parse(e.target.result.toString().trim()));
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2018-01-11 22:22:50 -05:00
|
|
|
};
|
|
|
|
reader.readAsText(file);
|
|
|
|
}
|
|
|
|
|
2017-11-21 16:24:25 -05:00
|
|
|
this.copy = function(e)
|
|
|
|
{
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2018-01-13 15:11:57 -05:00
|
|
|
|
2018-07-26 04:40:06 -04:00
|
|
|
if(e.target !== this.picker.el){
|
2018-07-26 02:56:06 -04:00
|
|
|
e.clipboardData.setData('text/source', dotgrid.tool.export(dotgrid.tool.layer()));
|
|
|
|
e.clipboardData.setData('text/plain', dotgrid.tool.path());
|
|
|
|
e.clipboardData.setData('text/html', dotgrid.renderer.to_svg());
|
|
|
|
e.clipboardData.setData('text/svg+xml', dotgrid.renderer.to_svg());
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2018-02-07 01:44:18 -05:00
|
|
|
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2018-02-07 01:44:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.cut = function(e)
|
|
|
|
{
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2018-02-07 01:44:18 -05:00
|
|
|
|
2018-07-26 04:40:06 -04:00
|
|
|
if(e.target !== this.picker.el){
|
2018-07-26 02:56:06 -04:00
|
|
|
e.clipboardData.setData('text/plain', dotgrid.tool.export(dotgrid.tool.layer()));
|
|
|
|
e.clipboardData.setData('text/html', dotgrid.renderer.to_svg());
|
|
|
|
e.clipboardData.setData('text/svg+xml', dotgrid.renderer.to_svg());
|
|
|
|
dotgrid.tool.layers[dotgrid.tool.index] = [];
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2018-02-07 01:44:18 -05:00
|
|
|
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2017-11-21 16:24:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.paste = function(e)
|
|
|
|
{
|
2018-07-26 04:40:06 -04:00
|
|
|
if(e.target !== this.picker.el){
|
2018-07-26 02:56:06 -04:00
|
|
|
var data = e.clipboardData.getData("text/source");
|
|
|
|
if (is_json(data)) {
|
|
|
|
data = JSON.parse(data.trim());
|
|
|
|
dotgrid.tool.import(data);
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2018-05-07 21:32:06 -04:00
|
|
|
}
|
2018-07-07 20:15:35 -04:00
|
|
|
|
2018-05-10 16:46:50 -04:00
|
|
|
dotgrid.guide.refresh();
|
2017-11-21 16:24:25 -05:00
|
|
|
}
|
2017-11-05 23:35:29 -05:00
|
|
|
}
|
2017-11-06 21:10:09 -05:00
|
|
|
|
2017-11-12 16:47:34 -05:00
|
|
|
window.addEventListener('resize', function(e)
|
|
|
|
{
|
2018-07-17 20:52:23 -04:00
|
|
|
var size = {width:step(window.innerWidth-90,15),height:step(window.innerHeight-120,15)}
|
|
|
|
|
|
|
|
dotgrid.tool.settings.size.width = size.width
|
|
|
|
dotgrid.tool.settings.size.height = size.height
|
|
|
|
|
|
|
|
dotgrid.grid_x = size.width/15
|
|
|
|
dotgrid.grid_y = size.height/15
|
|
|
|
|
|
|
|
dotgrid.grid_width = dotgrid.tool.settings.size.width/dotgrid.grid_x;
|
|
|
|
dotgrid.grid_height = dotgrid.tool.settings.size.height/dotgrid.grid_y;
|
|
|
|
|
|
|
|
dotgrid.guide.resize(size);
|
|
|
|
|
|
|
|
dotgrid.interface.refresh();
|
|
|
|
dotgrid.guide.refresh();
|
|
|
|
|
2017-11-12 16:47:34 -05:00
|
|
|
}, false);
|
|
|
|
|
2018-01-11 22:22:50 -05:00
|
|
|
window.addEventListener('dragover',function(e)
|
2017-11-06 21:10:09 -05:00
|
|
|
{
|
|
|
|
e.stopPropagation();
|
2018-01-11 22:22:50 -05:00
|
|
|
e.preventDefault();
|
|
|
|
e.dataTransfer.dropEffect = 'copy';
|
2018-01-13 15:11:57 -05:00
|
|
|
});
|
2018-03-21 03:10:09 -04:00
|
|
|
|
|
|
|
String.prototype.capitalize = function()
|
|
|
|
{
|
|
|
|
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
|
2018-05-09 03:22:00 -04:00
|
|
|
}
|
2018-07-17 20:52:23 -04:00
|
|
|
|
|
|
|
function is_json(text){ try{ JSON.parse(text);return true; } catch(error){ return false; }}
|
|
|
|
function pos_is_equal(a,b){ return a && b && a.x == b.x && a.y == b.y }
|
|
|
|
function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
|
2018-08-02 18:57:35 -04:00
|
|
|
function step(v,s){ return Math.round(v/s) * s; }
|