mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
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:
parent
6b7c6b6c4c
commit
0d98727328
6 changed files with 9 additions and 25 deletions
|
@ -34,6 +34,7 @@ var Item = this.Item = Base.extend(Callback, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, /** @lends Item# */{
|
}, /** @lends Item# */{
|
||||||
|
_boundsSelected: false,
|
||||||
// Provide information about fields to be serialized, with their defaults
|
// Provide information about fields to be serialized, with their defaults
|
||||||
// that can be ommited.
|
// that can be ommited.
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
|
@ -2510,10 +2511,6 @@ var Item = this.Item = Base.extend(Callback, {
|
||||||
ctx.globalAlpha = this._opacity;
|
ctx.globalAlpha = this._opacity;
|
||||||
},
|
},
|
||||||
|
|
||||||
drawSelected: function(ctx, matrix) {
|
|
||||||
// Do nothing
|
|
||||||
},
|
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
drawSelectedBounds: function(bounds, ctx, matrix) {
|
drawSelectedBounds: function(bounds, ctx, matrix) {
|
||||||
var coords = matrix._transformCorners(bounds);
|
var coords = matrix._transformCorners(bounds);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
|
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
|
||||||
_type: 'placedsymbol',
|
_type: 'placedsymbol',
|
||||||
|
_boundsSelected: true,
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
symbol: null
|
symbol: null
|
||||||
},
|
},
|
||||||
|
@ -106,12 +107,6 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
||||||
|
|
||||||
draw: function(ctx, param) {
|
draw: function(ctx, param) {
|
||||||
Item.draw(this.symbol._definition, ctx, param);
|
Item.draw(this.symbol._definition, ctx, param);
|
||||||
},
|
|
||||||
|
|
||||||
drawSelected: function(ctx, matrix) {
|
|
||||||
Item.drawSelectedBounds(this.symbol._definition.getBounds(), ctx,
|
|
||||||
matrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: PlacedSymbol#embed()
|
// TODO: PlacedSymbol#embed()
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
_type: 'raster',
|
_type: 'raster',
|
||||||
|
_boundsSelected: true,
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
source: null
|
source: null
|
||||||
},
|
},
|
||||||
|
@ -486,10 +487,5 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
ctx.drawImage(element,
|
ctx.drawImage(element,
|
||||||
-this._size.width / 2, -this._size.height / 2);
|
-this._size.width / 2, -this._size.height / 2);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
drawSelected: function(ctx, matrix) {
|
|
||||||
Item.drawSelectedBounds(new Rectangle(this._size).setCenter(0, 0), ctx,
|
|
||||||
matrix);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -318,11 +318,13 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
ctx.strokeStyle = ctx.fillStyle = '#009dec';
|
ctx.strokeStyle = ctx.fillStyle = '#009dec';
|
||||||
for (var id in this._selectedItems) {
|
for (var id in this._selectedItems) {
|
||||||
var item = this._selectedItems[id];
|
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());
|
var mx = getGlobalMatrix(item, matrix.clone());
|
||||||
item.drawSelected(ctx, mx);
|
if (item.drawSelected)
|
||||||
|
item.drawSelected(ctx, mx);
|
||||||
if (item._boundsSelected)
|
if (item._boundsSelected)
|
||||||
Item.drawSelectedBounds(item.getBounds(), ctx, mx);
|
Item.drawSelectedBounds(item._getBounds(), ctx, mx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
|
|
@ -73,13 +73,6 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
|
||||||
ctx.strokeText(line, 0, 0);
|
ctx.strokeText(line, 0, 0);
|
||||||
ctx.translate(0, leading);
|
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() {
|
}, new function() {
|
||||||
var measureCtx = null;
|
var measureCtx = null;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
* @extends Item
|
* @extends Item
|
||||||
*/
|
*/
|
||||||
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
||||||
|
_boundsSelected: true,
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
content: null
|
content: null
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue