From b420a6f05ee98a12ab1810f2379f0ebd94a19161 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Mon, 16 Jun 2014 10:41:00 -0400 Subject: [PATCH] Fixed costume center when importing costumes from the library or importing images into the bitmap editor --- src/svgeditor/BitmapEdit.as | 4 ++-- src/svgeditor/SVGEdit.as | 32 +++++++++++++++----------------- src/ui/parts/ImagesPart.as | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/svgeditor/BitmapEdit.as b/src/svgeditor/BitmapEdit.as index 9b8117c..fc46b9e 100644 --- a/src/svgeditor/BitmapEdit.as +++ b/src/svgeditor/BitmapEdit.as @@ -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'); diff --git a/src/svgeditor/SVGEdit.as b/src/svgeditor/SVGEdit.as index a555418..d797e5a 100644 --- a/src/svgeditor/SVGEdit.as +++ b/src/svgeditor/SVGEdit.as @@ -24,19 +24,19 @@ package svgeditor { import flash.geom.*; import flash.text.*; import flash.utils.*; - + import scratch.ScratchCostume; - + import svgeditor.*; import svgeditor.objs.*; import svgeditor.tools.*; - + import svgutils.*; - + import ui.parts.ImagesPart; - + import uiwidgets.*; - + public class SVGEdit extends ImageEdit { public static const tools:Array = [ { name: 'select', desc: 'Select' }, @@ -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 { + 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()) { - insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, false); + insertBitmap(c.baseLayerBitmap.clone(), c.costumeName, false, p.x, p.y); 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)); 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); } @@ -524,4 +522,4 @@ package svgeditor { return null; } } -} \ No newline at end of file +} diff --git a/src/ui/parts/ImagesPart.as b/src/ui/parts/ImagesPart.as index eb05d00..87335f1 100644 --- a/src/ui/parts/ImagesPart.as +++ b/src/ui/parts/ImagesPart.as @@ -361,7 +361,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); }