Move control point to TS

This commit is contained in:
Paulo Gustavo Veiga 2022-02-09 20:02:57 -08:00
parent 2e191a168a
commit d8b7fd81fa
2 changed files with 44 additions and 17 deletions

View File

@ -21,6 +21,7 @@ import { $assert } from '@wisemapping/core-js';
import Point from '@wisemapping/web2d'; import Point from '@wisemapping/web2d';
import { Mindmap } from '..'; import { Mindmap } from '..';
import CommandContext from './CommandContext'; import CommandContext from './CommandContext';
import ControlPoint from './ControlPoint';
import Events from './Events'; import Events from './Events';
import NodeModel from './model/NodeModel'; import NodeModel from './model/NodeModel';
import RelationshipModel from './model/RelationshipModel'; import RelationshipModel from './model/RelationshipModel';
@ -44,7 +45,7 @@ abstract class ActionDispatcher extends Events {
abstract moveTopic(topicId: number, position: Point): void; abstract moveTopic(topicId: number, position: Point): void;
abstract moveControlPoint(ctrlPoint: this, point: Point): void; abstract moveControlPoint(ctrlPoint: ControlPoint, point: Point): void;
abstract changeFontFamilyToTopic(topicIds: number[], fontFamily: string): void; abstract changeFontFamilyToTopic(topicIds: number[], fontFamily: string): void;

View File

@ -20,8 +20,33 @@ import { $defined } from '@wisemapping/core-js';
import Shape from './util/Shape'; import Shape from './util/Shape';
import ActionDispatcher from './ActionDispatcher'; import ActionDispatcher from './ActionDispatcher';
import Workspace from './Workspace';
class ControlPoint { class ControlPoint {
private control1: Elipse;
private control2: Elipse;
private _controlPointsController: Elipse[];
private _controlLines: Line[];
private _isBinded: boolean;
_line: Line;
private _workspace: Workspace;
private _endPoint: any[];
private _orignalCtrlPoint: any;
private _controls: any;
private _mouseMoveFunction: (e: Event) => void;
private _mouseUpFunction: (e: Event) => void;
constructor() { constructor() {
this.control1 = new Elipse({ this.control1 = new Elipse({
width: 6, width: 6,
@ -70,7 +95,7 @@ class ControlPoint {
}); });
} }
setLine(line) { setLine(line: Line) {
if ($defined(this._line)) { if ($defined(this._line)) {
this._removeLine(); this._removeLine();
} }
@ -93,7 +118,7 @@ class ControlPoint {
if ($defined(this._line)) this._createControlPoint(); if ($defined(this._line)) this._createControlPoint();
} }
_createControlPoint() { private _createControlPoint() {
this._controls = this._line.getLine().getControlPoints(); this._controls = this._line.getLine().getControlPoints();
let pos = this._line.getLine().getFrom(); let pos = this._line.getLine().getFrom();
this._controlPointsController[0].setPosition( this._controlPointsController[0].setPosition(
@ -117,11 +142,11 @@ class ControlPoint {
); );
} }
_removeLine() { private _removeLine() {
// Overwrite default behaviour ... // Overwrite default behaviour ...
} }
_mouseDown(event, point, me) { private _mouseDown(event: Event, point, me) {
if (!this._isBinded) { if (!this._isBinded) {
this._isBinded = true; this._isBinded = true;
this._mouseMoveFunction = (e) => { this._mouseMoveFunction = (e) => {
@ -129,7 +154,7 @@ class ControlPoint {
}; };
this._workspace.getScreenManager().addEvent('mousemove', this._mouseMoveFunction); this._workspace.getScreenManager().addEvent('mousemove', this._mouseMoveFunction);
this._mouseUpFunction = (e) => { this._mouseUpFunction = (e: Event) => {
me._mouseUp(e, point, me); me._mouseUp(e, point, me);
}; };
this._workspace.getScreenManager().addEvent('mouseup', this._mouseUpFunction); this._workspace.getScreenManager().addEvent('mouseup', this._mouseUpFunction);
@ -139,7 +164,7 @@ class ControlPoint {
return false; return false;
} }
_mouseMoveEvent(event, point) { private _mouseMoveEvent(event: MouseEvent, point: Point) {
const screen = this._workspace.getScreenManager(); const screen = this._workspace.getScreenManager();
const pos = screen.getWorkspaceMousePosition(event); const pos = screen.getWorkspaceMousePosition(event);
@ -162,7 +187,7 @@ class ControlPoint {
this._line.getLine().updateLine(point); this._line.getLine().updateLine(point);
} }
_mouseUp(event, point) { private _mouseUp(event, point) {
this._workspace.getScreenManager().removeEvent('mousemove', this._mouseMoveFunction); this._workspace.getScreenManager().removeEvent('mousemove', this._mouseMoveFunction);
this._workspace.getScreenManager().removeEvent('mouseup', this._mouseUpFunction); this._workspace.getScreenManager().removeEvent('mouseup', this._mouseUpFunction);
@ -177,7 +202,7 @@ class ControlPoint {
return false; return false;
} }
setVisibility(visible) { setVisibility(visible: boolean) {
if (visible) { if (visible) {
this._controlLines[0].moveToFront(); this._controlLines[0].moveToFront();
this._controlLines[1].moveToFront(); this._controlLines[1].moveToFront();
@ -190,7 +215,7 @@ class ControlPoint {
this._controlLines[1].setVisibility(visible); this._controlLines[1].setVisibility(visible);
} }
addToWorkspace(workspace) { addToWorkspace(workspace: Workspace): void {
this._workspace = workspace; this._workspace = workspace;
workspace.append(this._controlPointsController[0]); workspace.append(this._controlPointsController[0]);
workspace.append(this._controlPointsController[1]); workspace.append(this._controlPointsController[1]);
@ -198,7 +223,7 @@ class ControlPoint {
workspace.append(this._controlLines[1]); workspace.append(this._controlLines[1]);
} }
removeFromWorkspace(workspace) { removeFromWorkspace(workspace: Workspace) {
this._workspace = null; this._workspace = null;
workspace.removeChild(this._controlPointsController[0]); workspace.removeChild(this._controlPointsController[0]);
workspace.removeChild(this._controlPointsController[1]); workspace.removeChild(this._controlPointsController[1]);
@ -206,20 +231,21 @@ class ControlPoint {
workspace.removeChild(this._controlLines[1]); workspace.removeChild(this._controlLines[1]);
} }
getControlPoint(index) { getControlPoint(index: number): ControlPoint {
return this._controls[index]; return this._controls[index];
} }
getOriginalEndPoint(index) { getOriginalEndPoint(index: number) {
return this._endPoint[index]; return this._endPoint[index];
} }
getOriginalCtrlPoint(index) { getOriginalCtrlPoint(index: number): ControlPoint {
return this._orignalCtrlPoint[index]; return this._orignalCtrlPoint[index];
} }
static FROM = 0;
static TO = 1;
} }
ControlPoint.FROM = 0;
ControlPoint.TO = 1;
export default ControlPoint; export default ControlPoint;