Skip to content

Conversation

@adroitwhiz
Copy link
Contributor

@adroitwhiz adroitwhiz commented Apr 15, 2020

Depends on scratchfoundation/paper.js#39, scratchfoundation/paper.js#40, #1166

Resolves

Resolves #540
Diff: https://github.com/adroitwhiz/scratch-paint/compare/stroke-gradient-part-1...adroitwhiz:stroke-gradient?expand=1

Proposed Changes

This PR adds support for (and contains a bunch of supporting changes for) setting outlines' colors to gradients in select mode, fill mode, and shape tools:
Peek 2020-04-15 12-40

The supporting changes include:

  • Combining "fill color", "fill color 2", and "gradient type" reducers into a single "swatch" reducer. A "swatch" (not sure what else to call it) consists of a primary color, a secondary color, and a gradient type (solid, horizontal, vertical, or radial).
    • I've further abstracted the "swatch" reducer into a swatch-reducer-generator function that generates swatch reducers given the names of actions it should respond to. This allows logic to be shared between fill and stroke reducers while still allowing each to have its own unique action names.
  • Modifying all helper functions in style-path.js to work on both fill and stroke.
  • Abstracting FillColorPickerComponent and StrokeColorPickerComponent into a ColorPickerComponent.
  • Abstracting the FillColorPicker and StrokeColorPicker containers into a ColorPicker container component generator.
    • As with the swatch reducer generator, this allows for multiple color picker containers that share the same logic, but are mapped to different Redux state.

It deliberately does not yet add support for gradient strokes in fill mode-- there's some behavior there that would best be ironed out at some point in the future.
Per design meeting we agreed to include gradient outlines in select mode, gradients in shape tools, and gradient outlines in the fill tool in one release

Reason for Changes

This has been a commonly-requested feature ever since 3.0 was first released to the public.

The supporting changes should also make it easier to implement things like #1003.

Test Coverage

Existing fill/outline color reducer tests have been merged together into one big color reducer test

@fsih
Copy link
Contributor

fsih commented May 15, 2020

This is awesome!
Adding @carljbowman for design feedback

@adroitwhiz adroitwhiz force-pushed the stroke-gradient branch 2 times, most recently from 8aaf088 to 45a8b22 Compare May 25, 2020 11:56
@adroitwhiz
Copy link
Contributor Author

image

These aren't showing up properly on the stage

return state;
// Gradient type may be solid when multiple gradient types are selected.
// In this case, changing the first color should not change the second color.
if (colors.gradientType !== GradientTypes.SOLID || colors.fillColor2 === MIXED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we figured out that the getColorsFromSelection function returns GradientType = SOLID, fill colors 1 and 2 = MIXED to indicate that the gradient type isn't actually solid, you've selected a bunch of things with different gradient types. (Just clarifying this for myself)

Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

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

Let's separate everything up to e89bed9 as a "refactor" pr
(caveat: we need to have getColorsFromSelection return mixed for all stroke gradients until the rest is hooked in)

Now, you can pass null in for a color instead of
{primary: null, secondary: null, gradientType: GradientTypes.SOLID}
and it'll still clear the color. Passing strokeWidth is also
optional now.
This *should* be safe because OvalTool and RectTool's wrapper "mode"
components, the only places that call onSelectionChanged, also update
the tools' color, and the color state reducers will always set the color
every time the selection changes, meaning it'll be updated anyway.
This means that gradient tools will also be enabled for the stroke color
indicator even in fill and bitmap modes, but that's okay because the
stroke color indicator will be disabled or hidden in those modes anyway.
Hopefully the comments help; the logic is kinda convoluted here
This fixes the bug where percertly horizontal gradients on perfectly
vertical lines and vice versa would not be rendered at all
The UX here isn't the best thing in the world but I think having the
functionality is important judging from the playtest
Previously, if you selected a shape with a gradient outline that had a
width of 0, its outline color wouldn't be null when it should have been.
- Set the stroke color to "null" when the width is set to 0
- Properly set the stroke color state when the width is increased from 0
@adroitwhiz adroitwhiz requested a review from fsih July 28, 2020 12:40
@adroitwhiz
Copy link
Contributor Author

@fsih The latest 4 commits are new, and should fix issues relating to changing the outline width to 0.

Did you run into "something strange" in a local build or my build? It looks like you ran into the bug that scratchfoundation/paper.js#40 fixes, so you may need to npm link paper.js, pull in that PR, and rebuild it.

@fsih
Copy link
Contributor

fsih commented Jul 28, 2020

@adroitwhiz Yup, it was a local build. You're right, that's probably what it was!

Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

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

Awesome! Let's do it!!

It looks like these issues are fixed as well:
#738
#697

fsih
fsih previously approved these changes Jul 28, 2020
Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

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

ignore this comment

@adroitwhiz
Copy link
Contributor Author

@fsih I noticed one more thing while testing this out again-- 3795999 makes it so that the fill tool now enforces the same minimum gradient size as the line tool does for perfectly horizontal/vertical lines

Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

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

Good catches

@adroitwhiz adroitwhiz merged commit 4f86762 into scratchfoundation:develop Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gradient outlines vector

3 participants