aboutsummaryrefslogtreecommitdiff
path: root/src/views/nodes/DocumentView.tsx
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-01-28 12:58:20 -0500
committerbob <bcz@cs.brown.edu>2019-01-28 12:58:20 -0500
commit5e1171dd68c227ad6e3a618dd77d0dcd97b2003c (patch)
tree511f2b211a7bdd29547e3e35e1b7e461744248d9 /src/views/nodes/DocumentView.tsx
parenta777df0f814019de6d1efb373b57b0c7049d2022 (diff)
got rid of force update for doc decs and adjusted point transforms to account for collection border width.
Diffstat (limited to 'src/views/nodes/DocumentView.tsx')
-rw-r--r--src/views/nodes/DocumentView.tsx29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/views/nodes/DocumentView.tsx b/src/views/nodes/DocumentView.tsx
index 8250d5405..1387f44b1 100644
--- a/src/views/nodes/DocumentView.tsx
+++ b/src/views/nodes/DocumentView.tsx
@@ -129,14 +129,15 @@ export class DocumentView extends React.Component<IProps> {
return SelectionManager.IsSelected(this) || this.props.ContainingCollectionView === undefined || this.props.ContainingCollectionView!.active;
}
+ hackToAccountForCollectionFreeFormBorderWidth: number = 2; // this is the border width of the collection
//
// Converts an input coordinate in application's screen space
// into a coordinate in the space of this document.
// NOTE: this is intended for use on DocumentViews that are CollectionFreeFormViews
//
public TransformToLocalPoint(screenX: number, screenY: number) {
- let ContainerX = screenX;
- let ContainerY = screenY;
+ let ContainerX = screenX - this.hackToAccountForCollectionFreeFormBorderWidth;
+ let ContainerY = screenY - this.hackToAccountForCollectionFreeFormBorderWidth;
// if this collection view is nested within another collection view, then
// first transform the screen point into the parent collection's coordinate space.
if (this.props.ContainingDocumentView != undefined) {
@@ -156,6 +157,30 @@ export class DocumentView extends React.Component<IProps> {
return {LocalX, Ss, W, Panxx, Xx, LocalY, Panyy, Yy, ContainerX, ContainerY};
}
+ //
+ // Converts the coordinate space of a document to a screen space coordinate.
+ //
+ public TransformToScreenPoint(localX: number, localY: number, Ss: number = 1, Panxx: number = 0, Panyy: number = 0): {ScreenX: number, ScreenY: number} {
+
+ let W = this.props.Document.GetFieldValue(KeyStore.Width, NumberField, Number(0));
+ let Xx = this.props.Document.GetFieldValue(KeyStore.X, NumberField, Number(0));
+ let Yy = this.props.Document.GetFieldValue(KeyStore.Y, NumberField, Number(0));
+
+ let parentX = (localX + (Xx + Panxx) / Ss - W / 2) * Ss + W / 2;
+ let parentY = (localY + (Yy + Panyy) / Ss) * Ss;
+
+ // if this collection view is nested within another collection view, then
+ // first transform the screen point into the parent collection's coordinate space.
+ if (this.props.ContainingDocumentView != undefined) {
+ let ss = this.props.ContainingDocumentView.props.Document.GetFieldValue(KeyStore.Scale, NumberField, Number(1));
+ let panxx = this.props.ContainingDocumentView.props.Document.GetFieldValue(KeyStore.PanX, NumberField, Number(0));
+ let panyy = this.props.ContainingDocumentView.props.Document.GetFieldValue(KeyStore.PanY, NumberField, Number(0));
+ let {ScreenX, ScreenY} = this.props.ContainingDocumentView.TransformToScreenPoint(parentX, parentY, ss, panxx, panyy);
+ return {ScreenX: ScreenX + this.hackToAccountForCollectionFreeFormBorderWidth, ScreenY: ScreenY + this.hackToAccountForCollectionFreeFormBorderWidth};
+ } else {
+ return {ScreenX: parentX, ScreenY: parentY};
+ }
+ }
onPointerDown = (e: React.PointerEvent): void => {
let me = this;