@@ -2970,35 +2970,34 @@ def _onmove(self, event):
29702970 # resize an existing shape
29712971 if self ._active_handle and self ._active_handle != 'C' :
29722972 x0 , x1 , y0 , y1 = self ._extents_on_press
2973- if len (state ) == 0 :
2974- # Switch variables so that only x1 and/or y1 are updated on move.
2975- if self ._active_handle in ['W' , 'SW' , 'NW' ]:
2976- x0 , x1 = x1 , event .xdata
2977- if self ._active_handle in ['S' , 'SW' , 'SE' ]:
2978- y0 , y1 = y1 , event .ydata
2979-
2980- if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
2981- x1 = event .xdata
2982- if self ._active_handle in ['N' , 'S' ] + self ._corner_order :
2983- y1 = event .ydata
2984-
2985- else :
2986- dx = event .xdata - self ._eventpress .xdata
2987- dy = event .ydata - self ._eventpress .ydata
2973+ dx = event .xdata - self ._eventpress .xdata
2974+ dy = event .ydata - self ._eventpress .ydata
29882975
2976+ # from center
2977+ if 'center' in state :
29892978 sizepress = [x1 - x0 , y1 - y0 ]
29902979 centerpress = [x0 + sizepress [0 ] / 2 , y0 + sizepress [1 ] / 2 ]
29912980 center = centerpress
2992-
2993- # from center
2994- if 'center' in state :
2995- if 'W' in self ._active_handle :
2996- dx = - dx
2997- if 'S' in self ._active_handle :
2998- dy = - dy
2999- dw = sizepress [0 ] / 2 + dx
3000- dh = sizepress [1 ] / 2 + dy
3001-
2981+ if 'square' in state :
2982+ if self ._active_handle in ['E' , 'W' ]:
2983+ # using E, W handle we need to update dy accordingly
2984+ dy = dx if self ._active_handle == 'E' else - dx
2985+ elif self ._active_handle in ['S' , 'N' ]:
2986+ # using S, N handle, we need to update dx accordingly
2987+ dx = dy if self ._active_handle == 'N' else - dy
2988+ elif self ._active_handle in self ._corner_order :
2989+ # This doesn't work
2990+ dx = dy = max (dx , dy )
2991+
2992+ if 'W' in self ._active_handle :
2993+ dx *= - 1
2994+ if 'S' in self ._active_handle :
2995+ dy *= - 1
2996+
2997+ dw = sizepress [0 ] / 2 + dx
2998+ dh = sizepress [1 ] / 2 + dy
2999+
3000+ if 'square' not in state :
30023001 # cancel changes in perpendicular direction
30033002 if self ._active_handle in ['E' , 'W' ]:
30043003 dh = sizepress [1 ] / 2
@@ -3007,7 +3006,25 @@ def _onmove(self, event):
30073006
30083007 x0 , x1 , y0 , y1 = (center [0 ] - dw , center [0 ] + dw ,
30093008 center [1 ] - dh , center [1 ] + dh )
3010-
3009+ else :
3010+ # Switch variables so that only x1 and/or y1 are updated on move
3011+ if 'W' in self ._active_handle :
3012+ x0 = x1
3013+ if 'S' in self ._active_handle :
3014+ y0 = y1
3015+
3016+ if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
3017+ x1 = event .xdata
3018+ if 'square' in state :
3019+ # update perpendicular direction
3020+ dy = dx if self ._active_handle == 'E' else - dx
3021+ y1 += dy
3022+ if self ._active_handle in ['N' , 'S' ] + self ._corner_order :
3023+ y1 = event .ydata
3024+ if 'square' in state :
3025+ # update perpendicular direction
3026+ dx = dy if self ._active_handle == 'N' else - dy
3027+ x1 += dx
30113028
30123029 # move existing shape
30133030 elif (self ._active_handle == 'C' or
0 commit comments