From d1fad873c7e00e3271ecf68a3eb00b1418b414c0 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 11 May 2018 09:57:14 +1200 Subject: [PATCH] Divided export options --- desktop/sources/scripts/dotgrid.js | 50 ++++++++++++++++++++-------- desktop/sources/scripts/interface.js | 12 ++----- desktop/sources/scripts/tool.js | 8 +++++ 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/desktop/sources/scripts/dotgrid.js b/desktop/sources/scripts/dotgrid.js index 28566a1..64f60c0 100644 --- a/desktop/sources/scripts/dotgrid.js +++ b/desktop/sources/scripts/dotgrid.js @@ -35,7 +35,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y) this.controller.add("default","File","New",() => { dotgrid.new(); },"CmdOrCtrl+N"); this.controller.add("default","File","Open",() => { dotgrid.open(); },"CmdOrCtrl+O"); - this.controller.add("default","File","Save",() => { dotgrid.save(); },"CmdOrCtrl+S"); + 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"); this.controller.add("default","Edit","Copy",() => { document.execCommand('copy'); },"CmdOrCtrl+C"); this.controller.add("default","Edit","Cut",() => { document.execCommand('cut'); },"CmdOrCtrl+X"); @@ -120,19 +122,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y) this.clear(); } - this.save = function() - { - dotgrid.guide.refresh(); - - dialog.showSaveDialog((fileName) => { - if (fileName === undefined){ return; } - fs.writeFile(fileName+".svg", dotgrid.render.to_svg()); - fs.writeFile(fileName+'.png', dotgrid.render.to_png()); - fs.writeFile(fileName+'.grid', dotgrid.tool.export()); - dotgrid.guide.refresh() - }); - } - this.open = function() { var paths = dialog.showOpenDialog({properties: ['openFile'],filters:[{name:"Dotgrid Image",extensions:["dot","grid"]}]}); @@ -146,6 +135,39 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y) }); } + this.save = function() + { + dotgrid.guide.refresh(); + + dialog.showSaveDialog({title:"Save to .grid"},(fileName) => { + if (fileName === undefined){ return; } + fs.writeFile(fileName+'.grid', dotgrid.tool.export()); + dotgrid.guide.refresh() + }); + } + + this.render = function() + { + dotgrid.guide.refresh(); + + dialog.showSaveDialog({title:"Render to .png"},(fileName) => { + if (fileName === undefined){ return; } + fs.writeFile(fileName+'.png', dotgrid.render.to_png()); + dotgrid.guide.refresh() + }); + } + + this.export = function() + { + dotgrid.guide.refresh(); + + dialog.showSaveDialog({title:"Exoprt to .svg"},(fileName) => { + if (fileName === undefined){ return; } + fs.writeFile(fileName+".svg", dotgrid.render.to_svg()); + dotgrid.guide.refresh() + }); + } + // Cursor this.mouse_down = function(e) diff --git a/desktop/sources/scripts/interface.js b/desktop/sources/scripts/interface.js index 01b9194..5cc1b17 100644 --- a/desktop/sources/scripts/interface.js +++ b/desktop/sources/scripts/interface.js @@ -62,15 +62,9 @@ function Interface() document.getElementById("color").className.baseVal = "icon"; // Mirror - if(dotgrid.tool.style().mirror_style == 0){ - document.getElementById("mirror_path").setAttribute("d","M60,60 L60,60 L120,120 M180,180 L180,180 L240,240 M210,90 L210,90 L180,120 M120,180 L120,180 L90,210") - } - else if(dotgrid.tool.style().mirror_style == 1){ - document.getElementById("mirror_path").setAttribute("d","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210") - } - else if(dotgrid.tool.style().mirror_style == 2){ - document.getElementById("mirror_path").setAttribute("d","M210,90 L210,90 L90,210 M60,60 L60,60 L120,120 M180,180 L180,180 L240,240") - } + if(dotgrid.tool.style().mirror_style == 0){ document.getElementById("mirror_path").setAttribute("d","M60,60 L60,60 L120,120 M180,180 L180,180 L240,240 M210,90 L210,90 L180,120 M120,180 L120,180 L90,210") } + else if(dotgrid.tool.style().mirror_style == 1){ document.getElementById("mirror_path").setAttribute("d","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210") } + else if(dotgrid.tool.style().mirror_style == 2){ document.getElementById("mirror_path").setAttribute("d","M210,90 L210,90 L90,210 M60,60 L60,60 L120,120 M180,180 L180,180 L240,240") } this.prev_operation = dotgrid.cursor.operation; } diff --git a/desktop/sources/scripts/tool.js b/desktop/sources/scripts/tool.js index c3fb910..2b4d567 100644 --- a/desktop/sources/scripts/tool.js +++ b/desktop/sources/scripts/tool.js @@ -30,18 +30,21 @@ function Tool() { this.vertices = []; dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); } this.undo = function() { this.layers = dotgrid.history.prev(); dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); } this.redo = function() { this.layers = dotgrid.history.next(); dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); } // I/O @@ -57,6 +60,7 @@ function Tool() dotgrid.history.push(this.layers); this.clear(); dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); } this.replace = function(dot) @@ -73,6 +77,7 @@ function Tool() this.clear(); dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); dotgrid.history.push(this.layers); } @@ -85,6 +90,7 @@ function Tool() this.layer().pop(); this.clear(); dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); } this.remove_segments_at = function(pos) @@ -103,12 +109,14 @@ function Tool() } this.clear(); dotgrid.guide.refresh(); + dotgrid.interface.refresh(true); } this.add_vertex = function(pos) { pos = {x:Math.abs(pos.x),y:Math.abs(pos.y)} this.vertices.push(pos); + dotgrid.interface.refresh(true); } this.vertex_at = function(pos)