aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-02-13 04:50:56 -0500
committerTyler Schicke <tyler_schicke@brown.edu>2019-02-13 04:50:56 -0500
commitc93c3e1970c6ecc91b60f1782e82b1bfdc7fef30 (patch)
tree47c30b57d3ec6ac3d1f535e8186c0cf527640010 /src/client/views/collections
parent46a4c26dbadefaf981637f79fb5f76e458baac9d (diff)
A lot of stuff working, a lot of other stuff not working
Diffstat (limited to 'src/client/views/collections')
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx10
-rw-r--r--src/client/views/collections/CollectionFreeFormView.tsx55
-rw-r--r--src/client/views/collections/CollectionSchemaView.tsx4
-rw-r--r--src/client/views/collections/CollectionViewBase.tsx10
4 files changed, 44 insertions, 35 deletions
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index d3e90d11c..c870a9cf0 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -16,6 +16,7 @@ import "./CollectionDockingView.scss";
import { CollectionViewBase, CollectionViewProps, COLLECTION_BORDER_WIDTH } from "./CollectionViewBase";
import React = require("react");
import { changeDependenciesStateTo0 } from "mobx/lib/internal";
+import { Utils } from "../../../Utils";
@observer
export class CollectionDockingView extends CollectionViewBase {
@@ -100,6 +101,7 @@ export class CollectionDockingView extends CollectionViewBase {
return (<DocumentView key={value[i].Id} Document={value[i]}
AddDocument={this.addDocument} RemoveDocument={this.removeDocument}
GetTransform={() => Transform.Identity}
+ isTopMost={true}
Scaling={1}
ContainingCollectionView={this} DocumentView={undefined} />);
}
@@ -307,12 +309,16 @@ class RenderClass {
this.render();
}
render() {
- var nativeWidth = this._document.GetNumber(KeyStore.NativeWidth, 0);
+ let nativeWidth = this._document.GetNumber(KeyStore.NativeWidth, 0);
let scaling = nativeWidth > 0 ? this._htmlElement!.clientWidth / nativeWidth : 1;
ReactDOM.render((
<DocumentView key={this._document.Id} Document={this._document}
AddDocument={this._collectionDockingView.addDocument} RemoveDocument={this._collectionDockingView.removeDocument}
- GetTransform={() => Transform.Identity}
+ GetTransform={() => {
+ let { scale, translateX, translateY } = Utils.GetScreenTransform(this._htmlElement);
+ return this._collectionDockingView.props.GetTransform().scale(scale).translate(-translateX, -translateY)
+ }}
+ isTopMost={true}
Scaling={scaling}
ContainingCollectionView={this._collectionDockingView} DocumentView={undefined} />
),
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index 975eaaae8..7947b1c51 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -14,6 +14,7 @@ import { NumberField } from "../../../fields/NumberField";
import { Documents } from "../../documents/Documents";
import { FieldWaiting } from "../../../fields/Field";
import { Transform } from "../../util/Transform";
+import { DocumentView } from "../nodes/DocumentView";
@observer
export class CollectionFreeFormView extends CollectionViewBase {
@@ -45,23 +46,21 @@ export class CollectionFreeFormView extends CollectionViewBase {
@action
drop = (e: Event, de: DragManager.DropEvent) => {
- const doc = de.data["document"];
+ const doc: DocumentView = de.data["document"];
var me = this;
- if (doc instanceof CollectionFreeFormDocumentView) {
- if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this) {
- doc.props.ContainingCollectionView.removeDocument(doc.props.Document);
- this.addDocument(doc.props.Document);
- }
- const xOffset = de.data["xOffset"] as number || 0;
- const yOffset = de.data["yOffset"] as number || 0;
- const { translateX, translateY } = Utils.GetScreenTransform(this._canvasRef.current!);
- const currScale = this.resizeScaling * this.zoomScaling * this.props.ContainingDocumentView!.ScalingToScreenSpace;
- const screenX = de.x - xOffset;
- const screenY = de.y - yOffset;
- doc.x = (screenX - translateX) / currScale;
- doc.y = (screenY - translateY) / currScale;
- this.bringToFront(doc);
+ if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this) {
+ doc.props.ContainingCollectionView.removeDocument(doc.props.Document);
+ this.addDocument(doc.props.Document);
}
+ const xOffset = de.data["xOffset"] as number || 0;
+ const yOffset = de.data["yOffset"] as number || 0;
+ const transform = doc.props.GetTransform();
+ const screenX = de.x - xOffset;
+ const screenY = de.y - yOffset;
+ const [x, y] = transform.transformPoint(screenX, screenY);
+ doc.props.Document.SetNumber(KeyStore.X, x);
+ doc.props.Document.SetNumber(KeyStore.Y, y);
+ this.bringToFront(doc);
e.stopPropagation();
}
@@ -94,8 +93,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
document.removeEventListener("pointerup", this.onPointerUp);
e.stopPropagation();
if (Math.abs(this._downX - e.clientX) < 3 && Math.abs(this._downY - e.clientY) < 3) {
- if (!SelectionManager.IsSelected(this.props.ContainingDocumentView as CollectionFreeFormDocumentView)) {
- SelectionManager.SelectDoc(this.props.ContainingDocumentView as CollectionFreeFormDocumentView, false);
+ if (!this.props.isSelected()) {
+ this.props.select(false);
}
}
}
@@ -105,11 +104,11 @@ export class CollectionFreeFormView extends CollectionViewBase {
if (!e.cancelBubble && this.active) {
e.preventDefault();
e.stopPropagation();
- let currScale: number = this.props.ContainingDocumentView!.ScalingToScreenSpace;
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);
- this.SetPan(x + (e.pageX - this._lastX) / currScale, y + (e.pageY - this._lastY) / currScale);
+ this.SetPan(x + dx, y + dy);
}
this._lastX = e.pageX;
this._lastY = e.pageY;
@@ -124,15 +123,14 @@ export class CollectionFreeFormView extends CollectionViewBase {
// if (modes[e.deltaMode] == 'pixels') coefficient = 50;
// else if (modes[e.deltaMode] == 'lines') coefficient = 1000; // This should correspond to line-height??
let transform = this.getTransform();
- let localTransform = this.getLocalTransform();
- let deltaScale = (1 - (e.deltaY / coefficient)) * transform.Scale;
- let newDeltaScale = this.isAnnotationOverlay ? Math.max(1, deltaScale) : deltaScale;
+ let deltaScale = (1 - (e.deltaY / coefficient));
let [x, y] = transform.transformPoint(e.clientX, e.clientY);
- localTransform.scaleAbout(newDeltaScale, x, y);
+ let localTransform = this.getLocalTransform();
+ localTransform.scaleAbout(deltaScale, x, y);
- this.props.DocumentForCollection.SetNumber(KeyStore.Scale, newDeltaScale);
+ this.props.DocumentForCollection.SetNumber(KeyStore.Scale, localTransform.Scale);
this.SetPan(localTransform.TranslateX, localTransform.TranslateY);
}
@@ -182,7 +180,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
}
@action
- bringToFront(doc: CollectionFreeFormDocumentView) {
+ bringToFront(doc: DocumentView) {
const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
const value: Document[] = Document.GetList<Document>(fieldKey, []);
@@ -213,12 +211,12 @@ export class CollectionFreeFormView extends CollectionViewBase {
getTransform = (): Transform => {
const [x, y] = this.translate;
- return this.props.GetTransform().scaled(this.scale).translate(x, y);
+ return this.props.GetTransform().translate(-COLLECTION_BORDER_WIDTH, -COLLECTION_BORDER_WIDTH).transform(this.getLocalTransform().inverse())
}
getLocalTransform = (): Transform => {
const [x, y] = this.translate;
- return new Transform(x, y, this.scale);
+ return Transform.Identity.scale(this.scale).translate(x, y);
}
render() {
@@ -249,8 +247,9 @@ export class CollectionFreeFormView extends CollectionViewBase {
AddDocument={this.addDocument}
RemoveDocument={this.removeDocument}
GetTransform={this.getTransform}
+ isTopMost={false}
Scaling={1}
- ContainingCollectionView={this} DocumentView={undefined} />);
+ ContainingCollectionView={this} DocumentView={this.props.ContainingDocumentView} />);
})}
</div>
</div>
diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index f1e882e20..adae8560e 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -27,7 +27,8 @@ export class CollectionSchemaView extends CollectionViewBase {
let props: FieldViewProps = {
doc: rowProps.value[0],
fieldKey: rowProps.value[1],
- DocumentViewForField: undefined,
+ isSelected: () => false,
+ isTopMost: false
}
let contents = (
<FieldView {...props} />
@@ -110,6 +111,7 @@ export class CollectionSchemaView extends CollectionViewBase {
AddDocument={this.addDocument} RemoveDocument={this.removeDocument}
GetTransform={() => Transform.Identity}//TODO This should probably be an actual transform
Scaling={1}
+ isTopMost={false}
DocumentView={undefined} ContainingCollectionView={this} />
)
} else {
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index cf5bc70c4..2c950c8ae 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -18,6 +18,9 @@ export interface CollectionViewProps {
DocumentForCollection: Document;
ContainingDocumentView: Opt<DocumentView>;
GetTransform: () => Transform;
+ isSelected: () => boolean;
+ isTopMost: boolean;
+ select: (ctrlPressed: boolean) => void;
BackgroundView: Opt<DocumentView>;
Scaling: number;
}
@@ -29,16 +32,15 @@ export class CollectionViewBase extends React.Component<CollectionViewProps> {
public static LayoutString(collectionType: string, fieldKey: string = "DataKey") {
return `<${collectionType} Scaling={Scaling} DocumentForCollection={Document}
- GetTransform={GetTransform} CollectionFieldKey={${fieldKey}}
+ GetTransform={GetTransform} CollectionFieldKey={${fieldKey}} isSelected={isSelected} select={select}
+ isTopMost={isTopMost}
ContainingDocumentView={DocumentView} BackgroundView={BackgroundView} />`;
}
@computed
public get active(): boolean {
var isSelected = (this.props.ContainingDocumentView instanceof CollectionFreeFormDocumentView && SelectionManager.IsSelected(this.props.ContainingDocumentView));
var childSelected = SelectionManager.SelectedDocuments().some(view => view.props.ContainingCollectionView == this);
- var topMost = this.props.ContainingDocumentView != undefined && (
- this.props.ContainingDocumentView.props.ContainingCollectionView == undefined ||
- this.props.ContainingDocumentView.props.ContainingCollectionView instanceof CollectionDockingView);
+ var topMost = this.props.isTopMost;
return isSelected || childSelected || topMost;
}
@action