From 29b5b0fa664827e244d3e6b5fa37ed23f04df886 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 10 Jan 2019 10:43:17 +1200 Subject: [PATCH 1/2] Added crest mode --- desktop/sources/index.html | 1 + desktop/sources/scripts/dotgrid.js | 22 ++++++++++------------ desktop/sources/scripts/manager.js | 16 +++++++++++----- desktop/sources/scripts/tool.js | 8 +++++++- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 1f12af5..a7834ee 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -70,6 +70,7 @@ DOTGRID.controller.add("default","Effect","Thinner",() => { DOTGRID.tool.toggle("thickness",-1) },"{"); DOTGRID.controller.add("default","Effect","Thicker +5",() => { DOTGRID.tool.toggle("thickness",5) },"]"); DOTGRID.controller.add("default","Effect","Thinner -5",() => { DOTGRID.tool.toggle("thickness",-5) },"["); + DOTGRID.controller.add("default","Effect","Toggle Crest",() => { DOTGRID.tool.toggleCrest(); }, "CmdOrCtrl+K"); DOTGRID.controller.add("default","Manual","Add Point",() => { DOTGRID.tool.addVertex(DOTGRID.cursor.pos); DOTGRID.renderer.update() },"Enter"); DOTGRID.controller.add("default","Manual","Move Up",() => { DOTGRID.cursor.pos.y -= 15; DOTGRID.renderer.update() },"Up"); diff --git a/desktop/sources/scripts/dotgrid.js b/desktop/sources/scripts/dotgrid.js index 968cb72..26521e2 100644 --- a/desktop/sources/scripts/dotgrid.js +++ b/desktop/sources/scripts/dotgrid.js @@ -144,18 +144,6 @@ function Dotgrid (width, height) { this.renderer.update() } - this.setZoom = function (scale) { - this.setSize({ width: this.tool.settings.size.width, height: this.tool.settings.size.height }, true, scale) - - try { - webFrame.setZoomFactor(scale) - } catch (err) { - console.log('Cannot zoom') - } - } - - // Draw - this.resize = function () { const size = { width: step(window.innerWidth - 90, 15), height: step(window.innerHeight - 120, 15) } @@ -173,6 +161,16 @@ function Dotgrid (width, height) { document.title = `Dotgrid — ${size.width}x${size.height}` } + this.setZoom = function (scale) { + this.setSize({ width: this.tool.settings.size.width, height: this.tool.settings.size.height }, true, scale) + + try { + webFrame.setZoomFactor(scale) + } catch (err) { + console.log('Cannot zoom') + } + } + // Events this.drag = function (e) { diff --git a/desktop/sources/scripts/manager.js b/desktop/sources/scripts/manager.js index 01860f9..1c577cd 100644 --- a/desktop/sources/scripts/manager.js +++ b/desktop/sources/scripts/manager.js @@ -28,16 +28,22 @@ function Manager (dotgrid) { const paths = DOTGRID.tool.paths() for (const id in this.layers) { - const style = styles[id] - const path = paths[id] - const layer = this.layers[id] + let style = styles[id] + let path = paths[id] + let layer = this.layers[id] + // Easter Egg + if (DOTGRID.tool.settings.crest === true) { + style = styles[0] + path = paths[0] + layer.setAttribute('transform', `rotate(${parseInt(id) * 120} ${(DOTGRID.tool.settings.size.width / 2) + 7.5} ${(DOTGRID.tool.settings.size.height / 2) + 15})`) + } + layer.style.strokeWidth = style.thickness layer.style.strokeLinecap = style.strokeLinecap layer.style.strokeLinejoin = style.strokeLinejoin layer.style.stroke = style.color layer.style.fill = style.fill - layer.style.transform = style.transform - layer.setAttribute('d', paths[id]) + layer.setAttribute('d', path) } } diff --git a/desktop/sources/scripts/tool.js b/desktop/sources/scripts/tool.js index 57cba69..1ae822e 100644 --- a/desktop/sources/scripts/tool.js +++ b/desktop/sources/scripts/tool.js @@ -2,7 +2,7 @@ function Tool (dotgrid) { this.index = 0 - this.settings = { size: { width: 300, height: 300 } } + this.settings = { size: { width: 300, height: 300 }, crest: false } this.layers = [[], [], []] this.styles = [ { thickness: 10, strokeLinecap: 'round', strokeLinejoin: 'round', color: '#f00', fill: 'none', mirror_style: 0, transform: 'rotate(45)' }, @@ -200,6 +200,12 @@ function Tool (dotgrid) { dotgrid.renderer.update() } + this.toggleCrest = function () { + this.settings.crest = this.settings.crest !== true + dotgrid.interface.update(true) + dotgrid.renderer.update() + } + this.misc = function (type) { dotgrid.picker.start() } From 1d5f5456f378733463bc205d06e9b009a0021ac0 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 10 Jan 2019 10:44:19 +1200 Subject: [PATCH 2/2] Added crest mode to web view --- web/events.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web/events.js b/web/events.js index b4bcf26..24dc65c 100644 --- a/web/events.js +++ b/web/events.js @@ -10,6 +10,7 @@ document.onkeyup = (e) => if((e.ctrlKey || e.metaKey) && ch == "s"){ DOTGRID.save(); e.preventDefault(); return; } if((e.ctrlKey || e.metaKey) && ch == "r"){ DOTGRID.render(); e.preventDefault(); return; } if((e.ctrlKey || e.metaKey) && ch == "e"){ DOTGRID.export(); e.preventDefault(); return; } + if((e.ctrlKey || e.metaKey) && ch == "k"){ DOTGRID.tool.toggleCrest(); e.preventDefault(); return; } if(ch == "backspace" && e.ctrlKey){ DOTGRID.theme.reset(); e.preventDefault(); } if(ch == "backspace"){ DOTGRID.tool.removeSegment(); e.preventDefault(); }