aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-03-08 00:12:37 -0500
committeryipstanley <stanley_yip@brown.edu>2019-03-08 00:12:37 -0500
commita25c7e5e436d772afe4b28300fc6999a78f7bba6 (patch)
tree6464cd134b322bb3f56900112064f3a2c8b26a5b /src/fields
parent0251cfba6ba20501d2598a890b7d67be6fc07379 (diff)
parent5a1da11a5767899aac2f1bfac6d33e0ee5d47c9e (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into improveText
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/InkField.ts47
-rw-r--r--src/fields/KeyStore.ts1
2 files changed, 48 insertions, 0 deletions
diff --git a/src/fields/InkField.ts b/src/fields/InkField.ts
new file mode 100644
index 000000000..a475e2aae
--- /dev/null
+++ b/src/fields/InkField.ts
@@ -0,0 +1,47 @@
+import { BasicField } from "./BasicField";
+import { Types } from "../server/Message";
+import { FieldId } from "./Field";
+
+export enum InkTool {
+ None,
+ Pen,
+ Highlighter,
+ Eraser
+}
+export interface StrokeData {
+ pathData: Array<{ x: number, y: number }>;
+ color: string;
+ width: string;
+ tool: InkTool;
+}
+export type StrokeMap = Map<string, StrokeData>;
+
+export class InkField extends BasicField<StrokeMap> {
+ constructor(data: StrokeMap = new Map, id?: FieldId, save: boolean = true) {
+ super(data, save, id);
+ }
+
+ ToScriptString(): string {
+ return `new InkField("${this.Data}")`;
+ }
+
+ Copy() {
+ return new InkField(this.Data);
+ }
+
+ ToJson(): { _id: string; type: Types; data: any; } {
+ return {
+ type: Types.Ink,
+ data: this.Data,
+ _id: this.Id,
+ }
+ }
+
+ static FromJson(id: string, data: any): InkField {
+ let map = new Map<string, StrokeData>();
+ Object.keys(data).forEach(key => {
+ map.set(key, data[key]);
+ });
+ return new InkField(map, id, false);
+ }
+} \ No newline at end of file
diff --git a/src/fields/KeyStore.ts b/src/fields/KeyStore.ts
index a3b39735d..9cdd18f4e 100644
--- a/src/fields/KeyStore.ts
+++ b/src/fields/KeyStore.ts
@@ -26,4 +26,5 @@ export namespace KeyStore {
export const Caption = new Key("Caption");
export const ActiveFrame = new Key("ActiveFrame");
export const DocumentText = new Key("DocumentText");
+ export const Ink = new Key("Ink");
}