IncrementalDisplayable.js 4.4 KB

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