Commit bd950b6d authored by Christian Winter's avatar Christian Winter

cursor class introduced

parent e4af2769
......@@ -11,6 +11,8 @@
<script src="scripts/Preferences.js"></script>
<script src="scripts/Cursor.js"></script>
<script src="scripts/objects/EObject.js"></script>
<script src="scripts/objects/Rectangle.js"></script>
......
......@@ -6,6 +6,8 @@
this._lastView;
this._currentView;
this.cursor = new Cursor();
// logic
this.logic = new Logic();
......
class Cursor {
constructor() {
this.position = Vector2.zero;
this.range = 10;
}
get currentPosition() {
return GridManager.grid.getNearestPointFor(this.position);
}
}
\ No newline at end of file
......@@ -357,17 +357,17 @@
if (e.shiftKey) {
let step = 1;
if (e.deltaX < 0)
cursorRange += step;
Application.cursor.range += step;
else if (e.deltaX > 0)
cursorRange = Math.max(cursorRange - step, 1);
Application.cursor.range = Math.max(Application.cursor.range - step, 1);
}
if (this.logic.currentState instanceof BrushSelectionState) {
let step = 0.2;
if (e.deltaY < 0)
cursorRange *= 1 + step;
Application.cursor.range *= 1 + step;
else if (e.deltaY > 0)
cursorRange *= 1 - step;
//cursorRange = Math.max(cursorRange - step, 1);
Application.cursor.range *= 1 - step;
//Application.cursor.range = Math.max(Application.cursor.range - step, 1);
}
else if (!e.shiftKey && !e.ctrlKey) {
if (e.deltaY < 0) // upscroll
......@@ -659,12 +659,12 @@
if (Preferences.selectVertices && Preferences.selectEdges) {
let s, e, m, _m;
for (let line of lines) {
s = Utilities.pointWithinCircle(line.start, mousePosition, cursorRange);
e = Utilities.pointWithinCircle(line.end, mousePosition, cursorRange);
s = Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range);
e = Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range);
_m = line.start.position.addVector(line.end.position);
_m = _m.divide(2);
_m = new LineEnding(_m.x, _m.y, line);
m = Utilities.pointWithinCircle(_m, mousePosition, cursorRange);
m = Utilities.pointWithinCircle(_m, mousePosition, Application.cursor.range);
if (s && !m && !e)
pointsToChangeSelection.push(line.start);
......@@ -673,10 +673,10 @@
else if (m) { // if one line ending and the middle of the line is within cursor range select whole line. otherwise weird selection happens when whole line is inside cursor range
pointsToChangeSelection.push(line.start);
pointsToChangeSelection.push(line.end);
} else if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange + (line.thickness * 0.5)) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange * 3))
} else if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range + (line.thickness * 0.5)) {
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range * 3))
pointsToChangeSelection.push(line.start);
else if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange * 3))
else if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range * 3))
pointsToChangeSelection.push(line.end);
else {
pointsToChangeSelection.push(line.start);
......@@ -698,14 +698,14 @@
// */
} else if (Preferences.selectEdges) {
for (let i = 0; i < lines.length; i++) {
if (Utilities.distancePointToLine(mousePosition, lines[i]) <= cursorRange) {
if (Utilities.distancePointToLine(mousePosition, lines[i]) <= Application.cursor.range) {
pointsToChangeSelection.push(lines[i].start);
pointsToChangeSelection.push(lines[i].end);
}
}
} else if (Preferences.selectVertices) {
for (let p of Utilities.linesToLineEndings(lines)) {
if (Utilities.pointWithinCircle(p, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(p, mousePosition, Application.cursor.range))
pointsToChangeSelection.push(p);
}
}
......
......@@ -14,7 +14,7 @@
selectionHit() {
for (let line of this.getAsLines())
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange)
if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range)
return true;
for (let instance of this.reference.data.instances)
......@@ -23,7 +23,7 @@
line.start.position = this.objectSpaceForPosition(line.start.position);
line.end.position = this.objectSpaceForPosition(line.end.position);
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange)
if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range)
return true;
}
}
......
......@@ -8,7 +8,6 @@ let toolbar;
var currentPosition = new Vector2(0, 0);
let mousePosition = new Vector2(0, 0);
let cursorRange = 9;
let currentLineThickness = 1;
let currentLineColor = Color.black();
......
......@@ -633,16 +633,16 @@
return;
if (this.view.logic.currentState instanceof MeasureState) {
let size = cursorRange * Math.PI * 2 / 6 * this.view.camera.zoom;
let size = Application.cursor.range * Math.PI * 2 / 6 * this.view.camera.zoom;
this.view.context.setLineDash([size, size]);
}
this.drawRealCircle(currentPosition, currentLineThickness * 0.5, 1, currentLineColor.toString(), false, true, true);
this.drawRealCircle(mousePosition, cursorRange, 2, Settings.selectionColor, false, true);
this.drawRealCircle(mousePosition, Application.cursor.range, 2, Settings.selectionColor, false, true);
if (this.view.logic.currentState instanceof BrushSelectionState)
this.drawRealCircle(mousePosition, cursorRange, 2, Settings.boxSelectionColor, false, true, true);
this.drawRealCircle(mousePosition, Application.cursor.range, 2, Settings.boxSelectionColor, false, true, true);
else if (this.view.logic.currentState instanceof MeasureState)
this.view.context.setLineDash([]);
......
......@@ -150,16 +150,16 @@
selectionHit() {
for (let line of this.data.lines)
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange)
if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range)
return true;
for (let p of this.data.points)
if (Utilities.pointWithinCircle(p, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(p, mousePosition, Application.cursor.range))
return true;
for (let instance of this.data.instances)
for (let line of instance.getAsLines())
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange)
if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range)
return true;
return false;
......
class BrushSelectionState extends State {
enter() {
this.cursorRange = cursorRange;
this.cursorRange = Application.cursor.range;
}
exit() {
cursorRange = this.cursorRange;
Application.cursor.range = this.cursorRange;
}
update() {
......@@ -14,12 +14,12 @@
if (Preferences.selectVertices && Preferences.selectEdges) {
let s, e, m, _m;
for (let line of Application.currentView.data.lines.concat(Application.currentView.selection.data.partialLines)) {
s = Utilities.pointWithinCircle(line.start, mousePosition, cursorRange);
e = Utilities.pointWithinCircle(line.end, mousePosition, cursorRange);
s = Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range);
e = Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range);
_m = line.start.position.addVector(line.end.position);
_m = _m.divide(2);
_m = new LineEnding(_m.x, _m.y, line);
m = Utilities.pointWithinCircle(_m, mousePosition, cursorRange);
m = Utilities.pointWithinCircle(_m, mousePosition, Application.cursor.range);
if (s && !m && !e)
newSelPoints.push(line.start);
......@@ -28,10 +28,10 @@
else if (m) { // if one line ending and the middle of the line is within cursor range select whole line. otherwise weird selection happens when whole line is inside cursor range
newSelPoints.push(line.start);
newSelPoints.push(line.end);
} else if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange + (line.thickness * 0.5)) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange * 3))
} else if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range + (line.thickness * 0.5)) {
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range * 3))
newSelPoints.push(line.start);
else if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange * 3))
else if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range * 3))
newSelPoints.push(line.end);
else {
newSelPoints.push(line.start);
......@@ -41,22 +41,22 @@
}
} else if (Preferences.selectEdges) {
for (let line of Application.currentView.data.lines.concat(Application.currentView.selection.data.partialLines)) {
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange + (line.thickness * 0.5)) {
if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range + (line.thickness * 0.5)) {
newSelPoints.push(line.start);
newSelPoints.push(line.end);
}
}
} else if (Preferences.selectVertices) {
for (let line of Application.currentView.data.lines) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range))
newSelPoints.push(line.start);
if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range))
newSelPoints.push(line.end);
}
for (let line of Application.currentView.selection.data.partialLines) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range))
newSelPoints.push(line.start);
if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range))
newSelPoints.push(line.end);
}
}
......@@ -79,12 +79,12 @@
if (Preferences.selectVertices && Preferences.selectEdges) {
let s, e, m, _m;
for (let line of Application.currentView.selection.data.lines.concat(Application.currentView.selection.data.partialLines)) {
s = Utilities.pointWithinCircle(line.start, mousePosition, cursorRange);
e = Utilities.pointWithinCircle(line.end, mousePosition, cursorRange);
s = Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range);
e = Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range);
_m = line.start.position.addVector(line.end.position);
_m = _m.divide(2);
_m = new LineEnding(_m.x, _m.y, line);
m = Utilities.pointWithinCircle(_m, mousePosition, cursorRange);
m = Utilities.pointWithinCircle(_m, mousePosition, Application.cursor.range);
if (s && !m && !e)
newUnselPoints.push(line.start);
......@@ -93,10 +93,10 @@
else if (m) { // if one line ending and the middle of the line is within cursor range select whole line. otherwise weird selection happens when whole line is inside cursor range
newUnselPoints.push(line.start);
newUnselPoints.push(line.end);
} else if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange + (line.thickness * 0.5)) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange * 3))
} else if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range + (line.thickness * 0.5)) {
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range * 3))
newUnselPoints.push(line.start);
else if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange * 3))
else if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range * 3))
newUnselPoints.push(line.end);
else {
newUnselPoints.push(line.start);
......@@ -106,7 +106,7 @@
}
} else if (Preferences.selectEdges) {
for (let line of Application.currentView.selection.data.lines.concat(Application.currentView.selection.data.partialLines)) {
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange + (line.thickness * 0.5)) {
if (Utilities.distancePointToLine(mousePosition, line) <= Application.cursor.range + (line.thickness * 0.5)) {
newUnselPoints.push(line.start);
newUnselPoints.push(line.end);
}
......@@ -114,16 +114,16 @@
}
else if (Preferences.selectVertices) {
for (let line of Application.currentView.selection.data.lines) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range))
newUnselPoints.push(line.start);
if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range))
newUnselPoints.push(line.end);
}
for (let line of Application.currentView.selection.data.partialLines) {
if (Utilities.pointWithinCircle(line.start, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.start, mousePosition, Application.cursor.range))
newUnselPoints.push(line.start);
if (Utilities.pointWithinCircle(line.end, mousePosition, cursorRange))
if (Utilities.pointWithinCircle(line.end, mousePosition, Application.cursor.range))
newUnselPoints.push(line.end);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment