RenderableElement.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. function RenderableElement() {
  2. }
  3. RenderableElement.prototype = {
  4. initRenderable: function () {
  5. // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange
  6. this.isInRange = false;
  7. // layer's display state
  8. this.hidden = false;
  9. // If layer's transparency equals 0, it can be hidden
  10. this.isTransparent = false;
  11. // list of animated components
  12. this.renderableComponents = [];
  13. },
  14. addRenderableComponent: function (component) {
  15. if (this.renderableComponents.indexOf(component) === -1) {
  16. this.renderableComponents.push(component);
  17. }
  18. },
  19. removeRenderableComponent: function (component) {
  20. if (this.renderableComponents.indexOf(component) !== -1) {
  21. this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1);
  22. }
  23. },
  24. prepareRenderableFrame: function (num) {
  25. this.checkLayerLimits(num);
  26. },
  27. checkTransparency: function () {
  28. if (this.finalTransform.mProp.o.v <= 0) {
  29. if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) {
  30. this.isTransparent = true;
  31. this.hide();
  32. }
  33. } else if (this.isTransparent) {
  34. this.isTransparent = false;
  35. this.show();
  36. }
  37. },
  38. /**
  39. * @function
  40. * Initializes frame related properties.
  41. *
  42. * @param {number} num
  43. * current frame number in Layer's time
  44. *
  45. */
  46. checkLayerLimits: function (num) {
  47. if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) {
  48. if (this.isInRange !== true) {
  49. this.globalData._mdf = true;
  50. this._mdf = true;
  51. this.isInRange = true;
  52. this.show();
  53. }
  54. } else if (this.isInRange !== false) {
  55. this.globalData._mdf = true;
  56. this.isInRange = false;
  57. this.hide();
  58. }
  59. },
  60. renderRenderable: function () {
  61. var i;
  62. var len = this.renderableComponents.length;
  63. for (i = 0; i < len; i += 1) {
  64. this.renderableComponents[i].renderFrame(this._isFirstFrame);
  65. }
  66. /* this.maskManager.renderFrame(this.finalTransform.mat);
  67. this.renderableEffectsManager.renderFrame(this._isFirstFrame); */
  68. },
  69. sourceRectAtTime: function () {
  70. return {
  71. top: 0,
  72. left: 0,
  73. width: 100,
  74. height: 100,
  75. };
  76. },
  77. getLayerSize: function () {
  78. if (this.data.ty === 5) {
  79. return { w: this.data.textData.width, h: this.data.textData.height };
  80. }
  81. return { w: this.data.width, h: this.data.height };
  82. },
  83. };
  84. export default RenderableElement;