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

Side by Side Diff: tools/dom/templates/html/impl/impl_CanvasRenderingContext2D.darttemplate

Issue 12775010: Added the CanvasImageSource interface, which all types that a canvas can draw (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed nits. Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
8 $!MEMBERS 8 $!MEMBERS
9 9
10 /** 10 /**
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 void setStrokeColorHsl(int h, num s, num l, [num a = 1]) { 42 void setStrokeColorHsl(int h, num s, num l, [num a = 1]) {
43 this.strokeStyle = 'hsla($h, $s%, $l%, $a)'; 43 this.strokeStyle = 'hsla($h, $s%, $l%, $a)';
44 } 44 }
45 45
46 @DomName('CanvasRenderingContext2D.arc') 46 @DomName('CanvasRenderingContext2D.arc')
47 void arc(num x, num y, num radius, num startAngle, num endAngle, 47 void arc(num x, num y, num radius, num startAngle, num endAngle,
48 [bool anticlockwise = false]) { 48 [bool anticlockwise = false]) {
49 $dom_arc(x, y, radius, startAngle, endAngle, anticlockwise); 49 $dom_arc(x, y, radius, startAngle, endAngle, anticlockwise);
50 } 50 }
51 51
52 /**
53 * Draws an image from a CanvasImageSource to this canvas.
54 *
55 * The entire image from [source] will be drawn to this context with its top
56 * left corner at the point ([destinationX], [destinationY]). If the image is
57 * larger than canvas will allow, the image will be cropped to fit the
58 * available space.
59 *
60 * CanvasElement canvas = new CanvasElement(width: 600, height: 600);
61 * CanvasRenderingContext2D ctx = canvas.context2d;
62 * ImageElement img = document.query('img');
63 *
64 * ctx.drawImage(img, 100, 100);
65 *
66 * VideoElement video = document.query('video');
67 * ctx.drawImage(video, 0, 0);
68 *
69 * CanvasElement otherCanvas = document.query('canvas');
70 * otherCanvas.width = 100;
71 * otherCanvas.height = 100;
72 * ctx.drawImage(otherCanvas, 590, 590); // will get cropped
73 *
74 * See also:
75 *
76 * * [CanvasImageSource] for more information on what data is retrieved
77 * from [source].
78 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage /the-canvas-element.html#dom-context-2d-drawimage)
79 * from the WHATWG.
80 */
81 @DomName('CanvasRenderingContext2D.drawImage')
82 void drawImage(CanvasImageSource source, num destinationX, num destinationY) {
83 $dom_drawImage(source, destinationX, destinationY);
84 }
85
86 /**
87 * Draws an image from a CanvasImageSource to an area of this canvas.
88 *
89 * The image will be drawn to an area of this canvas defined by
90 * [destinationRect]. If [sourceRect] is not provided, then
91 * the entire rectangular image from [source] will be drawn to this context.
92 * If the dimensions of [source] or [sourceRect]
93 * differ from [destinationRect], then the image will be scaled to fit.
94 * If the image is larger than canvas
95 * will allow, the image will be cropped to fit the available space.
96 *
97 * CanvasElement canvas = new CanvasElement(width: 600, height: 600);
98 * CanvasRenderingContext2D ctx = canvas.context2d;
99 * ImageElement img = document.query('img');
100 * img.width = 100;
101 * img.height = 100;
102 *
103 * // Scale the image to 20x20.
104 * ctx.drawImageAtScale(img, new Rect(50, 50, 20, 20));
105 *
106 * VideoElement video = document.query('video');
107 * video.width = 100;
108 * video.height = 100;
109 * // Take the middle 20x20 pixels from the video and stretch them.
110 * ctx.drawImageAtScale(video, new Rect(50, 50, 100, 100),
111 * sourceRect: new Rect(40, 40, 20, 20));
112 *
113 * // Draw the top 100x20 pixels from the otherCanvas.
114 * CanvasElement otherCanvas = document.query('canvas');
115 * ctx.drawImageAtScale(otherCanvas, new Rect(0, 0, 100, 20),
116 * sourceRect: new Rect(0, 0, 100, 20));
117 *
118 * See also:
119 *
120 * * [CanvasImageSource] for more information on what data is retrieved
121 * from [source].
122 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage /the-canvas-element.html#dom-context-2d-drawimage)
123 * from the WHATWG.
124 */
125 @DomName('CanvasRenderingContext2D.drawImage')
126 void drawImageAtScale(CanvasImageSource source, Rect destinationRect,
127 {Rect sourceRect}) {
128 if (sourceRect == null) {
129 $dom_drawImage(source,
130 destinationRect.left,
131 destinationRect.top,
132 destinationRect.width,
133 destinationRect.height);
134 } else {
135 $dom_drawImage(source,
136 sourceRect.left,
137 sourceRect.top,
138 sourceRect.width,
139 sourceRect.height,
140 destinationRect.left,
141 destinationRect.top,
142 destinationRect.width,
143 destinationRect.height);
144 }
145 }
52 146
53 $if DART2JS 147 $if DART2JS
54 @DomName('CanvasRenderingContext2D.lineDashOffset') 148 @DomName('CanvasRenderingContext2D.lineDashOffset')
55 num get lineDashOffset => JS('num', 149 num get lineDashOffset => JS('num',
56 '#.lineDashOffset || #.webkitLineDashOffset', this, this); 150 '#.lineDashOffset || #.webkitLineDashOffset', this, this);
57 151
58 @DomName('CanvasRenderingContext2D.lineDashOffset') 152 @DomName('CanvasRenderingContext2D.lineDashOffset')
59 void set lineDashOffset(num value) => JS('void', 153 void set lineDashOffset(num value) => JS('void',
60 'typeof #.lineDashOffset != "undefined" ? #.lineDashOffset = # : ' 154 'typeof #.lineDashOffset != "undefined" ? #.lineDashOffset = # : '
61 '#.webkitLineDashOffset = #', this, this, value, this, value); 155 '#.webkitLineDashOffset = #', this, this, value, this, value);
62 $endif 156 $endif
63 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698