From 0d987273280f29d1093c368439369fa4d0d3ef3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 24 Feb 2013 15:53:37 -0800 Subject: [PATCH] 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; --- src/item/Item.js | 5 +---- src/item/PlacedSymbol.js | 7 +------ src/item/Raster.js | 6 +----- src/project/Project.js | 8 +++++--- src/text/PointText.js | 7 ------- src/text/TextItem.js | 1 + 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 9ca4e3d8..70e5de93 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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); diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 0e825de5..bf93a143 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -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() }); diff --git a/src/item/Raster.js b/src/item/Raster.js index fc36d281..c9b77085 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -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); } }); diff --git a/src/project/Project.js b/src/project/Project.js index 10de3d3c..96b4c8db 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -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(); diff --git a/src/text/PointText.js b/src/text/PointText.js index 75e4ea1b..42d27f9f 100644 --- a/src/text/PointText.js +++ b/src/text/PointText.js @@ -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; diff --git a/src/text/TextItem.js b/src/text/TextItem.js index 525e9078..44cc25b6 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -22,6 +22,7 @@ * @extends Item */ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{ + _boundsSelected: true, _serializeFields: { content: null },