mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
More clean-up of selection handling refactoring.
This commit is contained in:
parent
336bc1092e
commit
00b2102b6d
5 changed files with 32 additions and 21 deletions
|
@ -784,11 +784,19 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
/**
|
||||
* This property is only present if the point is an anchor or control point
|
||||
* of a {@link Segment} or a {@link Curve}. In this case, it returns
|
||||
* {@true it is selected}
|
||||
* {@true if it is selected}
|
||||
*
|
||||
* @name Point#selected
|
||||
* @property
|
||||
* @return {Boolean} {@true if the point is selected}
|
||||
*
|
||||
* @example {@paperscript}
|
||||
* var path = new Path.Circle({
|
||||
* center: [80, 50],
|
||||
* radius: 40
|
||||
* });
|
||||
*
|
||||
* // Select the third segment point:
|
||||
* path.segments[2].point.selected = true;
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -1887,7 +1887,7 @@ new function() { // Injection scope for hit-test functions shared with project
|
|||
// See if we should check self (own content), by filtering for type,
|
||||
// guides and selected items if that's required.
|
||||
var checkSelf = !(options.guides && !this._guide
|
||||
|| options.selected && !this.isSelected(true)
|
||||
|| options.selected && !this.isSelected()
|
||||
// Support legacy Item#type property to match hyphenated
|
||||
// class-names.
|
||||
|| options.type && options.type !== Base.hyphenate(this._class)
|
||||
|
|
|
@ -935,7 +935,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
*/
|
||||
isFullySelected: function() {
|
||||
var length = this._segments.length;
|
||||
return this.isSelected(true) && length > 0 && this._segmentSelection
|
||||
return this.isSelected() && length > 0 && this._segmentSelection
|
||||
=== length * /*#=*/SegmentSelection.ALL;
|
||||
},
|
||||
|
||||
|
|
|
@ -282,16 +282,13 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
}
|
||||
},
|
||||
|
||||
_getSelection: function(point) {
|
||||
return !point ? /*#=*/SegmentSelection.ALL
|
||||
: point === this._point ? /*#=*/SegmentSelection.POINT
|
||||
: point === this._handleIn ? /*#=*/SegmentSelection.HANDLE_IN
|
||||
: point === this._handleOut ? /*#=*/SegmentSelection.HANDLE_OUT
|
||||
: 0;
|
||||
changeSelection: function(flag, selected) {
|
||||
var selection = this._selection;
|
||||
this.setSelection(selected ? selection | flag : selection & ~flag);
|
||||
},
|
||||
|
||||
/**
|
||||
* Specifies whether the {@link #point} of the segment is selected.
|
||||
* Specifies whether the segment is selected.
|
||||
*
|
||||
* @bean
|
||||
* @type Boolean
|
||||
|
@ -305,14 +302,12 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
* // Select the third segment point:
|
||||
* path.segments[2].selected = true;
|
||||
*/
|
||||
isSelected: function(_point) {
|
||||
return !!(this._selection & this._getSelection(_point));
|
||||
isSelected: function() {
|
||||
return !!(this._selection & /*#=*/SegmentSelection.ALL);
|
||||
},
|
||||
|
||||
setSelected: function(selected, _point) {
|
||||
var selection = this._selection,
|
||||
flag = this._getSelection(_point);
|
||||
this.setSelection(selected ? selection | flag : selection & ~flag);
|
||||
setSelected: function(selected) {
|
||||
this.changeSelection(/*#=*/SegmentSelection.ALL, selected);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,11 +78,19 @@ var SegmentPoint = Point.extend({
|
|||
return Numerical.isZero(this._x) && Numerical.isZero(this._y);
|
||||
},
|
||||
|
||||
setSelected: function(selected) {
|
||||
this._owner.setSelected(selected, this);
|
||||
isSelected: function() {
|
||||
return !!(this._owner._selection & this._getSelection());
|
||||
},
|
||||
|
||||
isSelected: function() {
|
||||
return this._owner.isSelected(this);
|
||||
setSelected: function(selected) {
|
||||
this._owner.changeSelection(this._getSelection(), selected);
|
||||
},
|
||||
|
||||
_getSelection: function() {
|
||||
var owner = this._owner;
|
||||
return this === owner._point ? /*#=*/SegmentSelection.POINT
|
||||
: this === owner._handleIn ? /*#=*/SegmentSelection.HANDLE_IN
|
||||
: this === owner._handleOut ? /*#=*/SegmentSelection.HANDLE_OUT
|
||||
: 0;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue