@@ -2984,6 +2984,7 @@ def _press(self, event):
29842984 self .update ()
29852985
29862986 if self ._active_handle is None and not self .ignore_event_outside :
2987+ # Start drawing a new rectangle
29872988 x = event .xdata
29882989 y = event .ydata
29892990 self .visible = False
@@ -3050,16 +3051,28 @@ def _release(self, event):
30503051 return False
30513052
30523053 def _onmove (self , event ):
3053- """Motion notify event handler."""
3054+ """
3055+ Motion notify event handler.
30543056
3057+ This can do one of four things:
3058+ - Translate
3059+ - Rotate
3060+ - Re-size
3061+ - Continue the creation of a new shape
3062+ """
30553063 state = self ._state
30563064 rotate = ('rotate' in state and
30573065 self ._active_handle in self ._corner_order )
30583066 eventpress = self ._eventpress
30593067 # The calculations are done for rotation at zero: we apply inverse
30603068 # transformation to events except when we rotate and move
3069+ state = self ._state
3070+ rotate = ('rotate' in state and
3071+ self ._active_handle in self ._corner_order )
30613072 move = self ._active_handle == 'C'
3062- if not move and not rotate :
3073+ resize = self ._active_handle and not move
3074+
3075+ if resize :
30633076 inv_tr = self ._get_rotation_transform ().inverted ()
30643077 event .xdata , event .ydata = inv_tr .transform (
30653078 [event .xdata , event .ydata ])
@@ -3090,8 +3103,7 @@ def _onmove(self, event):
30903103 np .arctan2 (a [1 ]- b [1 ], a [0 ]- b [0 ]))
30913104 self .rotation = np .rad2deg (self ._rotation_on_press + angle )
30923105
3093- # resize an existing shape
3094- elif self ._active_handle and self ._active_handle != 'C' :
3106+ elif resize :
30953107 size_on_press = [x1 - x0 , y1 - y0 ]
30963108 center = [x0 + size_on_press [0 ] / 2 , y0 + size_on_press [1 ] / 2 ]
30973109
@@ -3123,13 +3135,10 @@ def _onmove(self, event):
31233135 else :
31243136 # change sign of relative changes to simplify calculation
31253137 # Switch variables so that x1 and/or y1 are updated on move
3126- x_factor = y_factor = 1
31273138 if 'W' in self ._active_handle :
31283139 x0 = x1
3129- x_factor *= - 1
31303140 if 'S' in self ._active_handle :
31313141 y0 = y1
3132- y_factor *= - 1
31333142 if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
31343143 x1 = event .xdata
31353144 if self ._active_handle in ['N' , 'S' ] + self ._corner_order :
@@ -3147,8 +3156,7 @@ def _onmove(self, event):
31473156 x1 = x0 + sign * abs (y1 - y0 ) * \
31483157 self ._aspect_ratio_correction
31493158
3150- # move existing shape
3151- elif self ._active_handle == 'C' :
3159+ elif move :
31523160 x0 , x1 , y0 , y1 = self ._extents_on_press
31533161 dx = event .xdata - eventpress .xdata
31543162 dy = event .ydata - eventpress .ydata
@@ -3157,8 +3165,8 @@ def _onmove(self, event):
31573165 y0 += dy
31583166 y1 += dy
31593167
3160- # new shape
31613168 else :
3169+ # Create a new shape
31623170 self ._rotation = 0
31633171 # Don't create a new rectangle if there is already one when
31643172 # ignore_event_outside=True
0 commit comments