General improvements

This commit is contained in:
KingOfDog
2019-04-03 16:15:15 +02:00
committed by Marcel
parent 1bf43ef28d
commit 23c24ded96
11 changed files with 828 additions and 152 deletions

View File

@@ -1,15 +1,26 @@
class Connection {
constructor(stateA, stateB) {
this.id = guid();
this.stateA = stateA;
this.stateB = stateB;
this.text = '';
this._text = '';
this.lineAngleAdjust = 0;
this.parallelPart = 0.5;
this.perpendicularPart = 0;
}
get text() {
return this._text;
}
set text(value) {
documents[activeDocument].addChange('connection', this.id, 'edit', ['_text'], [this._text], true);
this._text = value;
documents[activeDocument].addChange('connection', this.id, 'edit', ['_text'], [this._text]);
}
getAnchorPoint() {
const dx = this.stateB.x - this.stateA.x;
const dy = this.stateB.y - this.stateA.y;
@@ -103,11 +114,11 @@ class Connection {
ctx.closePath();
// Draws the text onto the line
if(stuff.isCircle) {
if (stuff.isCircle) {
let startAngle = stuff.startAngle,
endAngle = stuff.endAngle;
if(endAngle < startAngle) {
if (endAngle < startAngle) {
endAngle += Math.PI * 2;
}

View File

@@ -1,16 +1,27 @@
class SelfConnection {
constructor(state, mouse) {
this.id = guid();
this.state = state;
this.anchorAngle = 0;
this.mouseOffsetAngle = 0;
this.text = '';
this._text = '';
if(mouse) {
this.setAnchorPoint(mouse.x, mouse.y);
}
}
get text() {
return this._text;
}
set text(value) {
documents[activeDocument].addChange('selfconnection', this.id, 'edit', ['_text'], [this._text], true);
this._text = value;
documents[activeDocument].addChange('selfconnection', this.id, 'edit', ['_text'], [this._text]);
}
setMouseStart(x, y) {
this.mouseOffsetAngle = this.anchorAngle - Math.atan2(y - this.state.y, x - this.state.x);
}

View File

@@ -1,25 +1,36 @@
class StartConnection {
constructor(state, start) {
this.id = guid();
this.state = state;
this.deltaX = 0;
this.deltaY = 0;
this.text = '';
this._text = '';
if(start) {
if (start) {
this.setAnchorPoint(start.x, start.y);
}
}
get text() {
return this._text;
}
set text(value) {
documents[activeDocument].addChange('startconnection', this.id, 'edit', ['_text'], [this._text], true);
this._text = value;
documents[activeDocument].addChange('startconnection', this.id, 'edit', ['_text'], [this._text]);
}
setAnchorPoint(x, y) {
this.deltaX = x - this.state.x;
this.deltaY = y - this.state.y;
if(Math.abs(this.deltaX) < settings.snapToPadding) {
if (Math.abs(this.deltaX) < settings.snapToPadding) {
this.deltaX = 0;
}
if(Math.abs(this.deltaY) < settings.snapToPadding) {
if (Math.abs(this.deltaY) < settings.snapToPadding) {
this.deltaY = 0;
}
}

View File

@@ -10,7 +10,17 @@ class State {
this.isActive = false;
this.activeTime = 0;
this.isAcceptState = false;
this.text = '';
this._text = '';
}
get text() {
return this._text;
}
set text(value) {
documents[activeDocument].addChange('state', this.id, 'edit', ['_text'], [this._text], true);
this._text = value;
documents[activeDocument].addChange('state', this.id, 'edit', ['_text'], [this._text]);
}
setMouseStart(x, y) {
@@ -58,7 +68,7 @@ class State {
}
ctx.fillStyle = settings.colors.getColor(this);
const width = ctx.measureText(this.text).width;
const width = ctx.measureText(convertLatexShortcuts(this.text)).width;
if(width < radius * .9)
ctx.drawText(this.text, this.x, this.y, null, selectedObject === this);
else
@@ -134,5 +144,4 @@ class State {
containsPoint(x, y) {
return (x - this.x) ** 2 + (y - this.y) ** 2 < radius ** 2;
}
}