diff options
author | Stanley Yip <stanley_yip@brown.edu> | 2019-12-03 18:54:41 -0500 |
---|---|---|
committer | Stanley Yip <stanley_yip@brown.edu> | 2019-12-03 18:54:41 -0500 |
commit | fb9f08295c10c35c11b647d00a3c830867dc3f7d (patch) | |
tree | 76126c5d894fc54a17bcfa901cb23bd93e473d61 | |
parent | cb2edb837ffa9df5ad966d44ac0c26622d6579f0 (diff) |
nothing new, infrastructure stuffs
-rw-r--r-- | src/Utils.ts | 4 | ||||
-rw-r--r-- | src/client/documents/Documents.ts | 2 | ||||
-rw-r--r-- | src/client/views/InkingStroke.tsx | 8 | ||||
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 22 | ||||
-rw-r--r-- | src/new_fields/InkField.ts | 6 | ||||
-rw-r--r-- | src/pen-gestures/GestureUtils.ts | 35 | ||||
-rw-r--r-- | src/pen-gestures/ndollar.ts (renamed from src/ndollar.ts) | 10 |
7 files changed, 59 insertions, 28 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index dc62d96e0..3db15f997 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -3,12 +3,8 @@ import v5 = require("uuid/v5"); import { Socket } from 'socket.io'; import { Message } from './server/Message'; import { RouteStore } from './server/RouteStore'; -import { NDollarRecognizer } from './ndollar'; export namespace Utils { - - export const GestureRecognizer = new NDollarRecognizer(false); - export const DRAG_THRESHOLD = 4; export function GenerateGuid(): string { diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index c5bf109a1..8c6aa2006 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -422,7 +422,7 @@ export namespace Docs { return InstanceFromProto(Prototypes.get(DocumentType.TEXT), "", options); } - export function InkDocument(color: string, tool: number, strokeWidth: number, points: { x: number, y: number }[], options: DocumentOptions = {}) { + export function InkDocument(color: string, tool: number, strokeWidth: number, points: { X: number, Y: number }[], options: DocumentOptions = {}) { let doc = InstanceFromProto(Prototypes.get(DocumentType.INK), new InkField(points), options); doc.color = color; doc.strokeWidth = strokeWidth; diff --git a/src/client/views/InkingStroke.tsx b/src/client/views/InkingStroke.tsx index a27f106e3..a2e9f0e55 100644 --- a/src/client/views/InkingStroke.tsx +++ b/src/client/views/InkingStroke.tsx @@ -13,8 +13,8 @@ import React = require("react"); type InkDocument = makeInterface<[typeof documentSchema]>; const InkDocument = makeInterface(documentSchema); -export function CreatePolyline(points: { x: number, y: number }[], left: number, top: number, color?: string, width?: number) { - let pts = points.reduce((acc: string, pt: { x: number, y: number }) => acc + `${pt.x - left},${pt.y - top} `, ""); +export function CreatePolyline(points: { X: number, Y: number }[], left: number, top: number, color?: string, width?: number) { + let pts = points.reduce((acc: string, pt: { X: number, Y: number }) => acc + `${pt.X - left},${pt.Y - top} `, ""); return ( <polyline points={pts} @@ -36,8 +36,8 @@ export class InkingStroke extends DocExtendableComponent<FieldViewProps, InkDocu render() { let data: InkData = Cast(this.Document.data, InkField)?.inkData ?? []; - let xs = data.map(p => p.x); - let ys = data.map(p => p.y); + let xs = data.map(p => p.X); + let ys = data.map(p => p.Y); let left = Math.min(...xs); let top = Math.min(...ys); let right = Math.max(...xs); diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index dcda13b00..6dd472c84 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -41,6 +41,7 @@ import { MarqueeView } from "./MarqueeView"; import React = require("react"); import { computedFn, keepAlive } from "mobx-utils"; import { TraceMobx } from "../../../../new_fields/util"; +import { GestureUtils } from "../../../../pen-gestures/GestureUtils"; library.add(faEye as any, faTable, faPaintBrush, faExpandArrowsAlt, faCompressArrowsAlt, faCompass, faUpload, faBraille, faChalkboard, faFileUpload); @@ -272,7 +273,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { return clusterColor; } - @observable private _points: { x: number, y: number }[] = []; + @observable private _points: { X: number, Y: number }[] = []; @action onPointerDown = (e: React.PointerEvent): void => { @@ -288,7 +289,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { e.stopPropagation(); e.preventDefault(); let point = this.getTransform().transformPoint(e.pageX, e.pageY); - this._points.push({ x: point[0], y: point[1] }); + this._points.push({ X: point[0], Y: point[1] }); } // if not using a pen and in no ink mode else if (InkingControl.Instance.selectedTool === InkTool.None) { @@ -336,11 +337,12 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { if (this._points.length > 1) { let B = this.svgBounds; - let points = this._points.map(p => ({ x: p.x - B.left, y: p.y - B.top })); + let points = this._points.map(p => ({ X: p.X - B.left, Y: p.Y - B.top })); - let result = Utils.GestureRecognizer.Recognize(new Array(points)); + let result = GestureUtils.GestureRecognizer.Recognize(new Array(points)); if (result) { console.log(result.Name); + this._points = []; } else { let inkDoc = Docs.Create.InkDocument(InkingControl.Instance.selectedColor, InkingControl.Instance.selectedTool, parseInt(InkingControl.Instance.selectedWidth), points, { width: B.width, height: B.height, x: B.left, y: B.top }); @@ -405,7 +407,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { const selectedTool = InkingControl.Instance.selectedTool; if (selectedTool === InkTool.Highlighter || selectedTool === InkTool.Pen || InteractionUtils.IsType(e, InteractionUtils.PENTYPE)) { let point = this.getTransform().transformPoint(e.clientX, e.clientY); - this._points.push({ x: point[0], y: point[1] }); + this._points.push({ X: point[0], Y: point[1] }); } else if (selectedTool === InkTool.None) { if (this._hitCluster && this.tryDragCluster(e)) { @@ -440,7 +442,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } else if (InkingControl.Instance.selectedTool !== InkTool.Eraser && InkingControl.Instance.selectedTool !== InkTool.Scrubber) { let point = this.getTransform().transformPoint(pt.clientX, pt.clientY); - this._points.push({ x: point[0], y: point[1] }); + this._points.push({ X: point[0], Y: point[1] }); } } e.stopPropagation(); @@ -846,8 +848,8 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } @computed get svgBounds() { - let xs = this._points.map(p => p.x); - let ys = this._points.map(p => p.y); + let xs = this._points.map(p => p.X); + let ys = this._points.map(p => p.Y); let right = Math.max(...xs); let left = Math.min(...xs); let bottom = Math.max(...ys); @@ -863,7 +865,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { let B = this.svgBounds; return ( - <svg width={B.width} height={B.height} style={{ transform: `translate(${B.left}px, ${B.top}px)` }}> + <svg width={B.width} height={B.height} style={{ transform: `translate(${B.left}px, ${B.top}px)`, position: "relative", zIndex: 30000 }}> {CreatePolyline(this._points, B.left, B.top)} </svg> ); @@ -932,7 +934,7 @@ class CollectionFreeFormViewPannableContents extends React.Component<CollectionF const pany = -this.props.panY(); const zoom = this.props.zoomScaling(); return <div className={freeformclass} style={{ touchAction: "none", borderRadius: "inherit", transform: `translate(${cenx}px, ${ceny}px) scale(${zoom}) translate(${panx}px, ${pany}px)` }}> - {this.props.children} + {this.props.children()} </div>; } }
\ No newline at end of file diff --git a/src/new_fields/InkField.ts b/src/new_fields/InkField.ts index 2d8bb582a..83d631958 100644 --- a/src/new_fields/InkField.ts +++ b/src/new_fields/InkField.ts @@ -13,14 +13,14 @@ export enum InkTool { } export interface PointData { - x: number; - y: number; + X: number; + Y: number; } export type InkData = Array<PointData>; const pointSchema = createSimpleSchema({ - x: true, y: true + X: true, Y: true }); const strokeDataSchema = createSimpleSchema({ diff --git a/src/pen-gestures/GestureUtils.ts b/src/pen-gestures/GestureUtils.ts new file mode 100644 index 000000000..caaa0736d --- /dev/null +++ b/src/pen-gestures/GestureUtils.ts @@ -0,0 +1,35 @@ +import { NDollarRecognizer } from "./ndollar"; +import { Type } from "typescript"; +import { InkField } from "../new_fields/InkField"; +import { Docs } from "../client/documents/Documents"; +import { Doc } from "../new_fields/Doc"; + +export namespace GestureUtils { + namespace GestureDataTypes { + export type BoxData = Doc[]; + } + + export const GestureRecognizer = new NDollarRecognizer(false); + + export enum Gestures { + Box = "box" + } + + export function GestureOptions(name: Gestures, gestureData: any): (() => any)[] { + switch (name) { + case Gestures.Box: + if (gestureData as GestureDataTypes.BoxData) { + return BoxOptions(gestureData as GestureDataTypes.BoxData); + } + break; + } + throw new Error("This means that you're trying to do something with the gesture that hasn't been defined yet. Define it in GestureUtils.ts"); + } + + function BoxOptions(gestureData: GestureDataTypes.BoxData): (() => any)[] { + if (gestureData instanceof Doc[]) { + return [() => Docs.Create.FreeformDocument(gestureData as Doc[], {})]; + } + return []; + } +}
\ No newline at end of file diff --git a/src/ndollar.ts b/src/pen-gestures/ndollar.ts index 6d7b8c5d9..5d4384202 100644 --- a/src/ndollar.ts +++ b/src/pen-gestures/ndollar.ts @@ -1,3 +1,5 @@ +import { GestureUtils } from "./GestureUtils"; + /** * The $N Multistroke Recognizer (JavaScript version) * Converted to TypeScript -syip2 @@ -125,15 +127,11 @@ export class Multistroke { var unistrokes = MakeUnistrokes(strokes, orders); // returns array of point arrays this.Unistrokes = new Array(unistrokes.length); // unistrokes for this multistroke for (var j = 0; j < unistrokes.length; j++) { - this.Unistrokes[j] = new Unistroke(name, useBoundedRotationInvariance, unistrokes[j]); + this.Unistrokes[j] = new Unistroke(this.Name, useBoundedRotationInvariance, unistrokes[j]); } } } -export enum Gestures { - Box = "box" -} - // // Result class // @@ -169,7 +167,7 @@ export class NDollarRecognizer { // one predefined multistroke for each multistroke type // this.Multistrokes = new Array(NumMultistrokes); - this.Multistrokes[0] = new Multistroke(Gestures.Box, useBoundedRotationInvariance, new Array( + this.Multistrokes[0] = new Multistroke(GestureUtils.Gestures.Box, useBoundedRotationInvariance, new Array( new Array(new Point(30, 146), new Point(30, 222), new Point(106, 225), new Point(106, 146)) )); |