Implement Item#bounds.selected to control drawing of selected item bounds.

This commit is contained in:
Jürg Lehni 2013-02-24 15:41:31 -08:00
parent a98e39374d
commit 6b7c6b6c4c
4 changed files with 35 additions and 8 deletions

View file

@ -829,6 +829,32 @@ var LinkedRectangle = Rectangle.extend({
this._owner[this._setter](this);
return this;
};
}, {})
}, {
/**
* Specifies whether an item's bounds are selected and will also
*
* Paper.js draws the visual bounds of selected items on top of your
* project. This can be useful for debugging.
*
* @type Boolean
* @default false
* @bean
*/
isSelected: function() {
return this._owner._boundsSelected;
},
setSelected: function(selected) {
var owner = this._owner;
if (owner.setSelected) {
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
// have to remain selected even when bounds are deselected
owner.setSelected(selected || owner._selectedSegmentState > 0);
}
}
})
);
});

View file

@ -475,7 +475,8 @@ var Item = this.Item = Base.extend(Callback, {
if (this._children && !arguments[1]) {
for (var i = 0, l = this._children.length; i < l; i++)
this._children[i].setSelected(selected);
} else if ((selected = !!selected) != this._selected) {
}
if ((selected = !!selected) != this._selected) {
this._selected = selected;
this._project._updateSelection(this);
this._changed(/*#=*/ Change.ATTRIBUTE);

View file

@ -1601,10 +1601,6 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
// Now stroke it and draw its handles:
ctx.stroke();
drawHandles(ctx, this._segments, matrix);
// If the path has no selected segments, draw its bounds too
if (this._selectedSegmentState == 0) {
Item.drawSelectedBounds(this.getBounds(), ctx, matrix);
}
}
};
}, new function() { // Path Smoothing

View file

@ -318,8 +318,12 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
ctx.strokeStyle = ctx.fillStyle = '#009dec';
for (var id in this._selectedItems) {
var item = this._selectedItems[id];
if (item._drawCount === this._drawCount)
item.drawSelected(ctx, getGlobalMatrix(item, matrix.clone()));
if (item._drawCount === this._drawCount) {
var mx = getGlobalMatrix(item, matrix.clone());
item.drawSelected(ctx, mx);
if (item._boundsSelected)
Item.drawSelectedBounds(item.getBounds(), ctx, mx);
}
}
ctx.restore();
}