-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I guess I never PRed this... Adds ability to override built-in objects to custom ones so you can do things like add shadows: ``` RiveAnimation.asset( 'assets/shadowtext.riv', objectGenerator: (coreTypeKey) { switch (coreTypeKey) { case ShapeBase.typeKey: return ShadowRiveShape(); } return null; }, ``` ![image](https://github.com/rive-app/rive/assets/454182/cae261b1-8005-4c49-9714-3bb1dca50cde) ``` class ShadowRiveShape extends Shape { Paint? _shadowPaint; @OverRide void onAdded() { if (name == 'ShadowShape') { // This was named "ShadowShape" we use that as a simple way to determine // that we want to add a drop shadow at runtime. _shadowPaint = Paint() ..imageFilter = ImageFilter.blur( // Make it a 10x10 black blur sigmaX: 10, sigmaY: 10, tileMode: TileMode.clamp, ); } super.onAdded(); } @OverRide K? clone<K extends Core<CoreContext>>() { var shape = ShadowRiveShape(); shape.copy(this); return shape as K; } @OverRide void draw(Canvas canvas) { var shadow = _shadowPaint; if (shadow != null) { // We draw a blurred version of this shape before regular drawing. Make // sure to respect clipping rules for the shadow too. bool clipped = clip(canvas); var path = pathComposer.fillPath; canvas.save(); if (!fillInWorld) { canvas.transform(worldTransform.mat4); } // Offset the shadow to the bottom right (change to whatever you want). canvas.translate(10, 10); canvas.drawPath(path, shadow); canvas.restore(); if (clipped) { canvas.restore(); } } // Draw the regular shape. super.draw(canvas); } } ``` Diffs= 99a2215da Add an object generator. (#6805) 7cb7eb812 Upgrade rive_wasm to the new premake system (#6789) Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
- Loading branch information
1 parent
bee93ab
commit 8487b7f
Showing
3 changed files
with
42 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
74e649ee25a9d65fd428f32d3dbd144e54c38aa8 | ||
99a2215daeffdfe537e2a900113a9d59ee7b9d3f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters