Skip to content
Snippets Groups Projects
Commit e66e5282 authored by adroitwhiz's avatar adroitwhiz
Browse files

Extract dragged sprites' drawables in screen space

parent d20b68c9
Branches
Tags
1 merge request!1Synching Fork
......@@ -304,25 +304,25 @@ class Stage extends React.Component {
}
this.setState({mouseDownTimeoutId: null});
}
drawDragCanvas (drawableData) {
drawDragCanvas (drawableData, x, y) {
const {
data,
width,
height,
x,
y
imageData,
x: boundsX,
y: boundsY,
width: boundsWidth,
height: boundsHeight
} = drawableData;
this.dragCanvas.width = width;
this.dragCanvas.height = height;
// Need to convert uint8array from WebGL readPixels into Uint8ClampedArray
// for ImageData constructor. Shares underlying buffer, so it is fast.
const imageData = new ImageData(
new Uint8ClampedArray(data.buffer), width, height);
this.dragCanvas.width = imageData.width;
this.dragCanvas.height = imageData.height;
// On high-DPI devices, the canvas size in layout-pixels is not equal to the size of the extracted data.
this.dragCanvas.style.width = `${boundsWidth}px`;
this.dragCanvas.style.height = `${boundsHeight}px`;
this.dragCanvas.getContext('2d').putImageData(imageData, 0, 0);
// Position so that pick location is at (0, 0) so that positionDragCanvas()
// can use translation to move to mouse position smoothly.
this.dragCanvas.style.left = `${-x}px`;
this.dragCanvas.style.top = `${-y}px`;
this.dragCanvas.style.left = `${boundsX - x}px`;
this.dragCanvas.style.top = `${boundsY - y}px`;
this.dragCanvas.style.display = 'block';
}
clearDragCanvas () {
......@@ -350,16 +350,20 @@ class Stage extends React.Component {
target.goToFront();
// Extract the drawable art
const drawableData = this.renderer.extractDrawable(drawableId, x, y);
const drawableData = this.renderer.extractDrawableScreenSpace(drawableId);
const [scratchMouseX, scratchMouseY] = this.getScratchCoords(x, y);
const offsetX = target.x - scratchMouseX;
const offsetY = -(target.y + scratchMouseY);
this.props.vm.startDrag(targetId);
this.setState({
isDragging: true,
dragId: targetId,
dragOffset: drawableData.scratchOffset
dragOffset: [offsetX, offsetY]
});
if (this.props.useEditorDragStyle) {
this.drawDragCanvas(drawableData);
this.drawDragCanvas(drawableData, x, y);
this.positionDragCanvas(x, y);
this.props.vm.postSpriteInfo({visible: false});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment