@@ -655,15 +655,24 @@ def _get_scaled_block_size(self, current_scale: float) -> float:
655655 return self .base_block_size * scale_ratio
656656
657657 def draw (self , cr : cairo .Context , image_to_widget_coords : Callable [[int , int ], tuple [float , float ]], scale : float ):
658- x1 , y1 = image_to_widget_coords (* self .start )
659- x2 , y2 = image_to_widget_coords (* self .end )
658+ crop = self ._get_image_crop ()
659+ if not crop :
660+ return
661+
662+ img_w , img_h = self .background_pixbuf .get_width (), self .background_pixbuf .get_height ()
663+
664+ crop_x_img = crop ['x' ] - img_w / 2
665+ crop_y_img = crop ['y' ] - img_h / 2
666+ crop_x2_img = crop_x_img + crop ['width' ]
667+ crop_y2_img = crop_y_img + crop ['height' ]
668+
669+ x1 , y1 = image_to_widget_coords (int (crop_x_img ), int (crop_y_img ))
670+ x2 , y2 = image_to_widget_coords (int (crop_x2_img ), int (crop_y2_img ))
671+
660672 x , y = min (x1 , x2 ), min (y1 , y2 )
661673 width , height = abs (x2 - x1 ), abs (y2 - y1 )
662674 if width < 1 or height < 1 :
663675 return
664- crop = self ._get_image_crop ()
665- if not crop :
666- return
667676
668677 scaled_block_size = self ._get_scaled_block_size (scale )
669678 self ._draw_pixelation (cr , crop , x , y , width , height , scaled_block_size )
0 commit comments