| OLD | NEW |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 /** | 52 /** |
| 53 * Draws an image from a CanvasImageSource to an area of this canvas. |
| 54 * |
| 55 * The image will be drawn to an area of this canvas defined by |
| 56 * [destRect]. [sourceRect] defines the region of the source image that is |
| 57 * drawn. |
| 58 * If [sourceRect] is not provided, then |
| 59 * the entire rectangular image from [source] will be drawn to this context. |
| 60 * |
| 61 * If the image is larger than canvas |
| 62 * will allow, the image will be clipped to fit the available space. |
| 63 * |
| 64 * CanvasElement canvas = new CanvasElement(width: 600, height: 600); |
| 65 * CanvasRenderingContext2D ctx = canvas.context2d; |
| 66 * ImageElement img = document.query('img'); |
| 67 * img.width = 100; |
| 68 * img.height = 100; |
| 69 * |
| 70 * // Scale the image to 20x20. |
| 71 * ctx.drawImageToRect(img, new Rect(50, 50, 20, 20)); |
| 72 * |
| 73 * VideoElement video = document.query('video'); |
| 74 * video.width = 100; |
| 75 * video.height = 100; |
| 76 * // Take the middle 20x20 pixels from the video and stretch them. |
| 77 * ctx.drawImageToRect(video, new Rect(50, 50, 100, 100), |
| 78 * sourceRect: new Rect(40, 40, 20, 20)); |
| 79 * |
| 80 * // Draw the top 100x20 pixels from the otherCanvas. |
| 81 * CanvasElement otherCanvas = document.query('canvas'); |
| 82 * ctx.drawImageToRect(otherCanvas, new Rect(0, 0, 100, 20), |
| 83 * sourceRect: new Rect(0, 0, 100, 20)); |
| 84 * |
| 85 * See also: |
| 86 * |
| 87 * * [CanvasImageSource] for more information on what data is retrieved |
| 88 * from [source]. |
| 89 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage
/the-canvas-element.html#dom-context-2d-drawimage) |
| 90 * from the WHATWG. |
| 91 */ |
| 92 @DomName('CanvasRenderingContext2D.drawImage') |
| 93 void drawImageToRect(CanvasImageSource source, Rect destRect, |
| 94 {Rect sourceRect}) { |
| 95 $if DART2JS |
| 96 if (sourceRect == null) { |
| 97 drawImageScaled(source, |
| 98 destRect.left, |
| 99 destRect.top, |
| 100 destRect.width, |
| 101 destRect.height); |
| 102 } else { |
| 103 drawImageScaledFromSource(source, |
| 104 sourceRect.left, |
| 105 sourceRect.top, |
| 106 sourceRect.width, |
| 107 sourceRect.height, |
| 108 destRect.left, |
| 109 destRect.top, |
| 110 destRect.width, |
| 111 destRect.height); |
| 112 } |
| 113 $else |
| 114 if (sourceRect == null) { |
| 115 $dom_drawImage(source, |
| 116 destRect.left, |
| 117 destRect.top, |
| 118 destRect.width, |
| 119 destRect.height); |
| 120 } else { |
| 121 $dom_drawImage(source, |
| 122 sourceRect.left, |
| 123 sourceRect.top, |
| 124 sourceRect.width, |
| 125 sourceRect.height, |
| 126 destRect.left, |
| 127 destRect.top, |
| 128 destRect.width, |
| 129 destRect.height); |
| 130 } |
| 131 $endif |
| 132 } |
| 133 |
| 134 /** |
| 53 * Draws an image from a CanvasImageSource to this canvas. | 135 * Draws an image from a CanvasImageSource to this canvas. |
| 54 * | 136 * |
| 55 * The entire image from [source] will be drawn to this context with its top | 137 * 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 | 138 * left corner at the point ([destX], [destY]). If the image is |
| 57 * larger than canvas will allow, the image will be cropped to fit the | 139 * larger than canvas will allow, the image will be clipped to fit the |
| 58 * available space. | 140 * available space. |
| 59 * | 141 * |
| 60 * CanvasElement canvas = new CanvasElement(width: 600, height: 600); | 142 * CanvasElement canvas = new CanvasElement(width: 600, height: 600); |
| 61 * CanvasRenderingContext2D ctx = canvas.context2d; | 143 * CanvasRenderingContext2D ctx = canvas.context2d; |
| 62 * ImageElement img = document.query('img'); | 144 * ImageElement img = document.query('img'); |
| 63 * | 145 * |
| 64 * ctx.drawImage(img, 100, 100); | 146 * ctx.drawImage(img, 100, 100); |
| 65 * | 147 * |
| 66 * VideoElement video = document.query('video'); | 148 * VideoElement video = document.query('video'); |
| 67 * ctx.drawImage(video, 0, 0); | 149 * ctx.drawImage(video, 0, 0); |
| 68 * | 150 * |
| 69 * CanvasElement otherCanvas = document.query('canvas'); | 151 * CanvasElement otherCanvas = document.query('canvas'); |
| 70 * otherCanvas.width = 100; | 152 * otherCanvas.width = 100; |
| 71 * otherCanvas.height = 100; | 153 * otherCanvas.height = 100; |
| 72 * ctx.drawImage(otherCanvas, 590, 590); // will get cropped | 154 * ctx.drawImage(otherCanvas, 590, 590); // will get clipped |
| 73 * | 155 * |
| 74 * See also: | 156 * See also: |
| 75 * | 157 * |
| 76 * * [CanvasImageSource] for more information on what data is retrieved | 158 * * [CanvasImageSource] for more information on what data is retrieved |
| 77 * from [source]. | 159 * from [source]. |
| 78 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage
/the-canvas-element.html#dom-context-2d-drawimage) | 160 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage
/the-canvas-element.html#dom-context-2d-drawimage) |
| 79 * from the WHATWG. | 161 * from the WHATWG. |
| 80 */ | 162 */ |
| 81 @DomName('CanvasRenderingContext2D.drawImage') | 163 @DomName('CanvasRenderingContext2D.drawImage') |
| 82 void drawImage(CanvasImageSource source, num destinationX, num destinationY) { | 164 $if DART2JS |
| 83 $dom_drawImage(source, destinationX, destinationY); | 165 @JSName('drawImage') |
| 166 void drawImage(CanvasImageSource source, num destX, num destY) native; |
| 167 $else |
| 168 void drawImage(CanvasImageSource source, num destX, num destY) { |
| 169 $dom_drawImage(source, destX, destY); |
| 84 } | 170 } |
| 171 $endif |
| 85 | 172 |
| 86 /** | 173 /** |
| 87 * Draws an image from a CanvasImageSource to an area of this canvas. | 174 * Draws an image from a CanvasImageSource to an area of this canvas. |
| 88 * | 175 * |
| 89 * The image will be drawn to an area of this canvas defined by | 176 * The image will be drawn to this context with its top left corner at the |
| 90 * [destinationRect]. If [sourceRect] is not provided, then | 177 * point ([destX], [destY]) and will be scaled to be [destWidth] wide and |
| 91 * the entire rectangular image from [source] will be drawn to this context. | 178 * [destHeight] tall. |
| 92 * If the dimensions of [source] or [sourceRect] | 179 * |
| 93 * differ from [destinationRect], then the image will be scaled to fit. | |
| 94 * If the image is larger than canvas | 180 * If the image is larger than canvas |
| 95 * will allow, the image will be cropped to fit the available space. | 181 * will allow, the image will be clipped to fit the available space. |
| 96 * | 182 * |
| 97 * CanvasElement canvas = new CanvasElement(width: 600, height: 600); | 183 * CanvasElement canvas = new CanvasElement(width: 600, height: 600); |
| 98 * CanvasRenderingContext2D ctx = canvas.context2d; | 184 * CanvasRenderingContext2D ctx = canvas.context2d; |
| 99 * ImageElement img = document.query('img'); | 185 * ImageElement img = document.query('img'); |
| 100 * img.width = 100; | 186 * img.width = 100; |
| 101 * img.height = 100; | 187 * img.height = 100; |
| 102 * | 188 * |
| 103 * // Scale the image to 20x20. | 189 * // Scale the image to 300x50 at the point (20, 20) |
| 104 * ctx.drawImageAtScale(img, new Rect(50, 50, 20, 20)); | 190 * ctx.drawImageScaled(img, 20, 20, 300, 50); |
| 191 * |
| 192 * See also: |
| 193 * |
| 194 * * [CanvasImageSource] for more information on what data is retrieved |
| 195 * from [source]. |
| 196 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage
/the-canvas-element.html#dom-context-2d-drawimage) |
| 197 * from the WHATWG. |
| 198 */ |
| 199 @DomName('CanvasRenderingContext2D.drawImage') |
| 200 $if DART2JS |
| 201 @JSName('drawImage') |
| 202 void drawImageScaled(CanvasImageSource source, |
| 203 num destX, num destY, num destWidth, num destHeight) native; |
| 204 $else |
| 205 void drawImageScaled(CanvasImageSource source, |
| 206 num destX, num destY, num destWidth, num destHeight) { |
| 207 $dom_drawImage(source, destX, destY, destWidth, destHeight); |
| 208 } |
| 209 $endif |
| 210 |
| 211 /** |
| 212 * Draws an image from a CanvasImageSource to an area of this canvas. |
| 213 * |
| 214 * The image is a region of [source] that is [sourceWidth] wide and |
| 215 * [destHeight] tall with top left corner at ([sourceX], [sourceY]). |
| 216 * The image will be drawn to this context with its top left corner at the |
| 217 * point ([destX], [destY]) and will be scaled to be [destWidth] wide and |
| 218 * [destHeight] tall. |
| 219 * |
| 220 * If the image is larger than canvas |
| 221 * will allow, the image will be clipped to fit the available space. |
| 105 * | 222 * |
| 106 * VideoElement video = document.query('video'); | 223 * VideoElement video = document.query('video'); |
| 107 * video.width = 100; | 224 * video.width = 100; |
| 108 * video.height = 100; | 225 * video.height = 100; |
| 109 * // Take the middle 20x20 pixels from the video and stretch them. | 226 * // Take the middle 20x20 pixels from the video and stretch them. |
| 110 * ctx.drawImageAtScale(video, new Rect(50, 50, 100, 100), | 227 * ctx.drawImageScaledFromSource(video, 40, 40, 20, 20, 50, 50, 100, 100); |
| 111 * sourceRect: new Rect(40, 40, 20, 20)); | |
| 112 * | 228 * |
| 113 * // Draw the top 100x20 pixels from the otherCanvas. | 229 * // Draw the top 100x20 pixels from the otherCanvas to this one. |
| 114 * CanvasElement otherCanvas = document.query('canvas'); | 230 * CanvasElement otherCanvas = document.query('canvas'); |
| 115 * ctx.drawImageAtScale(otherCanvas, new Rect(0, 0, 100, 20), | 231 * ctx.drawImageScaledFromSource(otherCanvas, 0, 0, 100, 20, 0, 0, 100, 20
); |
| 116 * sourceRect: new Rect(0, 0, 100, 20)); | |
| 117 * | 232 * |
| 118 * See also: | 233 * See also: |
| 119 * | 234 * |
| 120 * * [CanvasImageSource] for more information on what data is retrieved | 235 * * [CanvasImageSource] for more information on what data is retrieved |
| 121 * from [source]. | 236 * from [source]. |
| 122 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage
/the-canvas-element.html#dom-context-2d-drawimage) | 237 * * [drawImage](http://www.whatwg.org/specs/web-apps/current-work/multipage
/the-canvas-element.html#dom-context-2d-drawimage) |
| 123 * from the WHATWG. | 238 * from the WHATWG. |
| 124 */ | 239 */ |
| 125 @DomName('CanvasRenderingContext2D.drawImage') | 240 @DomName('CanvasRenderingContext2D.drawImage') |
| 126 void drawImageAtScale(CanvasImageSource source, Rect destinationRect, | 241 $if DART2JS |
| 127 {Rect sourceRect}) { | 242 @JSName('drawImage') |
| 128 if (sourceRect == null) { | 243 void drawImageScaledFromSource(CanvasImageSource source, |
| 129 $dom_drawImage(source, | 244 num sourceX, num sourceY, num sourceWidth, num sourceHeight, |
| 130 destinationRect.left, | 245 num destX, num destY, num destWidth, num destHeight) native; |
| 131 destinationRect.top, | 246 $else |
| 132 destinationRect.width, | 247 void drawImageScaledFromSource(CanvasImageSource source, |
| 133 destinationRect.height); | 248 num sourceX, num sourceY, num sourceWidth, num sourceHeight, |
| 134 } else { | 249 num destX, num destY, num destWidth, num destHeight) { |
| 135 $dom_drawImage(source, | 250 $dom_drawImage(source, sourceX, sourceY, sourceWidth, sourceHeight, |
| 136 sourceRect.left, | 251 destX, destY, destWidth, destHeight); |
| 137 sourceRect.top, | |
| 138 sourceRect.width, | |
| 139 sourceRect.height, | |
| 140 destinationRect.left, | |
| 141 destinationRect.top, | |
| 142 destinationRect.width, | |
| 143 destinationRect.height); | |
| 144 } | |
| 145 } | 252 } |
| 253 $endif |
| 146 | 254 |
| 147 $if DART2JS | 255 $if DART2JS |
| 148 @DomName('CanvasRenderingContext2D.lineDashOffset') | 256 @DomName('CanvasRenderingContext2D.lineDashOffset') |
| 149 num get lineDashOffset => JS('num', | 257 num get lineDashOffset => JS('num', |
| 150 '#.lineDashOffset || #.webkitLineDashOffset', this, this); | 258 '#.lineDashOffset || #.webkitLineDashOffset', this, this); |
| 151 | 259 |
| 152 @DomName('CanvasRenderingContext2D.lineDashOffset') | 260 @DomName('CanvasRenderingContext2D.lineDashOffset') |
| 153 void set lineDashOffset(num value) => JS('void', | 261 void set lineDashOffset(num value) => JS('void', |
| 154 'typeof #.lineDashOffset != "undefined" ? #.lineDashOffset = # : ' | 262 'typeof #.lineDashOffset != "undefined" ? #.lineDashOffset = # : ' |
| 155 '#.webkitLineDashOffset = #', this, this, value, this, value); | 263 '#.webkitLineDashOffset = #', this, this, value, this, value); |
| 264 $else |
| 265 // TODO(amouravski): Add Dartium native methods for drawImage once we figure |
| 266 // out how to not break native bindings. |
| 156 $endif | 267 $endif |
| 157 } | 268 } |
| 269 |
| OLD | NEW |