Simplify drawing of seleced bounds by having Item#_boundsSelelected default to true for Raster, PlacedSymbol and TextItem.

One can now turn it off for these using item.bounds.selected = false;
This commit is contained in:
Jürg Lehni 2013-02-24 15:53:37 -08:00
parent 6b7c6b6c4c
commit 0d98727328
6 changed files with 9 additions and 25 deletions

View file

@ -34,6 +34,7 @@ var Item = this.Item = Base.extend(Callback, {
}
}
}, /** @lends Item# */{
_boundsSelected: false,
// Provide information about fields to be serialized, with their defaults
// that can be ommited.
_serializeFields: {
@ -2510,10 +2511,6 @@ var Item = this.Item = Base.extend(Callback, {
ctx.globalAlpha = this._opacity;
},
drawSelected: function(ctx, matrix) {
// Do nothing
},
statics: {
drawSelectedBounds: function(bounds, ctx, matrix) {
var coords = matrix._transformCorners(bounds);

View file

@ -20,6 +20,7 @@
*/
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
_type: 'placedsymbol',
_boundsSelected: true,
_serializeFields: {
symbol: null
},
@ -106,12 +107,6 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
draw: function(ctx, param) {
Item.draw(this.symbol._definition, ctx, param);
},
drawSelected: function(ctx, matrix) {
Item.drawSelectedBounds(this.symbol._definition.getBounds(), ctx,
matrix);
}
// TODO: PlacedSymbol#embed()
});

View file

@ -19,6 +19,7 @@
*/
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
_type: 'raster',
_boundsSelected: true,
_serializeFields: {
source: null
},
@ -486,10 +487,5 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
ctx.drawImage(element,
-this._size.width / 2, -this._size.height / 2);
}
},
drawSelected: function(ctx, matrix) {
Item.drawSelectedBounds(new Rectangle(this._size).setCenter(0, 0), ctx,
matrix);
}
});

View file

@ -318,11 +318,13 @@ 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) {
if (item._drawCount === this._drawCount
&& (item.drawSelected || item._boundsSelected)) {
var mx = getGlobalMatrix(item, matrix.clone());
item.drawSelected(ctx, mx);
if (item.drawSelected)
item.drawSelected(ctx, mx);
if (item._boundsSelected)
Item.drawSelectedBounds(item.getBounds(), ctx, mx);
Item.drawSelectedBounds(item._getBounds(), ctx, mx);
}
}
ctx.restore();

View file

@ -73,13 +73,6 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
ctx.strokeText(line, 0, 0);
ctx.translate(0, leading);
}
},
// TODO: Should we be drawing the selection like this? Perhaps a small
// rectangle for the starting point of the text and a colored line on
// the baseline for its width?
drawSelected: function(ctx, matrix) {
Item.drawSelectedBounds(this._getBounds(), ctx, matrix);
}
}, new function() {
var measureCtx = null;

View file

@ -22,6 +22,7 @@
* @extends Item
*/
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
_boundsSelected: true,
_serializeFields: {
content: null
},