Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pen #72

Merged
merged 13 commits into from Jan 20, 2017
Merged

Pen #72

merged 13 commits into from Jan 20, 2017

Conversation

cwillisf
Copy link
Contributor

@cwillisf cwillisf commented Jan 19, 2017

Resolves

This set of changes adds rendering support for Scratch 2.0-style pen features as a step toward #6.

Proposed Changes

This introduces a new class, called PenSkin, which acts like an initially invisible "costume" that has pen-related functionality. The renderer's API can be used to create a PenSkin and assign it to a Drawable corresponding to the pen "layer" in Scratch, then call pen-related methods on the renderer to draw on the PenSkin.

Since the PenSkin is hosted by a regular Drawable, in theory we could implement some features that Scratch 2.0 did not have. This includes multiple pen layers, graphical effects on pen layers, moving pen layers, and more. This might not be desirable in core Scratch 3.0, but I think we should consider allowing extensions access to these features.

Reason for Changes

Implementing pen features brings us closer to Scratch 2.0 compatibility.

Test Coverage

The renderer does not currently have tests.

Christopher Willis-Ford added 12 commits December 15, 2016 13:35
This is the absolute basics of a working pen layer. Still to do:
- Make it so that the pen layer can be in the drawables list so that it
  can be in front of the backdrop but behind other Drawables.
- Remove current debug canvas operations
- Add pen layer API
The skin-based implementation of `Drawable` has been moved into a new
class called `SkinnedDrawable`. This makes room for `PenLayer` to become
a new type of `Drawable`.
It turns out that it might make sense for the pen to share these
features. Splitting them out would likely work too, but would introduce
unnecessary complexity.
To test, load the playground and type `renderer.createPenDrawable()`
into the JS console. Note that the pen layer is now just another
drawable object, so it can move and use effects.
The `setStageSize` wasn't working correctly. This change fixes that and
also notifies active `PenDrawable` instances about the resize. This was
implemented by making the renderer an `EventEmitter`.
Merge the "skin classes" work from another branch and move/convert the
pen work from `PenDrawable` to `PenSkin`.
Also clean up the code around our calls to `readPixels`:
- Use `Uint8Array` instead of `Buffer` to hold the pixels
- Use `ImageData.data.set` instead of a `for` loop when copying pixels
  to a canvas
Scratch uses y=up, whereas WebGL and the Canvas element both use y=down.
To make this work, we set a non-conventional projection matrix when
rendering to the stage. Some of the internal renders (touching color,
stamp, etc.) were using a y-flipped projection matrix, though, which
means that the output was double-flipped and would appear incorrect. For
the touching-color block this just meant a cosmetic issue: the debug
canvas looks upside-down. For pen stamp, though, it's a real issue since
the stamp was appearing upside down on the stage.

This change ensures that the projection matrix for every internal render
follows WebGL / Canvas conventions, and that we only y-flip on the final
render to the stage.
Changes include:
- Implement pen clear
- Upack pen-related location parameters
- Fix inverted vertical position on pen actions
- Remove canvas debug content
- Set `strokeStyle` instead of `fillStyle`
- Remove location parameter from stamp operation: always stamp in place
Copy link
Contributor

@thisandagain thisandagain left a comment

Choose a reason for hiding this comment

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

Really minor note. This looks great @cwillisf

this._canvasDirty = true;
}

_setAttributes (context, penAttributes) {

This comment was marked as abuse.

@griffpatch
Copy link
Contributor

griffpatch commented Jan 20, 2017 via email

@cwillisf cwillisf merged commit abd7672 into scratchfoundation:develop Jan 20, 2017
@cwillisf cwillisf deleted the pen branch January 20, 2017 21:21
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.

None yet

4 participants