Fixed grid for selection and stamp tools in bitmap editor

This commit is contained in:
Nathan Dinsmore 2014-06-17 10:55:17 -04:00
parent 5132c96eb2
commit 4939b8d6da
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 contentLayer:Sprite = workArea.getContentLayer();
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));
}
@ -112,7 +112,7 @@ public class BitmapEdit extends ImageEdit {
r = r.intersection(bm.rect); // constrain selection to bitmap content
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));
if (stampMode) {
highlightTool('bitmapSelect');

View file

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