mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 23:39:59 -05:00
Further simplify and compress code.
This commit is contained in:
parent
f71967f3d3
commit
c6d96784ba
1 changed files with 28 additions and 34 deletions
|
@ -144,46 +144,40 @@ var Segment = this.Segment = Base.extend({
|
||||||
var selected = !!selected, // convert to boolean
|
var selected = !!selected, // convert to boolean
|
||||||
state = this._selectionState,
|
state = this._selectionState,
|
||||||
wasSelected = !!state,
|
wasSelected = !!state,
|
||||||
pointSelected = !!(state & SelectionState.POINT),
|
// For performance reasons use array indices to access the various
|
||||||
handleInSelected = !!(state & SelectionState.HANDLE_IN),
|
// selection states: 0 = point, 1 = handleIn, 2 = handleOut
|
||||||
handleOutSelected = !!(state & SelectionState.HANDLE_OUT);
|
selection = [
|
||||||
|
!!(state & SelectionState.POINT),
|
||||||
|
!!(state & SelectionState.HANDLE_IN),
|
||||||
|
!!(state & SelectionState.HANDLE_OUT)
|
||||||
|
];
|
||||||
if (point == this._point) {
|
if (point == this._point) {
|
||||||
if (pointSelected != selected) {
|
if (selected) {
|
||||||
if (selected) {
|
// We're selecting point, deselect the handles
|
||||||
handleInSelected = handleOutSelected = false;
|
selection[1] = selection[2] = false;
|
||||||
} else {
|
} else {
|
||||||
var previous = this.getPrevious(),
|
var previous = this.getPrevious(),
|
||||||
next = this.getNext();
|
next = this.getNext();
|
||||||
// When deselecting a point, the handles get selected
|
// When deselecting a point, the handles get selected instead
|
||||||
// instead depending on the selection state of their
|
// depending on the selection state of their neighbors.
|
||||||
// neighbors.
|
selection[1] = previous && (previous._point.isSelected()
|
||||||
handleInSelected = previous
|
|| previous._handleOut.isSelected());
|
||||||
&& (previous._point.isSelected()
|
selection[2] = next && (next._point.isSelected()
|
||||||
|| previous._handleOut.isSelected());
|
|| next._handleIn.isSelected());
|
||||||
handleOutSelected = next
|
|
||||||
&& (next._point.isSelected()
|
|
||||||
|| next._handleOut.isSelected());
|
|
||||||
}
|
|
||||||
pointSelected = selected;
|
|
||||||
}
|
}
|
||||||
} else if (point == this._handleIn) {
|
selection[0] = selected;
|
||||||
if (handleInSelected != selected) {
|
} else {
|
||||||
|
var index = point == this._handleIn ? 1 : 2;
|
||||||
|
if (selection[index] != selected) {
|
||||||
// When selecting handles, the point get deselected.
|
// When selecting handles, the point get deselected.
|
||||||
if (selected)
|
if (selected)
|
||||||
pointSelected = false;
|
selection[0] = false;
|
||||||
handleInSelected = selected;
|
selection[index] = selected;
|
||||||
}
|
|
||||||
} else if (point == this._handleOut) {
|
|
||||||
if (handleOutSelected != selected) {
|
|
||||||
// When selecting handles, the point get deselected.
|
|
||||||
if (selected)
|
|
||||||
pointSelected = false;
|
|
||||||
handleOutSelected = selected;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._selectionState = (pointSelected ? SelectionState.POINT : 0)
|
this._selectionState = (selection[0] ? SelectionState.POINT : 0)
|
||||||
| (handleInSelected ? SelectionState.HANDLE_IN : 0)
|
| (selection[1] ? SelectionState.HANDLE_IN : 0)
|
||||||
| (handleOutSelected ? SelectionState.HANDLE_OUT : 0);
|
| (selection[2] ? SelectionState.HANDLE_OUT : 0);
|
||||||
// If the selection state of the segment has changed, we need to let
|
// If the selection state of the segment has changed, we need to let
|
||||||
// it's path know and possibly add or remove it from
|
// it's path know and possibly add or remove it from
|
||||||
// document._selectedItems
|
// document._selectedItems
|
||||||
|
|
Loading…
Reference in a new issue