From a9a8789af6319a2d4d55b1433ab130fa9fbc211a Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sun, 19 Apr 2020 20:44:33 -0400 Subject: [PATCH 1/9] Clear lastVec in onBroadMouseDown --- src/helper/blob-tools/broad-brush-helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helper/blob-tools/broad-brush-helper.js b/src/helper/blob-tools/broad-brush-helper.js index dbd81eb6..a0be22ef 100644 --- a/src/helper/blob-tools/broad-brush-helper.js +++ b/src/helper/blob-tools/broad-brush-helper.js @@ -34,6 +34,7 @@ class BroadBrushHelper { onBroadMouseDown (event, tool, options) { this.steps = 0; this.smoothed = 0; + this.lastVec = null; tool.minDistance = Math.min(5, Math.max(2 / paper.view.zoom, options.brushSize / 2)); tool.maxDistance = options.brushSize; if (event.event.button > 0) return; // only first mouse button From 55bc3dc4b6de0660853c15e61b39f721acdcd983 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sun, 19 Apr 2020 20:50:19 -0400 Subject: [PATCH 2/9] Don't double-add points to broad brush path --- src/helper/blob-tools/broad-brush-helper.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/helper/blob-tools/broad-brush-helper.js b/src/helper/blob-tools/broad-brush-helper.js index a0be22ef..c5d4cec5 100644 --- a/src/helper/blob-tools/broad-brush-helper.js +++ b/src/helper/blob-tools/broad-brush-helper.js @@ -38,7 +38,7 @@ class BroadBrushHelper { tool.minDistance = Math.min(5, Math.max(2 / paper.view.zoom, options.brushSize / 2)); tool.maxDistance = options.brushSize; if (event.event.button > 0) return; // only first mouse button - + this.finalPath = new paper.Path.Circle({ center: event.point, radius: options.brushSize / 2 @@ -46,7 +46,7 @@ class BroadBrushHelper { styleBlob(this.finalPath, options); this.lastPoint = event.point; } - + onBroadMouseDrag (event, tool, options) { this.steps++; const step = (event.delta).normalize(options.brushSize / 2); @@ -97,12 +97,8 @@ class BroadBrushHelper { this.finalPath.insert(0, new paper.Segment(this.lastPoint.subtract(step))); this.finalPath.add(new paper.Segment(this.lastPoint.add(step))); } - const top = event.middlePoint.add(step); - const bottom = event.middlePoint.subtract(step); - this.finalPath.add(top); this.finalPath.add(event.point.add(step)); - this.finalPath.insert(0, bottom); this.finalPath.insert(0, event.point.subtract(step)); if (this.finalPath.segments.length > this.smoothed + (this.smoothingThreshold * 2)) { @@ -220,7 +216,7 @@ class BroadBrushHelper { this.finalPath.remove(); this.finalPath = newPath; } - + // Try to merge end caps for (const cap of this.endCaps) { const temp = this.union(this.finalPath, cap); From baa95edc47faef3d772038f1e41784085025334d Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sun, 19 Apr 2020 21:34:39 -0400 Subject: [PATCH 3/9] Set broad brush stroke angle to vertex normal --- src/helper/blob-tools/broad-brush-helper.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/helper/blob-tools/broad-brush-helper.js b/src/helper/blob-tools/broad-brush-helper.js index c5d4cec5..791905e1 100644 --- a/src/helper/blob-tools/broad-brush-helper.js +++ b/src/helper/blob-tools/broad-brush-helper.js @@ -79,7 +79,6 @@ class BroadBrushHelper { this.endCaps.push(this.union(circ, this.union(rect, rect2))); } } - this.lastVec = event.delta; step.angle += 90; // Move the first point out away from the drag so that the end of the path is rounded @@ -98,12 +97,27 @@ class BroadBrushHelper { this.finalPath.add(new paper.Segment(this.lastPoint.add(step))); } + // Update angle of the last brush step's points to match the average angle of the last mouse vector and this + // mouse vector (aka the vertex normal). + if (this.lastVec) { + const lastNormal = this.lastVec.normalize(options.brushSize / 2).rotate(90); + const averageNormal = new paper.Point( + lastNormal.x + step.x, + lastNormal.y + step.y + ).normalize(options.brushSize / 2); + + this.finalPath.segments[0].point = this.lastPoint.subtract(averageNormal); + this.finalPath.segments[this.finalPath.segments.length - 1].point = this.lastPoint.add(averageNormal); + } + this.finalPath.add(event.point.add(step)); this.finalPath.insert(0, event.point.subtract(step)); if (this.finalPath.segments.length > this.smoothed + (this.smoothingThreshold * 2)) { this.simplify(1); } + + this.lastVec = event.delta; this.lastPoint = event.point; } From 690efcb39f0802331631e0ad57d2b733e478f72e Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sun, 19 Apr 2020 21:56:42 -0400 Subject: [PATCH 4/9] Use proper mouse delta in onBroadMouseUp The given event.delta is the difference between the mouse down coords and the mouse up coords, but we want the difference between the last mouse drag coords and the mouse up coords. --- src/helper/blob-tools/broad-brush-helper.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/helper/blob-tools/broad-brush-helper.js b/src/helper/blob-tools/broad-brush-helper.js index 791905e1..be69cb6e 100644 --- a/src/helper/blob-tools/broad-brush-helper.js +++ b/src/helper/blob-tools/broad-brush-helper.js @@ -196,10 +196,15 @@ class BroadBrushHelper { return this.finalPath; } + let delta = this.lastVec; + // If the mouse up is at the same point as the mouse drag event then we need // the second to last point to get the right direction vector for the end cap if (!event.point.equals(this.lastPoint)) { - const step = event.delta.normalize(options.brushSize / 2); + // The given event.delta is the difference between the mouse down coords and the mouse up coords, + // but we want the difference between the last mouse drag coords and the mouse up coords. + delta = event.point.subtract(this.lastPoint); + const step = delta.normalize(options.brushSize / 2); step.angle += 90; const top = event.point.add(step); @@ -210,7 +215,7 @@ class BroadBrushHelper { // Simplify before adding end cap so cap doesn't get warped this.simplify(1); - const handleVec = event.delta.normalize(options.brushSize / 2); + const handleVec = delta.normalize(options.brushSize / 2); this.finalPath.add(new paper.Segment( event.point.add(handleVec), handleVec.rotate(90), From b94a2addf37f870d4ba081fcaee16789bc693fa6 Mon Sep 17 00:00:00 2001 From: Jacco Kulman Date: Sun, 21 Jun 2020 09:52:04 +0200 Subject: [PATCH 5/9] Keyboard shortcuts added --- src/hocs/keyboard-shortcuts-hoc.jsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/hocs/keyboard-shortcuts-hoc.jsx b/src/hocs/keyboard-shortcuts-hoc.jsx index 736b22a7..c3796094 100644 --- a/src/hocs/keyboard-shortcuts-hoc.jsx +++ b/src/hocs/keyboard-shortcuts-hoc.jsx @@ -9,6 +9,7 @@ import CopyPasteHOC from './copy-paste-hoc.jsx'; import {selectAllBitmap} from '../helper/bitmap'; import {clearSelection, deleteSelection, getSelectedLeafItems, selectAllItems, selectAllSegments} from '../helper/selection'; +import {groupSelection, ungroupSelection} from '../helper/group'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {changeMode} from '../reducers/modes'; @@ -47,11 +48,23 @@ const KeyboardShortcutsHOC = function (WrappedComponent) { this.props.onRedo(); } else if (event.key === 'z') { this.props.onUndo(); + } else if (event.shiftKey && event.key.toLowerCase() === 'g') { + ungroupSelection(clearSelectedItems, setSelectedItems, this.props.onUpdateImage); + event.preventDefault(); + } else if (event.key === 'g') { + groupSelection(clearSelectedItems, setSelectedItems, this.props.onUpdateImage); + event.preventDefault(); } else if (event.key === 'c') { this.props.onCopyToClipboard(); } else if (event.key === 'v') { this.changeToASelectMode(); this.props.onPasteFromClipboard(); + } else if (event.key === 'x') { + this.props.onCopyToClipboard(); + if (deleteSelection(this.props.mode, this.props.onUpdateImage)) { + this.props.setSelectedItems(this.props.format); + } + event.preventDefault(); } else if (event.key === 'a') { this.changeToASelectMode(); event.preventDefault(); From 78af17cccf35a70cb346a051cdbb4d68d5787223 Mon Sep 17 00:00:00 2001 From: Jacco Kulman Date: Sun, 21 Jun 2020 09:57:27 +0200 Subject: [PATCH 6/9] shouldShow checks added --- src/hocs/keyboard-shortcuts-hoc.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hocs/keyboard-shortcuts-hoc.jsx b/src/hocs/keyboard-shortcuts-hoc.jsx index c3796094..1d51d087 100644 --- a/src/hocs/keyboard-shortcuts-hoc.jsx +++ b/src/hocs/keyboard-shortcuts-hoc.jsx @@ -9,7 +9,7 @@ import CopyPasteHOC from './copy-paste-hoc.jsx'; import {selectAllBitmap} from '../helper/bitmap'; import {clearSelection, deleteSelection, getSelectedLeafItems, selectAllItems, selectAllSegments} from '../helper/selection'; -import {groupSelection, ungroupSelection} from '../helper/group'; +import {groupSelection, shouldShowGroup, ungroupSelection, shouldShowUngroup} from '../helper/group'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {changeMode} from '../reducers/modes'; @@ -49,10 +49,14 @@ const KeyboardShortcutsHOC = function (WrappedComponent) { } else if (event.key === 'z') { this.props.onUndo(); } else if (event.shiftKey && event.key.toLowerCase() === 'g') { - ungroupSelection(clearSelectedItems, setSelectedItems, this.props.onUpdateImage); + if (shouldShowUngroup()) { + ungroupSelection(clearSelectedItems, setSelectedItems, this.props.onUpdateImage); + } event.preventDefault(); } else if (event.key === 'g') { - groupSelection(clearSelectedItems, setSelectedItems, this.props.onUpdateImage); + if (shouldShowGroup()) { + groupSelection(clearSelectedItems, setSelectedItems, this.props.onUpdateImage); + } event.preventDefault(); } else if (event.key === 'c') { this.props.onCopyToClipboard(); From 8a886a7b733a36665c9870b3879f1e83d4a6d19b Mon Sep 17 00:00:00 2001 From: Jacco Kulman Date: Sun, 21 Jun 2020 10:16:16 +0200 Subject: [PATCH 7/9] Only cut if something is selected --- src/hocs/keyboard-shortcuts-hoc.jsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hocs/keyboard-shortcuts-hoc.jsx b/src/hocs/keyboard-shortcuts-hoc.jsx index 1d51d087..deb2449a 100644 --- a/src/hocs/keyboard-shortcuts-hoc.jsx +++ b/src/hocs/keyboard-shortcuts-hoc.jsx @@ -8,7 +8,7 @@ import CopyPasteHOC from './copy-paste-hoc.jsx'; import {selectAllBitmap} from '../helper/bitmap'; import {clearSelection, deleteSelection, getSelectedLeafItems, - selectAllItems, selectAllSegments} from '../helper/selection'; + selectAllItems, selectAllSegments, getSelectedRootItems} from '../helper/selection'; import {groupSelection, shouldShowGroup, ungroupSelection, shouldShowUngroup} from '../helper/group'; import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items'; import {changeMode} from '../reducers/modes'; @@ -64,9 +64,12 @@ const KeyboardShortcutsHOC = function (WrappedComponent) { this.changeToASelectMode(); this.props.onPasteFromClipboard(); } else if (event.key === 'x') { - this.props.onCopyToClipboard(); - if (deleteSelection(this.props.mode, this.props.onUpdateImage)) { - this.props.setSelectedItems(this.props.format); + const selectedItems = getSelectedRootItems(); + if (selectedItems.length > 0) { + this.props.onCopyToClipboard(); + if (deleteSelection(this.props.mode, this.props.onUpdateImage)) { + this.props.setSelectedItems(this.props.format); + } } event.preventDefault(); } else if (event.key === 'a') { From 5a154e708eb8bd1d69c91872d6a85fa39cd510a6 Mon Sep 17 00:00:00 2001 From: Jacco Kulman Date: Sat, 27 Jun 2020 14:41:24 +0200 Subject: [PATCH 8/9] ungroup --- src/helper/group.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/helper/group.js b/src/helper/group.js index 4e23aa7a..a5379fa5 100644 --- a/src/helper/group.js +++ b/src/helper/group.js @@ -92,6 +92,8 @@ const ungroupItems = function (items, setSelectedItems, onUpdateImage) { if (!item.hasChildren()) { emptyGroups.push(item); } + } else if (setSelectedItems) { + item.selected = true; } } if (setSelectedItems) { From 374810c865cb0afd39884abc2b827073fb2b1e01 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2020 22:18:33 +0000 Subject: [PATCH 9/9] Bump @scratch/paper from 0.11.20200529164227 to 0.11.20200709220949 Bumps [@scratch/paper](https://github.com/paperjs/paper.js) from 0.11.20200529164227 to 0.11.20200709220949. - [Release notes](https://github.com/paperjs/paper.js/releases) - [Changelog](https://github.com/paperjs/paper.js/blob/develop/CHANGELOG.md) - [Commits](https://github.com/paperjs/paper.js/commits) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0bb427b..ca0d6fe1 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "url": "git+ssh://git@github.com/LLK/scratch-paint.git" }, "dependencies": { - "@scratch/paper": "0.11.20200529164227", + "@scratch/paper": "0.11.20200709220949", "classnames": "2.2.5", "keymirror": "0.1.1", "lodash.bindall": "4.4.0",