3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
+ using System . Net ;
6
7
using System . Numerics ;
7
8
using Windows . Foundation ;
8
9
using Windows . UI . Xaml ;
@@ -40,13 +41,22 @@ private void InitImageLayout(bool animate = false)
40
41
/// Update image source transform.
41
42
/// </summary>
42
43
/// <param name="animate">Whether animation is enabled.</param>
43
- private void UpdateImageLayout ( bool animate = false )
44
+ private bool UpdateImageLayout ( bool animate = false )
44
45
{
45
46
if ( Source != null && IsValidRect ( CanvasRect ) )
46
47
{
47
48
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 ;
49
57
}
58
+
59
+ return false ;
50
60
}
51
61
52
62
/// <summary>
@@ -55,11 +65,11 @@ private void UpdateImageLayout(bool animate = false)
55
65
/// <param name="viewport">Viewport</param>
56
66
/// <param name="viewportImageRect"> The real image area of viewport.</param>
57
67
/// <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 )
59
69
{
60
70
if ( ! IsValidRect ( viewport ) || ! IsValidRect ( viewportImageRect ) )
61
71
{
62
- return ;
72
+ return false ;
63
73
}
64
74
65
75
var imageScale = viewport . Width / viewportImageRect . Width ;
@@ -69,12 +79,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect
69
79
_inverseImageTransform . ScaleX = _inverseImageTransform . ScaleY = 1 / imageScale ;
70
80
_inverseImageTransform . TranslateX = - _imageTransform . TranslateX / imageScale ;
71
81
_inverseImageTransform . TranslateY = - _imageTransform . TranslateY / imageScale ;
72
- var selectedRect = _imageTransform . TransformBounds ( _currentCroppedRect ) ;
73
82
_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 ) ) ;
78
83
79
84
if ( animate )
80
85
{
@@ -88,8 +93,7 @@ private void UpdateImageLayoutWithViewport(Rect viewport, Rect viewportImageRect
88
93
targetVisual . Scale = new Vector3 ( ( float ) imageScale ) ;
89
94
}
90
95
91
- UpdateSelectionThumbs ( startPoint , endPoint , animate ) ;
92
- UpdateMaskArea ( animate ) ;
96
+ return true ;
93
97
}
94
98
95
99
/// <summary>
@@ -275,7 +279,12 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos)
275
279
_currentCroppedRect = croppedRect ;
276
280
var viewportRect = GetUniformRect ( CanvasRect , selectedRect . Width / selectedRect . Height ) ;
277
281
var viewportImgRect = _inverseImageTransform . TransformBounds ( selectedRect ) ;
278
- UpdateImageLayoutWithViewport ( viewportRect , viewportImgRect ) ;
282
+
283
+ if ( TryUpdateImageLayoutWithViewport ( viewportRect , viewportImgRect ) )
284
+ {
285
+ UpdateSelectionThumbs ( ) ;
286
+ UpdateMaskArea ( ) ;
287
+ }
279
288
}
280
289
else
281
290
{
@@ -284,6 +293,15 @@ private void UpdateCroppedRect(ThumbPosition position, Point diffPos)
284
293
}
285
294
}
286
295
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
+
287
305
/// <summary>
288
306
/// Positions the thumbs for the selection rectangle.
289
307
/// </summary>
0 commit comments