@@ -2985,6 +2985,7 @@ def _press(self, event):
29852985 self .update ()
29862986
29872987 if self ._active_handle is None and not self .ignore_event_outside :
2988+ # Start drawing a new rectangle
29882989 x = event .xdata
29892990 y = event .ydata
29902991 self .visible = False
@@ -3051,16 +3052,28 @@ def _release(self, event):
30513052 return False
30523053
30533054 def _onmove (self , event ):
3054- """Motion notify event handler."""
3055+ """
3056+ Motion notify event handler.
30553057
3058+ This can do one of four things:
3059+ - Translate
3060+ - Rotate
3061+ - Re-size
3062+ - Continue the creation of a new shape
3063+ """
30563064 state = self ._state
30573065 rotate = ('rotate' in state and
30583066 self ._active_handle in self ._corner_order )
30593067 eventpress = self ._eventpress
30603068 # The calculations are done for rotation at zero: we apply inverse
30613069 # transformation to events except when we rotate and move
3070+ state = self ._state
3071+ rotate = ('rotate' in state and
3072+ self ._active_handle in self ._corner_order )
30623073 move = self ._active_handle == 'C'
3063- if not move and not rotate :
3074+ resize = self ._active_handle and not move
3075+
3076+ if resize :
30643077 inv_tr = self ._get_rotation_transform ().inverted ()
30653078 event .xdata , event .ydata = inv_tr .transform (
30663079 [event .xdata , event .ydata ])
@@ -3091,8 +3104,7 @@ def _onmove(self, event):
30913104 np .arctan2 (a [1 ]- b [1 ], a [0 ]- b [0 ]))
30923105 self .rotation = np .rad2deg (self ._rotation_on_press + angle )
30933106
3094- # resize an existing shape
3095- elif self ._active_handle and self ._active_handle != 'C' :
3107+ elif resize :
30963108 size_on_press = [x1 - x0 , y1 - y0 ]
30973109 center = [x0 + size_on_press [0 ] / 2 , y0 + size_on_press [1 ] / 2 ]
30983110
@@ -3145,8 +3157,7 @@ def _onmove(self, event):
31453157 x1 = x0 + sign * abs (y1 - y0 ) * \
31463158 self ._aspect_ratio_correction
31473159
3148- # move existing shape
3149- elif self ._active_handle == 'C' :
3160+ elif move :
31503161 x0 , x1 , y0 , y1 = self ._extents_on_press
31513162 dx = event .xdata - eventpress .xdata
31523163 dy = event .ydata - eventpress .ydata
@@ -3155,8 +3166,8 @@ def _onmove(self, event):
31553166 y0 += dy
31563167 y1 += dy
31573168
3158- # new shape
31593169 else :
3170+ # Create a new shape
31603171 self ._rotation = 0
31613172 # Don't create a new rectangle if there is already one when
31623173 # ignore_event_outside=True
0 commit comments