mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Refactored shape brushes to use the properties system
This commit is contained in:
1 parent
128a656f4b
commit
ebea8b16a3
40 files changed
+650
-686
No files matched your search
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user