5c760c60b43e378301ebb3eb5d300b368d0b12c592c82be61f3c1ace53d528f50806b1a46d8be72a9f8459162b159bb75bd40976c7e269dd8f3a4d169f8c76 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // CompoundPath to improve performance
  2. import Path from './Path';
  3. import PathProxy from '../core/PathProxy';
  4. export interface CompoundPathShape {
  5. paths: Path[]
  6. }
  7. export default class CompoundPath extends Path {
  8. type = 'compound'
  9. shape: CompoundPathShape
  10. private _updatePathDirty() {
  11. const paths = this.shape.paths;
  12. let dirtyPath = this.shapeChanged();
  13. for (let i = 0; i < paths.length; i++) {
  14. // Mark as dirty if any subpath is dirty
  15. dirtyPath = dirtyPath || paths[i].shapeChanged();
  16. }
  17. if (dirtyPath) {
  18. this.dirtyShape();
  19. }
  20. }
  21. beforeBrush() {
  22. this._updatePathDirty();
  23. const paths = this.shape.paths || [];
  24. const scale = this.getGlobalScale();
  25. // Update path scale
  26. for (let i = 0; i < paths.length; i++) {
  27. if (!paths[i].path) {
  28. paths[i].createPathProxy();
  29. }
  30. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  31. }
  32. }
  33. buildPath(ctx: PathProxy | CanvasRenderingContext2D, shape: CompoundPathShape) {
  34. const paths = shape.paths || [];
  35. for (let i = 0; i < paths.length; i++) {
  36. paths[i].buildPath(ctx, paths[i].shape, true);
  37. }
  38. }
  39. afterBrush() {
  40. const paths = this.shape.paths || [];
  41. for (let i = 0; i < paths.length; i++) {
  42. paths[i].pathUpdated();
  43. }
  44. }
  45. getBoundingRect() {
  46. this._updatePathDirty.call(this);
  47. return Path.prototype.getBoundingRect.call(this);
  48. }
  49. }