33// See the LICENSE file in the project root for more information.
44
55using System ;
6+ using System . Net ;
67using System . Numerics ;
78using Windows . Foundation ;
89using Windows . UI . Xaml ;
@@ -40,13 +41,22 @@ private void InitImageLayout(bool animate = false)
4041 /// Update image source transform.
4142 /// </summary>
4243 /// <param name="animate">Whether animation is enabled.</param>
43- private void UpdateImageLayout ( bool animate = false )
44+ private bool UpdateImageLayout ( bool animate = false )
4445 {
4546 if ( Source != null && IsValidRect ( CanvasRect ) )
4647 {
4748 var uniformSelectedRect = GetUniformRect ( CanvasRect , _currentCroppedRect . Width / _currentCroppedRect . Height ) ;
48- UpdateImageLayoutWithViewport ( uniformSelectedRect , _currentCroppedRect , animate ) ;
49+
50+ if ( TryUpdateImageLayoutWithViewport ( uniformSelectedRect , _currentCroppedRect , animate ) )
51+ {
52+ UpdateSelectionThumbs ( animate ) ;
53+ UpdateMaskArea ( animate ) ;
54+ }
55+
56+ return true ;
4957 }
58+
59+ return false ;
5060 }
5161
5262 /// <summary>
@@ -55,11 +65,11 @@ private void UpdateImageLayout(bool animate = false)
5565 /// <param name="viewport">Viewport</param>
5666 /// <param name="viewportImageRect"> The real image area of viewport.</param>
5767 /// <param name="animate">Whether animation is enabled.</param>
58- private void UpdateImageLayoutWithViewport ( Rect viewport , Rect viewportImageRect , bool animate = false )
68+ private bool TryUpdateImageLayoutWithViewport ( Rect viewport , Rect viewportImageRect , bool animate = false )
5969 {
6070 if ( ! IsValidRect ( viewport ) || ! IsValidRect ( viewportImageRect ) )
6171 {
62- return ;
72+ return false ;
6373 }
6474
6575 var imageScale = viewport . Width / viewportImageRect . Width ;
@@ -69,12 +79,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect
6979 _inverseImageTransform . ScaleX = _inverseImageTransform . ScaleY = 1 / imageScale ;
7080 _inverseImageTransform . TranslateX = - _imageTransform . TranslateX / imageScale ;
7181 _inverseImageTransform . TranslateY = - _imageTransform . TranslateY / imageScale ;
72- var selectedRect = _imageTransform . TransformBounds ( _currentCroppedRect ) ;
7382 _restrictedSelectRect = _imageTransform . TransformBounds ( _restrictedCropRect ) ;
74- var startPoint = GetSafePoint ( _restrictedSelectRect , new Point ( selectedRect . X , selectedRect . Y ) ) ;
75- var endPoint = GetSafePoint ( _restrictedSelectRect , new Point (
76- selectedRect . X + selectedRect . Width ,
77- selectedRect . Y + selectedRect . Height ) ) ;
7883
7984 if ( animate )
8085 {
@@ -88,8 +93,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect
8893 targetVisual . Scale = new Vector3 ( ( float ) imageScale ) ;
8994 }
9095
91- UpdateSelectionThumbs ( startPoint , endPoint , animate ) ;
92- UpdateMaskArea ( animate ) ;
96+ return true ;
9397 }
9498
9599 /// <summary>
@@ -275,7 +279,12 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos)
275279 _currentCroppedRect = croppedRect ;
276280 var viewportRect = GetUniformRect ( CanvasRect , selectedRect . Width / selectedRect . Height ) ;
277281 var viewportImgRect = _inverseImageTransform . TransformBounds ( selectedRect ) ;
278- UpdateImageLayoutWithViewport ( viewportRect , viewportImgRect ) ;
282+
283+ if ( TryUpdateImageLayoutWithViewport ( viewportRect , viewportImgRect ) )
284+ {
285+ UpdateSelectionThumbs ( ) ;
286+ UpdateMaskArea ( ) ;
287+ }
279288 }
280289 else
281290 {
@@ -284,6 +293,15 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos)
284293 }
285294 }
286295
296+ private void UpdateSelectionThumbs ( bool animate = false )
297+ {
298+ var selectedRect = _imageTransform . TransformBounds ( _currentCroppedRect ) ;
299+ var startPoint = GetSafePoint ( _restrictedSelectRect , new Point ( selectedRect . X , selectedRect . Y ) ) ;
300+ var endPoint = GetSafePoint ( _restrictedSelectRect , new Point ( selectedRect . X + selectedRect . Width , selectedRect . Y + selectedRect . Height ) ) ;
301+
302+ UpdateSelectionThumbs ( startPoint , endPoint , animate ) ;
303+ }
304+
287305 /// <summary>
288306 /// Positions the thumbs for the selection rectangle.
289307 /// </summary>
0 commit comments