@@ -2984,6 +2984,7 @@ def _press(self, event):
2984
2984
self .update ()
2985
2985
2986
2986
if self ._active_handle is None and not self .ignore_event_outside :
2987
+ # Start drawing a new rectangle
2987
2988
x = event .xdata
2988
2989
y = event .ydata
2989
2990
self .visible = False
@@ -3050,16 +3051,28 @@ def _release(self, event):
3050
3051
return False
3051
3052
3052
3053
def _onmove (self , event ):
3053
- """Motion notify event handler."""
3054
+ """
3055
+ Motion notify event handler.
3054
3056
3057
+ This can do one of four things:
3058
+ - Translate
3059
+ - Rotate
3060
+ - Re-size
3061
+ - Continue the creation of a new shape
3062
+ """
3055
3063
state = self ._state
3056
3064
rotate = ('rotate' in state and
3057
3065
self ._active_handle in self ._corner_order )
3058
3066
eventpress = self ._eventpress
3059
3067
# The calculations are done for rotation at zero: we apply inverse
3060
3068
# 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 )
3061
3072
move = self ._active_handle == 'C'
3062
- if not move and not rotate :
3073
+ resize = self ._active_handle and not move
3074
+
3075
+ if resize :
3063
3076
inv_tr = self ._get_rotation_transform ().inverted ()
3064
3077
event .xdata , event .ydata = inv_tr .transform (
3065
3078
[event .xdata , event .ydata ])
@@ -3090,8 +3103,7 @@ def _onmove(self, event):
3090
3103
np .arctan2 (a [1 ]- b [1 ], a [0 ]- b [0 ]))
3091
3104
self .rotation = np .rad2deg (self ._rotation_on_press + angle )
3092
3105
3093
- # resize an existing shape
3094
- elif self ._active_handle and self ._active_handle != 'C' :
3106
+ elif resize :
3095
3107
size_on_press = [x1 - x0 , y1 - y0 ]
3096
3108
center = [x0 + size_on_press [0 ] / 2 , y0 + size_on_press [1 ] / 2 ]
3097
3109
@@ -3123,13 +3135,10 @@ def _onmove(self, event):
3123
3135
else :
3124
3136
# change sign of relative changes to simplify calculation
3125
3137
# Switch variables so that x1 and/or y1 are updated on move
3126
- x_factor = y_factor = 1
3127
3138
if 'W' in self ._active_handle :
3128
3139
x0 = x1
3129
- x_factor *= - 1
3130
3140
if 'S' in self ._active_handle :
3131
3141
y0 = y1
3132
- y_factor *= - 1
3133
3142
if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
3134
3143
x1 = event .xdata
3135
3144
if self ._active_handle in ['N' , 'S' ] + self ._corner_order :
@@ -3147,8 +3156,7 @@ def _onmove(self, event):
3147
3156
x1 = x0 + sign * abs (y1 - y0 ) * \
3148
3157
self ._aspect_ratio_correction
3149
3158
3150
- # move existing shape
3151
- elif self ._active_handle == 'C' :
3159
+ elif move :
3152
3160
x0 , x1 , y0 , y1 = self ._extents_on_press
3153
3161
dx = event .xdata - eventpress .xdata
3154
3162
dy = event .ydata - eventpress .ydata
@@ -3157,8 +3165,8 @@ def _onmove(self, event):
3157
3165
y0 += dy
3158
3166
y1 += dy
3159
3167
3160
- # new shape
3161
3168
else :
3169
+ # Create a new shape
3162
3170
self ._rotation = 0
3163
3171
# Don't create a new rectangle if there is already one when
3164
3172
# ignore_event_outside=True
0 commit comments