mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2025-01-10 14:42:13 -05:00
Selection limit (#572)
This commit is contained in:
parent
500908acad
commit
6c84cbf76d
2 changed files with 13 additions and 11 deletions
|
@ -659,11 +659,6 @@ const scaleBitmap = function (canvas, scale) {
|
|||
* @param {paper.Raster} item raster to change
|
||||
*/
|
||||
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.
|
||||
// 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
|
||||
|
@ -719,6 +714,10 @@ const commitArbitraryTransformation_ = function (item, destination) {
|
|||
* @param {paper.Raster} bitmap raster to draw selection to
|
||||
*/
|
||||
const commitSelectionToBitmap = function (selection, bitmap) {
|
||||
if (!selection.matrix.isInvertible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
maybeApplyScaleToCanvas_(selection);
|
||||
commitArbitraryTransformation_(selection, bitmap);
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ import paper from '@scratch/paper';
|
|||
import {rectSelect} from '../guides';
|
||||
import {clearSelection, processRectangularSelection} from '../selection';
|
||||
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. */
|
||||
class SelectionBoxTool {
|
||||
|
@ -44,12 +45,14 @@ class SelectionBoxTool {
|
|||
onMouseUpBitmap (event) {
|
||||
if (event.event.button > 0) return; // only first mouse button
|
||||
if (this.selectionRect) {
|
||||
const rect = new paper.Rectangle(
|
||||
Math.round(this.selectionRect.bounds.x),
|
||||
Math.round(this.selectionRect.bounds.y),
|
||||
Math.round(this.selectionRect.bounds.width),
|
||||
Math.round(this.selectionRect.bounds.height),
|
||||
);
|
||||
const rect = new paper.Rectangle({
|
||||
from: new paper.Point(
|
||||
Math.max(0, Math.round(this.selectionRect.bounds.topLeft.x)),
|
||||
Math.max(0, Math.round(this.selectionRect.bounds.topLeft.y))),
|
||||
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
|
||||
this.selectionRect.remove();
|
||||
|
|
Loading…
Reference in a new issue