1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
import React = require("react");
import AntimodeMenu from "../../AntimodeMenu";
import { observer } from "mobx-react";
import { observable, action, computed } from "mobx";
import "./InkOptionsMenu.scss";
import { ActiveInkColor, ActiveInkBezierApprox, ActiveFillColor, ActiveArrowStart, ActiveArrowEnd, SetActiveInkWidth, SetActiveInkColor, SetActiveBezierApprox, SetActiveFillColor, SetActiveArrowStart, SetActiveArrowEnd, ActiveDash, SetActiveDash } from "../../InkingStroke";
import { Scripting } from "../../../util/Scripting";
import { InkTool } from "../../../../fields/InkField";
import { ColorState } from "react-color";
import { Utils } from "../../../../Utils";
import GestureOverlay from "../../GestureOverlay";
import { Doc } from "../../../../fields/Doc";
import { SelectionManager } from "../../../util/SelectionManager";
import { DocumentView } from "../../../views/nodes/DocumentView";
import { Document } from "../../../../fields/documentSchemas";
import { DocumentType } from "../../../documents/DocumentTypes";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { IconProp, library } from '@fortawesome/fontawesome-svg-core';
import { faBold, faItalic, faChevronLeft, faUnderline, faStrikethrough, faSubscript, faSuperscript, faIndent, faEyeDropper, faCaretDown, faPalette, faArrowsAlt, faHighlighter, faLink, faPaintRoller, faSleigh, faBars, faFillDrip, faBrush, faPenNib, faShapes, faArrowLeft, faEllipsisH, faBezierCurve, } from "@fortawesome/free-solid-svg-icons";
library.add(faBold, faItalic, faChevronLeft, faUnderline, faStrikethrough, faSuperscript, faSubscript, faIndent, faEyeDropper, faCaretDown, faPalette, faArrowsAlt, faHighlighter, faLink, faPaintRoller, faBars, faFillDrip, faBrush, faPenNib, faShapes, faArrowLeft, faEllipsisH, faBezierCurve);
@observer
export default class InkOptionsMenu extends AntimodeMenu {
static Instance: InkOptionsMenu;
private _palette = ["#D0021B", "#F5A623", "#F8E71C", "#8B572A", "#7ED321", "#417505", "#9013FE", "#4A90E2", "#50E3C2", "#B8E986", "#000000", "#4A4A4A", "#9B9B9B", "#FFFFFF", "none"];
private _width = ["1", "5", "10", "100"];
// private _buttons = ["circle", "triangle", "rectangle", "arrow", "line"];
// private _icons = ["O", "∆", "ロ", "➜", "-"];
private _buttons = ["circle", "triangle", "rectangle", "line", "noRec", "",];
private _icons = ["O", "∆", "ロ", "⎯", "✖︎", " "];
//arrowStart and arrowEnd must match and defs must exist in Inking Stroke
private _arrowStart = ["arrowHead", "arrowHead", "dot", "dot", "none"];
private _arrowEnd = ["none", "arrowEnd", "none", "dot", "none"];
private _arrowIcons = ["→", "↔︎", "•", "••", " "];
@observable _colorBtn = false;
@observable _widthBtn = false;
@observable _fillBtn = false;
@observable _arrowBtn = false;
@observable _dashBtn = false;
@observable _shapeBtn = false;
constructor(props: Readonly<{}>) {
super(props);
InkOptionsMenu.Instance = this;
this._canFade = false; // don't let the inking menu fade away
}
getColors = () => {
return this._palette;
}
@action
changeArrow = (arrowStart: string, arrowEnd: string) => {
SetActiveArrowStart(arrowStart);
SetActiveArrowEnd(arrowEnd);
}
@action
changeColor = (color: string, type: 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: "",
};
if (type === "color") {
SetActiveInkColor(Utils.colorString(col));
} else if (type === "fill") {
SetActiveFillColor(Utils.colorString(col));
}
}
@action
editProperties = (value: any, field: string) => {
SelectionManager.SelectedDocuments().forEach(action((element: DocumentView) => {
const doc = Document(element.rootDoc);
if (doc.type === DocumentType.INK) {
switch (field) {
case "width":
doc.strokeWidth = Number(value);
break;
case "color":
doc.color = String(value);
break;
case "fill":
doc.fillColor = String(value);
break;
case "bezier":
// doc.strokeBezier === 300 ? doc.strokeBezier = 0 : doc.strokeBezier = 300;
break;
case "arrowStart":
doc.arrowStart = String(value);
break;
case "arrowEnd":
doc.arrowEnd = String(value);
break;
case "dash":
doc.dash = Number(value);
default:
break;
}
}
}));
}
@action
changeBezier = (e: React.PointerEvent): void => {
SetActiveBezierApprox(!ActiveInkBezierApprox() ? "300" : "");
this.editProperties(0, "bezier");
}
@action
changeDash = (e: React.PointerEvent): void => {
SetActiveDash(ActiveDash() === "0" ? "2" : "0");
this.editProperties(ActiveDash(), "dash");
}
@computed get arrowPicker() {
var currIcon;
for (var i = 0; i < this._arrowStart.length; i++) {
if (this._arrowStart[i] === ActiveArrowStart() && this._arrowEnd[i] === ActiveArrowEnd()) {
currIcon = this._arrowIcons[i];
if (this._arrowIcons[i] === " ") {
currIcon = "➤";
}
}
}
var arrowPicker = <button
className="antimodeMenu-button"
key="arrow"
onPointerDown={action(e => this._arrowBtn = !this._arrowBtn)}
style={{ backgroundColor: this._arrowBtn ? "121212" : "" }}>
{currIcon}
</button>;
if (this._arrowBtn) {
arrowPicker = <div className="btn2-group" key="arrows">
{arrowPicker}
{this._arrowStart.map((arrowStart, i) => {
return <button
className="antimodeMenu-button"
key={arrowStart}
onPointerDown={action(() => { SetActiveArrowStart(arrowStart); SetActiveArrowEnd(this._arrowEnd[i]); this.editProperties(arrowStart, "arrowStart"), this.editProperties(this._arrowEnd[i], "arrowEnd"); this._arrowBtn = false; })}
style={{ backgroundColor: this._arrowBtn ? "121212" : "" }}>
{this._arrowIcons[i]}
</button>;
})}
</div>;
}
return arrowPicker;
}
@computed get widthPicker() {
var widthPicker = <button
className="antimodeMenu-button"
key="width"
onPointerDown={action(e => this._widthBtn = !this._widthBtn)}
style={{ backgroundColor: this._widthBtn ? "121212" : "" }}>
<FontAwesomeIcon icon="bars" size="lg" />
</button>;
if (this._widthBtn) {
widthPicker = <div className="btn2-group" key="width">
{widthPicker}
{this._width.map(wid => {
return <button
className="antimodeMenu-button"
key={wid}
onPointerDown={action(() => { SetActiveInkWidth(wid); this._widthBtn = false; this.editProperties(wid, "width"); })}
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" : "" }}>
<FontAwesomeIcon icon="pen-nib" size="lg" />
<div className="color-previewI" style={{ backgroundColor: ActiveInkColor() ?? "121212" }}></div>
</button>;
if (this._colorBtn) {
colorPicker = <div className="btn-group" key="color">
{colorPicker}
{this._palette.map(color => {
return <button
className="antimodeMenu-button"
key={color}
onPointerDown={action(() => { this.changeColor(color, "color"); this._colorBtn = false; this.editProperties(color, "color"); })}
style={{ backgroundColor: this._colorBtn ? "121212" : "" }}>
{/* <FontAwesomeIcon icon="pen-nib" size="lg" /> */}
<div className="color-previewII" style={{ backgroundColor: color }}></div>
</button>;
})}
</div>;
}
return colorPicker;
}
@computed get fillPicker() {
var fillPicker = <button
className="antimodeMenu-button"
key="fill"
title="fillChanger"
onPointerDown={action(e => this._fillBtn = !this._fillBtn)}
style={{ backgroundColor: this._fillBtn ? "121212" : "" }}>
<FontAwesomeIcon icon="fill-drip" size="lg" />
<div className="color-previewI" style={{ backgroundColor: ActiveFillColor() ?? "121212" }}></div>
</button>;
if (this._fillBtn) {
fillPicker = <div className="btn-group" key="fill">
{fillPicker}
{this._palette.map(color => {
return <button
className="antimodeMenu-button"
key={color}
onPointerDown={action(() => { this.changeColor(color, "fill"); this._fillBtn = false; this.editProperties(color, "fill"); })}
style={{ backgroundColor: this._fillBtn ? "121212" : "" }}>
<div className="color-previewII" style={{ backgroundColor: color }}></div>
</button>;
})}
</div>;
}
return fillPicker;
}
@computed get shapePicker() {
var currIcon;
if (GestureOverlay.Instance.InkShape === "") {
currIcon = <FontAwesomeIcon icon="shapes" size="lg" />;
} else {
for (var i = 0; i < this._icons.length; i++) {
if (GestureOverlay.Instance.InkShape === this._buttons[i]) {
currIcon = this._icons[i];
}
}
}
var shapePicker = <button
className="antimodeMenu-button"
key="shape"
onPointerDown={action(e => this._shapeBtn = !this._shapeBtn)}
style={{ backgroundColor: this._shapeBtn ? "121212" : "" }}>
{currIcon}
</button>;
if (this._shapeBtn) {
shapePicker = <div className="btn2-group" key="shape">
{shapePicker}
{this._buttons.map((btn, i) => {
var ttl = btn;
if (btn === "") {
ttl = "no shape";
}
if (btn === "noRec") {
ttl = "disable shape recognition";
}
return <button
className="antimodeMenu-button"
title={`Draw ${btn}`}
key={ttl}
onPointerDown={action((e) => { GestureOverlay.Instance.InkShape = btn; this._shapeBtn = false; })}
style={{ backgroundColor: this._shapeBtn ? "121212" : "" }}>
{this._icons[i]}
</button>;
})}
</div>;
}
return shapePicker;
}
@computed get bezierButton() {
return <button
className="antimodeMenu-button"
title="Bezier changer"
key="bezier"
onPointerDown={e => this.changeBezier(e)}
style={{ backgroundColor: ActiveInkBezierApprox() ? "121212" : "" }}>
<FontAwesomeIcon icon="bezier-curve" size="lg" />
</button>;
}
@computed get dashButton() {
return <button
className="antimodeMenu-button"
title="dash changer"
key="dash"
onPointerDown={e => this.changeDash(e)}
style={{ backgroundColor: ActiveDash() !== "0" ? "121212" : "" }}>
<FontAwesomeIcon icon="ellipsis-h" size="lg" />
</button>;
}
render() {
const buttons = [
// <button className="antimodeMenu-button" title="Drag" key="drag" onPointerDown={e => this.dragStart(e)}>
// <FontAwesomeIcon icon="arrows-alt" size="lg" />
// </button>,
this.shapePicker,
this.bezierButton,
this.widthPicker,
this.colorPicker,
this.fillPicker,
this.arrowPicker,
this.dashButton,
];
return this.getElement(buttons);
}
}
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);
}
});
|