Removed OpacityHelper

This commit is contained in:
ClemensFischer 2025-01-05 09:22:50 +01:00
parent 3afbdadf0c
commit b9a34fd5e4
10 changed files with 144 additions and 171 deletions

View file

@ -161,21 +161,7 @@ namespace MapControl
centerCts?.Cancel();
centerAnimation = new Animation
{
FillMode = FillMode.Forward,
Duration = AnimationDuration,
Easing = AnimationEasing,
Children =
{
new KeyFrame
{
KeyTime = AnimationDuration,
Setters = { new Setter(CenterProperty, new Location(targetCenter.Latitude, CoerceLongitude(targetCenter.Longitude))) }
}
}
};
centerAnimation = CreateAnimation(CenterProperty, new Location(targetCenter.Latitude, CoerceLongitude(targetCenter.Longitude)));
centerCts = new CancellationTokenSource();
await centerAnimation.RunAsync(this, centerCts.Token);
@ -226,21 +212,7 @@ namespace MapControl
{
zoomLevelCts?.Cancel();
zoomLevelAnimation = new Animation
{
FillMode = FillMode.Forward,
Duration = AnimationDuration,
Easing = AnimationEasing,
Children =
{
new KeyFrame
{
KeyTime = AnimationDuration,
Setters = { new Setter(ZoomLevelProperty, targetZoomLevel) }
}
}
};
zoomLevelAnimation = CreateAnimation(ZoomLevelProperty, targetZoomLevel);
zoomLevelCts = new CancellationTokenSource();
await zoomLevelAnimation.RunAsync(this, zoomLevelCts.Token);
@ -288,21 +260,7 @@ namespace MapControl
headingCts?.Cancel();
headingAnimation = new Animation
{
FillMode = FillMode.Forward,
Duration = AnimationDuration,
Easing = AnimationEasing,
Children =
{
new KeyFrame
{
KeyTime = AnimationDuration,
Setters = { new Setter(HeadingProperty, targetHeading) }
}
}
};
headingAnimation = CreateAnimation(HeadingProperty, targetHeading);
headingCts = new CancellationTokenSource();
await headingAnimation.RunAsync(this, headingCts.Token);
@ -317,5 +275,23 @@ namespace MapControl
headingAnimation = null;
}
}
private Animation CreateAnimation(DependencyProperty property, object value)
{
return new Animation
{
FillMode = FillMode.Forward,
Duration = AnimationDuration,
Easing = AnimationEasing,
Children =
{
new KeyFrame
{
KeyTime = AnimationDuration,
Setters = { new Setter(property, value) }
}
}
};
}
}
}

View file

@ -0,0 +1,32 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Threading.Tasks;
namespace MapControl
{
public partial class MapImageLayer
{
public static void FadeOver(Image topImage, Image bottomImage)
{
var animation = new Animation
{
FillMode = FillMode.Forward,
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
_ = animation.RunAsync(topImage).ContinueWith(
_ => bottomImage.Opacity = 0d,
TaskScheduler.FromCurrentSynchronizationContext());
}
}
}

View file

@ -1,56 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Threading.Tasks;
using System;
namespace MapControl
{
public static class OpacityHelper
{
public static Task FadeIn(Control element)
{
var animation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = TimeSpan.Zero,
Setters = { new Setter(Visual.OpacityProperty, 0d) }
},
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
return animation.RunAsync(element);
}
public static async Task SwapOpacitiesAsync(Control topElement, Control bottomElement)
{
var animation = new Animation
{
FillMode = FillMode.Forward,
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
await animation.RunAsync(topElement);
bottomElement.Opacity = 0d;
}
}
}

View file

@ -2,13 +2,33 @@
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
namespace MapControl
{
public partial class Tile
{
private void AnimateImageOpacity()
{
_ = OpacityHelper.FadeIn(Image);
var animation = new Animation
{
Duration = MapBase.ImageFadeDuration,
Children =
{
new KeyFrame
{
KeyTime = TimeSpan.Zero,
Setters = { new Setter(Visual.OpacityProperty, 0d) }
},
new KeyFrame
{
KeyTime = MapBase.ImageFadeDuration,
Setters = { new Setter(Visual.OpacityProperty, 1d) }
}
}
};
_ = animation.RunAsync(Image);
}
}
}