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

Side by Side Diff: sky/sdk/example/game/lib/sprite.dart

Issue 1226113007: Add @override annotation to known overriden methods (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 part of sprites; 1 part of sprites;
2 2
3 /// A Sprite is a [Node] that renders a bitmap image to the screen. 3 /// A Sprite is a [Node] that renders a bitmap image to the screen.
4 class Sprite extends NodeWithSize { 4 class Sprite extends NodeWithSize {
5 5
6 /// The texture that the sprite will render to screen. 6 /// The texture that the sprite will render to screen.
7 /// 7 ///
8 /// If the texture is null, the sprite will be rendered as a red square 8 /// If the texture is null, the sprite will be rendered as a red square
9 /// marking the bounds of the sprite. 9 /// marking the bounds of the sprite.
10 /// 10 ///
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 /// 57 ///
58 /// mySprite.opacity = 0.5; 58 /// mySprite.opacity = 0.5;
59 double get opacity => _opacity; 59 double get opacity => _opacity;
60 60
61 void set opacity(double opacity) { 61 void set opacity(double opacity) {
62 assert(opacity != null); 62 assert(opacity != null);
63 assert(opacity >= 0.0 && opacity <= 1.0); 63 assert(opacity >= 0.0 && opacity <= 1.0);
64 _opacity = opacity; 64 _opacity = opacity;
65 } 65 }
66 66
67 @override
67 void paint(PaintingCanvas canvas) { 68 void paint(PaintingCanvas canvas) {
68 canvas.save(); 69 canvas.save();
69 70
70 // Account for pivot point 71 // Account for pivot point
71 applyTransformForPivot(canvas); 72 applyTransformForPivot(canvas);
72 73
73 if (texture != null) { 74 if (texture != null) {
74 double w = texture.size.width; 75 double w = texture.size.width;
75 double h = texture.size.height; 76 double h = texture.size.height;
76 77
77 if (w <= 0 || h <= 0) return; 78 if (w <= 0 || h <= 0) return;
78 79
79 double scaleX = size.width / w; 80 double scaleX = size.width / w;
80 double scaleY = size.height / h; 81 double scaleY = size.height / h;
81 82
82 if (constrainProportions) { 83 if (constrainProportions) {
83 // Constrain proportions, using the smallest scale and by centering the image 84 // Constrain proportions, using the smallest scale and by centering the image
84 if (scaleX < scaleY) { 85 if (scaleX < scaleY) {
85 canvas.translate(0.0, (size.height - scaleX * h) / 2.0); 86 canvas.translate(0.0, (size.height - scaleX * h) / 2.0);
86 scaleY = scaleX; 87 scaleY = scaleX;
87 } else { 88 } else {
88 canvas.translate((size.width - scaleY * w) / 2.0, 0.0); 89 canvas.translate((size.width - scaleY * w) / 2.0, 0.0);
89 scaleX = scaleY; 90 scaleX = scaleY;
90 } 91 }
91 } 92 }
92 93
93 canvas.scale(scaleX, scaleY); 94 canvas.scale(scaleX, scaleY);
94 95
95 // Setup paint object for opacity and transfer mode 96 // Setup paint object for opacity and transfer mode
96 Paint paint = new Paint(); 97 Paint paint = new Paint();
97 paint.color = new Color.fromARGB((255.0*_opacity).toInt(), 255, 255, 255); 98 paint.color = new Color.fromARGB((255.0*_opacity).toInt(), 255, 255, 255);
98 if (colorOverlay != null) { 99 if (colorOverlay != null) {
99 paint.setColorFilter(new ColorFilter.mode(colorOverlay, TransferMode.src ATop)); 100 paint.setColorFilter(new ColorFilter.mode(colorOverlay, TransferMode.src ATop));
100 } 101 }
101 if (transferMode != null) { 102 if (transferMode != null) {
102 paint.setTransferMode(transferMode); 103 paint.setTransferMode(transferMode);
103 } 104 }
104 105
105 // Do actual drawing of the sprite 106 // Do actual drawing of the sprite
106 texture.drawTexture(canvas, Point.origin, paint); 107 texture.drawTexture(canvas, Point.origin, paint);
107 } else { 108 } else {
108 // Paint a red square for missing texture 109 // Paint a red square for missing texture
109 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), 110 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height),
110 new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); 111 new Paint()..color = const Color.fromARGB(255, 255, 0, 0));
111 } 112 }
112 canvas.restore(); 113 canvas.restore();
113 } 114 }
114 } 115 }
OLDNEW
« no previous file with comments | « sky/sdk/example/game/lib/particle_system.dart ('k') | sky/sdk/example/rendering/sector_layout.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698