mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Rename Raster#getSubImage() to #getSubCanvas(), and use insert: false combined with #insertAbove() to correctly insert newly created rasters.
This commit is contained in:
parent
5981ddf89f
commit
cc565b3fe2
3 changed files with 15 additions and 7 deletions
|
@ -1307,9 +1307,13 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
matrix.applyToContext(ctx);
|
||||
// See Project#draw() for an explanation of Base.merge()
|
||||
this.draw(ctx, Base.merge({ transforms: [matrix] }));
|
||||
var raster = new Raster(canvas);
|
||||
raster.setPosition(topLeft.add(size.divide(2)));
|
||||
ctx.restore();
|
||||
var raster = new Raster({
|
||||
canvas: canvas,
|
||||
insert: false
|
||||
});
|
||||
raster.setPosition(topLeft.add(size.divide(2)));
|
||||
raster.insertAbove(this);
|
||||
// NOTE: We don't need to release the canvas since it now belongs to the
|
||||
// Raster!
|
||||
return raster;
|
||||
|
|
|
@ -244,7 +244,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
this._size = new Size(image.width, image.height);
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
this._changed(/*#=*/ Change.GEOMETRY | /*#=*/ Change.PIXELS);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -330,7 +330,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
*
|
||||
* @return {Canvas} the sub image as a Canvas object
|
||||
*/
|
||||
getSubImage: function(rect) {
|
||||
getSubCanvas: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var ctx = CanvasProvider.getContext(rect.getSize());
|
||||
ctx.drawImage(this.getCanvas(), rect.x, rect.y,
|
||||
|
@ -349,9 +349,13 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
*/
|
||||
getSubRaster: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var raster = new Raster(this.getSubImage(rect));
|
||||
var raster = new Raster({
|
||||
canvas: this.getSubCanvas(rect),
|
||||
insert: false
|
||||
});
|
||||
raster.translate(rect.getCenter().subtract(this.getSize().divide(2)));
|
||||
raster._matrix.preConcatenate(this._matrix);
|
||||
raster.insertAbove(this);
|
||||
return raster;
|
||||
},
|
||||
|
||||
|
|
|
@ -91,10 +91,10 @@ asyncTest('Raster#getPixel / setPixel', function(callback) {
|
|||
};
|
||||
});
|
||||
|
||||
asyncTest('Raster#getSubImage', function(callback) {
|
||||
asyncTest('Raster#getSubCanvas', function(callback) {
|
||||
var raster = new Raster('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABlJREFUeNpi+s/AwPCfgYmR4f9/hv8AAQYAHiAFAS8Lwy8AAAAASUVORK5CYII=');
|
||||
raster.onLoad = function() {
|
||||
var canvas = raster.getSubImage(new Rectangle({
|
||||
var canvas = raster.getSubCanvas(new Rectangle({
|
||||
point: [1, 0],
|
||||
size: [1, 2]
|
||||
}));
|
||||
|
|
Loading…
Reference in a new issue