-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1842 from Wibble199/feature/particle-layer
Particle layer
- Loading branch information
Showing
13 changed files
with
881 additions
and
45 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
Project-Aurora/Project-Aurora/Controls/Control_LayerPreview.xaml
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,24 @@ | ||
<UserControl x:Class="Aurora.Controls.Control_LayerPreview" | ||
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:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" | ||
xmlns:u="clr-namespace:Aurora.Utils" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded"> | ||
<UserControl.Resources> | ||
<u:ColorToBrushConverter x:Key="ColorToBrushConv" /> | ||
</UserControl.Resources> | ||
|
||
<DockPanel LastChildFill="True"> | ||
<DockPanel LastChildFill="True" DockPanel.Dock="Bottom" Height="28" Margin="0,8,0,0"> | ||
<Label Content="Preview background" /> | ||
<xctk:ColorPicker x:Name="previewBg" Margin="4,2" SelectedColor="Black" /> | ||
</DockPanel> | ||
<Border Background="{Binding ElementName=previewBg, Path=SelectedColor, Converter={StaticResource ColorToBrushConv}}"> | ||
<Image x:Name="imagePreview" /> | ||
</Border> | ||
</DockPanel> | ||
</UserControl> |
69 changes: 69 additions & 0 deletions
69
Project-Aurora/Project-Aurora/Controls/Control_LayerPreview.xaml.cs
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,69 @@ | ||
using Aurora.Settings.Layers; | ||
using System.IO; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace Aurora.Controls { | ||
|
||
/// <summary> | ||
/// A control that is capable of rendering the preview of any layer that correctly implements <see cref="INotifyRender"/>. | ||
/// </summary> | ||
public partial class Control_LayerPreview : UserControl { | ||
|
||
private bool eventsAttached; | ||
|
||
public Control_LayerPreview() { | ||
InitializeComponent(); | ||
} | ||
|
||
#region Target Layer Property | ||
public INotifyRender TargetLayer { | ||
get => (INotifyRender)GetValue(TargetLayerProperty); | ||
set => SetValue(TargetLayerProperty, value); | ||
} | ||
public static readonly DependencyProperty TargetLayerProperty = | ||
DependencyProperty.Register("TargetLayer", typeof(INotifyRender), typeof(Control_LayerPreview), new PropertyMetadata(null, TargetLayerChanged)); | ||
|
||
private static void TargetLayerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { | ||
var control = (Control_LayerPreview)d; | ||
// If the events are currently attached (I.E. a preview is currently running, then remove the handler from the old target and add to the new one) | ||
if (control.eventsAttached) { | ||
if (e.OldValue is INotifyRender old) | ||
old.LayerRender -= control.RenderLayerPreview; | ||
if (e.NewValue is INotifyRender @new) | ||
@new.LayerRender += control.RenderLayerPreview; | ||
} | ||
} | ||
#endregion | ||
|
||
// Start listening for when the particle layer is rendered so we can update the preview | ||
private void UserControl_Loaded(object sender, RoutedEventArgs e) { | ||
if (TargetLayer != null) | ||
TargetLayer.LayerRender += RenderLayerPreview; | ||
eventsAttached = true; | ||
} | ||
|
||
// Stop listenting for when the particle layer is rendered (since you can't see the image now anyways) | ||
private void UserControl_Unloaded(object sender, RoutedEventArgs e) { | ||
if (TargetLayer != null) | ||
TargetLayer.LayerRender -= RenderLayerPreview; | ||
eventsAttached = false; | ||
} | ||
|
||
// Take the bitmap from the layer and transform it into a format that can be used by WPF | ||
private void RenderLayerPreview(object sender, System.Drawing.Bitmap bitmap) => | ||
Dispatcher.Invoke(delegate { | ||
using (var ms = new MemoryStream()) { | ||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); | ||
ms.Position = 0; | ||
var bitmapImg = new BitmapImage(); | ||
bitmapImg.BeginInit(); | ||
bitmapImg.StreamSource = ms; | ||
bitmapImg.CacheOption = BitmapCacheOption.OnLoad; | ||
bitmapImg.EndInit(); | ||
imagePreview.Source = bitmapImg; | ||
} | ||
}); | ||
} | ||
} |
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
81 changes: 81 additions & 0 deletions
81
Project-Aurora/Project-Aurora/Settings/Layers/Control_ParticleLayer.xaml
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,81 @@ | ||
<UserControl x:Class="Aurora.Settings.Layers.Control_ParticleLayer" | ||
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:Aurora.Settings.Layers" | ||
xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox" | ||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" | ||
xmlns:u="clr-namespace:Aurora.Utils" | ||
xmlns:controls="clr-namespace:Aurora.Controls" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
Loaded="UserControl_Loaded"> | ||
<UserControl.Resources> | ||
<local:ParticleSpawnLocationsIsRegionConverter x:Key="ParticleSpawnLocationsIsRegionConv" /> | ||
</UserControl.Resources> | ||
|
||
<Grid u:GridHelper.Columns="140px,80px,80px,40px,280px" | ||
u:GridHelper.Rows="28px,28px,32px,28px,28px,28px,28px,28px,28px,28px,28px,28px,28px,28px,28px,1*"> | ||
|
||
<Label Content="Spawn location" HorizontalAlignment="Right" /> | ||
<ComboBox Grid.Column="1" Grid.ColumnSpan="2" Margin="4,2" SelectedValue="{Binding Properties._SpawnLocation}" ItemsSource="{u:EnumToItemsSource {x:Type local:ParticleSpawnLocations}}" DisplayMemberPath="Text" SelectedValuePath="Value" /> | ||
|
||
<Label Content="Color (over time)" Grid.Row="1" HorizontalAlignment="Right" /> | ||
<ncore:ColorBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="4,2" x:Name="gradientEditor" BrushChanged="GradientEditor_BrushChanged" /> | ||
|
||
<Label Content="Min" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Bottom" /> | ||
<Label Content="Max" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Bottom" /> | ||
|
||
<Label Content="Spawn time" Grid.Row="3" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="3" Grid.Column="1" x:Name="minSpawnTime" Value="{Binding Properties._MinSpawnTime}" Maximum="{Binding ElementName=maxSpawnTime, Path=Value}" Minimum="0" Increment=".1" Margin="4,2" /> | ||
<xctk:SingleUpDown Grid.Row="3" Grid.Column="2" x:Name="maxSpawnTime" Value="{Binding Properties._MaxSpawnTime}" Minimum="{Binding ElementName=minSpawnTime, Path=Value}" Increment=".1" Margin="4,2" /> | ||
|
||
<Label Content="Spawn amount" Grid.Row="4" HorizontalAlignment="Right" /> | ||
<xctk:IntegerUpDown Grid.Row="4" Grid.Column="1" x:Name="minSpawnAmount" Value="{Binding Properties._MinSpawnAmount}" Maximum="{Binding ElementName=maxSpawnAmount, Path=Value}" Minimum="1" Margin="4,2" /> | ||
<xctk:IntegerUpDown Grid.Row="4" Grid.Column="2" x:Name="maxSpawnAmount" Value="{Binding Properties._MaxSpawnAmount}" Minimum="{Binding ElementName=minSpawnAmount, Path=Value}" Margin="4,2" /> | ||
|
||
<Label Content="Lifetime" Grid.Row="5" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="5" Grid.Column="1" x:Name="minLifetime" Value="{Binding Properties._MinLifetime}" Maximum="{Binding ElementName=maxLifetime, Path=Value}" Increment=".1" Margin="4,2" /> | ||
<xctk:SingleUpDown Grid.Row="5" Grid.Column="2" x:Name="maxLifetime" Value="{Binding Properties._MaxLifetime}" Minimum="{Binding ElementName=minLifetime, Path=Value}" Increment=".1" Margin="4,2" /> | ||
|
||
<Label Content="Initial horizontal velocity" Grid.Row="6" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="6" Grid.Column="1" x:Name="minInitialVelocityX" Value="{Binding Properties._MinInitialVelocityX}" Maximum="{Binding ElementName=maxInitialVelocityX, Path=Value}" Increment=".1" Margin="4,2" /> | ||
<xctk:SingleUpDown Grid.Row="6" Grid.Column="2" x:Name="maxInitialVelocityX" Value="{Binding Properties._MaxInitialVelocityX}" Minimum="{Binding ElementName=minInitialVelocityX, Path=Value}" Increment=".1" Margin="4,2" /> | ||
|
||
<Label Content="Initial vertical velocity" Grid.Row="7" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="7" Grid.Column="1" x:Name="minInitialVelocityY" Value="{Binding Properties._MinInitialVelocityY}" Maximum="{Binding ElementName=maxInitialVelocityY, Path=Value}" Increment=".1" Margin="4,2" /> | ||
<xctk:SingleUpDown Grid.Row="7" Grid.Column="2" x:Name="maxInitialVelocityY" Value="{Binding Properties._MaxInitialVelocityY}" Minimum="{Binding ElementName=minInitialVelocityY, Path=Value}" Increment=".1" Margin="4,2" /> | ||
|
||
<Label Content="Horizontal acceleration" Grid.Row="8" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2" Value="{Binding Properties._AccelerationX}" Increment=".1" Margin="4,2" /> | ||
|
||
<Label Content="Vertical acceleration" Grid.Row="9" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="9" Grid.Column="1" Grid.ColumnSpan="2" Value="{Binding Properties._AccelerationY}" Increment=".1" Margin="4,2" /> | ||
|
||
<Label Content="Horizontal Drag" Grid.Row="10" HorizontalAlignment="Right" /> | ||
<Slider Grid.Row="10" Grid.Column="1" Grid.ColumnSpan="2" Value="{Binding Properties._DragX}" Minimum="0" Maximum="1" Margin="4,2" /> | ||
|
||
<Label Content="Vertical Drag" Grid.Row="11" HorizontalAlignment="Right" /> | ||
<Slider Grid.Row="11" Grid.Column="1" Grid.ColumnSpan="2" Value="{Binding Properties._DragY}" Minimum="0" Maximum="1" Margin="4,2" /> | ||
|
||
<Label Content="Initial particle size" Grid.Row="12" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="12" Grid.Column="1" x:Name="minInitialSize" Value="{Binding Properties._MinSize}" Maximum="{Binding ElementName=maxInitialSize, Path=Value}" Increment="1" Margin="4,2" /> | ||
<xctk:SingleUpDown Grid.Row="12" Grid.Column="2" x:Name="maxInitialSize" Value="{Binding Properties._MaxSize}" Minimum="{Binding ElementName=minInitialSize, Path=Value}" Increment="1" Margin="4,2" /> | ||
|
||
<Label Content="Size change" Grid.Row="13" HorizontalAlignment="Right" /> | ||
<xctk:SingleUpDown Grid.Row="13" Grid.Column="1" Grid.ColumnSpan="2" Value="{Binding Properties._DeltaSize}" Increment=".5" Margin="4,2" /> | ||
|
||
<Label Content="Presets" Grid.Row="14" HorizontalAlignment="Right" /> | ||
<DockPanel Grid.Row="14" Grid.Column="1" Grid.ColumnSpan="2" Margin="4,2"> | ||
<Button Content="Apply" DockPanel.Dock="Right" Margin="4,0,0,0" Padding="6,0" Click="ApplyButton_Click" /> | ||
<ComboBox x:Name="presetsCombo" DisplayMemberPath="Text" SelectedValuePath="ApplyFunc" /> | ||
</DockPanel> | ||
|
||
<!-- Note that we cannot set the visibility of this to Hidden or Collapsed, else the control will not be initialised (and therefore will not show the freeform region). It can just be moved really far offscreen instead. --> | ||
<controls:KeySequence Margin="100000,100000,0,0" Title="Spawn region" Sequence="{Binding Properties._Sequence, Mode=TwoWay}" ShowOnCanvas="{Binding Properties._SpawnLocation, Mode=OneWay, Converter={StaticResource ParticleSpawnLocationsIsRegionConv}}" /> | ||
|
||
<Label Content="Preview" Grid.Column="4" /> | ||
<controls:Control_LayerPreview Grid.Column="4" Grid.Row="1" Grid.RowSpan="5" TargetLayer="{Binding .}" /> | ||
</Grid> | ||
</UserControl> |
Oops, something went wrong.