CanvasElement.hx 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. // This file is generated from mozilla\HTMLCanvasElement.webidl. Do not edit!
  23. package js.html;
  24. /**
  25. The `HTMLCanvasElement` interface provides properties and methods for manipulating the layout and presentation of canvas elements. The `HTMLCanvasElement` interface also inherits the properties and methods of the `HTMLElement` interface.
  26. Documentation [HTMLCanvasElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  27. @see <https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement>
  28. **/
  29. @:native("HTMLCanvasElement")
  30. extern class CanvasElement extends Element {
  31. /**
  32. Is a positive `integer` reflecting the `width` HTML attribute of the `canvas` element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of `300` is used.
  33. **/
  34. var width : Int;
  35. /**
  36. Is a positive `integer` reflecting the `height` HTML attribute of the `canvas` element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of `150` is used.
  37. **/
  38. var height : Int;
  39. /**
  40. Returns a drawing context on the canvas, or null if the context ID is not supported. A drawing context lets you draw on the canvas. Calling getContext with `"2d"` returns a `CanvasRenderingContext2D` object, whereas calling it with `"webgl"` (or `"experimental-webgl"`) returns a `WebGLRenderingContext` object. This context is only available on browsers that implement WebGL.
  41. @throws DOMError
  42. **/
  43. function getContext( contextId : String, ?contextOptions : Dynamic ) : Dynamic;
  44. /**
  45. Returns a data-URL containing a representation of the image in the format specified by the `type` parameter (defaults to `png`). The returned image is in a resolution of 96dpi.
  46. @throws DOMError
  47. **/
  48. function toDataURL( type : String = "", ?encoderOptions : Dynamic ) : String;
  49. /**
  50. Creates a `Blob` object representing the image contained in the canvas; this file may be cached on the disk or stored in memory at the discretion of the user agent.
  51. @throws DOMError
  52. **/
  53. function toBlob( callback : Blob -> Void, type : String = "", ?encoderOptions : Dynamic ) : Void;
  54. /**
  55. Returns a `CanvasCaptureMediaStream` that is a real-time video capture of the surface of the canvas.
  56. @throws DOMError
  57. **/
  58. function captureStream( ?frameRate : Float ) : CanvasCaptureMediaStream;
  59. /** Shorthand for getting a CanvasRenderingContext2D. */
  60. inline function getContext2d( ?attribs : {} ) : CanvasRenderingContext2D {
  61. return cast getContext("2d", attribs);
  62. }
  63. /** Shorthand for getting a js.html.webgl.RenderingContext. */
  64. inline function getContextWebGL( ?attribs : js.html.webgl.ContextAttributes ) : js.html.webgl.RenderingContext {
  65. return CanvasUtil.getContextWebGL(this, attribs);
  66. }
  67. /** Shorthand for getting a js.html.webgl.WebGL2RenderingContext. */
  68. inline function getContextWebGL2( ?attribs : js.html.webgl.ContextAttributes ) : js.html.webgl.WebGL2RenderingContext {
  69. return this.getContext('webgl2', attribs);
  70. }
  71. }
  72. private class CanvasUtil {
  73. public static function getContextWebGL( canvas :CanvasElement, attribs :{} ) {
  74. for (name in ["webgl", "experimental-webgl"]) {
  75. var ctx = canvas.getContext(name, attribs);
  76. if (ctx != null) return ctx;
  77. }
  78. return null;
  79. }
  80. }