Chromium Code Reviews| 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 library android_extension; | 5 library android_extension; |
| 6 | 6 |
| 7 class CanvasElement { | |
|
vsm
2013/02/04 18:18:41
I think I'd prefer not exposing CanvasElement - it
gram
2013/02/04 22:02:28
The motivation is because if we want to create add
| |
| 8 int _height; | |
| 9 int _width; | |
| 10 | |
| 11 get height => _height; | |
| 12 get width => _width; | |
| 13 | |
| 14 CanvasRenderingContext2D _context2d; | |
| 15 WebGLRenderingContext _context3d; | |
| 16 | |
| 17 CanvasElement({int width, int height}) { | |
| 18 _width = (width == null) ? getDeviceScreenWidth() : width; | |
| 19 _height = (height == null) ? getDeviceScreenHeight() : height; | |
| 20 } | |
| 21 | |
| 22 CanvasRenderingContext getContext(String contextId) { | |
| 23 if (contextId == "2d") { | |
| 24 if (_context2d == null) { | |
| 25 _context2d = new CanvasRenderingContext2D(this, _width, _height); | |
| 26 } | |
| 27 return _context2d; | |
| 28 } else if (contextId == "webgl") { | |
| 29 if (_context3d == null) { | |
| 30 _context3d = new WebGLRenderingContext(this); | |
| 31 } | |
| 32 return _context3d; | |
| 33 } | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 class CanvasRenderingContext { | |
| 38 final CanvasElement canvas; | |
| 39 | |
| 40 CanvasRenderingContext(this.canvas); | |
| 41 } | |
| 42 | |
| 7 // The simplest way to call native code: top-level functions. | 43 // The simplest way to call native code: top-level functions. |
| 8 int systemRand() native "SystemRand"; | 44 int systemRand() native "SystemRand"; |
| 9 void systemSrand(int seed) native "SystemSrand"; | 45 void systemSrand(int seed) native "SystemSrand"; |
| 10 void log(String what) native "Log"; | 46 void log(String what) native "Log"; |
| 11 | 47 |
| 48 int getDeviceScreenWidth() native "GetDeviceScreenWidth"; | |
| 49 int getDeviceScreenHeight() native "GetDeviceScreenHeight"; | |
| 50 | |
| 12 // EGL functions. | 51 // EGL functions. |
| 13 void glSwapBuffers() native "SwapBuffers"; | 52 void glSwapBuffers() native "SwapBuffers"; |
| 14 | 53 |
| 15 // GL functions. | 54 // GL functions. |
| 16 void glAttachShader(int program, int shader) native "GLAttachShader"; | 55 void glAttachShader(int program, int shader) native "GLAttachShader"; |
| 17 void glBindBuffer(int target, int buffer) native "GLBindBuffer"; | 56 void glBindBuffer(int target, int buffer) native "GLBindBuffer"; |
| 18 void glBufferData(int target, List data, int usage) native "GLBufferData"; | 57 void glBufferData(int target, List data, int usage) native "GLBufferData"; |
| 19 void glClearColor(num r, num g, num b, num alpha) native "GLClearColor"; | 58 void glClearColor(num r, num g, num b, num alpha) native "GLClearColor"; |
| 20 void glClearDepth(num depth) native "GLClearDepth"; | 59 void glClearDepth(num depth) native "GLClearDepth"; |
| 21 void glClear(int mask) native "GLClear"; | 60 void glClear(int mask) native "GLClear"; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 int glStaticDraw() native "GLStaticDraw"; | 108 int glStaticDraw() native "GLStaticDraw"; |
| 70 int glTriangleStrip() native "GLTriangleStrip"; | 109 int glTriangleStrip() native "GLTriangleStrip"; |
| 71 int glTriangles() native "GLTriangles"; | 110 int glTriangles() native "GLTriangles"; |
| 72 int glTrue() native "GLTrue"; | 111 int glTrue() native "GLTrue"; |
| 73 int glValidateStatus() native "GLValidateStatus"; | 112 int glValidateStatus() native "GLValidateStatus"; |
| 74 int glVertexShader() native "GLVertexShader"; | 113 int glVertexShader() native "GLVertexShader"; |
| 75 | 114 |
| 76 String glGetShaderInfoLog(int shader) native "GLGetShaderInfoLog"; | 115 String glGetShaderInfoLog(int shader) native "GLGetShaderInfoLog"; |
| 77 String glGetProgramInfoLog(int program) native "GLGetProgramInfoLog"; | 116 String glGetProgramInfoLog(int program) native "GLGetProgramInfoLog"; |
| 78 | 117 |
| 79 class WebGLRenderingContext { | 118 class WebGLRenderingContext extends CanvasRenderingContext { |
| 80 WebGLRenderingContext(); | 119 WebGLRenderingContext(canvas) : super(canvas); |
| 81 | 120 |
| 82 static get ARRAY_BUFFER => glArrayBuffer(); | 121 static get ARRAY_BUFFER => glArrayBuffer(); |
| 83 static get COLOR_BUFFER_BIT => glColorBufferBit(); | 122 static get COLOR_BUFFER_BIT => glColorBufferBit(); |
| 84 static get COMPILE_STATUS => glCompileStatus(); | 123 static get COMPILE_STATUS => glCompileStatus(); |
| 85 static get DELETE_STATUS => glDeleteStatus(); | 124 static get DELETE_STATUS => glDeleteStatus(); |
| 86 static get DEPTH_BUFFER_BIT => glDepthBufferBit(); | 125 static get DEPTH_BUFFER_BIT => glDepthBufferBit(); |
| 87 static get FLOAT => glFloat(); | 126 static get FLOAT => glFloat(); |
| 88 static get FRAGMENT_SHADER => glFragmentShader(); | 127 static get FRAGMENT_SHADER => glFragmentShader(); |
| 89 static get LINK_STATUS => glLinkStatus(); | 128 static get LINK_STATUS => glLinkStatus(); |
| 90 static get STATIC_DRAW => glStaticDraw(); | 129 static get STATIC_DRAW => glStaticDraw(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 viewport(x, y, width, height) => glViewport(x, y, width, height); | 188 viewport(x, y, width, height) => glViewport(x, y, width, height); |
| 150 getShaderInfoLog(shader) => glGetShaderInfoLog(shader); | 189 getShaderInfoLog(shader) => glGetShaderInfoLog(shader); |
| 151 getProgramInfoLog(program) => glGetProgramInfoLog(program); | 190 getProgramInfoLog(program) => glGetProgramInfoLog(program); |
| 152 | 191 |
| 153 // TODO(vsm): Kill. | 192 // TODO(vsm): Kill. |
| 154 noSuchMethod(invocation) { | 193 noSuchMethod(invocation) { |
| 155 throw new Exception('Unimplemented ${invocation.memberName}'); | 194 throw new Exception('Unimplemented ${invocation.memberName}'); |
| 156 } | 195 } |
| 157 } | 196 } |
| 158 | 197 |
| 159 var gl = new WebGLRenderingContext(); | |
| 160 | |
| 161 //------------------------------------------------------------------ | 198 //------------------------------------------------------------------ |
| 162 // Simple audio support. | 199 // Simple audio support. |
| 163 | 200 |
| 164 void playBackground(String path) native "PlayBackground"; | 201 void playBackground(String path) native "PlayBackground"; |
| 165 void stopBackground() native "StopBackground"; | 202 void stopBackground() native "StopBackground"; |
| 166 | 203 |
| 167 //------------------------------------------------------------------- | 204 //------------------------------------------------------------------- |
| 168 // Set up print(). | 205 // Set up print(). |
| 169 | 206 |
| 170 get _printClosure => (s) { | 207 get _printClosure => (s) { |
| 171 try { | 208 try { |
| 172 log(s); | 209 log(s); |
| 173 } catch (_) { | 210 } catch (_) { |
| 174 throw(s); | 211 throw(s); |
| 175 } | 212 } |
| 176 }; | 213 }; |
| 177 | 214 |
| 178 //------------------------------------------------------------------ | 215 //------------------------------------------------------------------ |
| 179 // Temp hack for compat with WebGL. | 216 // Temp hack for compat with WebGL. |
| 180 | 217 |
| 181 class Float32Array extends List<double> { | 218 class Float32Array extends List<double> { |
| 182 Float32Array.fromList(List a) { | 219 Float32Array.fromList(List a) { |
| 183 addAll(a); | 220 addAll(a); |
| 184 } | 221 } |
| 185 } | 222 } |
| 186 | 223 |
| 224 //------------------------------------------------------------------ | |
| 225 // 2D canvas support | |
| 226 | |
| 227 int C2DSetWidth(int handle, int width) | |
| 228 native "C2DSetWidth"; | |
| 229 int C2DSetHeight(int handle, int height) | |
| 230 native "C2DSetHeight"; | |
| 231 | |
| 232 double C2DSetGlobalAlpha(int handle, double globalAlpha) | |
|
vsm
2013/02/04 18:18:41
I think we should use "num" instead of "double" he
gram
2013/02/04 22:02:28
No, it won't throw, because the wrapper functions
vsm
2013/02/04 22:16:01
Got it.
On 2013/02/04 22:02:28, gram wrote:
| |
| 233 native "C2DSetGlobalAlpha"; | |
| 234 void C2DSetFillStyle(int handle, fs) | |
| 235 native "C2DSetFillStyle"; | |
| 236 String C2DSetFont(int handle, String font) | |
| 237 native "C2DSetFont"; | |
| 238 void C2DSetGlobalCompositeOperation(int handle, String op) | |
| 239 native "C2DSetGlobalCompositeOperation"; | |
| 240 C2DSetLineCap(int handle, String lc) | |
| 241 native "C2DSetLineCap"; | |
| 242 C2DSetLineJoin(int handle, String lj) | |
| 243 native "C2DSetLineJoin"; | |
| 244 C2DSetLineWidth(int handle, double w) | |
| 245 native "C2DSetLineWidth"; | |
| 246 C2DSetMiterLimit(int handle, double limit) | |
| 247 native "C2DSetMiterLimit"; | |
| 248 C2DSetShadowBlur(int handle, double blur) | |
| 249 native "C2DSetShadowBlur"; | |
| 250 C2DSetShadowColor(int handle, String color) | |
| 251 native "C2DSetShadowColor"; | |
| 252 C2DSetShadowOffsetX(int handle, double offset) | |
| 253 native "C2DSetShadowOffsetX"; | |
| 254 C2DSetShadowOffsetY(int handle, double offset) | |
| 255 native "C2DSetShadowOffsetY"; | |
| 256 void C2DSetStrokeStyle(int handle, ss) | |
| 257 native "C2DSetStrokeStyle"; | |
| 258 String C2DSetTextAlign(int handle, String align) | |
| 259 native "C2DSetTextAlign"; | |
| 260 String C2DSetTextBaseline(int handle, String baseline) | |
| 261 native "C2DSetTextBaseline"; | |
| 262 C2DGetBackingStorePixelRatio(int handle) | |
| 263 native "C2DGetBackingStorePixelRatio"; | |
| 264 void C2DSetImageSmoothingEnabled(int handle, bool ise) | |
| 265 native "C2DSetImageSmoothingEnabled"; | |
| 266 void C2DSetLineDash(int handle, List v) | |
| 267 native "C2DSetLineDash"; | |
| 268 C2DSetLineDashOffset(int handle, int v) | |
| 269 native "C2DSetLineDashOffset"; | |
| 270 void C2DArc(int handle, double x, double y, double radius, | |
| 271 double startAngle, double endAngle, [bool anticlockwise = false]) | |
| 272 native "C2DArc"; | |
| 273 void C2DArcTo(int handle, double x1, double y1, | |
| 274 double x2, double y2, double radius) | |
| 275 native "C2DArcTo"; | |
| 276 void C2DArcTo2(int handle, double x1, double y1, | |
| 277 double x2, double y2, double radiusX, | |
| 278 double radiusY, double rotation) | |
| 279 native "C2DArcTo2"; | |
| 280 void C2DBeginPath(int handle) | |
| 281 native "C2DBeginPath"; | |
| 282 void C2DBezierCurveTo(int handle, double cp1x, double cp1y, | |
| 283 double cp2x, double cp2y, double x, double y) | |
| 284 native "C2DBezierCurveTo"; | |
| 285 void C2DClearRect(int handle, double x, double y, double w, double h) | |
| 286 native "C2DClearRect"; | |
| 287 void C2DClip(int handle) | |
| 288 native "C2DClip"; | |
| 289 void C2DClosePath(int handle) | |
| 290 native "C2DClosePath"; | |
| 291 ImageData C2DCreateImageDataFromDimensions(int handle, num w, num h) | |
| 292 native "C2DCreateImageDataFromDimensions"; | |
| 293 void C2DDrawImage(int handle, String src_url, | |
| 294 int sx, int sy, | |
| 295 bool has_src_dimensions, int sw, int sh, | |
| 296 int dx, int dy, | |
| 297 bool has_dst_dimensions, int dw, int dh) | |
| 298 native "C2DDrawImage"; | |
| 299 void C2DFill(int handle) | |
| 300 native "C2DFill"; | |
| 301 void C2DFillRect(int handle, double x, double y, double w, double h) | |
| 302 native "C2DFillRect"; | |
| 303 void C2DFillText(int handle, String text, double x, double y, double maxWidth) | |
| 304 native "C2DFillText"; | |
| 305 ImageData C2DGetImageData(num sx, num sy, num sw, num sh) | |
| 306 native "C2DGetImageData"; | |
| 307 void C2DLineTo(int handle, double x, double y) | |
| 308 native "C2DLineTo"; | |
| 309 double C2DMeasureText(int handle, String text) | |
| 310 native "C2DMeasureText"; | |
| 311 void C2DMoveTo(int handle, double x, double y) | |
| 312 native "C2DMoveTo"; | |
| 313 void C2DPutImageData(int handle, ImageData imagedata, double dx, double dy) | |
| 314 native "C2DPutImageData"; | |
| 315 void C2DQuadraticCurveTo(int handle, double cpx, double cpy, double x, double y) | |
| 316 native "C2DQuadraticCurveTo"; | |
| 317 void C2DRect(int handle, double x, double y, double w, double h) | |
| 318 native "C2DRect"; | |
| 319 void C2DRestore(int handle) | |
| 320 native "C2DRestore"; | |
| 321 void C2DRotate(int handle, double a) | |
| 322 native "C2DRotate"; | |
| 323 void C2DSave(int handle) | |
| 324 native "C2DSave"; | |
| 325 void C2DScale(int handle, double sx, double sy) | |
| 326 native "C2DScale"; | |
| 327 void C2DSetTransform(int handle, double m11, double m12, | |
| 328 double m21, double m22, double dx, double dy) | |
| 329 native "C2DSetTransform"; | |
| 330 void C2DStroke(int handle) | |
| 331 native "C2DStroke"; | |
| 332 void C2DStrokeRect(int handle, double x, double y, double w, double h) | |
| 333 native "C2DStrokeRect"; | |
| 334 void C2DStrokeText(int handle, String text, double x, double y, double maxWidth) | |
| 335 native "C2DStrokeText"; | |
| 336 void C2DTransform(int handle, double m11, double m12, | |
| 337 double m21, double m22, double dx, double dy) | |
| 338 native "C2DTransform"; | |
| 339 void C2DTranslate(int handle, double x, double y) | |
| 340 native "C2DTranslate"; | |
| 341 | |
| 342 void C2DCreateNativeContext(int handle, int width, int height) | |
| 343 native "C2DCreateNativeContext"; | |
| 344 | |
| 345 class ElementEvents { | |
| 346 final List load; | |
| 347 ElementEvents() | |
| 348 : load =new List() { | |
| 349 } | |
| 350 } | |
| 351 | |
| 352 class ImageElement { | |
| 353 ElementEvents on; | |
| 354 String _src; | |
| 355 int _width; | |
| 356 int _height; | |
| 357 | |
| 358 get src => _src; | |
| 359 set src(String v) { | |
| 360 _src = v; | |
| 361 for (var e in on.load) { | |
| 362 e(this); | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 get width => _width; | |
| 367 set width(int widthp) => _width = widthp; | |
| 368 | |
| 369 get height => _height; | |
| 370 set height(int heightp) => _height = heightp; | |
| 371 | |
| 372 ImageElement({String srcp, int widthp, int heightp}) | |
| 373 : on = new ElementEvents(), | |
| 374 _src = srcp, | |
| 375 _width = widthp, | |
| 376 _height = heightp { | |
| 377 } | |
| 378 } | |
| 379 | |
| 380 class ImageData { | |
| 381 final Uint8ClampedArray data; | |
| 382 final int height; | |
| 383 final int width; | |
| 384 ImageData(this.height, this.width, this.data); | |
| 385 } | |
| 386 | |
| 387 class TextMetrics { | |
| 388 final num width; | |
| 389 TextMetrics(this.width); | |
| 390 } | |
| 391 | |
| 392 class CanvasRenderingContext2D extends CanvasRenderingContext { | |
| 393 // TODO(gram): We need to support multiple contexts, for cached content | |
| 394 // prerendered to an offscreen buffer. For this we will use handles, with | |
| 395 // handle 0 being the physical display. | |
| 396 static int _next_handle = 0; | |
| 397 int _handle = 0; | |
| 398 | |
| 399 int _width, _height; | |
| 400 set width(int w) { _width = C2DSetWidth(_handle, w); } | |
| 401 get width => _width; | |
| 402 set height(int h) { _height = C2DSetHeight(_handle, h); } | |
| 403 get height => _height; | |
| 404 | |
| 405 CanvasRenderingContext2D(canvas, width, height) : super(canvas) { | |
| 406 _width = width; | |
| 407 _height = height; | |
| 408 C2DCreateNativeContext(_handle = _next_handle++, width, height); | |
| 409 } | |
| 410 | |
| 411 double _alpha = 1.0; | |
| 412 set globalAlpha(a) { | |
|
vsm
2013/02/04 22:16:01
num a
| |
| 413 _alpha = C2DSetGlobalAlpha(_handle, a.toDouble()); | |
| 414 } | |
| 415 get globalAlpha => _alpha; | |
| 416 | |
| 417 // TODO(gram): make sure we support compound assignments like: | |
| 418 // fillStyle = strokeStyle = "red" | |
| 419 var _fillStyle = "#000"; | |
| 420 set fillStyle(fs) { | |
| 421 C2DSetFillStyle(_handle, _fillStyle = fs); | |
| 422 } | |
| 423 get fillStyle => _fillStyle; | |
| 424 | |
| 425 String _font = "10px sans-serif"; | |
| 426 set font(String f) { _font = C2DSetFont(_handle, f); } | |
| 427 get font => _font; | |
| 428 | |
| 429 String _globalCompositeOperation = "source-over"; | |
| 430 set globalCompositeOperation(String o) => | |
| 431 C2DSetGlobalCompositeOperation(_handle, _globalCompositeOperation = o); | |
| 432 get globalCompositeOperation => _globalCompositeOperation; | |
| 433 | |
| 434 String _lineCap = "butt"; // "butt", "round", "square" | |
| 435 get lineCap => _lineCap; | |
| 436 set lineCap(String lc) => C2DSetLineCap(_handle, _lineCap = lc); | |
| 437 | |
| 438 int _lineDashOffset = 0; | |
| 439 get lineDashOffset => _lineDashOffset; | |
| 440 set lineDashOffset(num v) { | |
| 441 _lineDashOffset = v.toInt(); | |
| 442 C2DSetLineDashOffset(_handle, _lineDashOffset); | |
| 443 } | |
| 444 | |
| 445 String _lineJoin = "miter"; // "round", "bevel", "miter" | |
| 446 get lineJoin => _lineJoin; | |
| 447 set lineJoin(lj) => C2DSetLineJoin(_handle, _lineJoin = lj); | |
|
vsm
2013/02/04 22:16:01
String lj
| |
| 448 | |
| 449 num _lineWidth = 1.0; | |
| 450 get lineWidth => _lineWidth; | |
| 451 set lineWidth(num w) { | |
| 452 C2DSetLineWidth(_handle, w.toDouble()); | |
| 453 _lineWidth = w; | |
| 454 } | |
| 455 | |
| 456 num _miterLimit = 10.0; // (default 10) | |
| 457 get miterLimit => _miterLimit; | |
| 458 set miterLimit(num limit) { | |
| 459 C2DSetMiterLimit(_handle, limit.toDouble()); | |
| 460 _miterLimit = limit; | |
| 461 } | |
| 462 | |
| 463 num _shadowBlur; | |
| 464 get shadowBlur => _shadowBlur; | |
| 465 set shadowBlur(num blur) { | |
| 466 _shadowBlur = blur; | |
| 467 C2DSetShadowBlur(_handle, blur.toDouble()); | |
| 468 } | |
| 469 | |
| 470 String _shadowColor; | |
| 471 get shadowColor => _shadowColor; | |
| 472 set shadowColor(String color) => | |
| 473 C2DSetShadowColor(_handle, _shadowColor = color); | |
| 474 | |
| 475 num _shadowOffsetX; | |
| 476 get shadowOffsetX => _shadowOffsetX; | |
| 477 set shadowOffsetX(num offset) { | |
| 478 _shadowOffsetX = offset; | |
| 479 C2DSetShadowOffsetX(_handle, offset.toDouble()); | |
| 480 } | |
| 481 | |
| 482 num _shadowOffsetY; | |
| 483 get shadowOffsetY => _shadowOffsetY; | |
| 484 set shadowOffsetY(num offset) { | |
| 485 _shadowOffsetY = offset; | |
| 486 C2DSetShadowOffsetY(_handle, offset.toDouble()); | |
| 487 } | |
| 488 | |
| 489 var _strokeStyle = "#000"; | |
| 490 get strokeStyle => _strokeStyle; | |
| 491 set strokeStyle(ss) { | |
| 492 C2DSetStrokeStyle(_handle, _strokeStyle = ss); | |
| 493 } | |
| 494 | |
| 495 String _textAlign = "start"; | |
| 496 get textAlign => _textAlign; | |
| 497 set textAlign(String a) { _textAlign = C2DSetTextAlign(_handle, a); } | |
| 498 | |
| 499 String _textBaseline = "alphabetic"; | |
| 500 get textBaseline => _textBaseline; | |
| 501 set textBaseline(String b) { _textBaseline = C2DSetTextBaseline(_handle, b); } | |
| 502 | |
| 503 get webkitBackingStorePixelRatio => C2DGetBackingStorePixelRatio(_handle); | |
| 504 | |
| 505 bool _webkitImageSmoothingEnabled; | |
| 506 get webkitImageSmoothingEnabled => _webkitImageSmoothingEnabled; | |
| 507 set webkitImageSmoothingEnabled(bool v) => | |
| 508 C2DSetImageSmoothingEnabled(_webkitImageSmoothingEnabled = v); | |
| 509 | |
| 510 get webkitLineDash => lineDash; | |
| 511 set webkitLineDash(List v) => lineDash = v; | |
| 512 | |
| 513 get webkitLineDashOffset => lineDashOffset; | |
| 514 set webkitLineDashOffset(num v) => lineDashOffset = v; | |
| 515 | |
| 516 // Methods | |
| 517 | |
| 518 void arc(num x, num y, num radius, num a1, num a2, bool anticlockwise) { | |
| 519 if (radius < 0) { | |
| 520 // throw IndexSizeError | |
| 521 } else { | |
| 522 C2DArc(_handle, x.toDouble(), y.toDouble(), radius.toDouble(), a1.toDouble (), a2.toDouble(), anticlockwise); | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 // Note - looking at the Dart docs it seems Dart doesn't support | |
| 527 // the second form in the browser. | |
| 528 void arcTo(num x1, num y1, num x2, num y2, | |
| 529 num radiusX, [num radiusY, num rotation]) { | |
| 530 if (radiusY == null) { | |
| 531 C2DArcTo(_handle, x1.toDouble(), y1.toDouble(), | |
| 532 x2.toDouble(), y2.toDouble(), radiusX.toDouble()); | |
| 533 } else { | |
| 534 C2DArcTo2(_handle, x1.toDouble(), y1.toDouble(), | |
| 535 x2.toDouble(), y2.toDouble(), | |
| 536 radiusX.toDouble(), radiusY.toDouble(), | |
| 537 rotation.toDouble()); | |
| 538 } | |
| 539 } | |
| 540 | |
| 541 void beginPath() => C2DBeginPath(_handle); | |
| 542 | |
| 543 void bezierCurveTo(num cp1x, num cp1y, num cp2x, num cp2y, | |
| 544 num x, num y) => | |
| 545 C2DBezierCurveTo(_handle, cp1x.toDouble(), cp1y.toDouble(), | |
| 546 cp2x.toDouble(), cp2y.toDouble(), | |
| 547 x.toDouble(), y.toDouble()); | |
| 548 | |
| 549 void clearRect(num x, num y, num w, num h) => | |
| 550 C2DClearRect(_handle, x.toDouble(), y.toDouble(), w.toDouble(), h.toDouble() ); | |
| 551 | |
| 552 void clip() => C2DClip(_handle); | |
| 553 | |
| 554 void closePath() => C2DClosePath(_handle); | |
| 555 | |
| 556 ImageData createImageData(var imagedata_OR_sw, [num sh = null]) { | |
| 557 if (sh == null) { | |
| 558 throw new Exception('Unimplemented createImageData(imagedata)'); | |
| 559 } else { | |
| 560 return C2DCreateImageDataFromDimensions(_handle, imagedata_OR_sw, sh); | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 CanvasGradient createLinearGradient(num x0, num y0, num x1, num y1) { | |
| 565 throw new Exception('Unimplemented createLinearGradient'); | |
| 566 } | |
| 567 | |
| 568 CanvasPattern createPattern(canvas_OR_image, String repetitionType) { | |
| 569 throw new Exception('Unimplemented createPattern'); | |
| 570 } | |
| 571 | |
| 572 CanvasGradient createRadialGradient(num x0, num y0, num x1, num y1, num r1) { | |
| 573 throw new Exception('Unimplemented createRadialGradient'); | |
| 574 } | |
| 575 | |
| 576 void drawImage(ImageElement image, num x1, num y1, | |
| 577 [num w1, num h1, num x2, num y2, num w2, num h2]) { | |
| 578 var w = (image.width == null) ? 0 : image.width; | |
| 579 var h = (image.height == null) ? 0 : image.height; | |
| 580 if (w1 == null) { // drawImage(image, dx, dy) | |
|
vsm
2013/02/04 18:18:41
"if (!?w1)" will test if w1 was actually not passe
gram
2013/02/04 22:02:28
Done.
| |
| 581 C2DDrawImage(_handle, image.src, 0, 0, false, w, h, | |
| 582 x1.toInt(), y1.toInt(), false, 0, 0); | |
| 583 } else if (x2 == null) { // drawImage(image, dx, dy, dw, dh) | |
| 584 C2DDrawImage(_handle, image.src, 0, 0, false, w, h, | |
| 585 x1.toInt(), y1.toInt(), true, w1.toInt(), h1.toInt()); | |
| 586 } else { // drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) | |
| 587 C2DDrawImage(_handle, image.src, | |
| 588 x1.toInt(), y1.toInt(), true, w1.toInt(), h1.toInt(), | |
| 589 x2.toInt(), y2.toInt(), true, w2.toInt(), h2.toInt()); | |
| 590 } | |
| 591 } | |
| 592 | |
| 593 void fill() => C2DFill(_handle); | |
| 594 | |
| 595 void fillRect(num x, num y, num w, num h) => | |
| 596 C2DFillRect(_handle, x.toDouble(), y.toDouble(), | |
| 597 w.toDouble(), h.toDouble()); | |
| 598 | |
| 599 void fillText(String text, num x, num y, [num maxWidth = -1]) => | |
| 600 C2DFillText(_handle, text, x.toDouble(), y.toDouble(), | |
| 601 maxWidth.toDouble()); | |
| 602 | |
| 603 ImageData getImageData(num sx, num sy, num sw, num sh) => | |
| 604 C2DGetImageData(sx, sy, sw, sh); | |
| 605 | |
| 606 List<double> _lineDash = null; | |
| 607 List<num> getLineDash() { | |
| 608 if (_lineDash == null) return []; | |
| 609 return _lineDash; // TODO(gram): should we return a copy? | |
| 610 } | |
| 611 | |
| 612 bool isPointInPath(num x, num y) { | |
| 613 throw new Exception('Unimplemented isPointInPath'); | |
| 614 } | |
| 615 | |
| 616 void lineTo(num x, num y) { | |
| 617 C2DLineTo(_handle, x.toDouble(), y.toDouble()); | |
| 618 } | |
| 619 | |
| 620 TextMetrics measureText(String text) { | |
| 621 double w = C2DMeasureText(_handle, text); | |
| 622 return new TextMetrics(w); | |
| 623 } | |
| 624 | |
| 625 void moveTo(num x, num y) => | |
| 626 C2DMoveTo(_handle, x.toDouble(), y.toDouble()); | |
| 627 | |
| 628 void putImageData(ImageData imagedata, num dx, num dy, | |
| 629 [num dirtyX, num dirtyY, num dirtyWidth, num dirtyHeight]) { | |
| 630 if (dirtyX != null || dirtyY != null) { | |
| 631 throw new Exception('Unimplemented putImageData'); | |
| 632 } else { | |
| 633 C2DPutImageData(_handle, imagedata, dx, dy); | |
| 634 } | |
| 635 } | |
| 636 | |
| 637 void quadraticCurveTo(num cpx, num cpy, num x, num y) => | |
| 638 C2DQuadraticCurveTo(_handle, cpx.toDouble(), cpy.toDouble(), | |
| 639 x.toDouble(), y.toDouble()); | |
| 640 | |
| 641 void rect(num x, num y, num w, num h) => | |
| 642 C2DRect(_handle, x.toDouble(), y.toDouble(), w.toDouble(), h.toDouble()); | |
| 643 | |
| 644 void restore() => C2DRestore(_handle); | |
| 645 | |
| 646 void rotate(num angle) => C2DRotate(_handle, angle.toDouble()); | |
| 647 | |
| 648 void save() => C2DSave(_handle); | |
| 649 | |
| 650 void scale(num x, num y) => C2DScale(_handle, x.toDouble(), y.toDouble()); | |
| 651 | |
| 652 void setFillColorHsl(int h, num s, num l, [num a = 1]) { | |
| 653 throw new Exception('Unimplemented setFillColorHsl'); | |
| 654 } | |
| 655 | |
| 656 void setFillColorRgb(int r, int g, int b, [num a = 1]) { | |
| 657 throw new Exception('Unimplemented setFillColorRgb'); | |
| 658 } | |
| 659 | |
| 660 void setLineDash(List<num> dash) { | |
| 661 var valid = true; | |
| 662 var new_dash; | |
| 663 if (dash.length % 2 == 1) { | |
| 664 new_dash = new List<double>(2 * dash.length); | |
| 665 for (int i = 0; i < dash.length; i++) { | |
| 666 double v = dash[i].toDouble(); | |
| 667 if (v < 0) { | |
| 668 valid = false; | |
| 669 break; | |
| 670 } | |
| 671 new_dash[i] = new_dash[i + dash.length] = v; | |
| 672 } | |
| 673 } else { | |
| 674 new_dash = new List<double>(dash.length); | |
| 675 for (int i = 0; i < dash.length; i++) { | |
| 676 double v = dash[i].toDouble(); | |
| 677 if (v < 0) { | |
| 678 valid = false; | |
| 679 break; | |
| 680 } | |
| 681 new_dash[i] = v; | |
| 682 } | |
| 683 } | |
| 684 if (valid) { | |
| 685 C2DSetLineDash(_handle, _lineDash = new_dash); | |
| 686 } | |
| 687 } | |
| 688 | |
| 689 void setStrokeColorHsl(int h, num s, num l, [num a = 1]) { | |
| 690 throw new Exception('Unimplemented setStrokeColorHsl'); | |
| 691 } | |
| 692 | |
| 693 void setStrokeColorRgb(int r, int g, int b, [num a = 1]) { | |
| 694 throw new Exception('Unimplemented setStrokeColorRgb'); | |
| 695 } | |
| 696 | |
| 697 void setTransform(num m11, num m12, num m21, num m22, num dx, num dy) => | |
| 698 C2DSetTransform(_handle, m11.toDouble(), m12.toDouble(), | |
| 699 m21.toDouble(), m22.toDouble(), | |
| 700 dx.toDouble(), dy.toDouble()); | |
| 701 | |
| 702 void stroke() => C2DStroke(_handle); | |
| 703 | |
| 704 void strokeRect(num x, num y, num w, num h, [num lineWidth]) => | |
| 705 C2DStrokeRect(_handle, x.toDouble(), y.toDouble(), w.toDouble(), h.toDouble( )); | |
| 706 | |
| 707 void strokeText(String text, num x, num y, [num maxWidth = -1]) => | |
| 708 C2DStrokeText(_handle, text, x.toDouble(), y.toDouble(), | |
| 709 maxWidth.toDouble()); | |
| 710 | |
| 711 void transform(num m11, num m12, num m21, num m22, num dx, num dy) => | |
| 712 C2DTransform(m11.toDouble(), m12.toDouble(), | |
| 713 m21.toDouble(), m22.toDouble(), | |
| 714 dx.toDouble(), dy.toDouble()); | |
| 715 | |
| 716 void translate(num x, num y) => | |
| 717 C2DTranslate(_handle, x.toDouble(), y.toDouble()); | |
| 718 | |
| 719 ImageData webkitGetImageDataHD(num sx, num sy, num sw, num sh) { | |
| 720 throw new Exception('Unimplemented webkitGetImageDataHD'); | |
| 721 } | |
| 722 | |
| 723 void webkitPutImageDataHD(ImageData imagedata, num dx, num dy, | |
| 724 [num dirtyX, num dirtyY, | |
| 725 num dirtyWidth, num dirtyHeight]) { | |
| 726 throw new Exception('Unimplemented webkitGetImageDataHD'); | |
| 727 } | |
| 728 | |
| 729 // TODO(vsm): Kill. | |
|
vsm
2013/02/04 18:18:41
Maybe we can delete this now.
gram
2013/02/04 22:02:28
I find it is still useful to catch bugs occasional
| |
| 730 noSuchMethod(invocation) { | |
| 731 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); | |
| 732 } | |
| 733 } | |
| 734 | |
| OLD | NEW |