IncrementalDisplayable.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { __extends } from "tslib";
  2. import Displayble from './Displayable.js';
  3. import BoundingRect from '../core/BoundingRect.js';
  4. var m = [];
  5. var IncrementalDisplayable = (function (_super) {
  6. __extends(IncrementalDisplayable, _super);
  7. function IncrementalDisplayable() {
  8. var _this = _super !== null && _super.apply(this, arguments) || this;
  9. _this.notClear = true;
  10. _this.incremental = true;
  11. _this._displayables = [];
  12. _this._temporaryDisplayables = [];
  13. _this._cursor = 0;
  14. return _this;
  15. }
  16. IncrementalDisplayable.prototype.traverse = function (cb, context) {
  17. cb.call(context, this);
  18. };
  19. IncrementalDisplayable.prototype.useStyle = function () {
  20. this.style = {};
  21. };
  22. IncrementalDisplayable.prototype.getCursor = function () {
  23. return this._cursor;
  24. };
  25. IncrementalDisplayable.prototype.innerAfterBrush = function () {
  26. this._cursor = this._displayables.length;
  27. };
  28. IncrementalDisplayable.prototype.clearDisplaybles = function () {
  29. this._displayables = [];
  30. this._temporaryDisplayables = [];
  31. this._cursor = 0;
  32. this.markRedraw();
  33. this.notClear = false;
  34. };
  35. IncrementalDisplayable.prototype.clearTemporalDisplayables = function () {
  36. this._temporaryDisplayables = [];
  37. };
  38. IncrementalDisplayable.prototype.addDisplayable = function (displayable, notPersistent) {
  39. if (notPersistent) {
  40. this._temporaryDisplayables.push(displayable);
  41. }
  42. else {
  43. this._displayables.push(displayable);
  44. }
  45. this.markRedraw();
  46. };
  47. IncrementalDisplayable.prototype.addDisplayables = function (displayables, notPersistent) {
  48. notPersistent = notPersistent || false;
  49. for (var i = 0; i < displayables.length; i++) {
  50. this.addDisplayable(displayables[i], notPersistent);
  51. }
  52. };
  53. IncrementalDisplayable.prototype.getDisplayables = function () {
  54. return this._displayables;
  55. };
  56. IncrementalDisplayable.prototype.getTemporalDisplayables = function () {
  57. return this._temporaryDisplayables;
  58. };
  59. IncrementalDisplayable.prototype.eachPendingDisplayable = function (cb) {
  60. for (var i = this._cursor; i < this._displayables.length; i++) {
  61. cb && cb(this._displayables[i]);
  62. }
  63. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  64. cb && cb(this._temporaryDisplayables[i]);
  65. }
  66. };
  67. IncrementalDisplayable.prototype.update = function () {
  68. this.updateTransform();
  69. for (var i = this._cursor; i < this._displayables.length; i++) {
  70. var displayable = this._displayables[i];
  71. displayable.parent = this;
  72. displayable.update();
  73. displayable.parent = null;
  74. }
  75. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  76. var displayable = this._temporaryDisplayables[i];
  77. displayable.parent = this;
  78. displayable.update();
  79. displayable.parent = null;
  80. }
  81. };
  82. IncrementalDisplayable.prototype.getBoundingRect = function () {
  83. if (!this._rect) {
  84. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  85. for (var i = 0; i < this._displayables.length; i++) {
  86. var displayable = this._displayables[i];
  87. var childRect = displayable.getBoundingRect().clone();
  88. if (displayable.needLocalTransform()) {
  89. childRect.applyTransform(displayable.getLocalTransform(m));
  90. }
  91. rect.union(childRect);
  92. }
  93. this._rect = rect;
  94. }
  95. return this._rect;
  96. };
  97. IncrementalDisplayable.prototype.contain = function (x, y) {
  98. var localPos = this.transformCoordToLocal(x, y);
  99. var rect = this.getBoundingRect();
  100. if (rect.contain(localPos[0], localPos[1])) {
  101. for (var i = 0; i < this._displayables.length; i++) {
  102. var displayable = this._displayables[i];
  103. if (displayable.contain(x, y)) {
  104. return true;
  105. }
  106. }
  107. }
  108. return false;
  109. };
  110. return IncrementalDisplayable;
  111. }(Displayble));
  112. export default IncrementalDisplayable;