Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: sky/examples/game/lib/sprite_node.dart

Issue 1164633004: Adds support for transfer mode in Paint and SpriteNode classes (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fixes indentations and whitespaces Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/examples/game/lib/game_world.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/game/lib/sprite_node.dart
diff --git a/sky/examples/game/lib/sprite_node.dart b/sky/examples/game/lib/sprite_node.dart
index ca6296a82d133880872b01accd2b8af498951110..406a3f4ab442a98a546e816a7af5dc5c21767e8f 100644
--- a/sky/examples/game/lib/sprite_node.dart
+++ b/sky/examples/game/lib/sprite_node.dart
@@ -6,6 +6,9 @@ class SpriteNode extends TransformNode {
Image _image;
bool constrainProportions = false;
+ double _opacity = 1.0;
+ Color colorOverlay;
+ TransferMode transferMode;
SpriteNode() {
this.pivot = new Vector2(0.5, 0.5);
@@ -15,7 +18,14 @@ class SpriteNode extends TransformNode {
this.pivot = new Vector2(0.5, 0.5);
_image = image;
}
-
+
+ double get opacity => _opacity;
+
+ void set opacity(double opacity) {
+ assert(opacity >= 0.0 && opacity <= 1.0);
+ _opacity = opacity;
+ }
+
void paint(PictureRecorder canvas) {
if (_image != null && _image.width > 0 && _image.height > 0) {
@@ -37,7 +47,18 @@ class SpriteNode extends TransformNode {
}
canvas.scale(scaleX, scaleY);
- canvas.drawImage(_image, 0.0, 0.0, new Paint()..setARGB(255, 255, 255, 255));
+
+ // Setup paint object for opacity and transfer mode
+ Paint paint = new Paint();
+ paint.setARGB((255.0*_opacity).toInt(), 255, 255, 255);
+ if (colorOverlay != null) {
+ paint.setColorFilter(new ColorFilter(colorOverlay, TransferMode.srcATopMode));
+ }
+ if (transferMode != null) {
+ paint.setTransferMode(transferMode);
+ }
+
+ canvas.drawImage(_image, 0.0, 0.0, paint);
canvas.restore();
}
else {
« no previous file with comments | « sky/examples/game/lib/game_world.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698