aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/InkControl.tsx
diff options
context:
space:
mode:
authorvkalev <vjk1883@gmail.com>2021-07-06 12:45:37 -0500
committervkalev <vjk1883@gmail.com>2021-07-06 12:45:37 -0500
commita0207bf861908da9235a1752a723e69ecdbba734 (patch)
tree1ee49e73d1204a4379be7da52d1bb6275a637646 /src/client/views/InkControl.tsx
parent89c8891e9def96a871d36ab7772e453b8d8c21c1 (diff)
refactoring
Diffstat (limited to 'src/client/views/InkControl.tsx')
-rw-r--r--src/client/views/InkControl.tsx101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/client/views/InkControl.tsx b/src/client/views/InkControl.tsx
deleted file mode 100644
index accb16f61..000000000
--- a/src/client/views/InkControl.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-import React = require("react");
-import { observable, action } from "mobx";
-import { observer } from "mobx-react";
-import { InkStrokeProperties } from "./InkStrokeProperties";
-import { setupMoveUpEvents, emptyFunction } from "../../Utils";
-import { UndoManager } from "../util/UndoManager";
-import { ControlPoint } from "../../fields/InkField";
-import { Transform } from "../util/Transform";
-
-export interface InkControlProps {
- control: ControlPoint;
- left: number;
- top: number;
- scaleX: number;
- scaleY: number;
- strokeWidth: number;
- ScreenToLocalTransform: () => Transform;
-}
-
-@observer
-export class InkControl extends React.Component<InkControlProps> {
- @observable private _overControl = false;
-
- @action
- onPointerEnter = () => {
- this._overControl = true;
- }
-
- @action
- onPointerLeave = () => {
- this._overControl = false;
- }
-
- /**
- * Handles the movement of a selected control point when the user clicks and drags.
- * @param controlNum The index of the currently selected control point.
- */
- @action
- onControlDown = (e: React.PointerEvent, controlNum: number): void => {
- if (InkStrokeProperties.Instance) {
- InkStrokeProperties.Instance.moveControl(0, 0, 1);
- const controlUndo = UndoManager.StartBatch("DocDecs set radius");
- const screenScale = this.props.ScreenToLocalTransform().Scale;
- setupMoveUpEvents(this, e,
- (e: PointerEvent, down: number[], delta: number[]) => {
- InkStrokeProperties.Instance?.moveControl(-delta[0] * screenScale, -delta[1] * screenScale, controlNum);
- return false;
- },
- () => controlUndo?.end(), emptyFunction);
- }
- }
-
- /**
- * Deletes the currently selected point.
- */
- @action
- onDelete = (e: KeyboardEvent) => {
- if (["-", "Backspace", "Delete"].includes(e.key)) {
- if (InkStrokeProperties.Instance?.deletePoints()) e.stopPropagation();
- }
- }
-
- /**
- * Changes the current selected control point.
- */
- @action
- changeCurrPoint = (i: number) => {
- if (InkStrokeProperties.Instance) {
- InkStrokeProperties.Instance._currPoint = i;
- document.addEventListener("keydown", this.onDelete, true);
- }
- }
-
-
- render() {
- const control = this.props.control;
- const left = this.props.left;
- const top = this.props.top;
- const scaleX = this.props.scaleX;
- const scaleY = this.props.scaleY;
- const strokeWidth = this.props.strokeWidth;
-
- return (
- <svg height="10" width="10" key={`ctrl${control.I}`}>
- <rect
- x={(control.X - left - strokeWidth / 2) * scaleX}
- y={(control.Y - top - strokeWidth / 2) * scaleY}
- height={this._overControl ? strokeWidth * 1.5 : strokeWidth}
- width={this._overControl ? strokeWidth * 1.5 : strokeWidth}
- strokeWidth={strokeWidth / 6} stroke="#1F85DE"
- fill={InkStrokeProperties.Instance?._currPoint === control.I ? "#1F85DE" : "white"}
- onPointerDown={(e) => { this.changeCurrPoint(control.I); this.onControlDown(e, control.I); }}
- onMouseEnter={this.onPointerEnter}
- onMouseLeave={this.onPointerLeave}
- pointerEvents="all"
- cursor="default"
- />
- </svg>
- )
- }
-} \ No newline at end of file