@@ -304,25 +304,25 @@ class Stage extends React.Component {
304
304
}
305
305
this . setState ( { mouseDownTimeoutId : null } ) ;
306
306
}
307
- drawDragCanvas ( drawableData ) {
307
+ drawDragCanvas ( drawableData , x , y ) {
308
308
const {
309
- data ,
310
- width ,
311
- height ,
312
- x ,
313
- y
309
+ imageData ,
310
+ x : boundsX ,
311
+ y : boundsY ,
312
+ width : boundsWidth ,
313
+ height : boundsHeight
314
314
} = drawableData ;
315
- this . dragCanvas . width = width ;
316
- this . dragCanvas . height = height ;
317
- // Need to convert uint8array from WebGL readPixels into Uint8ClampedArray
318
- // for ImageData constructor. Shares underlying buffer, so it is fast.
319
- const imageData = new ImageData (
320
- new Uint8ClampedArray ( data . buffer ) , width , height ) ;
315
+ this . dragCanvas . width = imageData . width ;
316
+ this . dragCanvas . height = imageData . height ;
317
+ // On high-DPI devices, the canvas size in layout-pixels is not equal to the size of the extracted data.
318
+ this . dragCanvas . style . width = ` ${ boundsWidth } px` ;
319
+ this . dragCanvas . style . height = ` ${ boundsHeight } px` ;
320
+
321
321
this . dragCanvas . getContext ( '2d' ) . putImageData ( imageData , 0 , 0 ) ;
322
322
// Position so that pick location is at (0, 0) so that positionDragCanvas()
323
323
// can use translation to move to mouse position smoothly.
324
- this . dragCanvas . style . left = `${ - x } px` ;
325
- this . dragCanvas . style . top = `${ - y } px` ;
324
+ this . dragCanvas . style . left = `${ boundsX - x } px` ;
325
+ this . dragCanvas . style . top = `${ boundsY - y } px` ;
326
326
this . dragCanvas . style . display = 'block' ;
327
327
}
328
328
clearDragCanvas ( ) {
@@ -350,16 +350,20 @@ class Stage extends React.Component {
350
350
target . goToFront ( ) ;
351
351
352
352
// Extract the drawable art
353
- const drawableData = this . renderer . extractDrawable ( drawableId , x , y ) ;
353
+ const drawableData = this . renderer . extractDrawableScreenSpace ( drawableId ) ;
354
+
355
+ const [ scratchMouseX , scratchMouseY ] = this . getScratchCoords ( x , y ) ;
356
+ const offsetX = target . x - scratchMouseX ;
357
+ const offsetY = - ( target . y + scratchMouseY ) ;
354
358
355
359
this . props . vm . startDrag ( targetId ) ;
356
360
this . setState ( {
357
361
isDragging : true ,
358
362
dragId : targetId ,
359
- dragOffset : drawableData . scratchOffset
363
+ dragOffset : [ offsetX , offsetY ]
360
364
} ) ;
361
365
if ( this . props . useEditorDragStyle ) {
362
- this . drawDragCanvas ( drawableData ) ;
366
+ this . drawDragCanvas ( drawableData , x , y ) ;
363
367
this . positionDragCanvas ( x , y ) ;
364
368
this . props . vm . postSpriteInfo ( { visible : false } ) ;
365
369
}
0 commit comments