elementFinder -> elementGrabber

This commit is contained in:
abakkk 2020-06-18 00:57:54 +02:00
parent 22ffa69f68
commit a569eed459
1 changed files with 59 additions and 59 deletions

118
draw.js
View File

@ -157,9 +157,9 @@ var DrawingArea = new Lang.Class({
set currentTool(tool) { set currentTool(tool) {
this._currentTool = tool; this._currentTool = tool;
if (Object.values(Manipulations).indexOf(tool) != -1) if (Object.values(Manipulations).indexOf(tool) != -1)
this._startElementFinder(); this._startElementGrabber();
else else
this._stopElementFinder(); this._stopElementGrabber();
}, },
_redisplay: function() { _redisplay: function() {
@ -228,11 +228,11 @@ var DrawingArea = new Lang.Class({
this.elements[i].points[2] == this.elements[i].points[1] || this.elements[i].points[2] == this.elements[i].points[1] ||
this.elements[i].points[2] == this.elements[i].points[0]); this.elements[i].points[2] == this.elements[i].points[0]);
this.elements[i].buildCairo(cr, { showTextRectangle: this.transformingElement && this.transformingElement == this.elements[i], this.elements[i].buildCairo(cr, { showTextRectangle: this.grabbedElement && this.grabbedElement == this.elements[i],
drawTextRectangle: this.finderPoint ? true : false }); drawTextRectangle: this.grabPoint ? true : false });
if (this.finderPoint) if (this.grabPoint)
this._findTransformingElement(cr, this.elements[i]); this._searchElementToGrab(cr, this.elements[i]);
if (this.elements[i].fill && !isStraightLine) { if (this.elements[i].fill && !isStraightLine) {
cr.fillPreserve(); cr.fillPreserve();
@ -304,7 +304,7 @@ var DrawingArea = new Lang.Class({
if (button == 1) { if (button == 1) {
if (Object.values(Manipulations).indexOf(this.currentTool) != -1) { if (Object.values(Manipulations).indexOf(this.currentTool) != -1) {
if (this.transformingElement) if (this.grabbedElement)
this._startTransforming(x, y, controlPressed, shiftPressed); this._startTransforming(x, y, controlPressed, shiftPressed);
} else { } else {
this._startDrawing(x, y, shiftPressed); this._startDrawing(x, y, shiftPressed);
@ -409,21 +409,21 @@ var DrawingArea = new Lang.Class({
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
}, },
_findTransformingElement: function(cr, element) { _searchElementToGrab: function(cr, element) {
if (element.getContainsPoint(cr, this.finderPoint[0], this.finderPoint[1])) if (element.getContainsPoint(cr, this.grabPoint[0], this.grabPoint[1]))
this.transformingElement = element; this.grabbedElement = element;
else if (this.transformingElement == element) else if (this.grabbedElement == element)
this.transformingElement = null; this.grabbedElement = null;
if (element == this.elements[this.elements.length - 1]) if (element == this.elements[this.elements.length - 1])
// All elements have been tested, the winner is the last. // All elements have been tested, the winner is the last.
this.updatePointerCursor(); this.updatePointerCursor();
}, },
_startElementFinder: function() { _startElementGrabber: function() {
this.elementFinderHandler = this.connect('motion-event', (actor, event) => { this.elementGrabberHandler = this.connect('motion-event', (actor, event) => {
if (this.motionHandler || this.transformingElementLocked) { if (this.motionHandler || this.grabbedElementLocked) {
this.finderPoint = null; this.grabPoint = null;
return; return;
} }
@ -432,18 +432,18 @@ var DrawingArea = new Lang.Class({
if (!s) if (!s)
return; return;
this.finderPoint = [x, y]; this.grabPoint = [x, y];
this.transformingElement = null; this.grabbedElement = null;
// this._redisplay calls this._findTransformingElement. // this._redisplay calls this._searchElementToGrab.
this._redisplay(); this._redisplay();
}); });
}, },
_stopElementFinder: function() { _stopElementGrabber: function() {
if (this.elementFinderHandler) { if (this.elementGrabberHandler) {
this.disconnect(this.elementFinderHandler); this.disconnect(this.elementGrabberHandler);
this.finderPoint = null; this.grabPoint = null;
this.elementFinderHandler = null; this.elementGrabberHandler = null;
} }
}, },
@ -454,14 +454,14 @@ var DrawingArea = new Lang.Class({
return; return;
if (this.currentTool == Manipulations.MIRROR) { if (this.currentTool == Manipulations.MIRROR) {
this.transformingElementLocked = !this.transformingElementLocked; this.grabbedElementLocked = !this.grabbedElementLocked;
if (this.transformingElementLocked) { if (this.grabbedElementLocked) {
this.updatePointerCursor(); this.updatePointerCursor();
return; return;
} }
} }
this.finderPoint = null; this.grabPoint = null;
this.buttonReleasedHandler = this.connect('button-release-event', (actor, event) => { this.buttonReleasedHandler = this.connect('button-release-event', (actor, event) => {
this._stopTransforming(); this._stopTransforming();
@ -469,17 +469,17 @@ var DrawingArea = new Lang.Class({
if (duplicate) { if (duplicate) {
// deep cloning // deep cloning
let copy = new DrawingElement(JSON.parse(JSON.stringify(this.transformingElement))); let copy = new DrawingElement(JSON.parse(JSON.stringify(this.grabbedElement)));
this.elements.push(copy); this.elements.push(copy);
this.transformingElement = copy; this.grabbedElement = copy;
} }
if (this.currentTool == Manipulations.MOVE) if (this.currentTool == Manipulations.MOVE)
this.transformingElement.startTransformation(startX, startY, controlPressed ? Transformations.ROTATION : Transformations.TRANSLATION); this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.ROTATION : Transformations.TRANSLATION);
else if (this.currentTool == Manipulations.RESIZE) else if (this.currentTool == Manipulations.RESIZE)
this.transformingElement.startTransformation(startX, startY, controlPressed ? Transformations.SCALE_DIRECTIONAL : Transformations.SCALE_PRESERVE); this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.SCALE_DIRECTIONAL : Transformations.SCALE_PRESERVE);
else if (this.currentTool == Manipulations.MIRROR) { else if (this.currentTool == Manipulations.MIRROR) {
this.transformingElement.startTransformation(startX, startY, controlPressed ? Transformations.INVERSION : Transformations.REFLECTION); this.grabbedElement.startTransformation(startX, startY, controlPressed ? Transformations.INVERSION : Transformations.REFLECTION);
this._redisplay(); this._redisplay();
} }
@ -498,31 +498,31 @@ var DrawingArea = new Lang.Class({
}, },
_updateTransforming: function(x, y, controlPressed) { _updateTransforming: function(x, y, controlPressed) {
if (controlPressed && this.transformingElement.lastTransformation.type == Transformations.TRANSLATION) { if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.TRANSLATION) {
this.transformingElement.stopTransformation(); this.grabbedElement.stopTransformation();
this.transformingElement.startTransformation(x, y, Transformations.ROTATION); this.grabbedElement.startTransformation(x, y, Transformations.ROTATION);
} else if (!controlPressed && this.transformingElement.lastTransformation.type == Transformations.ROTATION) { } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.ROTATION) {
this.transformingElement.stopTransformation(); this.grabbedElement.stopTransformation();
this.transformingElement.startTransformation(x, y, Transformations.TRANSLATION); this.grabbedElement.startTransformation(x, y, Transformations.TRANSLATION);
} }
if (controlPressed && this.transformingElement.lastTransformation.type == Transformations.SCALE_PRESERVE) { if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.SCALE_PRESERVE) {
this.transformingElement.stopTransformation(); this.grabbedElement.stopTransformation();
this.transformingElement.startTransformation(x, y, Transformations.SCALE_DIRECTIONAL); this.grabbedElement.startTransformation(x, y, Transformations.SCALE_DIRECTIONAL);
} else if (!controlPressed && this.transformingElement.lastTransformation.type == Transformations.SCALE_DIRECTIONAL) { } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.SCALE_DIRECTIONAL) {
this.transformingElement.stopTransformation(); this.grabbedElement.stopTransformation();
this.transformingElement.startTransformation(x, y, Transformations.SCALE_PRESERVE); this.grabbedElement.startTransformation(x, y, Transformations.SCALE_PRESERVE);
} }
if (controlPressed && this.transformingElement.lastTransformation.type == Transformations.REFLECTION) { if (controlPressed && this.grabbedElement.lastTransformation.type == Transformations.REFLECTION) {
this.transformingElement.transformations.pop(); this.grabbedElement.transformations.pop();
this.transformingElement.startTransformation(x, y, Transformations.INVERSION); this.grabbedElement.startTransformation(x, y, Transformations.INVERSION);
} else if (!controlPressed && this.transformingElement.lastTransformation.type == Transformations.INVERSION) { } else if (!controlPressed && this.grabbedElement.lastTransformation.type == Transformations.INVERSION) {
this.transformingElement.transformations.pop(); this.grabbedElement.transformations.pop();
this.transformingElement.startTransformation(x, y, Transformations.REFLECTION); this.grabbedElement.startTransformation(x, y, Transformations.REFLECTION);
} }
this.transformingElement.updateTransformation(x, y); this.grabbedElement.updateTransformation(x, y);
this._redisplay(); this._redisplay();
}, },
@ -536,9 +536,9 @@ var DrawingArea = new Lang.Class({
this.buttonReleasedHandler = null; this.buttonReleasedHandler = null;
} }
this.transformingElement.stopTransformation(); this.grabbedElement.stopTransformation();
this.transformingElement = null; this.grabbedElement = null;
this.transformingElementLocked = false; this.grabbedElementLocked = false;
this._redisplay(); this._redisplay();
}, },
@ -671,10 +671,10 @@ var DrawingArea = new Lang.Class({
}, },
updatePointerCursor: function(controlPressed) { updatePointerCursor: function(controlPressed) {
if (this.currentTool == Manipulations.MIRROR && this.transformingElementLocked) if (this.currentTool == Manipulations.MIRROR && this.grabbedElementLocked)
this.setPointerCursor('CROSSHAIR'); this.setPointerCursor('CROSSHAIR');
else if (Object.values(Manipulations).indexOf(this.currentTool) != -1) else if (Object.values(Manipulations).indexOf(this.currentTool) != -1)
this.setPointerCursor(this.transformingElement ? 'MOVE_OR_RESIZE_WINDOW' : 'DEFAULT'); this.setPointerCursor(this.grabbedElement ? 'MOVE_OR_RESIZE_WINDOW' : 'DEFAULT');
else if (!this.currentElement || (this.currentElement.shape == Shapes.TEXT && this.currentElement.textState == TextStates.WRITING)) else if (!this.currentElement || (this.currentElement.shape == Shapes.TEXT && this.currentElement.textState == TextStates.WRITING))
this.setPointerCursor(this.currentTool == Shapes.NONE ? 'POINTING_HAND' : 'CROSSHAIR'); this.setPointerCursor(this.currentTool == Shapes.NONE ? 'POINTING_HAND' : 'CROSSHAIR');
else if (this.currentElement.shape != Shapes.NONE && controlPressed) else if (this.currentElement.shape != Shapes.NONE && controlPressed)
@ -889,9 +889,9 @@ var DrawingArea = new Lang.Class({
this.disconnect(this._onKeyboardPopupMenuHandler); this.disconnect(this._onKeyboardPopupMenuHandler);
this._onKeyboardPopupMenuHandler = null; this._onKeyboardPopupMenuHandler = null;
} }
if (this.elementFinderHandler) { if (this.elementGrabberHandler) {
this.disconnect(this.elementFinderHandler); this.disconnect(this.elementGrabberHandler);
this.elementFinderHandler = null; this.elementGrabberHandler = null;
} }
if (this.motionHandler) { if (this.motionHandler) {
this.disconnect(this.motionHandler); this.disconnect(this.motionHandler);