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