From 7a930753120a7b66c0e6f226e36b0624287dd544 Mon Sep 17 00:00:00 2001 From: Frederic Kettelhoit Date: Thu, 19 Mar 2020 12:12:35 +0100 Subject: [PATCH] Add button to toggle layer as mask --- links/main.css | 3 ++- scripts/client.js | 1 + scripts/interface.js | 7 ++++++- scripts/tool.js | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/links/main.css b/links/main.css index e7eb9d2..e5051b6 100644 --- a/links/main.css +++ b/links/main.css @@ -35,7 +35,7 @@ body { padding: 0px; font-family:"input_mono_regular",courier,monospace; -webkit #interface #menu svg.icon#option_color { opacity: 1.0; z-index:1001; position: relative; } #interface #menu svg.icon#option_color:hover { opacity: 0.8 } -#interface #picker { position: absolute; line-height: 20px; z-index: 0; width: 30px; opacity: 0; transition: all 250ms; font-size: 11px; border-radius: 3px; left: 200px; top: 0px; text-transform: uppercase; height:20px; padding:5px 0px;left:280px; overflow:hidden;} +#interface #picker { position: absolute; line-height: 20px; z-index: 0; width: 30px; opacity: 0; transition: all 250ms; font-size: 11px; border-radius: 3px; left: 200px; top: 0px; text-transform: uppercase; height:20px; padding:5px 0px;left:310px; overflow:hidden;} #interface #picker:before { content:"#"; position: absolute; left:10px; opacity: 0; transition: opacity 500ms} #interface #picker input { background:transparent; position: absolute; left: 20px; height: 20px; width: 60px; line-height: 20px; opacity: 0; transition: opacity 500ms; text-transform: uppercase;} #interface #color_path { transition: all 500ms; } @@ -47,6 +47,7 @@ body { padding: 0px; font-family:"input_mono_regular",courier,monospace; -webkit #interface.picker #option_thickness { opacity: 0 !important } #interface.picker #option_mirror { opacity: 0 !important } #interface.picker #option_fill { opacity: 0 !important } +#interface.picker #option_mask { opacity: 0 !important } /* Web Specific */ diff --git a/scripts/client.js b/scripts/client.js index cec13a8..4002e04 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -79,6 +79,7 @@ function Client () { this.acels.set('Style', 'Linejoin', 'W', () => { this.tool.toggle('linejoin') }) this.acels.set('Style', 'Mirror', 'E', () => { this.tool.toggle('mirror') }) this.acels.set('Style', 'Fill', 'R', () => { this.tool.toggle('fill') }) + this.acels.set('Style', 'Mask', 'C', () => { this.tool.toggle('mask') }) this.acels.set('Style', 'Thicker', '}', () => { this.tool.toggle('thickness', 1) }) this.acels.set('Style', 'Thinner', '{', () => { this.tool.toggle('thickness', -1) }) this.acels.set('Style', 'Thicker +5', ']', () => { this.tool.toggle('thickness', 5) }) diff --git a/scripts/interface.js b/scripts/interface.js index 867b902..94ca637 100644 --- a/scripts/interface.js +++ b/scripts/interface.js @@ -23,7 +23,8 @@ function Interface (client) { linejoin: { key: 'W', icon: 'M60,60 L120,120 L180,120 M120,180 L180,180 L240,240' }, thickness: { key: '', icon: 'M120,90 L120,90 L90,120 L180,210 L210,180 Z M105,105 L105,105 L60,60 M195,195 L195,195 L240,240' }, mirror: { key: 'E', icon: 'M60,60 L60,60 L120,120 M180,180 L180,180 L240,240 M210,90 L210,90 L180,120 M120,180 L120,180 L90,210' }, - fill: { key: 'R', icon: 'M60,60 L60,150 L150,150 L240,150 L240,240 Z' } + fill: { key: 'R', icon: 'M60,60 L60,150 L150,150 L240,150 L240,240 Z' }, + mask: { key: 'C', icon: 'M105,180 L105,180 L105,240 L240,240 L240,105 L180,105 L105,105 M105,180 L105,180 L105,105 M60,60 L60,60 L60,150 L150,150 L150,60 Z ' } }, misc: { color: { key: 'G', icon: 'M150,60 A90,90 0 0,1 240,150 A-90,90 0 0,1 150,240 A-90,-90 0 0,1 60,150 A90,-90 0 0,1 150,60' } @@ -138,6 +139,7 @@ function Interface (client) { options.toggle.linejoin.el.className.baseVal = client.tool.layer().length < 1 || !multiVertices ? 'icon inactive' : 'icon' options.toggle.mirror.el.className.baseVal = client.tool.layer().length < 1 ? 'icon inactive' : 'icon' options.toggle.fill.el.className.baseVal = client.tool.layer().length < 1 ? 'icon inactive' : 'icon' + options.toggle.mask.el.className.baseVal = client.tool.layer().length < 1 ? 'icon inactive' : 'icon' options.misc.color.el.children[0].style.fill = client.tool.style().color options.misc.color.el.children[0].style.stroke = client.tool.style().color options.misc.color.el.className.baseVal = 'icon' @@ -149,6 +151,9 @@ function Interface (client) { // Grid document.getElementById('grid_path').setAttribute('d', client.renderer.showExtras ? 'M65,155 Q155,245 245,155 M65,155 Q155,65 245,155 M155,125 A30,30 0 0,1 185,155 A30,30 0 0,1 155,185 A30,30 0 0,1 125,155 A30,30 0 0,1 155,125 ' : 'M65,155 Q155,245 245,155 M65,155 ') + // Mask + if (!client.tool.style().mask) { document.getElementById('mask_path').setAttribute('d', 'M105,180 L105,180 L105,240 L240,240 L240,105 L180,105 L105,105 M105,180 L105,180 L105,105 M60,60 L60,60 L60,150 L150,150 L150,60 Z ') } else { document.getElementById('mask_path').setAttribute('d', 'M105,180 L105,180 L105,240 L240,240 L240,105 L180,105 L180,180 M105,180 L105,180 L180,180 M60,60 L60,60 L60,150 L150,150 L150,60 Z ') } + // Mirror document.getElementById('mirror_path').setAttribute('d', mirrorPaths[client.tool.style().mirror_style]) this.prev_operation = client.cursor.operation diff --git a/scripts/tool.js b/scripts/tool.js index badf8de..5b639e2 100644 --- a/scripts/tool.js +++ b/scripts/tool.js @@ -191,6 +191,8 @@ function Tool (client) { this.style().strokeLinejoin = a[this.i.linejoin % a.length] } else if (type === 'fill') { this.style().fill = this.style().fill === 'none' ? this.style().color : 'none' + } else if (type === 'mask') { + this.style().mask = !this.style().mask } else if (type === 'thickness') { this.style().thickness = clamp(this.style().thickness + mod, 1, 100) } else if (type === 'mirror') {