mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Fix some issues with import not centering costume
This commit is contained in:
parent
582ab61665
commit
cb34c29db6
1 changed files with 36 additions and 32 deletions
|
@ -29,10 +29,12 @@ class PaperCanvas extends React.Component {
|
||||||
paper.remove();
|
paper.remove();
|
||||||
}
|
}
|
||||||
importSvg (svg, rotationCenterX, rotationCenterY) {
|
importSvg (svg, rotationCenterX, rotationCenterY) {
|
||||||
const imported = paper.project.importSVG(svg,
|
paper.project.importSVG(svg, {
|
||||||
{
|
|
||||||
expandShapes: true,
|
expandShapes: true,
|
||||||
onLoad: function (item) {
|
onLoad: function (item) {
|
||||||
|
const itemWidth = item.bounds.width;
|
||||||
|
const itemHeight = item.bounds.height;
|
||||||
|
|
||||||
// Remove viewbox
|
// Remove viewbox
|
||||||
if (item.clipped) {
|
if (item.clipped) {
|
||||||
let mask;
|
let mask;
|
||||||
|
@ -44,25 +46,27 @@ class PaperCanvas extends React.Component {
|
||||||
}
|
}
|
||||||
item.clipped = false;
|
item.clipped = false;
|
||||||
mask.remove();
|
mask.remove();
|
||||||
// Consider removing clip mask here?
|
|
||||||
}
|
}
|
||||||
while (item.reduce() !== item) {
|
|
||||||
|
// Reduce single item nested in groups
|
||||||
|
if (item.children && item.children.length === 1) {
|
||||||
item = item.reduce();
|
item = item.reduce();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
if (typeof rotationCenterX !== 'undefined' && typeof rotationCenterY !== 'undefined') {
|
if (typeof rotationCenterX !== 'undefined' && typeof rotationCenterY !== 'undefined') {
|
||||||
imported.position =
|
item.position =
|
||||||
paper.project.view.center
|
paper.project.view.center
|
||||||
.add(imported.bounds.width / 2, imported.bounds.height / 2)
|
.add(itemWidth / 2, itemHeight / 2)
|
||||||
.subtract(rotationCenterX, rotationCenterY);
|
.subtract(rotationCenterX, rotationCenterY);
|
||||||
} else {
|
} else {
|
||||||
// Center
|
// Center
|
||||||
imported.position = paper.project.view.center;
|
item.position = paper.project.view.center;
|
||||||
}
|
}
|
||||||
|
|
||||||
paper.project.view.update();
|
paper.project.view.update();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
setCanvas (canvas) {
|
setCanvas (canvas) {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
if (this.props.canvasRef) {
|
if (this.props.canvasRef) {
|
||||||
|
|
Loading…
Reference in a new issue