Skip to content

Feature/paint boolean ops - #8917

Merged
pufferfish101007 merged 28 commits into
ScratchAddons:masterfrom
griffpatch:feature/paint-boolean-ops
Aug 3, 2026
Merged

Feature/paint boolean ops#8917
pufferfish101007 merged 28 commits into
ScratchAddons:masterfrom
griffpatch:feature/paint-boolean-ops

Conversation

@griffpatch

@griffpatch griffpatch commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Note added by @DNin01

This pull request incorporates code generated by Claude Sonnet.

Changes

Adds a new Boolean shape operations addon to the vector costume editor.

A Shaping section is injected into the editor toolbar with two layout modes: inline (wide toolbar, five buttons sit directly in the bar) and collapsed (narrow toolbar, a single trigger button opens a hover dropdown panel).

image image

Operations added:

Button Shortcut Behaviour
Unite click Merges all selected shapes into one, keeping the backmost shape's fill/stroke
Subtract click Cuts the upper shape(s) out of the backmost shape; Shift = Punch Through (cuts all other shapes); Alt = keep cutter
Intersect click Keeps only the overlapping region; Alt = Divide (splits all shapes into every distinct non-overlapping fragment, Illustrator-style)
Combine / Release click Combines selected paths into a CompoundPath with even-odd fill (punch-through holes), or releases a CompoundPath back into individual paths
Expand click Expands each shape by half its stroke width, converting the visual stroke to a filled outline
Open / Close Path Reshape mode context bar Opens a closed path at the selected anchor, duplicating the break-point so both endpoints overlap at the same position; closes an open path, merging endpoints if they are within 5 units

Additional details:

  • Text-to-path: selected text items are automatically converted to path outlines before any boolean operation, using a rasterise → threshold → marching-squares trace → Bézier curve-fit pipeline (we could add a hefty library to the dependencies to do this natively?)
  • Group awareness: Subtract, Intersect, and Punch Through descend recursively into paper.js Groups, preserving the original nesting structure
  • Style preservation: fill/stroke/strokeWidth are snapshotted before and restored after every operation (paper.js boolean ops silently lose styles)
  • Scratch open-circle fix: Scratch stores circles as open paths whose last point coincides with the first; a pre-processing step detects and closes these before boolean ops to avoid corrupt results
  • Dynamic enable/disable: the shaping section and mode-tools button are removed when the addon is disabled; button enabled states update live from the current paper.js selection

Reason for changes

The vector costume editor has no boolean shape tools. Creating complex shapes — cutouts, compound letters, logos, overlapping fills — requires tediously cutting paths by hand with the Reshape tool. Every professional illustration app (Illustrator Pathfinder, Inkscape Path menu, Figma boolean groups) provides these operations as first-class features. This addon brings the full set directly into the editor toolbar.

Tests

Tested in Chrome:

  • Unite, Subtract, Intersect on two plain paths
  • Subtract+Shift (Punch Through) on a stack of three shapes
  • Subtract+Alt / Intersect+Alt (keep cutter / Divide)
  • Combine and Release round-trip on a CompoundPath
  • Expand on paths with and without a stroke
  • Open/Close Path in Reshape mode, including handle preservation at the join and the 5-unit merge snap
  • Text-to-path conversion triggered via Unite and Subtract on PointText items
  • Group-aware Subtract where the target is a paper.js Group
  • All operations on Scratch circles (pseudo-open paths) — no corrupt output
  • Dynamic enable/disable via the addon toggle
  • Inline ↔ collapsed toolbar layout in response to toolbar width

@griffpatch
griffpatch force-pushed the feature/paint-boolean-ops branch from b432be2 to 7168ed1 Compare March 27, 2026 18:41
@TSFBCE24RhythmHeaveners

This comment was marked as off-topic.

@griffpatch

This comment was marked as off-topic.

@griffpatch
griffpatch force-pushed the feature/paint-boolean-ops branch 2 times, most recently from 27c66df to aec01e3 Compare March 27, 2026 23:00
@Joeclinton1
Joeclinton1 requested a review from CST1229 March 28, 2026 02:04

@Joeclinton1 Joeclinton1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything (almost) works! Amazing addon. I'm super impressed with the code inside and how this handles the edge cases.

Bugs:

  1. Alt drag should duplicate an object and drag the duplicate only, but alt drag on a shape with a hole, duplicates and drags both parts.
  2. if you click an object and then deselect it by clicking itself with shift (or sometimes ctrl) held down, the boolean operations will be grayed out the next time you click a shape. This doesn't always happen, but it is reproducible.

Ux change:
Personally the functionality of combine/release/expand is not clear without reading the PR description. In the addon description could you describe the different boolean features? Also maybe the tool tip could give some info.

@TSFBCE24RhythmHeaveners

This comment was marked as off-topic.

@Samq64 Samq64 added type: enhancement New feature for the project new addon Related to new addons to this extension. `scope: addon` should still be added. labels Mar 28, 2026
@griffpatch

griffpatch commented Mar 28, 2026

Copy link
Copy Markdown
Contributor Author

@Joeclinton1 Everything (almost) works! Amazing addon. I'm super impressed with the code inside and how this handles the edge cases.

Bugs:

  1. Alt drag should duplicate an object and drag the duplicate only, but alt drag on a shape with a hole, duplicates and drags both parts.

This is actually a Scratch bug - If you import any SVG with a compound share, alt dragging it will show a similar issue - It's also present in Penguin Mod and other costume editors. However, I hate that bug too and I've found a solution so I've included a patch to Scratch's paint editor bug in this addon (can be turned off if wanted with a toggle)

  1. if you click an object and then deselect it by clicking itself with shift (or sometimes ctrl) held down, the boolean operations will be grayed out the next time you click a shape. This doesn't always happen, but it is reproducible.

I've not been able to reproduce this one myself yet.

Ux change: Personally the functionality of combine/release/expand is not clear without reading the PR description. In the addon description could you describe the different boolean features? Also maybe the tool tip could give some info.

Agreed... I just didn't want to over-do it with lots of explanation text. I'll have a think

@griffpatch

This comment was marked as off-topic.

@TSFBCE24RhythmHeaveners

This comment was marked as off-topic.

@CubesterYT

Copy link
Copy Markdown

That's not nice. Is it like you are using PenguinMod? or is it original?

This PR is completely unrelated to PenguinMod, he stated he wasn't aware of the mod till now. This is a completely original implementation. Please stop bugging him.

@griffpatch
griffpatch force-pushed the feature/paint-boolean-ops branch from 1919d89 to 5fcb8a4 Compare March 28, 2026 17:25
@griffpatch
griffpatch requested a review from Joeclinton1 March 28, 2026 17:27

@pufferfish101007 pufferfish101007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very exciting. I've left some comments, primarily regarding code style. I think the standard is for class selectors to be written as [class*="class_class-name_"] with a trailing underscore but I didn't make a comment for every occurrence. I trust that the various algorithms work!

Comment thread addons/paint-boolean-ops/text-to-path.js Outdated
Comment thread addons/paint-boolean-ops/text-to-path.js Outdated
Comment thread addons/paint-boolean-ops/text-to-path.js Outdated
Comment thread addons/paint-boolean-ops/text-to-path.js
Comment thread addons/paint-boolean-ops/userscript.js Outdated
Comment thread addons/paint-boolean-ops/userscript.js Outdated
Comment thread addons/paint-boolean-ops/userscript.js Outdated
Comment thread addons/paint-boolean-ops/userscript.js Outdated
Comment thread addons/paint-boolean-ops/userscript.js Outdated
Comment thread addons/paint-boolean-ops/userscript.js Outdated
@DNin01 DNin01 added this to the v1.46.0 milestone Mar 28, 2026
- Remove dead #PRE_BLUR and #DEBUG flags and their branches
- Remove redundant bare block scopes
- Add style.css for dropdown static styles (move from inline cssText)
- Replace all setTimeout(updateButtonStates,50) with deferUpdateButtonStates() using double-rAF
- Add comment explaining why the defer is needed
- Remove '-- Private --' comment that was inaccurate
- Add RDP comment explaining 1e-10 guard and fallback
- Use class*= with trailing _ for CSS module selectors
- Update mode-tools selectors to use trailing _
@griffpatch
griffpatch force-pushed the feature/paint-boolean-ops branch from 776e9ec to 453a110 Compare March 28, 2026 23:58
@TSFBCE24RhythmHeaveners

Copy link
Copy Markdown

I tested it and It felt like PenguinMod's.

@pufferfish101007 pufferfish101007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing the menu collapsing - it really makes a difference for small screens. It is not cleared up when the addon is dynamically disabled but that doesn't affect normal reusability at all, and will probably be a very rare occurrence in the wild.

Overall looks good to me; as usual, my approval doesn't count towards the required number, but I'll give an approving review anyway.

@pufferfish101007 pufferfish101007 linked an issue Jul 20, 2026 that may be closed by this pull request
@pufferfish101007

Copy link
Copy Markdown
Contributor

I have just noticed that @Samq64's concerns re. compact editor compatibility from #8917 (comment) haven't been addressed

@Samq64

Samq64 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Wihtout editor-compact: Shrinking then expanding the window causes the tools to disappear entirely until it becomes wide enough to display all of them without the overflow menu.

With editor-compact: While shrinking the tools appear both in the toolbar and in the overflow menu. Expanding works as expected.

@griffpatch

Copy link
Copy Markdown
Contributor Author

Wihtout editor-compact: Shrinking then expanding the window causes the tools to disappear entirely until it becomes wide enough to display all of them without the overflow menu.

With editor-compact: While shrinking the tools appear both in the toolbar and in the overflow menu. Expanding works as expected.

I have separated off the toolbar integrating code from the main addon code which is a big code quality improvement. And have reworked that scripting to be more resilient. It should now collapse and expand robustly as well as react to enabling / disabling consistently.

Thanks for your bug reports!

@Samq64

Samq64 commented Jul 25, 2026

Copy link
Copy Markdown
Member

I have not re-tested yet but one more minor thing from yesterday: with editor-compact could the overflow menu's padding be reduced to match the height of the tools?

@griffpatch

Copy link
Copy Markdown
Contributor Author

I have not re-tested yet but one more minor thing from yesterday: with editor-compact could the overflow menu's padding be reduced to match the height of the tools?

This isn't an issue with this extension, but would require a change to the editor-compact addon I believe?
The clean fix belongs in editor-compact/userstyle.css: reduce vertical padding for [class*="fixed-tools_mod-menu-item_"]. That will compact Front/Back and our operations consistently.

@mxmou mxmou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few suggestions for the addon's presentation on the settings page.

Comment thread addons/paint-boolean-ops/addon.json Outdated
Comment thread addons/paint-boolean-ops/addon.json Outdated
Comment thread addons/paint-boolean-ops/addon.json Outdated
Comment thread addons/paint-boolean-ops/addon.json
@griffpatch

Copy link
Copy Markdown
Contributor Author

Thanks, I have made the requested wording changes in 392da5b. The description and info text now use full sentences, the Expand text uses Scratch's outline wording and explains the fill edge, and there is a notice that the buttons may move into the More menu on smaller screens. I also brought the tooltips into line with the same wording. JSON and whitespace checks pass.

@pufferfish101007

Copy link
Copy Markdown
Contributor

Just noticed that the PR description mentions the "Open / Close Path" tool, which isn't mentioned in the addon description. Could some explanation of that be added too, preferably with a more scratch-friendly name?

Comment thread addons/paint-boolean-ops/userscript.js Outdated
@griffpatch

Copy link
Copy Markdown
Contributor Author

I made a small change to have the correct bounding box drawn after a boolean operation

@griffpatch

Copy link
Copy Markdown
Contributor Author

Just noticed that the PR description mentions the "Open / Close Path" tool, which isn't mentioned in the addon description. Could some explanation of that be added too, preferably with a more scratch-friendly name?

Quite right - I've changed the label and added tooltips

@pufferfish101007

Copy link
Copy Markdown
Contributor

So nearly there! Unfortunately it looks like d2f7547 sometimes overcompensates (by quite a lot!)

2026-08-03.19-26-10.mp4

(I checked and that commit is the culprit)

If I fully ungroup all of the subgroups by pressing the ungroup button again, the bug doesn't occur.

@griffpatch

Copy link
Copy Markdown
Contributor Author

So nearly there! Unfortunately it looks like d2f7547 sometimes overcompensates (by quite a lot!)

2026-08-03.19-26-10.mp4
(I checked and that commit is the culprit)

If I fully ungroup all of the subgroups by pressing the ungroup button again, the bug doesn't occur.

Oh wow - you are great at finding gotchas! - This wasn't a bug in the latest commit, but it did reveal a bug that I hadn't tracked down previously but had seen... that when you combine shapes, sometimes it just didn't look right... It was combining shapes with nested groupings, the nested transformations were not being undone so some of the inner shapes got transported far away! hence the weird selection you saw! I've patched this and WOW does the combine look so much better now! Thanks for spotting that!

@pufferfish101007

Copy link
Copy Markdown
Contributor

Hopefully final things (all of which I'm happy to push):

@griffpatch

Copy link
Copy Markdown
Contributor Author

Hopefully final things (all of which I'm happy to push):

Done

@pufferfish101007
pufferfish101007 merged commit 2c43897 into ScratchAddons:master Aug 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new addon Related to new addons to this extension. `scope: addon` should still be added. status: needs review PR needs 1 more approval type: enhancement New feature for the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combine shapes in costume editor

8 participants