diff options
| author | Bob Zeleznik <zzzman@gmail.com> | 2020-06-08 20:45:38 -0400 |
|---|---|---|
| committer | Bob Zeleznik <zzzman@gmail.com> | 2020-06-08 20:45:38 -0400 |
| commit | 4cc9c6ae9a2735266994c62c01818de4bdc25ac6 (patch) | |
| tree | 703d80fb6d2b41f14728e04d8c6c3e0aa0302a5b /src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx | |
| parent | 3dea269077151542bc2450bccd749ede87681556 (diff) | |
final cleanup of ink related stuff so that things are more structured and we avoid input cycles
Diffstat (limited to 'src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx')
| -rw-r--r-- | src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx | 95 |
1 files changed, 51 insertions, 44 deletions
diff --git a/src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx b/src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx index b35c9682e..5a27f74e5 100644 --- a/src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx +++ b/src/client/views/collections/collectionFreeForm/InkOptionsMenu.tsx @@ -1,15 +1,15 @@ import React = require("react"); import AntimodeMenu from "../../AntimodeMenu"; import { observer } from "mobx-react"; -import { observable, action } from "mobx"; +import { observable, action, computed } from "mobx"; import "./InkOptionsMenu.scss"; -import { InkingStroke } from "../../InkingStroke"; +import { ActiveInkColor, ActiveInkBezierApprox, SetActiveInkWidth, SetActiveInkColor, SetActiveBezierApprox } from "../../InkingStroke"; import { Scripting } from "../../../util/Scripting"; import { InkTool } from "../../../../fields/InkField"; -import { InkingControl } from "../../InkingControl"; -import { StrCast } from "../../../../fields/Types"; import { ColorState } from "react-color"; -import { ColorBox } from "../../nodes/ColorBox"; +import { Utils } from "../../../../Utils"; +import GestureOverlay from "../../GestureOverlay"; +import { Doc } from "../../../../fields/Doc"; @observer export default class InkOptionsMenu extends AntimodeMenu { @@ -35,15 +35,15 @@ export default class InkOptionsMenu extends AntimodeMenu { 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: "", }; - ColorBox.switchColor(col); + SetActiveInkColor(Utils.colorString(col)); } @action changeBezier = (e: React.PointerEvent): void => { - InkingControl.Instance.switchBezier(!InkingStroke.InkBezierApprox ? "300" : ""); + SetActiveBezierApprox(!ActiveInkBezierApprox() ? "300" : ""); } - render() { + @computed get widthPicker() { var widthPicker = <button className="antimodeMenu-button" key="width" @@ -52,30 +52,33 @@ export default class InkOptionsMenu extends AntimodeMenu { W </button>; if (this._widthBtn) { - widthPicker = <div className="btn2-group"> + widthPicker = <div className="btn2-group" key="width"> {widthPicker} {this._width.map(wid => { return <button className="antimodeMenu-button" key={wid} - onPointerDown={action(() => { InkingControl.Instance.switchWidth(wid); this._widthBtn = false; })} + onPointerDown={action(() => { SetActiveInkWidth(wid); this._widthBtn = false; })} style={{ backgroundColor: this._widthBtn ? "121212" : "" }}> {wid} </button>; })} </div>; } + return widthPicker; + } + @computed get colorPicker() { var colorPicker = <button className="antimodeMenu-button" key="color" title="colorChanger" onPointerDown={action(e => this._colorBtn = !this._colorBtn)} style={{ backgroundColor: this._colorBtn ? "121212" : "" }}> - <div className="color-preview" style={{ backgroundColor: InkingStroke.InkColor ?? "121212" }}></div> + <div className="color-preview" style={{ backgroundColor: ActiveInkColor() ?? "121212" }}></div> </button>; if (this._colorBtn) { - colorPicker = <div className="btn-group"> + colorPicker = <div className="btn-group" key="color"> {colorPicker} {this._palette.map(color => { return <button @@ -88,46 +91,50 @@ export default class InkOptionsMenu extends AntimodeMenu { })} </div>; } + return colorPicker; + } - const buttons = [ - <button className="antimodeMenu-button" - title="Drag" - key="drag" - onPointerDown={e => this.dragStart(e)}> - ✜ - </button>, - <> - {this._buttons.map((btn, i) => <button - className="antimodeMenu-button" - title={`Draw ${btn}`} - key={btn} - onPointerDown={action(e => InkingStroke.InkShape = btn)} - style={btn === InkingStroke.InkShape ? { backgroundColor: "121212" } : {}}> - {this._icons[i]} - </button>)}, - </>, - <button + @computed get shapeButtons() { + return <> + {this._buttons.map((btn, i) => <button className="antimodeMenu-button" - title="Bezier changer" - key="bezier" - onPointerDown={e => this.changeBezier(e)} - style={InkingStroke.InkBezierApprox ? { backgroundColor: "121212" } : {}}> - B - </button>, - widthPicker, - colorPicker, + title={`Draw ${btn}`} + key={btn} + onPointerDown={action(e => GestureOverlay.Instance.InkShape = btn)} + style={{ backgroundColor: btn === GestureOverlay.Instance.InkShape ? "121212" : "" }}> + {this._icons[i]} + </button>)}, + </>; + } + + @computed get bezierButton() { + return <button + className="antimodeMenu-button" + title="Bezier changer" + key="bezier" + onPointerDown={e => this.changeBezier(e)} + style={ { backgroundColor:ActiveInkBezierApprox() ? "121212":"" } }> + B + </button>; + } + + render() { + const buttons = [ + <button className="antimodeMenu-button" title="Drag" key="drag" onPointerDown={e => this.dragStart(e)}> ✜ </button>, + this.shapeButtons, + this.bezierButton, + this.widthPicker, + this.colorPicker, ]; return this.getElement(buttons); } } -Scripting.addGlobal(function activatePen(pen: any) { - InkingControl.Instance.switchTool(pen ? InkTool.Pen : InkTool.None); - if (pen) { - InkingControl.Instance.switchWidth(StrCast(pen.inkWidth, "1")); - InkingControl.Instance.switchColor(StrCast(pen.inkColor, "black")); - InkingControl.Instance.switchBezier(StrCast(pen.inkBezier, "")); +Scripting.addGlobal(function activatePen(penBtn: any) { + if (penBtn) { + Doc.SetSelectedTool(InkTool.Pen); InkOptionsMenu.Instance.jumpTo(300, 300); } else { + Doc.SetSelectedTool(InkTool.None); InkOptionsMenu.Instance.fadeOut(true); } });
\ No newline at end of file |
