Selection limit (#572)

This commit is contained in:
DD Liu 2018-08-03 13:10:45 -04:00 committed by GitHub
parent 500908acad
commit 6c84cbf76d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View file

@ -659,11 +659,6 @@ const scaleBitmap = function (canvas, scale) {
* @param {paper.Raster} item raster to change * @param {paper.Raster} item raster to change
*/ */
const maybeApplyScaleToCanvas_ = function (item) { const maybeApplyScaleToCanvas_ = function (item) {
if (!item.matrix.isInvertible()) {
item.remove();
return;
}
// context.drawImage will anti-alias the image if both width and height are reduced. // context.drawImage will anti-alias the image if both width and height are reduced.
// However, it will preserve pixel colors if only one or the other is reduced, and // However, it will preserve pixel colors if only one or the other is reduced, and
// imageSmoothingEnabled is set to false. Therefore, we can avoid aliasing by scaling // imageSmoothingEnabled is set to false. Therefore, we can avoid aliasing by scaling
@ -719,6 +714,10 @@ const commitArbitraryTransformation_ = function (item, destination) {
* @param {paper.Raster} bitmap raster to draw selection to * @param {paper.Raster} bitmap raster to draw selection to
*/ */
const commitSelectionToBitmap = function (selection, bitmap) { const commitSelectionToBitmap = function (selection, bitmap) {
if (!selection.matrix.isInvertible()) {
return;
}
maybeApplyScaleToCanvas_(selection); maybeApplyScaleToCanvas_(selection);
commitArbitraryTransformation_(selection, bitmap); commitArbitraryTransformation_(selection, bitmap);
}; };

View file

@ -2,6 +2,7 @@ import paper from '@scratch/paper';
import {rectSelect} from '../guides'; import {rectSelect} from '../guides';
import {clearSelection, processRectangularSelection} from '../selection'; import {clearSelection, processRectangularSelection} from '../selection';
import {getRaster} from '../layer'; import {getRaster} from '../layer';
import {ART_BOARD_WIDTH, ART_BOARD_HEIGHT} from '../view';
/** Tool to handle drag selection. A dotted line box appears and everything enclosed is selected. */ /** Tool to handle drag selection. A dotted line box appears and everything enclosed is selected. */
class SelectionBoxTool { class SelectionBoxTool {
@ -44,12 +45,14 @@ class SelectionBoxTool {
onMouseUpBitmap (event) { onMouseUpBitmap (event) {
if (event.event.button > 0) return; // only first mouse button if (event.event.button > 0) return; // only first mouse button
if (this.selectionRect) { if (this.selectionRect) {
const rect = new paper.Rectangle( const rect = new paper.Rectangle({
Math.round(this.selectionRect.bounds.x), from: new paper.Point(
Math.round(this.selectionRect.bounds.y), Math.max(0, Math.round(this.selectionRect.bounds.topLeft.x)),
Math.round(this.selectionRect.bounds.width), Math.max(0, Math.round(this.selectionRect.bounds.topLeft.y))),
Math.round(this.selectionRect.bounds.height), to: new paper.Point(
); Math.min(ART_BOARD_WIDTH, Math.round(this.selectionRect.bounds.bottomRight.x)),
Math.min(ART_BOARD_HEIGHT, Math.round(this.selectionRect.bounds.bottomRight.y)))
});
// Remove dotted rectangle // Remove dotted rectangle
this.selectionRect.remove(); this.selectionRect.remove();