diff options
| author | bob <bcz@cs.brown.edu> | 2019-02-06 16:11:42 -0500 |
|---|---|---|
| committer | bob <bcz@cs.brown.edu> | 2019-02-06 16:11:42 -0500 |
| commit | 59d5992f2a101eff7743328c3fdefe6a0006ada9 (patch) | |
| tree | b28dbb2e06f1fffeafcd2b43845072f9f3f6f1fc /src/views/collections/CollectionFreeFormView.tsx | |
| parent | 7598b88bbad9690c59f8b164144aa0d02a0a211f (diff) | |
| parent | 84eea14a86265ce0585342d9f3a3c4107c02df17 (diff) | |
woring db stub.
Diffstat (limited to 'src/views/collections/CollectionFreeFormView.tsx')
| -rw-r--r-- | src/views/collections/CollectionFreeFormView.tsx | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/src/views/collections/CollectionFreeFormView.tsx b/src/views/collections/CollectionFreeFormView.tsx index d48d096ce..45d37ca4f 100644 --- a/src/views/collections/CollectionFreeFormView.tsx +++ b/src/views/collections/CollectionFreeFormView.tsx @@ -13,7 +13,7 @@ import "./CollectionFreeFormView.scss"; import { Utils } from "../../Utils"; import { CollectionViewBase, CollectionViewProps, COLLECTION_BORDER_WIDTH } from "./CollectionViewBase"; import { SelectionManager } from "../../util/SelectionManager"; -import { WAITING } from "../../fields/Field"; +import { FieldWaiting } from "../../fields/Field"; @observer export class CollectionFreeFormView extends CollectionViewBase { @@ -33,15 +33,15 @@ export class CollectionFreeFormView extends CollectionViewBase { const doc = de.data["document"]; var me = this; if (doc instanceof CollectionFreeFormDocumentView) { - if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this && doc.props.ContainingCollectionView != WAITING) { + if (doc.props.ContainingCollectionView && doc.props.ContainingCollectionView !== this && doc.props.ContainingCollectionView != FieldWaiting) { 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 { scale, translateX, translateY } = Utils.GetScreenTransform(this._canvasRef.current!); - if (this.props.ContainingDocumentView != WAITING) { - let sscale = this.props.ContainingDocumentView!.props.Document.GetFieldValue(KeyStore.Scale, NumberField, Number(1)) + if (this.props.ContainingDocumentView != FieldWaiting) { + let sscale = this.props.ContainingDocumentView!.props.Document.GetData(KeyStore.Scale, NumberField, Number(1)) const screenX = de.x - xOffset; const screenY = de.y - yOffset; const docX = (screenX - translateX) / sscale / scale; @@ -64,12 +64,8 @@ export class CollectionFreeFormView extends CollectionViewBase { } } - downactive: boolean = false; @action onPointerDown = (e: React.PointerEvent): void => { - var me = this; - me.downactive = this.active; - var title = this.props.DocumentForCollection.Title; if ((e.button === 2 && this.active) || !e.defaultPrevented) { document.removeEventListener("pointermove", this.onPointerMove); @@ -92,16 +88,14 @@ export class CollectionFreeFormView extends CollectionViewBase { @action onPointerMove = (e: PointerEvent): void => { var me = this; - var act = me.active; - var title = me.props.DocumentForCollection.Title; - if (!e.cancelBubble && this.active && this.props.ContainingDocumentView != WAITING) { + if (!e.cancelBubble && this.active && this.props.ContainingDocumentView != FieldWaiting) { e.preventDefault(); e.stopPropagation(); let currScale: number = this.props.ContainingDocumentView!.ScalingToScreenSpace; - let x = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanX, NumberField, Number(0)); - let y = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanY, NumberField, Number(0)); - this.props.DocumentForCollection.SetFieldValue(KeyStore.PanX, x + (e.pageX - this._lastX) / currScale, NumberField); - this.props.DocumentForCollection.SetFieldValue(KeyStore.PanY, y + (e.pageY - this._lastY) / currScale, NumberField); + let x = this.props.DocumentForCollection.GetData(KeyStore.PanX, NumberField, Number(0)); + let y = this.props.DocumentForCollection.GetData(KeyStore.PanY, NumberField, Number(0)); + this.props.DocumentForCollection.SetData(KeyStore.PanX, x + (e.pageX - this._lastX) / currScale, NumberField); + this.props.DocumentForCollection.SetData(KeyStore.PanY, y + (e.pageY - this._lastY) / currScale, NumberField); } this._lastX = e.pageX; this._lastY = e.pageY; @@ -111,7 +105,7 @@ export class CollectionFreeFormView extends CollectionViewBase { onPointerWheel = (e: React.WheelEvent): void => { e.stopPropagation(); - if (this.props.ContainingDocumentView == WAITING) + if (this.props.ContainingDocumentView == FieldWaiting) return; let { LocalX, Ss, Panxx, Xx, LocalY, Panyy, Yy, ContainerX, ContainerY } = this.props.ContainingDocumentView!.TransformToLocalPoint(e.pageX, e.pageY); @@ -123,9 +117,9 @@ export class CollectionFreeFormView extends CollectionViewBase { let dx = ContainerX - newContainerX; let dy = ContainerY - newContainerY; - this.props.DocumentForCollection.SetField(KeyStore.Scale, new NumberField(deltaScale)); - this.props.DocumentForCollection.SetFieldValue(KeyStore.PanX, Panxx + dx, NumberField); - this.props.DocumentForCollection.SetFieldValue(KeyStore.PanY, Panyy + dy, NumberField); + this.props.DocumentForCollection.Set(KeyStore.Scale, new NumberField(deltaScale)); + this.props.DocumentForCollection.SetData(KeyStore.PanX, Panxx + dx, NumberField); + this.props.DocumentForCollection.SetData(KeyStore.PanY, Panyy + dy, NumberField); } @action @@ -135,8 +129,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.GetFieldValue(KeyStore.PanX, NumberField, Number(0)); - const pany: number = this.props.DocumentForCollection.GetFieldValue(KeyStore.PanY, NumberField, Number(0)); + const panx: number = this.props.DocumentForCollection.GetData(KeyStore.PanX, NumberField, Number(0)); + const pany: number = this.props.DocumentForCollection.GetData(KeyStore.PanY, NumberField, Number(0)); let x = e.pageX - panx let y = e.pageY - pany @@ -146,11 +140,11 @@ export class CollectionFreeFormView extends CollectionViewBase { let doc = Documents.ImageDocument(url, { x: x, y: y }) - let docs = that.props.DocumentForCollection.GetFieldT(KeyStore.Data, ListField); - if (docs != WAITING) { + let docs = that.props.DocumentForCollection.GetT(KeyStore.Data, ListField); + if (docs != FieldWaiting) { if (!docs) { docs = new ListField<Document>(); - that.props.DocumentForCollection.SetField(KeyStore.Data, docs) + that.props.DocumentForCollection.Set(KeyStore.Data, docs) } docs.Data.push(doc); } @@ -169,27 +163,26 @@ export class CollectionFreeFormView extends CollectionViewBase { bringToFront(doc: CollectionFreeFormDocumentView) { const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props; - const value: Document[] = Document.GetListField<Document>(fieldKey, []); - var topmost = value.reduce((topmost, d) => Math.max(d.GetNumberField(KeyStore.ZIndex, 0), topmost), -1000); + const value: Document[] = Document.GetList<Document>(fieldKey, []); + var topmost = value.reduce((topmost, d) => Math.max(d.GetNumber(KeyStore.ZIndex, 0), topmost), -1000); value.map(d => { - var zind = d.GetNumberField(KeyStore.ZIndex, 0); + var zind = d.GetNumber(KeyStore.ZIndex, 0); if (zind != topmost - 1 - (topmost - zind) && d != doc.props.Document) { - d.SetFieldValue(KeyStore.ZIndex, topmost - 1 - (topmost - zind), NumberField); + d.SetData(KeyStore.ZIndex, topmost - 1 - (topmost - zind), NumberField); } }) - if (doc.props.Document.GetNumberField(KeyStore.ZIndex, 0) != 0) { - doc.props.Document.SetFieldValue(KeyStore.ZIndex, 0, NumberField); + if (doc.props.Document.GetNumber(KeyStore.ZIndex, 0) != 0) { + doc.props.Document.SetData(KeyStore.ZIndex, 0, NumberField); } } render() { const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props; - const value: Document[] = Document.GetListField<Document>(fieldKey, []); - const panx: number = Document.GetNumberField(KeyStore.PanX, 0); - const pany: number = Document.GetNumberField(KeyStore.PanY, 0); - const currScale: number = Document.GetNumberField(KeyStore.Scale, 1); - const data = Document.GetField(KeyStore.Data); + const value: Document[] = Document.GetList<Document>(fieldKey, []); + const panx: number = Document.GetNumber(KeyStore.PanX, 0); + const pany: number = Document.GetNumber(KeyStore.PanY, 0); + const currScale: number = Document.GetNumber(KeyStore.Scale, 1); return ( <div className="border" style={{ |
