aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/InkStrokeProperties.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-12-21 14:55:48 -0500
committerbobzel <zzzman@gmail.com>2023-12-21 14:55:48 -0500
commit1caba64ee0f32ee8af79263cd4ef2a8bc5d5146e (patch)
tree0fa0e957d1f342fdc6ed4a4b43f5dddfddb1298a /src/client/views/InkStrokeProperties.ts
parent02eb7da95df283606d4275a22d9451cef371c3b5 (diff)
parent2691b951d96f2ce7652acbea9e340b61737b3b57 (diff)
Merge branch 'moreUpgrading' into dataViz-annotations
Diffstat (limited to 'src/client/views/InkStrokeProperties.ts')
-rw-r--r--src/client/views/InkStrokeProperties.ts31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/client/views/InkStrokeProperties.ts b/src/client/views/InkStrokeProperties.ts
index 62165bc48..a628c7120 100644
--- a/src/client/views/InkStrokeProperties.ts
+++ b/src/client/views/InkStrokeProperties.ts
@@ -1,5 +1,5 @@
import { Bezier } from 'bezier-js';
-import { action, observable, reaction } from 'mobx';
+import { action, makeObservable, observable, reaction, runInAction } from 'mobx';
import { Doc, NumListCast, Opt } from '../../fields/Doc';
import { InkData, InkField, InkTool, PointData } from '../../fields/InkField';
import { List } from '../../fields/List';
@@ -12,7 +12,7 @@ import { DocumentManager } from '../util/DocumentManager';
import { undoBatch } from '../util/UndoManager';
import { InkingStroke } from './InkingStroke';
import { DocumentView } from './nodes/DocumentView';
-import _ = require('lodash');
+import * as _ from 'lodash';
export class InkStrokeProperties {
static _Instance: InkStrokeProperties | undefined;
@@ -25,6 +25,7 @@ export class InkStrokeProperties {
constructor() {
InkStrokeProperties._Instance = this;
+ makeObservable(this);
reaction(
() => this._controlButton,
button => button && (Doc.ActiveTool = InkTool.None)
@@ -49,7 +50,7 @@ export class InkStrokeProperties {
(strokes instanceof DocumentView ? [strokes] : strokes)?.forEach(
action(inkView => {
if (!requireCurrPoint || this._currentPoint !== -1) {
- const doc = inkView.rootDoc;
+ const doc = inkView.Document;
if (doc.type === DocumentType.INK && doc.width && doc.height) {
const ink = Cast(doc.stroke, InkField)?.inkData;
if (ink) {
@@ -83,10 +84,9 @@ export class InkStrokeProperties {
* @param control The list of all control points of the ink.
*/
@undoBatch
- @action
addPoints = (inkView: DocumentView, t: number, i: number, controls: { X: number; Y: number }[]) => {
this.applyFunction(inkView, (view: DocumentView, ink: InkData) => {
- const doc = view.rootDoc;
+ const doc = view.Document;
const array = [controls[i], controls[i + 1], controls[i + 2], controls[i + 3]];
const newsegs = new Bezier(array.map(p => ({ x: p.X, y: p.Y }))).split(t);
const splicepts = [...newsegs.left.points, ...newsegs.right.points];
@@ -94,7 +94,7 @@ export class InkStrokeProperties {
// Updating the indices of the control points whose handle tangency has been broken.
doc.brokenInkIndices = new List(Cast(doc.brokenInkIndices, listSpec('number'), []).map(control => (control > i ? control + 4 : control)));
- this._currentPoint = -1;
+ runInAction(() => (this._currentPoint = -1));
return controls;
});
@@ -154,12 +154,11 @@ export class InkStrokeProperties {
* Deletes the current control point of the selected ink instance.
*/
@undoBatch
- @action
deletePoints = (inkView: DocumentView, preserve: boolean) =>
this.applyFunction(
inkView,
(view: DocumentView, ink: InkData) => {
- const doc = view.rootDoc;
+ const doc = view.Document;
const newPoints = ink.slice();
const brokenIndices = NumListCast(doc.brokenInkIndices);
if (preserve || this._currentPoint === 0 || this._currentPoint === ink.length - 1 || brokenIndices.includes(this._currentPoint)) {
@@ -187,7 +186,7 @@ export class InkStrokeProperties {
}
}
doc.brokenInkIndices = new List(brokenIndices.map(control => (control >= this._currentPoint ? control - 4 : control)));
- this._currentPoint = -1;
+ runInAction(() => (this._currentPoint = -1));
return newPoints.length < 4 ? undefined : newPoints;
},
true
@@ -200,7 +199,6 @@ export class InkStrokeProperties {
* @param scrpt The center point of the rotation in screen coordinates
*/
@undoBatch
- @action
rotateInk = (inkStrokes: DocumentView[], angle: number, scrpt: PointData) => {
this.applyFunction(inkStrokes, (view: DocumentView, ink: InkData, xScale: number, yScale: number, inkStrokeWidth: number) => {
const inkCenterPt = view.ComponentView?.ptFromScreen?.(scrpt);
@@ -222,7 +220,6 @@ export class InkStrokeProperties {
* @param scrpt The center point of the rotation in screen coordinates
*/
@undoBatch
- @action
stretchInk = (inkStrokes: DocumentView[], scaling: number, scrpt: PointData, scrVec: PointData, scaleUniformly: boolean) => {
this.applyFunction(inkStrokes, (view: DocumentView, ink: InkData) => {
const ptFromScreen = view.ComponentView?.ptFromScreen;
@@ -243,7 +240,6 @@ export class InkStrokeProperties {
* Handles the movement/scaling of a control point.
*/
@undoBatch
- @action
moveControlPtHandle = (inkView: DocumentView, deltaX: number, deltaY: number, controlIndex: number, origInk?: InkData) =>
this.applyFunction(inkView, (view: DocumentView, ink: InkData) => {
const order = controlIndex % 4;
@@ -335,7 +331,7 @@ export class InkStrokeProperties {
* Handles the movement/scaling of a control point.
*/
snapControl = (inkView: DocumentView, controlIndex: number) => {
- const inkDoc = inkView.rootDoc;
+ const inkDoc = inkView.Document;
const ink = Cast(inkDoc[Doc.LayoutFieldKey(inkDoc)], InkField)?.inkData;
if (ink) {
@@ -378,9 +374,9 @@ export class InkStrokeProperties {
.filter(doc => doc.type === DocumentType.INK)
.forEach(doc => {
const testInkView = DocumentManager.Instance.getDocumentView(doc, containingDocView);
- const snapped = testInkView?.ComponentView?.snapPt?.(screenDragPt, doc === inkView.rootDoc ? this.excludeSelfSnapSegs(ink, controlIndex) : []);
+ const snapped = testInkView?.ComponentView?.snapPt?.(screenDragPt, doc === inkView.Document ? this.excludeSelfSnapSegs(ink, controlIndex) : []);
if (snapped && snapped.distance < snapData.distance) {
- const snappedInkPt = doc === inkView.rootDoc ? snapped.nearestPt : inkView.ComponentView?.ptFromScreen?.(testInkView?.ComponentView?.ptToScreen?.(snapped.nearestPt) ?? { X: 0, Y: 0 }); // convert from snapped ink coordinate system to dragged ink coordinate system by converting to/from screen space
+ const snappedInkPt = doc === inkView.Document ? snapped.nearestPt : inkView.ComponentView?.ptFromScreen?.(testInkView?.ComponentView?.ptToScreen?.(snapped.nearestPt) ?? { X: 0, Y: 0 }); // convert from snapped ink coordinate system to dragged ink coordinate system by converting to/from screen space
if (snappedInkPt) {
snapData = { nearestPt: snappedInkPt, distance: snapped.distance };
@@ -397,7 +393,7 @@ export class InkStrokeProperties {
*/
snapHandleTangent = (inkView: DocumentView, controlIndex: number, handleIndexA: number, handleIndexB: number) => {
this.applyFunction(inkView, (view: DocumentView, ink: InkData) => {
- const doc = view.rootDoc;
+ const doc = view.Document;
const brokenIndices = Cast(doc.brokenInkIndices, listSpec('number'), []);
const ind = brokenIndices.findIndex(value => value === controlIndex);
if (ind !== -1) {
@@ -456,10 +452,9 @@ export class InkStrokeProperties {
* Handles the movement/scaling of a handle point.
*/
@undoBatch
- @action
moveTangentHandle = (inkView: DocumentView, deltaX: number, deltaY: number, handleIndex: number, oppositeHandleIndex: number, controlIndex: number) =>
this.applyFunction(inkView, (view: DocumentView, ink: InkData) => {
- const doc = view.rootDoc;
+ const doc = view.Document;
const closed = InkingStroke.IsClosed(ink);
const oldHandlePoint = ink[handleIndex];
const oppositeHandlePoint = ink[oppositeHandleIndex];