Merge pull request #274 from nathan/bitmap-selection-misalignment

Fixed grid for selection and stamp tools in bitmap editor
This commit is contained in:
Shane M. Clements 2014-06-18 12:25:23 +02:00
commit a3427cd77d
2 changed files with 10 additions and 9 deletions

View file

@ -103,7 +103,7 @@ public class BitmapEdit extends ImageEdit {
var toolsLayer:Sprite = getToolsLayer(); var toolsLayer:Sprite = getToolsLayer();
var contentLayer:Sprite = workArea.getContentLayer(); var contentLayer:Sprite = workArea.getContentLayer();
var p:Point = contentLayer.globalToLocal(toolsLayer.localToGlobal(toolsP)); var p:Point = contentLayer.globalToLocal(toolsLayer.localToGlobal(toolsP));
var roundedP:Point = new Point(2 * Math.round(p.x / 2), 2 * Math.round(p.y / 2)); // round to nearest half pixel var roundedP:Point = workArea.getScale() == 1 ? new Point(Math.round(p.x), Math.round(p.y)) : new Point(Math.round(p.x * 2) / 2, Math.round(p.y * 2) / 2);
return toolsLayer.globalToLocal(contentLayer.localToGlobal(roundedP)); return toolsLayer.globalToLocal(contentLayer.localToGlobal(roundedP));
} }
@ -112,7 +112,7 @@ public class BitmapEdit extends ImageEdit {
r = r.intersection(bm.rect); // constrain selection to bitmap content r = r.intersection(bm.rect); // constrain selection to bitmap content
if ((r.width < 1) || (r.height < 1)) return null; // empty rectangle if ((r.width < 1) || (r.height < 1)) return null; // empty rectangle
var selectionBM:BitmapData = new BitmapData(r.width, r.height, true, 0);; var selectionBM:BitmapData = new BitmapData(r.width, r.height, true, 0);
selectionBM.copyPixels(bm, r, new Point(0, 0)); selectionBM.copyPixels(bm, r, new Point(0, 0));
if (stampMode) { if (stampMode) {
highlightTool('bitmapSelect'); highlightTool('bitmapSelect');

View file

@ -615,11 +615,11 @@ package svgeditor.tools {
if(moveOffset) { if(moveOffset) {
x = parent.mouseX - moveOffset.x; x = parent.mouseX - moveOffset.x;
y = parent.mouseY - moveOffset.y; y = parent.mouseY - moveOffset.y;
if(editor is BitmapEdit) { if (editor is BitmapEdit) {
var toolsP:Point = editor.snapToGrid(toolsLayer.globalToLocal(parent.localToGlobal(new Point(x, y)))); var p:Point = toolsLayer.globalToLocal(localToGlobal(new Point(topLeftHandle.x, topLeftHandle.y)));
var parentP:Point = parent.globalToLocal(toolsLayer.localToGlobal(toolsP)); var snapped:Point = editor.snapToGrid(p);
x = parentP.x; x += snapped.x - p.x;
y = parentP.y; y += snapped.y - p.y;
} }
updateTarget(); updateTarget();
} else { } else {
@ -805,9 +805,10 @@ package svgeditor.tools {
// Compute the selection rectangle relative to the bitmap content. // Compute the selection rectangle relative to the bitmap content.
var contentP:Point = contentLayer.globalToLocal(toolsLayer.localToGlobal(rect.topLeft)); var contentP:Point = contentLayer.globalToLocal(toolsLayer.localToGlobal(rect.topLeft));
var scale:Number = editor.getWorkArea().getScale(); var scale:Number = editor.getWorkArea().getScale();
// trace(contentP.x, contentP.y, rect.width, rect.height, scale);
var r:Rectangle = new Rectangle( var r:Rectangle = new Rectangle(
2 * Math.floor(contentP.x), 2 * Math.floor(contentP.y), Math.floor(contentP.x * 2), Math.floor(contentP.y * 2),
2 * Math.ceil(rect.width / scale), 2 * Math.ceil(rect.height / scale)); Math.ceil(rect.width / scale * 2), Math.ceil(rect.height / scale * 2));
var selectedBM:SVGBitmap = (editor as BitmapEdit).getSelection(r); var selectedBM:SVGBitmap = (editor as BitmapEdit).getSelection(r);
if (selectedBM) select(new Selection([selectedBM])); if (selectedBM) select(new Selection([selectedBM]));
} else { } else {