not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.7 KiB

  1. /**
  2. _enyo.Canvas_ is a control that generates a <canvas> HTML tag. It may
  3. contain other canvas components that are derived not from
  4. <a href="#enyo.Control">enyo.Control</a>, but from
  5. <a href="#enyo.canvas.Control">enyo.canvas.Control</a>. These aren't true
  6. controls in the sense of being DOM elements; they are, rather, shapes drawn
  7. into the canvas.
  8. */
  9. enyo.kind({
  10. name: "enyo.Canvas",
  11. kind: enyo.Control,
  12. tag: "canvas",
  13. attributes: {
  14. //* Width of the canvas element
  15. width: 500,
  16. //* Height of the canvas element
  17. height: 500
  18. },
  19. defaultKind: "enyo.canvas.Control",
  20. //* @protected
  21. generateInnerHtml: function() {
  22. return '';
  23. },
  24. teardownChildren: function() {
  25. },
  26. rendered: function() {
  27. this.renderChildren();
  28. },
  29. /*
  30. addChild and removeChild of Control kind assumes children are Controls.
  31. CanvasControls are not, so we use UiComponent's version, the superkind of Control
  32. */
  33. addChild: function() {
  34. enyo.UiComponent.prototype.addChild.apply(this, arguments);
  35. },
  36. removeChild: function() {
  37. enyo.UiComponent.prototype.removeChild.apply(this, arguments);
  38. },
  39. renderChildren: function(inContext) {
  40. var ctx = inContext;
  41. var canvas = this.hasNode();
  42. if (!ctx) {
  43. if (canvas.getContext) {
  44. ctx = canvas.getContext('2d');
  45. }
  46. }
  47. if (ctx) {
  48. for (var i=0, c; (c=this.children[i]); i++) {
  49. c.render(ctx);
  50. }
  51. }
  52. },
  53. //* @public
  54. /**
  55. Refreshes the canvas context, clears existing drawings, and redraws all
  56. of the children.
  57. */
  58. update: function() {
  59. var canvas = this.hasNode();
  60. if (canvas.getContext) {
  61. var ctx = canvas.getContext('2d');
  62. var b = this.getBounds();
  63. // clear canvas
  64. ctx.clearRect(0, 0, b.width, b.height);
  65. this.renderChildren(ctx);
  66. }
  67. }
  68. });