More clean-up of selection handling refactoring.

This commit is contained in:
Jürg Lehni 2016-03-17 13:36:02 +01:00
parent 336bc1092e
commit 00b2102b6d
5 changed files with 32 additions and 21 deletions

View file

@ -784,11 +784,19 @@ var Point = Base.extend(/** @lends Point# */{
/** /**
* This property is only present if the point is an anchor or control 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 * 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 * @name Point#selected
* @property * @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;
*/ */
/** /**

View file

@ -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, // See if we should check self (own content), by filtering for type,
// guides and selected items if that's required. // guides and selected items if that's required.
var checkSelf = !(options.guides && !this._guide var checkSelf = !(options.guides && !this._guide
|| options.selected && !this.isSelected(true) || options.selected && !this.isSelected()
// Support legacy Item#type property to match hyphenated // Support legacy Item#type property to match hyphenated
// class-names. // class-names.
|| options.type && options.type !== Base.hyphenate(this._class) || options.type && options.type !== Base.hyphenate(this._class)

View file

@ -935,7 +935,7 @@ var Path = PathItem.extend(/** @lends Path# */{
*/ */
isFullySelected: function() { isFullySelected: function() {
var length = this._segments.length; var length = this._segments.length;
return this.isSelected(true) && length > 0 && this._segmentSelection return this.isSelected() && length > 0 && this._segmentSelection
=== length * /*#=*/SegmentSelection.ALL; === length * /*#=*/SegmentSelection.ALL;
}, },

View file

@ -282,16 +282,13 @@ var Segment = Base.extend(/** @lends Segment# */{
} }
}, },
_getSelection: function(point) { changeSelection: function(flag, selected) {
return !point ? /*#=*/SegmentSelection.ALL var selection = this._selection;
: point === this._point ? /*#=*/SegmentSelection.POINT this.setSelection(selected ? selection | flag : selection & ~flag);
: point === this._handleIn ? /*#=*/SegmentSelection.HANDLE_IN
: point === this._handleOut ? /*#=*/SegmentSelection.HANDLE_OUT
: 0;
}, },
/** /**
* Specifies whether the {@link #point} of the segment is selected. * Specifies whether the segment is selected.
* *
* @bean * @bean
* @type Boolean * @type Boolean
@ -305,14 +302,12 @@ var Segment = Base.extend(/** @lends Segment# */{
* // Select the third segment point: * // Select the third segment point:
* path.segments[2].selected = true; * path.segments[2].selected = true;
*/ */
isSelected: function(_point) { isSelected: function() {
return !!(this._selection & this._getSelection(_point)); return !!(this._selection & /*#=*/SegmentSelection.ALL);
}, },
setSelected: function(selected, _point) { setSelected: function(selected) {
var selection = this._selection, this.changeSelection(/*#=*/SegmentSelection.ALL, selected);
flag = this._getSelection(_point);
this.setSelection(selected ? selection | flag : selection & ~flag);
}, },
/** /**

View file

@ -78,11 +78,19 @@ var SegmentPoint = Point.extend({
return Numerical.isZero(this._x) && Numerical.isZero(this._y); return Numerical.isZero(this._x) && Numerical.isZero(this._y);
}, },
setSelected: function(selected) { isSelected: function() {
this._owner.setSelected(selected, this); return !!(this._owner._selection & this._getSelection());
}, },
isSelected: function() { setSelected: function(selected) {
return this._owner.isSelected(this); 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;
} }
}); });