mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Skia WIP
This commit is contained in:
parent
9148323ad5
commit
b8a678c97f
@ -110,6 +110,9 @@
|
||||
<Reference Include="Serilog.Sinks.File, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.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>
|
||||
@ -125,7 +128,6 @@
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.3.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<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>
|
||||
@ -156,6 +158,7 @@
|
||||
<Compile Include="Events\FrameRenderingEventArgs.cs" />
|
||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||
<Compile Include="Extensions\DirectoryInfoExtensions.cs" />
|
||||
<Compile Include="Extensions\DoubleExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbColorExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbDeviceExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
|
||||
@ -189,7 +192,6 @@
|
||||
<Compile Include="Models\Profile\Profile.cs" />
|
||||
<Compile Include="Ninject\CoreModule.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RGB.NET\DirectBitmap.cs" />
|
||||
<Compile Include="RGB.NET\GraphicsDecorator.cs" />
|
||||
<Compile Include="Services\DeviceService.cs" />
|
||||
<Compile Include="Services\Interfaces\ILayerService.cs" />
|
||||
@ -230,5 +232,7 @@
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Fody.6.0.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.5\build\Fody.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\PropertyChanged.Fody.3.1.3\build\PropertyChanged.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\PropertyChanged.Fody.3.1.3\build\PropertyChanged.Fody.props'))" />
|
||||
<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>
|
||||
<Import Project="..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" />
|
||||
</Project>
|
||||
@ -1,23 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.RGB.NET;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Events
|
||||
{
|
||||
public class FrameRenderingEventArgs : EventArgs
|
||||
{
|
||||
public FrameRenderingEventArgs(List<Module> modules, Bitmap bitmap, double deltaTime, RGBSurface rgbSurface)
|
||||
public FrameRenderingEventArgs(List<Module> modules, GraphicsDecorator graphicsDecorator, double deltaTime, RGBSurface rgbSurface)
|
||||
{
|
||||
Modules = modules;
|
||||
Bitmap = bitmap;
|
||||
GraphicsDecorator = graphicsDecorator;
|
||||
DeltaTime = deltaTime;
|
||||
RgbSurface = rgbSurface;
|
||||
}
|
||||
|
||||
public List<Module> Modules { get; }
|
||||
public Bitmap Bitmap { get; }
|
||||
public GraphicsDecorator GraphicsDecorator { get; }
|
||||
public double DeltaTime { get; }
|
||||
public RGBSurface RgbSurface { get; }
|
||||
}
|
||||
|
||||
12
src/Artemis.Core/Extensions/DoubleExtensions.cs
Normal file
12
src/Artemis.Core/Extensions/DoubleExtensions.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Extensions
|
||||
{
|
||||
public static class DoubleExtensions
|
||||
{
|
||||
public static int RoundToInt(this double number)
|
||||
{
|
||||
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Storage.Entities.Surface;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
using Stylet;
|
||||
using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
@ -38,8 +39,8 @@ namespace Artemis.Core.Models.Surface
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
}
|
||||
|
||||
public Rectangle RenderRectangle { get; private set; }
|
||||
public GraphicsPath RenderPath { get; private set; }
|
||||
public SKRect RenderRectangle { get; private set; }
|
||||
public SKPath RenderPath { get; private set; }
|
||||
|
||||
public IRGBDevice RgbDevice { get; }
|
||||
public Plugin Plugin { get; }
|
||||
@ -95,6 +96,12 @@ namespace Artemis.Core.Models.Surface
|
||||
|
||||
internal void CalculateRenderProperties()
|
||||
{
|
||||
RenderRectangle = SKRect.Create(
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.Y * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt()
|
||||
);
|
||||
RenderRectangle = new Rectangle(
|
||||
(int) Math.Round(RgbDevice.Location.X * Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
(int) Math.Round(RgbDevice.Location.Y * Surface.Scale, MidpointRounding.AwayFromZero),
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
@ -37,8 +38,8 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time since the last render</param>
|
||||
/// <param name="surface">The RGB Surface to render to</param>
|
||||
/// <param name="graphics"></param>
|
||||
public abstract void Render(double deltaTime, ArtemisSurface surface, Graphics graphics);
|
||||
/// <param name="canvas"></param>
|
||||
public abstract void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the module's view model is being show, return view models here to create tabs for them
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Artemis.Core.RGB.NET
|
||||
{
|
||||
public class DirectBitmap : IDisposable
|
||||
{
|
||||
public DirectBitmap(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
Bits = new int[width * height];
|
||||
BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
|
||||
Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject());
|
||||
}
|
||||
|
||||
public Bitmap Bitmap { get; }
|
||||
public int[] Bits { get; }
|
||||
public bool Disposed { get; private set; }
|
||||
public int Height { get; }
|
||||
public int Width { get; }
|
||||
|
||||
protected GCHandle BitsHandle { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Disposed) return;
|
||||
Disposed = true;
|
||||
Bitmap.Dispose();
|
||||
BitsHandle.Free();
|
||||
}
|
||||
|
||||
public void SetPixel(int x, int y, Color colour)
|
||||
{
|
||||
var index = x + y * Width;
|
||||
var col = colour.ToArgb();
|
||||
|
||||
Bits[index] = col;
|
||||
}
|
||||
|
||||
public Color GetPixel(int x, int y)
|
||||
{
|
||||
var index = x + y * Width;
|
||||
if (index >= 0 && index - 1 <= Bits.Length)
|
||||
{
|
||||
var col = Bits[index];
|
||||
var result = Color.FromArgb(col);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return Color.Black;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,13 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using Color = RGB.NET.Core.Color;
|
||||
using Rectangle = RGB.NET.Core.Rectangle;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.RGB.NET
|
||||
{
|
||||
public class GraphicsDecorator : AbstractDecorator, IBrushDecorator, IDisposable
|
||||
{
|
||||
private readonly double _scale;
|
||||
private DirectBitmap _bitmap;
|
||||
|
||||
public GraphicsDecorator(ILedGroup ledGroup, double scale)
|
||||
{
|
||||
@ -18,27 +15,27 @@ namespace Artemis.Core.RGB.NET
|
||||
|
||||
var leds = ledGroup.GetLeds().ToList();
|
||||
if (!leds.Any())
|
||||
_bitmap = null;
|
||||
else
|
||||
{
|
||||
var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.X + l.AbsoluteLedRectangle.Size.Width) * scale, 4096);
|
||||
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.Y + l.AbsoluteLedRectangle.Size.Height) * scale, 4096);
|
||||
return;
|
||||
|
||||
_bitmap = new DirectBitmap((int) width, (int) height);
|
||||
}
|
||||
var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.X + l.AbsoluteLedRectangle.Size.Width) * scale, 4096);
|
||||
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.Y + l.AbsoluteLedRectangle.Size.Height) * scale, 4096);
|
||||
Bitmap = new SKBitmap(new SKImageInfo(RoundToInt(width), RoundToInt(height)));
|
||||
Canvas = new SKCanvas(Bitmap);
|
||||
}
|
||||
|
||||
public SKBitmap Bitmap { get; private set; }
|
||||
public SKCanvas Canvas { get; private set; }
|
||||
|
||||
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
||||
{
|
||||
if (Bitmap == null)
|
||||
return new Color(0, 0, 0);
|
||||
|
||||
var x = renderTarget.Led.AbsoluteLedRectangle.Center.X * _scale;
|
||||
var y = renderTarget.Led.AbsoluteLedRectangle.Center.Y * _scale;
|
||||
if (_bitmap != null && _bitmap.Width - 1 >= x && _bitmap.Height - 1 >= y)
|
||||
{
|
||||
var pixel = _bitmap.GetPixel((int) x, (int) y);
|
||||
return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
|
||||
}
|
||||
|
||||
return new Color(0, 0, 0);
|
||||
var pixel = Bitmap.GetPixel(RoundToInt(x), RoundToInt(y));
|
||||
return new Color(pixel.Alpha, pixel.Red, pixel.Green, pixel.Blue);
|
||||
}
|
||||
|
||||
public override void OnDetached(IDecoratable decoratable)
|
||||
@ -48,27 +45,15 @@ namespace Artemis.Core.RGB.NET
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_bitmap?.Dispose();
|
||||
_bitmap = null;
|
||||
Bitmap?.Dispose();
|
||||
Canvas?.Dispose();
|
||||
Bitmap = null;
|
||||
Canvas = null;
|
||||
}
|
||||
|
||||
public Graphics GetGraphics()
|
||||
private int RoundToInt(double number)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _bitmap == null ? null : Graphics.FromImage(_bitmap.Bitmap);
|
||||
}
|
||||
catch (AccessViolationException)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Bitmap GetBitmap()
|
||||
{
|
||||
return _bitmap?.Bitmap;
|
||||
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,6 @@ using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
using Color = System.Drawing.Color;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@ -78,26 +77,20 @@ namespace Artemis.Core.Services
|
||||
module.Update(args.DeltaTime);
|
||||
}
|
||||
|
||||
// If there is no graphics decorator, skip the frame
|
||||
if (_rgbService.GraphicsDecorator == null)
|
||||
// If there is no ready graphics decorator, skip the frame
|
||||
if (_rgbService.GraphicsDecorator?.Canvas == null)
|
||||
return;
|
||||
|
||||
// Render all active modules
|
||||
using (var g = _rgbService.GraphicsDecorator.GetGraphics())
|
||||
_rgbService.GraphicsDecorator.Canvas.Clear();
|
||||
lock (_modules)
|
||||
{
|
||||
// If there are no graphics, skip the frame
|
||||
if (g == null)
|
||||
return;
|
||||
|
||||
g.Clear(Color.Black);
|
||||
lock (_modules)
|
||||
{
|
||||
foreach (var module in _modules)
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, g);
|
||||
}
|
||||
foreach (var module in _modules)
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, _rgbService.GraphicsDecorator.Canvas);
|
||||
}
|
||||
|
||||
OnFrameRendering(new FrameRenderingEventArgs(_modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
|
||||
|
||||
OnFrameRendering(new FrameRenderingEventArgs(_modules, _rgbService.GraphicsDecorator, args.DeltaTime, _rgbService.Surface));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -107,7 +100,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
||||
{
|
||||
OnFrameRendered(new FrameRenderedEventArgs(_rgbService.GraphicsDecorator.GetBitmap(), _rgbService.Surface));
|
||||
OnFrameRendered(new FrameRenderedEventArgs(_rgbService.GraphicsDecorator, _rgbService.Surface));
|
||||
}
|
||||
|
||||
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="AppDomainToolkit" version="1.0.4.3" targetFramework="net461" />
|
||||
<package id="Ben.Demystifier" version="0.1.4" targetFramework="net472" />
|
||||
@ -15,6 +14,7 @@
|
||||
<package id="Serilog" version="2.8.0" targetFramework="net472" />
|
||||
<package id="Serilog.Enrichers.Demystify" version="1.0.0-dev-00019" targetFramework="net472" />
|
||||
<package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net472" />
|
||||
<package id="SkiaSharp" version="1.68.1" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.2.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Collections.Immutable" version="1.6.0-preview8.19405.3" targetFramework="net472" />
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -48,12 +50,27 @@
|
||||
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</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.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>
|
||||
<Private>False</Private>
|
||||
@ -100,4 +117,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,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="MaterialDesignColors" version="1.2.0" targetFramework="net472" />
|
||||
<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.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>
|
||||
@ -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>
|
||||
@ -117,16 +117,31 @@
|
||||
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Serilog.2.8.0\lib\net46\Serilog.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.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.3.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.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ComponentModel.Annotations.4.6.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<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>
|
||||
</Reference>
|
||||
@ -420,5 +435,7 @@
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Fody.6.0.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.5\build\Fody.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\PropertyChanged.Fody.3.1.3\build\PropertyChanged.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\PropertyChanged.Fody.3.1.3\build\PropertyChanged.Fody.props'))" />
|
||||
<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>
|
||||
<Import Project="..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" />
|
||||
</Project>
|
||||
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="Castle.Core" version="4.4.0" targetFramework="net461" />
|
||||
<package id="ControlzEx" version="3.0.2.4" targetFramework="net472" />
|
||||
@ -17,7 +16,12 @@
|
||||
<package id="Ninject.Extensions.Factory" version="3.3.2" targetFramework="net461" />
|
||||
<package id="PropertyChanged.Fody" version="3.1.3" targetFramework="net472" />
|
||||
<package id="Serilog" version="2.8.0" targetFramework="net472" />
|
||||
<package id="SkiaSharp" version="1.68.1" targetFramework="net472" />
|
||||
<package id="Stylet" version="1.3.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.4.0" targetFramework="net472" />
|
||||
<package id="System.ComponentModel.Annotations" version="4.6.0" targetFramework="net472" />
|
||||
<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>
|
||||
Loading…
x
Reference in New Issue
Block a user