mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Skia WIP
This commit is contained in:
1 parent
f8037feb81
commit
0e3afef6ca
16 files changed
+172
-166
No files matched your search
@@ -13,6 +13,8 @@
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -42,15 +44,26 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp, Version=1.68.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Stylet, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.2.0\lib\net45\Stylet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Drawing.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
@@ -97,4 +110,11 @@
|
||||
<PostBuildEvent>echo Copying plugin to Artemis.UI output directory
|
||||
XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,21 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.Plugins.Modules.General.ViewModels;
|
||||
using RGB.NET.Core;
|
||||
using Color = System.Drawing.Color;
|
||||
using SkiaSharp;
|
||||
using Color = RGB.NET.Core.Color;
|
||||
|
||||
namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public class GeneralModule : ProfileModule
|
||||
{
|
||||
private readonly ColorBlend _rainbowColorBlend;
|
||||
private readonly PluginSettings _settings;
|
||||
|
||||
public GeneralModule(PluginInfo pluginInfo, PluginSettings settings, ISurfaceService surfaceService) : base(pluginInfo)
|
||||
@@ -23,31 +22,25 @@ namespace Artemis.Plugins.Modules.General
|
||||
_settings = settings;
|
||||
DisplayName = "General";
|
||||
ExpandsMainDataModel = true;
|
||||
DeviceBrushes = new Dictionary<ArtemisDevice, TextureBrush>();
|
||||
DeviceShaders = new Dictionary<ArtemisDevice, SKShader>();
|
||||
RainbowColors = new List<SKColor>();
|
||||
|
||||
var testSetting = _settings.GetSetting("TestSetting", DateTime.Now);
|
||||
|
||||
Hues = new int[1000];
|
||||
for (var i = 0; i < 1000; i++)
|
||||
Hues[i] = ColorHelpers.GetRandomHue();
|
||||
|
||||
_rainbowColorBlend = new ColorBlend(9);
|
||||
for (var i = 0; i < 9; i++)
|
||||
{
|
||||
_rainbowColorBlend.Positions[i] = i / 8f;
|
||||
if (i != 8)
|
||||
_rainbowColorBlend.Colors[i] = ColorHelpers.ColorFromHSV(i * 32, 1, 1);
|
||||
RainbowColors.Add(SKColor.FromHsv(i * 32, 1, 1));
|
||||
else
|
||||
_rainbowColorBlend.Colors[i] = ColorHelpers.ColorFromHSV(0, 1, 1);
|
||||
RainbowColors.Add(SKColor.FromHsv(0, 1, 1));
|
||||
}
|
||||
|
||||
surfaceService.SurfaceConfigurationUpdated += (sender, args) => DeviceBrushes.Clear();
|
||||
surfaceService.SurfaceConfigurationUpdated += (sender, args) => DeviceShaders.Clear();
|
||||
var testSetting = _settings.GetSetting("TestSetting", DateTime.Now);
|
||||
}
|
||||
|
||||
public int[] Hues { get; set; }
|
||||
public int MovePercentage { get; set; }
|
||||
|
||||
public Dictionary<ArtemisDevice, TextureBrush> DeviceBrushes { get; set; }
|
||||
public Dictionary<ArtemisDevice, SKShader> DeviceShaders { get; set; }
|
||||
public List<SKColor> RainbowColors { get; set; }
|
||||
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
@@ -59,13 +52,6 @@ namespace Artemis.Plugins.Modules.General
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
for (var i = 0; i < Hues.Length; i++)
|
||||
{
|
||||
Hues[i]++;
|
||||
if (Hues[i] > 360)
|
||||
Hues[i] = 0;
|
||||
}
|
||||
|
||||
MovePercentage++;
|
||||
if (MovePercentage > 100)
|
||||
MovePercentage = 0;
|
||||
@@ -74,29 +60,31 @@ namespace Artemis.Plugins.Modules.General
|
||||
}
|
||||
|
||||
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas)
|
||||
{
|
||||
// Per-device coloring, slower
|
||||
// RenderPerDevice(surface, graphics);
|
||||
foreach (var device in surface.Devices)
|
||||
{
|
||||
if (!DeviceShaders.ContainsKey(device))
|
||||
DeviceShaders.Add(device,
|
||||
SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(device.RenderRectangle.Width, device.RenderRectangle.Height), RainbowColors.ToArray(), SKShaderTileMode.Clamp));
|
||||
|
||||
// Per-LED coloring, slowest
|
||||
// RenderPerLed(surface, graphics);
|
||||
var brush = DeviceShaders[device];
|
||||
brush.TranslateTransform((int) Math.Round(device.RenderRectangle.Width / 100.0 * MovePercentage), 0);
|
||||
graphics.FillPath(brush, device.RenderPath);
|
||||
brush.TranslateTransform((int) Math.Round(device.RenderRectangle.Width / 100.0 * MovePercentage) * -1, 0);
|
||||
|
||||
base.Render(deltaTime, surface, graphics);
|
||||
}
|
||||
|
||||
public void RenderFullSurface(ArtemisSurface surface, Graphics graphics)
|
||||
{
|
||||
graphics.DrawRectangle(new Pen(Color.Red), device.RenderRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderPerDevice(ArtemisSurface surface, Graphics graphics)
|
||||
{
|
||||
foreach (var device in surface.Devices)
|
||||
{
|
||||
if (!DeviceBrushes.ContainsKey(device))
|
||||
DeviceBrushes.Add(device, new TextureBrush(RenderGradientForDevice(device), WrapMode.Tile));
|
||||
if (!DeviceShaders.ContainsKey(device))
|
||||
DeviceShaders.Add(device, new TextureBrush(RenderGradientForDevice(device), WrapMode.Tile));
|
||||
|
||||
var brush = DeviceBrushes[device];
|
||||
var brush = DeviceShaders[device];
|
||||
brush.TranslateTransform((int) Math.Round(device.RenderRectangle.Width / 100.0 * MovePercentage), 0);
|
||||
graphics.FillPath(brush, device.RenderPath);
|
||||
brush.TranslateTransform((int) Math.Round(device.RenderRectangle.Width / 100.0 * MovePercentage) * -1, 0);
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="QRCoder" version="1.3.5" targetFramework="net461" />
|
||||
<package id="SkiaSharp" version="1.68.1" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.2.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.4.0" targetFramework="net472" />
|
||||
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net461" />
|
||||
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
||||
Reference in new issue
Block a user