@@ -122,15 +122,14 @@ public void MoveSelection(MouseEventArgs e)
122
122
var newWidth = ( int ) ( _rectEnd . X - _rectStart . X ) ;
123
123
var newHeight = ( int ) ( _rectEnd . Y - _rectStart . Y ) ;
124
124
125
- // fix ratio
126
- if ( Math . Abs ( newWidth ) > Math . Abs ( newHeight ) ) newWidth = ( int ) ( newHeight * GausRatioYx ) ;
127
- if ( Math . Abs ( newHeight ) > Math . Abs ( newWidth ) ) newHeight = ( int ) ( newWidth * GausRatioXy ) ;
128
-
129
- // only quadratic zooming in 4th quadrant allowed
125
+ // show rectangle only in 4th quadrant
130
126
if ( newWidth > 0 && newHeight > 0 )
131
127
{
132
- ZoomingRectangle . Width = newWidth ;
133
- ZoomingRectangle . Height = newHeight ;
128
+ ( ZoomingRectangle . Width , ZoomingRectangle . Height ) = FixRatio ( newWidth , newHeight ) ;
129
+ }
130
+ else
131
+ {
132
+ ( ZoomingRectangle . Width , ZoomingRectangle . Height ) = ( 0 , 0 ) ;
134
133
}
135
134
}
136
135
}
@@ -141,16 +140,23 @@ public void EndSelection()
141
140
if ( _isZooming )
142
141
{
143
142
// remember positions
144
- var startX = ( int ) ZoomingRectangle . Margin . Left ;
145
- var startY = ( int ) ZoomingRectangle . Margin . Top ;
146
- var width = ( int ) ZoomingRectangle . Width ;
147
- var height = ( int ) ZoomingRectangle . Height ;
143
+ var startX = ( int ) _rectStart . X ;
144
+ var startY = ( int ) _rectStart . Y ;
145
+ var width = ( int ) ( _rectEnd . X - _rectStart . X ) ;
146
+ var height = ( int ) ( _rectEnd . Y - _rectStart . Y ) ;
147
+
148
+ // only quadratic zooming in 4th quadrant allowed
149
+ if ( width > 0 && height > 0 )
150
+ {
151
+ // fix ratio
152
+ ( width , height ) = FixRatio ( width , height ) ;
148
153
149
- // disable zooming and hide rectangle
150
- AbortSelection ( ) ;
154
+ // disable zooming and hide rectangle
155
+ AbortSelection ( ) ;
151
156
152
- // invoke event handler
153
- ZoomSelected ? . Invoke ( this , new ZoomSelectionEventArgs ( startX , startY , width , height ) ) ;
157
+ // invoke event handler
158
+ ZoomSelected ? . Invoke ( this , new ZoomSelectionEventArgs ( startX , startY , width , height ) ) ;
159
+ }
154
160
}
155
161
}
156
162
@@ -163,5 +169,13 @@ public void AbortSelection()
163
169
ZoomingRectangle . Width = 0 ;
164
170
ZoomingRectangle . Height = 0 ;
165
171
}
172
+
173
+ private static ( int width , int height ) FixRatio ( int width , int height )
174
+ {
175
+ if ( Math . Abs ( width ) > Math . Abs ( height ) ) width = ( int ) ( height * GausRatioYx ) ;
176
+ if ( Math . Abs ( height ) > Math . Abs ( width ) ) height = ( int ) ( width * GausRatioXy ) ;
177
+
178
+ return ( width , height ) ;
179
+ }
166
180
}
167
181
}
0 commit comments