Refactored shape brushes to use the properties system

This commit is contained in:
Robert committed 2020-02-11 16:36:34 +01:00
1 parent 128a656f4b
commit ebea8b16a3
40 files changed
+650 -686

No files matched your search

@@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp>
<ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
@@ -90,8 +90,6 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="NoiseBrushSettings.cs" />
<Compile Include="NoiseBrushViewModel.cs" />
<Compile Include="NoiseBrush.cs" />
<Compile Include="NoiseBrushProvider.cs" />
<Compile Include="Utilities\OpenSimplexNoise.cs" />
@@ -115,12 +113,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Page Include="NoiseBrushView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@@ -1,5 +1,6 @@
using System;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Plugins.LayerBrushes.Noise.Utilities;
using SkiaSharp;
@@ -13,20 +14,25 @@ namespace Artemis.Plugins.LayerBrushes.Noise
private readonly OpenSimplexNoise _noise;
private float _z;
public NoiseBrush(Layer layer, NoiseBrushSettings settings, LayerBrushDescriptor descriptor) : base(layer, settings, descriptor)
public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
{
Settings = settings;
MainColorProperty = RegisterLayerProperty<SKColor>("Brush.MainColor", "Main color", "The main color of the noise.");
ScaleProperty = RegisterLayerProperty<SKSize>("Brush.Scale", "Scale", "The scale of the noise.");
AnimationSpeedProperty = RegisterLayerProperty<float>("Brush.AnimationSpeed", "Animation speed", "The speed at which the noise moves.");
ScaleProperty.InputAffix = "%";
_z = Rand.Next(0, 4096);
_noise = new OpenSimplexNoise(Rand.Next(0, 4096));
}
public new NoiseBrushSettings Settings { get; }
public LayerProperty<SKColor> MainColorProperty { get; set; }
public LayerProperty<SKSize> ScaleProperty { get; set; }
public LayerProperty<float> AnimationSpeedProperty { get; set; }
public override void Update(double deltaTime)
{
// TODO: Come up with a better way to use deltaTime
_z += Settings.AnimationSpeed / 500f / 0.04f * (float) deltaTime;
_z += AnimationSpeedProperty.CurrentValue / 500f / 0.04f * (float) deltaTime;
if (_z >= float.MaxValue)
_z = 0;
@@ -34,17 +40,15 @@ namespace Artemis.Plugins.LayerBrushes.Noise
base.Update(deltaTime);
}
public override LayerBrushViewModel GetViewModel()
{
return new NoiseBrushViewModel(this);
}
public override void Render(SKCanvas canvas, SKPath path, SKPaint paint)
{
var mainColor = MainColorProperty.CurrentValue;
var scale = ScaleProperty.CurrentValue;
// Scale down the render path to avoid computing a value for every pixel
var width = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / Scale);
var height = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / Scale);
var opacity = (float) Math.Round(Settings.Color.Alpha / 255.0, 2, MidpointRounding.AwayFromZero);
var opacity = (float) Math.Round(mainColor.Alpha / 255.0, 2, MidpointRounding.AwayFromZero);
using (var bitmap = new SKBitmap(new SKImageInfo(width, height)))
{
bitmap.Erase(new SKColor(0, 0, 0, 0));
@@ -60,15 +64,14 @@ namespace Artemis.Plugins.LayerBrushes.Noise
{
for (var y = yStart; y < yEnd; y++)
{
var v = _noise.Evaluate(Settings.XScale * x / width, Settings.YScale * y / height, _z);
var v = _noise.Evaluate(scale.Width * x / width, scale.Height * y / height, _z);
var alpha = (byte) ((v + 1) * 127 * opacity);
// There's some fun stuff we can do here, like creating hard lines
// if (alpha > 128)
// alpha = 255;
// else
// alpha = 0;
var color = new SKColor(Settings.Color.Red, Settings.Color.Green, Settings.Color.Blue, alpha);
bitmap.SetPixel((int) x, (int) y, color);
bitmap.SetPixel((int) x, (int) y, new SKColor(mainColor.Red, mainColor.Green, mainColor.Blue, alpha));
}
}
}
@@ -1,44 +0,0 @@
using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Noise
{
public class NoiseBrushSettings : LayerBrushSettings
{
private float _animationSpeed;
private SKBlendMode _blendMode;
private SKColor _color;
private float _xScale;
private float _yScale;
public SKColor Color
{
get => _color;
set => SetAndNotify(ref _color, value);
}
public SKBlendMode BlendMode
{
get => _blendMode;
set => SetAndNotify(ref _blendMode, value);
}
public float XScale
{
get => _xScale;
set => SetAndNotify(ref _xScale, value);
}
public float YScale
{
get => _yScale;
set => SetAndNotify(ref _yScale, value);
}
public float AnimationSpeed
{
get => _animationSpeed;
set => SetAndNotify(ref _animationSpeed, value);
}
}
}
@@ -1,140 +0,0 @@
<UserControl x:Class="Artemis.Plugins.LayerBrushes.Noise.NoiseBrushView"
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:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
xmlns:noiseBrush="clr-namespace:Artemis.Plugins.LayerBrushes.Noise"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type noiseBrush:NoiseBrushViewModel}}">
<!-- <UserControl.Resources> -->
<!-- <ResourceDictionary> -->
<!-- <ResourceDictionary.MergedDictionaries> -->
<!-- <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> -->
<!-- </ResourceDictionary.MergedDictionaries> -->
<!-- <converters:SKColorToColorConverter x:Key="SKColorToColorConverter" /> -->
<!-- </ResourceDictionary> -->
<!-- </UserControl.Resources> -->
<!-- -->
<!-- <Grid Margin="12"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- </Grid.RowDefinitions> -->
<!-- -->
<!-- <Grid Grid.Row="0"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Text="Noise color" /> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <artemis:ColorPicker Color="{Binding Brush.Settings.Color, Converter={StaticResource SKColorToColorConverter}}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- <Grid Grid.Row="1"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="Blend mode" /> -->
<!-- </TextBlock> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"> -->
<!-- <Run Text="Affects how the noise is rendered on the rest of the layer" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <ComboBox HorizontalAlignment="Left" -->
<!-- ItemsSource="{Binding BlendModes}" -->
<!-- SelectedValuePath="Value" -->
<!-- DisplayMemberPath="Description" -->
<!-- Width="100" -->
<!-- SelectedValue="{Binding Brush.Settings.BlendMode}" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- <Grid Grid.Row="2"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="X Scale" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding Brush.Settings.XScale}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- ~1~ Sample 1 @1@ -->
<!-- <Grid Grid.Row="3"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="Y Scale" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding Brush.Settings.YScale}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- ~1~ Setting 2 @1@ -->
<!-- <Grid Grid.Row="4"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="Animation speed" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- -->
<!-- <Slider Orientation="Horizontal" TickFrequency="1" Minimum="1" Maximum="100" Value="{Binding Brush.Settings.AnimationSpeed}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- </Grid> -->
</UserControl>
@@ -1,18 +0,0 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.UI.Shared.Utilities;
using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Noise
{
public class NoiseBrushViewModel : LayerBrushViewModel
{
public NoiseBrushViewModel(NoiseBrush brush) : base(brush)
{
Brush = brush;
}
public new NoiseBrush Brush { get; }
public IEnumerable<ValueDescription> BlendModes => EnumUtilities.GetAllValuesAndDescriptions(typeof(SKBlendMode));
}
}