-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snowfall effect Setup OnlinePictureClient to support more online sources Contributes to #453
- Loading branch information
1 parent
51d6fb0
commit 50b0253
Showing
20 changed files
with
5,011 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<UserControl x:Class="Daybreak.Controls.SnowfallOverlay" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Daybreak.Controls" | ||
xmlns:effects="clr-namespace:System.Windows.Media.Extensions.Effects;assembly=WpfExtended" | ||
mc:Ignorable="d" | ||
Loaded="UserControl_Loaded" | ||
Unloaded="UserControl_Unloaded" | ||
x:Name="_this" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<UserControl.Effect> | ||
<BlurEffect | ||
KernelType="Box" | ||
Radius="2"/> | ||
</UserControl.Effect> | ||
<UserControl.Triggers> | ||
<EventTrigger RoutedEvent="UserControl.Loaded"> | ||
<BeginStoryboard> | ||
<Storyboard> | ||
<DoubleAnimation Storyboard.TargetName="_this" | ||
Storyboard.TargetProperty="Time" | ||
From="0" | ||
To="200" | ||
Duration="4:0:0" | ||
RepeatBehavior="Forever"/> | ||
</Storyboard> | ||
</BeginStoryboard> | ||
</EventTrigger> | ||
</UserControl.Triggers> | ||
<Grid> | ||
<Grid> | ||
<Grid.Background> | ||
<ImageBrush x:Name="Host1" | ||
TileMode="Tile" | ||
ViewportUnits="Absolute" | ||
Viewport="0, 0, 100, 100"> | ||
<ImageBrush.RelativeTransform> | ||
<TransformGroup> | ||
<TranslateTransform x:Name="SnowfallTransform1" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" /> | ||
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize1, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize1, Mode=OneWay}" /> | ||
</TransformGroup> | ||
</ImageBrush.RelativeTransform> | ||
</ImageBrush> | ||
</Grid.Background> | ||
</Grid> | ||
<Grid> | ||
<Grid.Background> | ||
<ImageBrush x:Name="Host2" | ||
TileMode="Tile" | ||
ViewportUnits="Absolute" | ||
Viewport="0, 0, 100, 100"> | ||
<ImageBrush.RelativeTransform> | ||
<TransformGroup> | ||
<TranslateTransform x:Name="SnowfallTransform2" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" /> | ||
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize2, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize2, Mode=OneWay}" /> | ||
</TransformGroup> | ||
</ImageBrush.RelativeTransform> | ||
</ImageBrush> | ||
</Grid.Background> | ||
</Grid> | ||
<Grid> | ||
<Grid.Background> | ||
<ImageBrush x:Name="Host3" | ||
TileMode="Tile" | ||
ViewportUnits="Absolute" | ||
Viewport="0, 0, 100, 100"> | ||
<ImageBrush.RelativeTransform> | ||
<TransformGroup> | ||
<TranslateTransform x:Name="SnowfallTransform3" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" /> | ||
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize3, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize3, Mode=OneWay}" /> | ||
</TransformGroup> | ||
</ImageBrush.RelativeTransform> | ||
</ImageBrush> | ||
</Grid.Background> | ||
</Grid> | ||
<Grid> | ||
<Grid.Background> | ||
<ImageBrush x:Name="Host4" | ||
TileMode="Tile" | ||
ViewportUnits="Absolute" | ||
Viewport="0, 0, 100, 100"> | ||
<ImageBrush.RelativeTransform> | ||
<TransformGroup> | ||
<TranslateTransform x:Name="SnowfallTransform4" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" /> | ||
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize4, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize4, Mode=OneWay}" /> | ||
</TransformGroup> | ||
</ImageBrush.RelativeTransform> | ||
</ImageBrush> | ||
</Grid.Background> | ||
</Grid> | ||
<Grid> | ||
<Grid.Background> | ||
<ImageBrush x:Name="Host5" | ||
TileMode="Tile" | ||
ViewportUnits="Absolute" | ||
Viewport="0, 0, 100, 100"> | ||
<ImageBrush.RelativeTransform> | ||
<TransformGroup> | ||
<TranslateTransform x:Name="SnowfallTransform5" X="0" Y="{Binding ElementName=_this, Path=Time, Mode=OneWay}" /> | ||
<ScaleTransform ScaleX="{Binding ElementName=_this, Path=FlakeSize5, Mode=OneWay}" ScaleY="{Binding ElementName=_this, Path=FlakeSize5, Mode=OneWay}" /> | ||
</TransformGroup> | ||
</ImageBrush.RelativeTransform> | ||
</ImageBrush> | ||
</Grid.Background> | ||
</Grid> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Extensions; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace Daybreak.Controls; | ||
/// <summary> | ||
/// Interaction logic for SnowfallOverlay.xaml | ||
/// </summary> | ||
public partial class SnowfallOverlay : UserControl | ||
{ | ||
private static readonly double[] Frequencies = new double[] { 0.5, 0.1, 5, 1 }; | ||
private static readonly double[] Amplitudes = new double[] { 1, 0.1, 0.1, 0.2 }; | ||
private static readonly double Divisor = Amplitudes.Sum(); | ||
|
||
[GenerateDependencyProperty] | ||
private double flakeSize1; | ||
[GenerateDependencyProperty] | ||
private double flakeSize2; | ||
[GenerateDependencyProperty] | ||
private double flakeSize3; | ||
[GenerateDependencyProperty] | ||
private double flakeSize4; | ||
[GenerateDependencyProperty] | ||
private double flakeSize5; | ||
[GenerateDependencyProperty] | ||
private double time; | ||
|
||
[GenerateDependencyProperty] | ||
private double windStrength1; | ||
[GenerateDependencyProperty] | ||
private double windStrength2; | ||
[GenerateDependencyProperty] | ||
private double windStrength3; | ||
[GenerateDependencyProperty] | ||
private double windStrength4; | ||
[GenerateDependencyProperty] | ||
private double windStrength5; | ||
|
||
[GenerateDependencyProperty] | ||
private double baseWind1; | ||
[GenerateDependencyProperty] | ||
private double baseWind2; | ||
[GenerateDependencyProperty] | ||
private double baseWind3; | ||
[GenerateDependencyProperty] | ||
private double baseWind4; | ||
[GenerateDependencyProperty] | ||
private double baseWind5; | ||
|
||
private CancellationTokenSource? tokenSource; | ||
|
||
public SnowfallOverlay() | ||
{ | ||
this.InitializeComponent(); | ||
this.InitializeImages(); | ||
} | ||
|
||
private void InitializeImages() | ||
{ | ||
using var snowTexture1 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow1.png"); | ||
using var snowTexture2 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow2.png"); | ||
using var snowTexture3 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow3.png"); | ||
using var snowTexture4 = this.GetType().Assembly.GetManifestResourceStream("Daybreak.Resources.Snow4.png"); | ||
var bitmap1 = BitmapFactory.FromStream(snowTexture1); | ||
var bitmap2 = BitmapFactory.FromStream(snowTexture2); | ||
var bitmap3 = BitmapFactory.FromStream(snowTexture3); | ||
var bitmap4 = BitmapFactory.FromStream(snowTexture4); | ||
this.Host1.ImageSource = bitmap4; | ||
this.Host2.ImageSource = bitmap3; | ||
this.Host3.ImageSource = bitmap2; | ||
this.Host4.ImageSource = bitmap1; | ||
this.Host5.ImageSource = bitmap1; | ||
} | ||
|
||
private async void SimulateWind(CancellationToken cancellationToken) | ||
{ | ||
while (!cancellationToken.IsCancellationRequested) | ||
{ | ||
var time = this.Time; | ||
this.SnowfallTransform1.X += this.BaseWind1 + this.GetNoise(time) * this.WindStrength1; | ||
this.SnowfallTransform2.X += this.BaseWind2 + this.GetNoise(time - 0.02) * this.WindStrength2; | ||
this.SnowfallTransform3.X += this.BaseWind3 + this.GetNoise(time - 0.03) * this.WindStrength3; | ||
this.SnowfallTransform4.X += this.BaseWind4 + this.GetNoise(time - 0.05) * this.WindStrength4; | ||
this.SnowfallTransform5.X += this.BaseWind5 + this.GetNoise(time - 0.08) * this.WindStrength5; | ||
await Task.Delay(16, cancellationToken).ConfigureAwait(true); | ||
} | ||
} | ||
|
||
private void UserControl_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
this.tokenSource?.Dispose(); | ||
this.tokenSource = new CancellationTokenSource(); | ||
this.SimulateWind(this.tokenSource.Token); | ||
} | ||
|
||
private void UserControl_Unloaded(object sender, RoutedEventArgs e) | ||
{ | ||
this.tokenSource?.Dispose(); | ||
this.tokenSource = default; | ||
} | ||
|
||
private double GetNoise(double source) | ||
{ | ||
var returnValue = 0d; | ||
for(var i = 0; i < Frequencies.Length; i++) | ||
{ | ||
var f = Frequencies[i]; | ||
var a = Amplitudes[i]; | ||
returnValue += a * Math.Sin(f * source * Math.PI * 2); | ||
} | ||
|
||
return returnValue / Divisor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.