CVCompElement.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. extendPrototype,
  3. } from '../../utils/functionExtensions';
  4. import {
  5. createSizedArray,
  6. } from '../../utils/helpers/arrays';
  7. import PropertyFactory from '../../utils/PropertyFactory';
  8. import CanvasRendererBase from '../../renderers/CanvasRendererBase';
  9. import CVBaseElement from './CVBaseElement';
  10. import ICompElement from '../CompElement';
  11. function CVCompElement(data, globalData, comp) {
  12. this.completeLayers = false;
  13. this.layers = data.layers;
  14. this.pendingElements = [];
  15. this.elements = createSizedArray(this.layers.length);
  16. this.initElement(data, globalData, comp);
  17. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  18. }
  19. extendPrototype([CanvasRendererBase, ICompElement, CVBaseElement], CVCompElement);
  20. CVCompElement.prototype.renderInnerContent = function () {
  21. var ctx = this.canvasContext;
  22. ctx.beginPath();
  23. ctx.moveTo(0, 0);
  24. ctx.lineTo(this.data.w, 0);
  25. ctx.lineTo(this.data.w, this.data.h);
  26. ctx.lineTo(0, this.data.h);
  27. ctx.lineTo(0, 0);
  28. ctx.clip();
  29. var i;
  30. var len = this.layers.length;
  31. for (i = len - 1; i >= 0; i -= 1) {
  32. if (this.completeLayers || this.elements[i]) {
  33. this.elements[i].renderFrame();
  34. }
  35. }
  36. };
  37. CVCompElement.prototype.destroy = function () {
  38. var i;
  39. var len = this.layers.length;
  40. for (i = len - 1; i >= 0; i -= 1) {
  41. if (this.elements[i]) {
  42. this.elements[i].destroy();
  43. }
  44. }
  45. this.layers = null;
  46. this.elements = null;
  47. };
  48. CVCompElement.prototype.createComp = function (data) {
  49. return new CVCompElement(data, this.globalData, this);
  50. };
  51. export default CVCompElement;