Merge pull request #256 from nathan/add-costume-offset

Fixed costume center when importing costumes from the library
This commit is contained in:
Nathan Dinsmore 2014-06-30 11:01:09 -04:00
commit 2e305c1112
3 changed files with 11 additions and 13 deletions

View file

@ -190,8 +190,8 @@ public class BitmapEdit extends ImageEdit {
var el:SVGElement = SVGElement.makeBitmapEl(c.bitmapForEditor(isScene), 0.5);
var sel:SVGBitmap = new SVGBitmap(el, el.bitmap);
sel.redraw();
sel.x = destP.x;
sel.y = destP.y;
sel.x = destP.x - c.width() / 2;
sel.y = destP.y - c.height() / 2;
workArea.getContentLayer().addChild(sel);
setToolMode('bitmapSelect');

View file

@ -271,7 +271,7 @@ package svgeditor {
workArea.clearContent();
if (c.isBitmap()) {
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, true);
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, true, targetCostume.rotationCenterX, targetCostume.rotationCenterY);
insertOldTextLayer();
} else {
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 {
if (c.isBitmap()) {
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, false);
insertOldTextLayer();
} 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));
if (c.isBitmap()) {
insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, false, p.x, p.y);
insertOldTextLayer();
} else {
installSVGData(c.baseLayerData, Math.round(p.x), Math.round(p.y), true);
}
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.
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);
@ -314,8 +312,8 @@ package svgeditor {
imgEl.setAttribute('width', bm.width);
imgEl.setAttribute('height', bm.height);
if (!isScene) {
var xOffset:int = Math.ceil((ImageCanvas.canvasWidth / 2) - targetCostume.rotationCenterX);
var yOffset:int = Math.ceil((ImageCanvas.canvasHeight / 2) - targetCostume.rotationCenterY);
var xOffset:int = Math.ceil(ImageCanvas.canvasWidth / 2 - destX);
var yOffset:int = Math.ceil(ImageCanvas.canvasHeight / 2 - destY);
imgEl.transform = new Matrix();
imgEl.transform.translate(xOffset, yOffset);
}

View file

@ -357,7 +357,7 @@ public class ImagesPart extends UIPart {
}
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);
}