From 650288a2ed7693d24e8363239e69b83d85e43c65 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 6 Nov 2017 08:53:59 +1300 Subject: [PATCH] Added mirror mode --- sources/media/icons/mirror.svg | 1 + sources/scripts/dotgrid.js | 23 +++++++++++++++++++++-- sources/scripts/keyboard.js | 6 +++++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 sources/media/icons/mirror.svg diff --git a/sources/media/icons/mirror.svg b/sources/media/icons/mirror.svg new file mode 100644 index 0000000..30cc4f9 --- /dev/null +++ b/sources/media/icons/mirror.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sources/scripts/dotgrid.js b/sources/scripts/dotgrid.js index dc4e31c..167863f 100644 --- a/sources/scripts/dotgrid.js +++ b/sources/scripts/dotgrid.js @@ -26,6 +26,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca var end = null; this.svg_el = null; + this.mirror_el = null; + + this.mirror = false; this.path = document.createElementNS("http://www.w3.org/2000/svg", "path"); this.segments = []; @@ -70,6 +73,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca cursor_end.id = "cursor_end"; this.element.appendChild(cursor_end); + this.mirror_el = document.createElementNS("http://www.w3.org/2000/svg", "g"); + this.mirror_path = document.createElementNS("http://www.w3.org/2000/svg", "path"); + // Vector this.svg_el = document.createElementNS("http://www.w3.org/2000/svg", "svg"); this.svg_el.setAttribute("class","vector"); @@ -85,8 +91,10 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.svg_el.style.fill = "none"; this.svg_el.style.strokeLinecap = this.linecap; this.element.appendChild(this.svg_el); - - this.svg_el.appendChild(this.path); + + this.svg_el.appendChild(this.path); + this.svg_el.appendChild(this.mirror_el); + this.mirror_el.appendChild(this.mirror_path); this.draw(); } @@ -104,6 +112,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca if(o == "arc_r"){ this.draw_arc("0,0"); } if(o == "bezier"){ this.draw_bezier(); } if(o == "close"){ this.draw_close(); } + if(o == "mirror"){ this.mirror = this.mirror == true ? false : true; this.draw(); } if(o == "export"){ this.export(); } } @@ -210,6 +219,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.svg_el.style.strokeLinecap = this.linecap; this.svg_el.style.strokeWidth = this.thickness; + this.mirror_path.setAttribute("d",this.mirror ? d : ''); + this.mirror_path.setAttribute("transform","translate(300,0),scale(-1,1)") + this.update_interface(); } @@ -327,6 +339,13 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca html += ""; } + if(this.segments.length > 0 && !this.mirror){ + html += ""; + } + else{ + html += ""; + } + if(this.segments.length > 0){ html += ""; } diff --git a/sources/scripts/keyboard.js b/sources/scripts/keyboard.js index 8b6baae..95df952 100644 --- a/sources/scripts/keyboard.js +++ b/sources/scripts/keyboard.js @@ -2,7 +2,11 @@ function Keyboard() { this.listen = function(event) { - console.log(event.keyCode) + // save + if(event.key == "s" && (event.ctrlKey || event.metaKey)){ + dotgrid.export(); + return; + } switch (event.keyCode) { case 83 : dotgrid.draw_arc(event.shiftKey ? "1,1" : "0,1"); break;