aboutsummaryrefslogtreecommitdiff
path: root/src/fields/InkField.ts
diff options
context:
space:
mode:
authortschicke-brown <tyler_schicke@brown.edu>2019-03-08 04:58:58 +0000
committerGitHub <noreply@github.com>2019-03-08 04:58:58 +0000
commit5a1da11a5767899aac2f1bfac6d33e0ee5d47c9e (patch)
tree303cc06880b6c5e0cc644f559c9548f95790423e /src/fields/InkField.ts
parent9940924f361f1b9d65d7cc0ad1e4f6f1f4d5d318 (diff)
parent889407852167dece0160127817e390336697e3a6 (diff)
Merge pull request #45 from browngraphicslab/inking
Inking
Diffstat (limited to 'src/fields/InkField.ts')
-rw-r--r--src/fields/InkField.ts47
1 files changed, 47 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