mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Merge pull request #256 from nathan/add-costume-offset
Fixed costume center when importing costumes from the library
This commit is contained in:
commit
2e305c1112
3 changed files with 11 additions and 13 deletions
|
@ -190,8 +190,8 @@ public class BitmapEdit extends ImageEdit {
|
||||||
var el:SVGElement = SVGElement.makeBitmapEl(c.bitmapForEditor(isScene), 0.5);
|
var el:SVGElement = SVGElement.makeBitmapEl(c.bitmapForEditor(isScene), 0.5);
|
||||||
var sel:SVGBitmap = new SVGBitmap(el, el.bitmap);
|
var sel:SVGBitmap = new SVGBitmap(el, el.bitmap);
|
||||||
sel.redraw();
|
sel.redraw();
|
||||||
sel.x = destP.x;
|
sel.x = destP.x - c.width() / 2;
|
||||||
sel.y = destP.y;
|
sel.y = destP.y - c.height() / 2;
|
||||||
workArea.getContentLayer().addChild(sel);
|
workArea.getContentLayer().addChild(sel);
|
||||||
|
|
||||||
setToolMode('bitmapSelect');
|
setToolMode('bitmapSelect');
|
||||||
|
|
|
@ -271,7 +271,7 @@ package svgeditor {
|
||||||
workArea.clearContent();
|
workArea.clearContent();
|
||||||
|
|
||||||
if (c.isBitmap()) {
|
if (c.isBitmap()) {
|
||||||
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, true);
|
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, true, targetCostume.rotationCenterX, targetCostume.rotationCenterY);
|
||||||
insertOldTextLayer();
|
insertOldTextLayer();
|
||||||
} else {
|
} else {
|
||||||
if (targetCostume.undoList.length == 0) recordForUndo(c.baseLayerData, c.rotationCenterX, c.rotationCenterY);
|
if (targetCostume.undoList.length == 0) recordForUndo(c.baseLayerData, c.rotationCenterX, c.rotationCenterY);
|
||||||
|
@ -285,21 +285,19 @@ package svgeditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function addCostume(c:ScratchCostume, destP:Point):void {
|
override public function addCostume(c:ScratchCostume, destP:Point):void {
|
||||||
|
var p:Point = new Point(ImageCanvas.canvasWidth / 2, ImageCanvas.canvasHeight / 2);
|
||||||
|
p = p.subtract(destP);
|
||||||
|
p = p.add(new Point(c.rotationCenterX, c.rotationCenterY));
|
||||||
if (c.isBitmap()) {
|
if (c.isBitmap()) {
|
||||||
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, false);
|
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, false, p.x, p.y);
|
||||||
insertOldTextLayer();
|
insertOldTextLayer();
|
||||||
} else {
|
} else {
|
||||||
var p:Point = new Point(ImageCanvas.canvasWidth / 2, ImageCanvas.canvasHeight / 2);
|
|
||||||
p = p.subtract(destP);
|
|
||||||
// TODO: Can we place the loaded SVG better? (Use the actual center instead of the rotation center)
|
|
||||||
//p = p.add(new Point(c.width()/2, c.height()/2));
|
|
||||||
p = p.add(new Point(c.rotationCenterX, c.rotationCenterY));
|
|
||||||
installSVGData(c.baseLayerData, Math.round(p.x), Math.round(p.y), true);
|
installSVGData(c.baseLayerData, Math.round(p.x), Math.round(p.y), true);
|
||||||
}
|
}
|
||||||
saveContent();
|
saveContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function insertBitmap(bm:BitmapData, name:String, isLoad:Boolean):void {
|
private function insertBitmap(bm:BitmapData, name:String, isLoad:Boolean, destX:Number, destY:Number):void {
|
||||||
// Insert the given bitmap.
|
// Insert the given bitmap.
|
||||||
if (!bm.transparent) { // convert to a 32-bit bitmap to support alpha (e.g. eraser tool)
|
if (!bm.transparent) { // convert to a 32-bit bitmap to support alpha (e.g. eraser tool)
|
||||||
var newBM:BitmapData = new BitmapData(bm.width, bm.height, true, 0);
|
var newBM:BitmapData = new BitmapData(bm.width, bm.height, true, 0);
|
||||||
|
@ -314,8 +312,8 @@ package svgeditor {
|
||||||
imgEl.setAttribute('width', bm.width);
|
imgEl.setAttribute('width', bm.width);
|
||||||
imgEl.setAttribute('height', bm.height);
|
imgEl.setAttribute('height', bm.height);
|
||||||
if (!isScene) {
|
if (!isScene) {
|
||||||
var xOffset:int = Math.ceil((ImageCanvas.canvasWidth / 2) - targetCostume.rotationCenterX);
|
var xOffset:int = Math.ceil(ImageCanvas.canvasWidth / 2 - destX);
|
||||||
var yOffset:int = Math.ceil((ImageCanvas.canvasHeight / 2) - targetCostume.rotationCenterY);
|
var yOffset:int = Math.ceil(ImageCanvas.canvasHeight / 2 - destY);
|
||||||
imgEl.transform = new Matrix();
|
imgEl.transform = new Matrix();
|
||||||
imgEl.transform.translate(xOffset, yOffset);
|
imgEl.transform.translate(xOffset, yOffset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,7 +357,7 @@ public class ImagesPart extends UIPart {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addCostume(c:ScratchCostume):void {
|
private function addCostume(c:ScratchCostume):void {
|
||||||
var p:Point = new Point(240 - (c.width() / 2), 180 - (c.height() / 2));
|
var p:Point = new Point(240, 180);
|
||||||
editor.addCostume(c, p);
|
editor.addCostume(c, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue