@@ -183,20 +183,6 @@ export function ScreenshotEditorFactoryv2({
183
183
}
184
184
} , [ currentRect ] ) ;
185
185
186
- hooks . useEffect ( ( ) => {
187
- const scaledCommands = drawCommands . map ( rect => {
188
- return {
189
- action : rect . action ,
190
- x : rect . x * scaleFactor ,
191
- y : rect . y * scaleFactor ,
192
- width : rect . width * scaleFactor ,
193
- height : rect . height * scaleFactor ,
194
- } ;
195
- } ) ;
196
-
197
- setDrawCommands ( scaledCommands ) ;
198
- } , [ scaleFactor ] ) ;
199
-
200
186
function drawBuffer ( ) : void {
201
187
const ctx = imageBuffer . getContext ( '2d' , { alpha : false } ) ;
202
188
const measurementDiv = measurementRef . current ;
@@ -221,10 +207,8 @@ export function ScreenshotEditorFactoryv2({
221
207
grayCtx . fillRect ( 0 , 0 , imageBuffer . width , imageBuffer . height ) ;
222
208
}
223
209
224
- const scale = imageBuffer . width / measurementDiv . clientWidth ;
225
-
226
210
drawCommands . forEach ( rect => {
227
- drawRect ( rect , grayCtx , scale ) ;
211
+ drawRect ( rect , grayCtx ) ;
228
212
} ) ;
229
213
ctx . drawImage ( grayWashBufferBig , 0 , 0 ) ;
230
214
}
@@ -248,8 +232,13 @@ export function ScreenshotEditorFactoryv2({
248
232
ctx . fillRect ( 0 , 0 , graywashCanvas . width , graywashCanvas . height ) ;
249
233
}
250
234
235
+ const measurementDiv = measurementRef . current ;
236
+ if ( ! measurementDiv ) {
237
+ return ;
238
+ }
239
+ const scale = measurementDiv . clientWidth / imageBuffer . width ;
251
240
drawCommands . forEach ( rect => {
252
- drawRect ( rect , ctx ) ;
241
+ drawRect ( rect , ctx , scale ) ;
253
242
} ) ;
254
243
255
244
if ( currentRect ) {
@@ -315,7 +304,19 @@ export function ScreenshotEditorFactoryv2({
315
304
const endY = Math . max ( 0 , Math . min ( e . clientY - boundingRect . top , graywashCanvas . height / DPI ) ) ;
316
305
// prevent drawing rect when clicking on the canvas (ie clicking delete)
317
306
if ( startX != endX && startY != endY ) {
318
- const rect = constructRect ( { action, startX, startY, endX, endY } ) ;
307
+ // scale to image buffer
308
+ const measurementDiv = measurementRef . current ;
309
+ if ( ! measurementDiv ) {
310
+ return ;
311
+ }
312
+ const scale = imageBuffer . width / measurementDiv . clientWidth ;
313
+ const rect = constructRect ( {
314
+ action,
315
+ startX : startX * scale ,
316
+ startY : startY * scale ,
317
+ endX : endX * scale ,
318
+ endY : endY * scale ,
319
+ } ) ;
319
320
setDrawCommands ( prev => [ ...prev , rect ] ) ;
320
321
}
321
322
0 commit comments