Seperate the private Segment#is/setSelected(point) methods from the newly added getter / setter.

This commit is contained in:
Jürg Lehni 2011-04-27 12:15:51 +01:00
parent 6204eef643
commit 92369bf14f
2 changed files with 23 additions and 26 deletions

View file

@ -125,11 +125,10 @@ var Segment = this.Segment = Base.extend({
return this._path && this._path._segments[this.getIndex() - 1] || null; return this._path && this._path._segments[this.getIndex() - 1] || null;
}, },
isSelected: function(/* point */) { _isSelected: function(point) {
var point = arguments.length ? arguments[0] : this._point;
var state = this._selectionState; var state = this._selectionState;
if (point == this._point) { if (point == this._point) {
return state == SelectionState.POINT; return !!(state & SelectionState.POINT);
} else if (point == this._handleIn) { } else if (point == this._handleIn) {
return !!(state & SelectionState.HANDLE_IN); return !!(state & SelectionState.HANDLE_IN);
} else if (point == this._handleOut) { } else if (point == this._handleOut) {
@ -138,23 +137,13 @@ var Segment = this.Segment = Base.extend({
return false; return false;
}, },
// TODO: Port setSelected(selected) back to Scriptographer _setSelected: function(point, selected) {
setSelected: function(/* point, selected */) {
var point, selected;
if (arguments.length == 2) {
// setSelected(point, selected)
point = arguments[0];
selected = !!arguments[1];
} else {
// setSelected(selected)
point = this._point;
selected = !!arguments[0];
}
if (!this._path) if (!this._path)
return; return;
var wasSelected = !!this._selectionState; var selected = !!selected, // convert to boolean
var state = this._selectionState, state = this._selectionState,
pointSelected = state == SelectionState.POINT, wasSelected = !!state,
pointSelected = !!(state & SelectionState.POINT);
handleInSelected = !!(state & SelectionState.HANDLE_IN); handleInSelected = !!(state & SelectionState.HANDLE_IN);
handleOutSelected = !!(state & SelectionState.HANDLE_OUT); handleOutSelected = !!(state & SelectionState.HANDLE_OUT);
previous = this.getPrevious(), previous = this.getPrevious(),
@ -180,8 +169,8 @@ var Segment = this.Segment = Base.extend({
&& (previous._point.isSelected() && (previous._point.isSelected()
|| previous._handleOut.isSelected()); || previous._handleOut.isSelected());
handleOutSelected = next != null handleOutSelected = next != null
&& (next._point.isSelected() && (next._point.isSelected()
|| next._handleOut.isSelected()); || next._handleOut.isSelected());
} }
pointSelected = selected; pointSelected = selected;
} }
@ -200,10 +189,9 @@ var Segment = this.Segment = Base.extend({
handleOutSelected = selected; handleOutSelected = selected;
} }
} }
this._selectionState = this._selectionState = (pointSelected ? SelectionState.POINT : 0)
(pointSelected ? SelectionState.POINT : 0) | (handleInSelected ? SelectionState.HANDLE_IN : 0)
| (handleInSelected ? SelectionState.HANDLE_IN : 0) | (handleOutSelected ? SelectionState.HANDLE_OUT : 0);
| (handleOutSelected ? 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
@ -222,6 +210,15 @@ var Segment = this.Segment = Base.extend({
} }
}, },
// TODO: Port setSelected(selected) back to Scriptographer
isSelected: function() {
return this._isSelected(this._point);
},
setSelected: function(selected) {
this._setSelected(this._point, selected);
},
reverse: function() { reverse: function() {
return new Segment(this._point, this._handleOut, this._handleIn); return new Segment(this._point, this._handleOut, this._handleIn);
}, },

View file

@ -31,11 +31,11 @@ var SegmentPoint = Point.extend({
}, },
setSelected: function(selected) { setSelected: function(selected) {
this._segment.setSelected(this, selected); this._segment._setSelected(this, selected);
}, },
isSelected: function() { isSelected: function() {
return this._segment.isSelected(this); return this._segment._isSelected(this);
}, },
statics: { statics: {