diff options
author | Monika Hedman <monika_hedman@brown.edu> | 2019-02-18 19:03:34 -0500 |
---|---|---|
committer | Monika Hedman <monika_hedman@brown.edu> | 2019-02-18 19:03:34 -0500 |
commit | eaeb373ed90d35ab1c29cd9c3e4a79f6c8fa30b0 (patch) | |
tree | 2adb423bf0f782fce6861d703114bc0140520766 /src/client/views/collections/CollectionFreeFormView.tsx | |
parent | 30986620c34c93e12509b2875e90cf5876838403 (diff) | |
parent | 842f571bfb4952d12804a8dbdc66aedbf2bf6b81 (diff) |
transforms update
Diffstat (limited to 'src/client/views/collections/CollectionFreeFormView.tsx')
-rw-r--r-- | src/client/views/collections/CollectionFreeFormView.tsx | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx index b81975d3d..26c8517b3 100644 --- a/src/client/views/collections/CollectionFreeFormView.tsx +++ b/src/client/views/collections/CollectionFreeFormView.tsx @@ -55,7 +55,8 @@ export class CollectionFreeFormView extends CollectionViewBase { } const xOffset = de.data["xOffset"] as number || 0; const yOffset = de.data["yOffset"] as number || 0; - const transform = doc.props.GetTransform(); + //this should be able to use translate and scale methods on an Identity transform, no? + const transform = me.getTransform(); const screenX = de.x - xOffset; const screenY = de.y - yOffset; const [x, y] = transform.transformPoint(screenX, screenY); @@ -107,7 +108,7 @@ export class CollectionFreeFormView extends CollectionViewBase { e.stopPropagation(); let x = this.props.DocumentForCollection.GetNumber(KeyStore.PanX, 0); let y = this.props.DocumentForCollection.GetNumber(KeyStore.PanY, 0); - let [dx, dy] = this.props.GetTransform().transformDirection(e.clientX - this._lastX, e.clientY - this._lastY); + let [dx, dy] = this.props.ScreenToLocalTransform().transformDirection(e.clientX - this._lastX, e.clientY - this._lastY); this.SetPan(x + dx, y + dy); } @@ -129,7 +130,7 @@ export class CollectionFreeFormView extends CollectionViewBase { let [x, y] = transform.transformPoint(e.clientX, e.clientY); let localTransform = this.getLocalTransform(); - localTransform.scaleAbout(deltaScale, x, y); + localTransform = localTransform.inverse().scaleAbout(deltaScale, x, y) this.props.DocumentForCollection.SetNumber(KeyStore.Scale, localTransform.Scale); this.SetPan(localTransform.TranslateX, localTransform.TranslateY); @@ -137,8 +138,8 @@ export class CollectionFreeFormView extends CollectionViewBase { @action private SetPan(panX: number, panY: number) { - const newPanX = Math.max(-(this.resizeScaling * this.zoomScaling - this.resizeScaling) * this.nativeWidth, Math.min(0, panX)); - const newPanY = Math.max(-(this.resizeScaling * this.zoomScaling - this.resizeScaling) * this.nativeHeight, Math.min(0, panY)); + const newPanX = Math.max((1 - this.zoomScaling) * this.nativeWidth, Math.min(0, panX)); + const newPanY = Math.max((1 - this.zoomScaling) * this.nativeHeight, Math.min(0, panY)); this.props.DocumentForCollection.SetNumber(KeyStore.PanX, this.isAnnotationOverlay ? newPanX : panX); this.props.DocumentForCollection.SetNumber(KeyStore.PanY, this.isAnnotationOverlay ? newPanY : panY); } @@ -150,8 +151,8 @@ export class CollectionFreeFormView extends CollectionViewBase { let fReader = new FileReader() let file = e.dataTransfer.items[0].getAsFile(); let that = this; - const panx: number = this.props.DocumentForCollection.GetData(KeyStore.PanX, NumberField, Number(0)); - const pany: number = this.props.DocumentForCollection.GetData(KeyStore.PanY, NumberField, Number(0)); + const panx: number = this.props.DocumentForCollection.GetNumber(KeyStore.PanX, 0); + const pany: number = this.props.DocumentForCollection.GetNumber(KeyStore.PanY, 0); let x = e.pageX - panx let y = e.pageY - pany @@ -211,13 +212,12 @@ export class CollectionFreeFormView extends CollectionViewBase { } getTransform = (): Transform => { - const [x, y] = this.translate; - return this.getLocalTransform().inverse().translate(-COLLECTION_BORDER_WIDTH, -COLLECTION_BORDER_WIDTH).transform(this.props.GetTransform()) + return this.props.ScreenToLocalTransform().translate(-COLLECTION_BORDER_WIDTH, -COLLECTION_BORDER_WIDTH).transform(this.getLocalTransform()) } getLocalTransform = (): Transform => { const [x, y] = this.translate; - return Transform.Identity.scale(this.scale).translate(x, y); + return Transform.Identity.translate(-x, -y).scale(1 / this.scale); } render() { @@ -242,12 +242,12 @@ export class CollectionFreeFormView extends CollectionViewBase { style={{ width: "100%", transformOrigin: "left top", transform: ` translate(${panx}px, ${pany}px) scale(${this.zoomScaling}, ${this.zoomScaling})` }} ref={this._canvasRef}> - {this.props.BackgroundView} + {this.props.BackgroundView ? this.props.BackgroundView() : null} {value.map(doc => { return (<CollectionFreeFormDocumentView key={doc.Id} Document={doc} AddDocument={this.addDocument} RemoveDocument={this.removeDocument} - GetTransform={this.getTransform} + ScreenToLocalTransform={this.getTransform} isTopMost={false} Scaling={1} ContainingCollectionView={this} DocumentView={this.props.ContainingDocumentView} />); |