mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Rename SegmentSelection related internal objects and properties.
Relates to #769, #980
This commit is contained in:
parent
08bf7bfe60
commit
1db419a87b
6 changed files with 54 additions and 51 deletions
|
@ -913,9 +913,9 @@ new function() {
|
|||
owner._boundsSelected = selected;
|
||||
// Update the owner's selected state too, so the bounds
|
||||
// actually get drawn. When deselecting, take a path's
|
||||
// _selectedSegmentState into account too, since it will
|
||||
// _segmentSelection into account too, since it will
|
||||
// have to remain selected even when bounds are deselected
|
||||
owner.setSelected(selected || owner._selectedSegmentState > 0);
|
||||
owner.setSelected(selected || owner._segmentSelection > 0);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*#*/ include('item/ChangeFlag.js');
|
||||
/*#*/ include('path/SelectionState.js');
|
||||
/*#*/ include('util/Numerical.js');
|
||||
/*#*/ include('item/ChangeFlag.js');
|
||||
/*#*/ include('path/SegmentSelection.js');
|
||||
|
|
|
@ -298,9 +298,12 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
var child = children[i],
|
||||
mx = child._matrix;
|
||||
if (!selectedItems[child._id])
|
||||
// Do not draw this child now if it's separately marked as selected,
|
||||
// as it would be drawn twice otherwise.
|
||||
if (!selectedItems[child._id]) {
|
||||
child._drawSelected(ctx, mx.isIdentity() ? matrix
|
||||
: matrix.appended(mx));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -111,11 +111,11 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
: null;
|
||||
// Always call setSegments() to initialize a few related variables.
|
||||
if (segments && segments.length > 0) {
|
||||
// This sets _curves and _selectedSegmentState too!
|
||||
// This sets _curves and _segmentSelection too!
|
||||
this.setSegments(segments);
|
||||
} else {
|
||||
this._curves = undefined; // For hidden class optimization
|
||||
this._selectedSegmentState = 0;
|
||||
this._segmentSelection = 0;
|
||||
if (!segments && typeof arg === 'string') {
|
||||
this.setPathData(arg);
|
||||
// Erase for _initialize() call below.
|
||||
|
@ -180,7 +180,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
setSegments: function(segments) {
|
||||
var fullySelected = this.isFullySelected();
|
||||
this._segments.length = 0;
|
||||
this._selectedSegmentState = 0;
|
||||
this._segmentSelection = 0;
|
||||
// Calculate new curves next time we call getCurves()
|
||||
this._curves = undefined;
|
||||
if (segments && segments.length > 0)
|
||||
|
@ -391,9 +391,9 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
segment._path = this;
|
||||
segment._index = index + i;
|
||||
// If parts of this segment are selected, adjust the internal
|
||||
// _selectedSegmentState now
|
||||
if (segment._selectionState)
|
||||
this._updateSelection(segment, 0, segment._selectionState);
|
||||
// _segmentSelection now
|
||||
if (segment._selection)
|
||||
this._updateSelection(segment, 0, segment._selection);
|
||||
}
|
||||
if (append) {
|
||||
// Append them all at the end by using push
|
||||
|
@ -732,8 +732,8 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// Update selection state accordingly
|
||||
for (var i = 0; i < amount; i++) {
|
||||
var segment = removed[i];
|
||||
if (segment._selectionState)
|
||||
this._updateSelection(segment, segment._selectionState, 0);
|
||||
if (segment._selection)
|
||||
this._updateSelection(segment, segment._selection, 0);
|
||||
// Clear the indices and path references of the removed segments
|
||||
segment._index = segment._path = null;
|
||||
}
|
||||
|
@ -935,8 +935,8 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
*/
|
||||
isFullySelected: function() {
|
||||
var length = this._segments.length;
|
||||
return this._selected && length > 0 && this._selectedSegmentState
|
||||
=== length * /*#=*/SelectionState.SEGMENT;
|
||||
return this._selected && length > 0 && this._segmentSelection
|
||||
=== length * /*#=*/SegmentSelection.SEGMENT;
|
||||
},
|
||||
|
||||
setFullySelected: function(selected) {
|
||||
|
@ -957,20 +957,21 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
|
||||
_selectSegments: function(selected) {
|
||||
var length = this._segments.length;
|
||||
this._selectedSegmentState = selected
|
||||
? length * /*#=*/SelectionState.SEGMENT : 0;
|
||||
for (var i = 0; i < length; i++)
|
||||
this._segments[i]._selectionState = selected
|
||||
? /*#=*/SelectionState.SEGMENT : 0;
|
||||
this._segmentSelection = selected
|
||||
? length * /*#=*/SegmentSelection.SEGMENT : 0;
|
||||
for (var i = 0; i < length; i++) {
|
||||
this._segments[i]._selection = selected
|
||||
? /*#=*/SegmentSelection.SEGMENT : 0;
|
||||
}
|
||||
},
|
||||
|
||||
_updateSelection: function(segment, oldState, newState) {
|
||||
segment._selectionState = newState;
|
||||
var total = this._selectedSegmentState += newState - oldState;
|
||||
_updateSelection: function(segment, oldSelection, newSelection) {
|
||||
segment._selection = newSelection;
|
||||
var selection = this._segmentSelection += newSelection - oldSelection;
|
||||
// Set this path as selected in case we have selected segments. Do not
|
||||
// unselect if we're down to 0, as the path itself can still remain
|
||||
// selected even when empty.
|
||||
if (total > 0)
|
||||
if (selection > 0)
|
||||
this.setSelected(true);
|
||||
},
|
||||
|
||||
|
@ -2051,18 +2052,18 @@ new function() { // Scope for drawing
|
|||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
var segment = segments[i];
|
||||
segment._transformCoordinates(matrix, coords);
|
||||
var state = segment._selectionState,
|
||||
var selection = segment._selection,
|
||||
pX = coords[0],
|
||||
pY = coords[1];
|
||||
if (state & /*#=*/SelectionState.HANDLE_IN)
|
||||
if (selection & /*#=*/SegmentSelection.HANDLE_IN)
|
||||
drawHandle(2);
|
||||
if (state & /*#=*/SelectionState.HANDLE_OUT)
|
||||
if (selection & /*#=*/SegmentSelection.HANDLE_OUT)
|
||||
drawHandle(4);
|
||||
// Draw a rectangle at segment.point:
|
||||
ctx.fillRect(pX - half, pY - half, size, size);
|
||||
// If the point is not selected, draw a white square that is 1 px
|
||||
// smaller on all sides:
|
||||
if (!(state & /*#=*/SelectionState.POINT)) {
|
||||
if (!(selection & /*#=*/SegmentSelection.POINT)) {
|
||||
var fillStyle = ctx.fillStyle;
|
||||
ctx.fillStyle = '#ffffff';
|
||||
ctx.fillRect(pX - half + 1, pY - half + 1, size - 2, size - 2);
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
var Segment = Base.extend(/** @lends Segment# */{
|
||||
_class: 'Segment',
|
||||
beans: true,
|
||||
// The selection state, a combination of SegmentSelection
|
||||
_selection: 0,
|
||||
|
||||
/**
|
||||
* Creates a new Segment object.
|
||||
|
@ -251,7 +253,13 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
this._handleOut.set(0, 0);
|
||||
},
|
||||
|
||||
_selectionState: 0,
|
||||
_getSelectionFlag: function(point) {
|
||||
return !point ? /*#=*/SegmentSelection.SEGMENT
|
||||
: point === this._point ? /*#=*/SegmentSelection.POINT
|
||||
: point === this._handleIn ? /*#=*/SegmentSelection.HANDLE_IN
|
||||
: point === this._handleOut ? /*#=*/SegmentSelection.HANDLE_OUT
|
||||
: 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Specifies whether the {@link #point} of the segment is selected.
|
||||
|
@ -269,38 +277,29 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
* path.segments[2].selected = true;
|
||||
*/
|
||||
isSelected: function(_point) {
|
||||
var state = this._selectionState;
|
||||
return !_point ? !!(state & /*#=*/SelectionState.SEGMENT)
|
||||
: _point === this._point ? !!(state & /*#=*/SelectionState.POINT)
|
||||
: _point === this._handleIn ? !!(state & /*#=*/SelectionState.HANDLE_IN)
|
||||
: _point === this._handleOut ? !!(state & /*#=*/SelectionState.HANDLE_OUT)
|
||||
: false;
|
||||
return !!(this._selection & this._getSelectionFlag(_point));
|
||||
},
|
||||
|
||||
setSelected: function(selected, _point) {
|
||||
var path = this._path,
|
||||
selected = !!selected, // convert to boolean
|
||||
state = this._selectionState,
|
||||
oldState = state,
|
||||
flag = !_point ? /*#=*/SelectionState.SEGMENT
|
||||
: _point === this._point ? /*#=*/SelectionState.POINT
|
||||
: _point === this._handleIn ? /*#=*/SelectionState.HANDLE_IN
|
||||
: _point === this._handleOut ? /*#=*/SelectionState.HANDLE_OUT
|
||||
: 0;
|
||||
selection = this._selection,
|
||||
oldSelection = selection,
|
||||
flag = this._getSelectionFlag(_point);
|
||||
if (selected) {
|
||||
state |= flag;
|
||||
selection |= flag;
|
||||
} else {
|
||||
state &= ~flag;
|
||||
selection &= ~flag;
|
||||
}
|
||||
// Set the selection state even if path is not defined yet, to allow
|
||||
// selected segments to be inserted into paths and make JSON
|
||||
// deserialization work.
|
||||
this._selectionState = state;
|
||||
this._selection = selection;
|
||||
// If the selection state of the segment has changed, we need to let
|
||||
// it's path know and possibly add or remove it from
|
||||
// project._selectedItems
|
||||
if (path && state !== oldState) {
|
||||
path._updateSelection(this, oldState, state);
|
||||
if (path && selection !== oldSelection) {
|
||||
path._updateSelection(this, oldSelection, selection);
|
||||
// Let path know that we changed something and the view should be
|
||||
// redrawn
|
||||
path._changed(/*#=*/Change.ATTRIBUTE);
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
* All rights reserved.
|
||||
*/
|
||||
|
||||
// Path#_selectedSegmentState is the addition of all segment's states, and is
|
||||
// compared with SelectionState.SEGMENT, the combination of all SelectionStates
|
||||
// to see if all segments are fully selected.
|
||||
var SelectionState = {
|
||||
// Path#_segmentSelection is the addition of all segment's states, and is
|
||||
// compared with SegmentSelection.SEGMENT, the combination of all
|
||||
// SegmentSelection values to see if all segments are fully selected.
|
||||
var SegmentSelection = {
|
||||
HANDLE_IN: 1,
|
||||
HANDLE_OUT: 2,
|
||||
POINT: 4,
|
Loading…
Reference in a new issue