From 632dec95b9fccccef13b50cb41fc598613a9df1e Mon Sep 17 00:00:00 2001
From: yunahi <60233430+yunahi@users.noreply.github.com>
Date: Mon, 8 Jun 2020 10:56:36 +0900
Subject: added ink options menu

---
 src/client/views/InkingControl.tsx | 46 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

(limited to 'src/client/views/InkingControl.tsx')

diff --git a/src/client/views/InkingControl.tsx b/src/client/views/InkingControl.tsx
index 41ee36d05..83109db1c 100644
--- a/src/client/views/InkingControl.tsx
+++ b/src/client/views/InkingControl.tsx
@@ -9,14 +9,15 @@ import { SelectionManager } from "../util/SelectionManager";
 import { undoBatch } from "../util/UndoManager";
 import GestureOverlay from "./GestureOverlay";
 import { FormattedTextBox } from "./nodes/formattedText/FormattedTextBox";
+import InkOptionsMenu from "./collections/collectionFreeForm/InkOptionsMenu";
 
 export class InkingControl {
     @observable static Instance: InkingControl;
     @computed private get _selectedTool(): InkTool { return FieldValue(NumCast(Doc.UserDoc().inkTool)) ?? InkTool.None; }
     @computed private get _selectedColor(): string { return CurrentUserUtils.ActivePen ? FieldValue(StrCast(CurrentUserUtils.ActivePen.backgroundColor)) ?? "rgb(0, 0, 0)" : "rgb(0, 0, 0)"; }
     @computed private get _selectedWidth(): string { return FieldValue(StrCast(Doc.UserDoc().inkWidth)) ?? "2"; }
+    @computed private get _selectedBezier(): string { return FieldValue(StrCast(Doc.UserDoc().inkBezier)) ?? "2"; }
     @observable public _open: boolean = false;
-
     constructor() {
         InkingControl.Instance = this;
     }
@@ -32,10 +33,21 @@ export class InkingControl {
         return (number < 16 ? "0" : "") + number.toString(16).toUpperCase();
     }
 
+    @action
+    inkOptionsMenuChangeColor = (color: string) => {
+        const col: ColorState = {
+            hex: color, hsl: { a: 0, h: 0, s: 0, l: 0, source: "" }, hsv: { a: 0, h: 0, s: 0, v: 0, source: "" },
+            rgb: { a: 0, r: 0, b: 0, g: 0, source: "" }, oldHue: 0, source: "",
+        };
+        this.switchColor(col);
+        InkOptionsMenu.Instance._colorBt = false;
+    }
+
     @undoBatch
     switchColor = action((color: ColorState): void => {
         Doc.UserDoc().backgroundColor = color.hex.startsWith("#") ?
             color.hex + (color.rgb.a ? this.decimalToHexString(Math.round(color.rgb.a * 255)) : "ff") : color.hex;
+        InkOptionsMenu.Instance._color = StrCast(Doc.UserDoc().backgroundColor);
         CurrentUserUtils.ActivePen && (CurrentUserUtils.ActivePen.backgroundColor = color.hex);
 
         if (InkingControl.Instance.selectedTool === InkTool.None) {
@@ -60,6 +72,23 @@ export class InkingControl {
         if (!isNaN(parseInt(width))) {
             Doc.UserDoc().inkWidth = width;
         }
+        InkOptionsMenu.Instance._widthBt = false;
+    }
+
+    @action
+    switchBezier = (bezier: string): void => {
+        if (!isNaN(parseInt(bezier))) {
+            Doc.UserDoc().inkBezier = bezier;
+        }
+    }
+
+    @action
+    inkOptionsMenuChangeBezier = (e: React.PointerEvent): void => {
+        if (InkOptionsMenu.Instance._bezierBt === true) {
+            Doc.UserDoc().inkBezier = "300";
+        } else {
+            Doc.UserDoc().inkBezier = "0";
+        }
     }
 
     @computed
@@ -83,8 +112,21 @@ export class InkingControl {
         return this._selectedWidth;
     }
 
+    @computed
+    get selectedBezier() {
+        return this._selectedBezier;
+    }
 }
-Scripting.addGlobal(function activatePen(pen: any, width: any, color: any) { InkingControl.Instance.switchTool(pen ? InkTool.Pen : InkTool.None); InkingControl.Instance.switchWidth(width); InkingControl.Instance.updateSelectedColor(color); });
+Scripting.addGlobal(function activatePen(pen: any, width: any, color: any) {
+    InkingControl.Instance.switchTool(pen ? InkTool.Pen : InkTool.None); InkingControl.Instance.switchWidth(width); InkingControl.Instance.updateSelectedColor(color);
+    //setup InkOptionsMenu(change jumpto value if necessary.Currenlty hardcoded to 300,300)
+    pen ? InkOptionsMenu.Instance.jumpTo(300, 300) : InkOptionsMenu.Instance.fadeOut(true);
+    InkOptionsMenu.Instance.changeColor = InkingControl.Instance.inkOptionsMenuChangeColor;
+    InkOptionsMenu.Instance.changeBezier = InkingControl.Instance.inkOptionsMenuChangeBezier;
+    InkOptionsMenu.Instance.changeWidth = InkingControl.Instance.switchWidth;
+    InkOptionsMenu.Instance._widthSelected = width;
+    InkOptionsMenu.Instance._color = color;
+});
 Scripting.addGlobal(function activateBrush(pen: any, width: any, color: any) { InkingControl.Instance.switchTool(pen ? InkTool.Highlighter : InkTool.None); InkingControl.Instance.switchWidth(width); InkingControl.Instance.updateSelectedColor(color); });
 Scripting.addGlobal(function activateEraser(pen: any) { return InkingControl.Instance.switchTool(pen ? InkTool.Eraser : InkTool.None); });
 Scripting.addGlobal(function activateStamp(pen: any) { return InkingControl.Instance.switchTool(pen ? InkTool.Stamp : InkTool.None); });
-- 
cgit v1.2.3-70-g09d2

