@@ -279,6 +279,9 @@ def __init__(self, view, parent_controller=None):
279279 #: float: Percentage of crosshair in y
280280 self .crosshair_y = 0.5
281281
282+ #: bool: the flag for offsetting the crosshair
283+ self .offset_crosshair = False
284+
282285 # Right-Click Popup Menu
283286 self .menu = tk .Menu (self .canvas , tearoff = 0 )
284287 self .menu .add_command (label = "Reset Display" , command = self .reset_display )
@@ -536,7 +539,7 @@ def initialize_non_live_display(self, microscope_state, camera_parameters):
536539 }
537540
538541 self .update_canvas_size ()
539- self .reset_display (False )
542+ self .reset_display (False , False )
540543
541544 def reset_display (self , display_flag = True , reset_crosshair = True ):
542545 """Set the display back to the original digital zoom.
@@ -549,6 +552,7 @@ def reset_display(self, display_flag=True, reset_crosshair=True):
549552 Flag for resetting the crosshair. Default True.
550553 """
551554 if reset_crosshair :
555+ self .offset_crosshair = False
552556 self .crosshair_x = 0.5
553557 self .crosshair_y = 0.5
554558 self .zoom_width = self .canvas_width
@@ -562,6 +566,7 @@ def reset_display(self, display_flag=True, reset_crosshair=True):
562566
563567 def move_crosshair (self ):
564568 """Move the crosshair to a non-default position."""
569+ self .offset_crosshair = True
565570 width = (self .zoom_rect [0 ][1 ] - self .zoom_rect [0 ][0 ]) / self .zoom_scale
566571 height = (self .zoom_rect [1 ][1 ] - self .zoom_rect [1 ][0 ]) / self .zoom_scale
567572 self .crosshair_x = self .move_to_x / width
@@ -808,12 +813,18 @@ def add_crosshair(self, image):
808813 Image data with cross-hair.
809814 """
810815 if self .apply_cross_hair :
811- crosshair_x = (
812- self .zoom_rect [0 ][1 ] - self .zoom_rect [0 ][0 ]
813- ) * self .crosshair_x + self .zoom_rect [0 ][0 ]
814- crosshair_y = (
815- self .zoom_rect [1 ][1 ] - self .zoom_rect [1 ][0 ]
816- ) * self .crosshair_y + self .zoom_rect [1 ][0 ]
816+ if self .offset_crosshair :
817+ width = (self .zoom_rect [0 ][1 ] - self .zoom_rect [0 ][0 ]) / self .zoom_scale
818+ height = (self .zoom_rect [1 ][1 ] - self .zoom_rect [1 ][0 ]) / self .zoom_scale
819+ crosshair_x = self .crosshair_x * width
820+ crosshair_y = self .crosshair_y * height
821+ else :
822+ crosshair_x = (
823+ self .zoom_rect [0 ][1 ] - self .zoom_rect [0 ][0 ]
824+ ) * self .crosshair_x + self .zoom_rect [0 ][0 ]
825+ crosshair_y = (
826+ self .zoom_rect [1 ][1 ] - self .zoom_rect [1 ][0 ]
827+ ) * self .crosshair_y + self .zoom_rect [1 ][0 ]
817828
818829 if crosshair_x < 0 or crosshair_x >= self .canvas_width :
819830 crosshair_x = - 1
@@ -1000,7 +1011,7 @@ def mouse_wheel(self, event):
10001011 self .zoom_height /= self .zoom_value
10011012
10021013 if self .zoom_width > self .canvas_width or self .zoom_height > self .canvas_height :
1003- self .reset_display (False , False )
1014+ self .reset_display (display_flag = False , reset_crosshair = False )
10041015 elif self .zoom_width < 5 or self .zoom_height < 5 :
10051016 return
10061017
0 commit comments