mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
Merge branch 'develop' into convertToBitmapShapeRendering
This commit is contained in:
commit
8622bfab69
6 changed files with 51 additions and 19 deletions
|
@ -26,7 +26,7 @@
|
|||
"react-dom": "^16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@scratch/paper": "0.11.20180329192534",
|
||||
"@scratch/paper": "0.11.20180411183636",
|
||||
"autoprefixer": "8.1.0",
|
||||
"babel-cli": "6.26.0",
|
||||
"babel-core": "^6.23.1",
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 46 KiB |
|
@ -1,5 +1,4 @@
|
|||
import paper from '@scratch/paper';
|
||||
import canvasBg from './background.png';
|
||||
import rasterSrc from './transparent.png';
|
||||
import log from '../log/log';
|
||||
|
||||
|
@ -112,19 +111,47 @@ const _makeRasterLayer = function () {
|
|||
return rasterLayer;
|
||||
};
|
||||
|
||||
const _makeBackgroundPaper = function (width, height, color) {
|
||||
// creates a checkerboard path of width * height squares in color on white
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
const pathPoints = [];
|
||||
while (x < width) {
|
||||
pathPoints.push(new paper.Point(x, y));
|
||||
x++;
|
||||
pathPoints.push(new paper.Point(x, y));
|
||||
y = y === 0 ? height : 0;
|
||||
}
|
||||
y = height - 1;
|
||||
x = width;
|
||||
while (y > 0) {
|
||||
pathPoints.push(new paper.Point(x, y));
|
||||
x = (x === 0 ? width : 0);
|
||||
pathPoints.push(new paper.Point(x, y));
|
||||
y--;
|
||||
}
|
||||
const vRect = new paper.Shape.Rectangle(new paper.Point(0, 0), new paper.Point(120, 90));
|
||||
vRect.fillColor = '#fff';
|
||||
vRect.guide = true;
|
||||
vRect.locked = true;
|
||||
const vPath = new paper.Path(pathPoints);
|
||||
vPath.fillRule = 'evenodd';
|
||||
vPath.fillColor = color;
|
||||
vPath.guide = true;
|
||||
vPath.locked = true;
|
||||
const vGroup = new paper.Group([vRect, vPath]);
|
||||
return vGroup;
|
||||
};
|
||||
|
||||
const _makeBackgroundGuideLayer = function () {
|
||||
const guideLayer = new paper.Layer();
|
||||
guideLayer.locked = true;
|
||||
const img = new Image();
|
||||
img.src = canvasBg;
|
||||
img.onload = () => {
|
||||
const raster = new paper.Raster(img);
|
||||
raster.parent = guideLayer;
|
||||
raster.guide = true;
|
||||
raster.locked = true;
|
||||
raster.position = paper.view.center;
|
||||
raster.sendToBack();
|
||||
};
|
||||
|
||||
const vBackground = _makeBackgroundPaper(120, 90, '#E5E5E5');
|
||||
vBackground.position = paper.view.center;
|
||||
vBackground.scaling = new paper.Point(4, 4);
|
||||
vBackground.guide = true;
|
||||
vBackground.locked = true;
|
||||
|
||||
const vLine = new paper.Path.Line(new paper.Point(0, -7), new paper.Point(0, 7));
|
||||
vLine.strokeWidth = 2;
|
||||
|
|
|
@ -51,7 +51,7 @@ class BoundingBoxTool {
|
|||
|
||||
/**
|
||||
* Should be called if the selection changes to update the bounds of the bounding box.
|
||||
* @param {Array<paper.Item>} selectedItems Array of selected items.
|
||||
* @param {?Array<paper.Item>} selectedItems Array of selected items.
|
||||
*/
|
||||
onSelectionChanged (selectedItems) {
|
||||
if (selectedItems && selectedItems.length) {
|
||||
|
|
|
@ -44,8 +44,13 @@ class FillTool extends paper.Tool {
|
|||
fill: true,
|
||||
guide: false,
|
||||
match: function (hitResult) {
|
||||
return (hitResult.item instanceof paper.Path || hitResult.item instanceof paper.PointText) &&
|
||||
(hitResult.item.hasFill() || hitResult.item.closed || isAlmostClosedPath(hitResult.item));
|
||||
if (hitResult.item instanceof paper.Path &&
|
||||
(hitResult.item.hasFill() || hitResult.item.closed || isAlmostClosedPath(hitResult.item))) {
|
||||
return true;
|
||||
}
|
||||
if (hitResult.item instanceof paper.PointText) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
hitUnfilledPaths: true,
|
||||
tolerance: FillTool.TOLERANCE / paper.view.zoom
|
||||
|
|
|
@ -22,10 +22,10 @@ test('undoRedoChangeFormat', () => {
|
|||
let defaultState;
|
||||
let reduxState = reducer(defaultState /* state */, changeFormat(Formats.BITMAP) /* action */);
|
||||
expect(reduxState).toBe(Formats.BITMAP);
|
||||
reduxState = reducer(reduxState /* state */, undo(Formats.UNDO_BITMAP) /* action */);
|
||||
expect(reduxState).toBe(Formats.UNDO_BITMAP);
|
||||
reduxState = reducer(reduxState /* state */, redo(Formats.UNDO_VECTOR) /* action */);
|
||||
expect(reduxState).toBe(Formats.UNDO_VECTOR);
|
||||
reduxState = reducer(reduxState /* state */, undo(Formats.BITMAP_SKIP_CONVERT) /* action */);
|
||||
expect(reduxState).toBe(Formats.BITMAP_SKIP_CONVERT);
|
||||
reduxState = reducer(reduxState /* state */, redo(Formats.VECTOR_SKIP_CONVERT) /* action */);
|
||||
expect(reduxState).toBe(Formats.VECTOR_SKIP_CONVERT);
|
||||
});
|
||||
|
||||
test('invalidChangeMode', () => {
|
||||
|
|
Loading…
Reference in a new issue