From 2e6c1f2c1710548ebf86476e1476c22889f11819 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 5 Nov 2021 18:27:07 -0400 Subject: ink document iteration not working --- src/client/views/InkingStroke.tsx | 2 +- .../collectionFreeForm/CollectionFreeFormView.tsx | 52 +++++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/views/InkingStroke.tsx b/src/client/views/InkingStroke.tsx index 81a888256..ecb46a5b3 100644 --- a/src/client/views/InkingStroke.tsx +++ b/src/client/views/InkingStroke.tsx @@ -130,7 +130,7 @@ export class InkingStroke extends ViewBoxBaseComponent { diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index f0064d15e..0941db5f8 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -114,6 +114,7 @@ export class CollectionFreeFormView extends CollectionSubView(); @observable _marqueeRef = React.createRef(); @observable _keyframeEditing = false; @@ -453,11 +454,7 @@ export class CollectionFreeFormView extends CollectionSubView { if (!InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE)) { - this._prevPoint = this._currPoint = { X: -1, Y: -1 }; document.removeEventListener("pointermove", this.onPointerMove); document.removeEventListener("pointerup", this.onPointerUp); this.removeMoveListeners(); this.removeEndListeners(); + if (CurrentUserUtils.SelectedTool !== InkTool.None) { + this._deleteList.forEach(ink => { + ink.props.removeDocument?.(ink.props.Document); + }); + this._prevPoint = this._currPoint = { X: -1, Y: -1 }; + this._deleteList = []; + } } } @@ -636,9 +639,15 @@ export class CollectionFreeFormView extends CollectionSubView { if (this.props.Document._isGroup) return; // groups don't pan when dragged -- instead let the event go through to allow the group itself to drag if (InteractionUtils.IsType(e, InteractionUtils.PENTYPE)) return; - if (InteractionUtils.IsType(e, InteractionUtils.ERASERTYPE)) { - this._prevPoint = this._currPoint; - this._currPoint = { X: e.clientX, Y: e.clientY } + if (CurrentUserUtils.SelectedTool !== InkTool.None) { + this._currPoint = { X: e.clientX, Y: e.clientY }; + const intersectStroke = this.getInkIntersection(); + if (intersectStroke) { + if (!this._deleteList.includes(intersectStroke)) { + this._deleteList.push(intersectStroke); + // lower intersectStroke opacity to give user a visual indicator + } + } } if (InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE)) { if (this.props.isContentActive(true)) e.stopPropagation(); @@ -655,15 +664,24 @@ export class CollectionFreeFormView extends CollectionSubView { - // this.children.filter((doc: Doc) => doc.type === DocumentType.INK) - // .forEach((doc: Doc) => { - // const inkView = DocumentManager.Instance.getDocumentView(doc, this.props.CollectionView); - // const ctrlPoints = inkView?.ComponentView?.inkScaledData().inkData.slice(); - // const array = [ctrlPoints[i], ctrlPoints[i + 1], ctrlPoints[i + 2], ctrlPoints[i + 3]]; - // const intersects = new Bezier(array.map(p => ({ x: p.X, y: p.Y }))).intersects({p1: {x: this._prevPoint.X, y: this._prevPoint.Y}, p2: {x: this._currPoint.X, y: this._currPoint.Y}}); - // if (intersects) return inkView; - // }); + this.props.childDocuments?.filter(doc => doc.type === DocumentType.INK) + .forEach(doc => { + console.log("in for each"); + const inkView = DocumentManager.Instance.getDocumentView(doc, this.props.CollectionView); + const ctrlPoints = Cast(inkView?.dataDoc[this.props.fieldKey], InkField)?.inkData ?? []; + for (var i = 0; i < ctrlPoints.length - 3; i += 4) { + const array = [ctrlPoints[i], ctrlPoints[i + 1], ctrlPoints[i + 2], ctrlPoints[i + 3]]; + const intersects = new Bezier(array.map(p => ({ x: p.X, y: p.Y }))).intersects( + { p1: { x: this._prevPoint.X, y: this._prevPoint.Y }, + p2: { x: this._currPoint.X, y: this._currPoint.Y } }); + if (intersects) return inkView; + } + }); return null; } -- cgit v1.2.3-70-g09d2