From 022e14e98d3fa953a93e64f39d224e164dc4ad3c Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 9 Feb 2020 23:20:36 +0100 Subject: [PATCH] Added different rendering strategies for fill modes --- src/Artemis.Core/Models/Profile/Layer.cs | 121 ++- .../Plugins/LayerBrush/LayerBrush.cs | 4 +- .../Corsair/Keyboards/K95RGBPLATINUMXT/UK.xml | 753 ++++++++++++++++++ .../Corsair/Keyboards/K95RGBPLATINUMXT/US.xml | 464 +++++++++++ .../ColorBrush.cs | 5 +- .../NoiseBrush.cs | 9 +- .../Visualization/Tools/EditToolViewModel.cs | 9 + 7 files changed, 1318 insertions(+), 47 deletions(-) create mode 100644 src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/UK.xml create mode 100644 src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/US.xml diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 72e419954..64487e9a0 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -1,5 +1,4 @@ - -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -179,7 +178,7 @@ namespace Artemis.Core.Models.Profile public override void Render(double deltaTime, SKCanvas canvas) { - if (Path == null || LayerShape == null) + if (Path == null || LayerShape?.Path == null) return; canvas.Save(); @@ -190,49 +189,93 @@ namespace Artemis.Core.Models.Profile paint.BlendMode = BlendModeProperty.CurrentValue; paint.Color = new SKColor(0, 0, 0, (byte) (OpacityProperty.CurrentValue * 2.55f)); - // Apply transformations - var sizeProperty = ScaleProperty.CurrentValue; - var rotationProperty = RotationProperty.CurrentValue; - - var anchorPosition = GetLayerAnchorPosition(); - var anchorProperty = AnchorPointProperty.CurrentValue; - - // Translation originates from the unscaled center of the layer and is tied to the anchor - var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width; - var y = anchorPosition.Y - Bounds.MidY - anchorProperty.Y * Bounds.Height; - - // Rotation is always applied on the canvas - canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y); - // canvas.Scale(sizeProperty.Width, sizeProperty.Height, anchorPosition.X, anchorPosition.Y); - // Once the other transformations are done it is save to translate - // canvas.Translate(x, y); - - // Placeholder - if (LayerShape?.Path != null) + switch (FillTypeProperty.CurrentValue) { - var testColors = new List(); - for (var i = 0; i < 9; i++) - { - if (i != 8) - testColors.Add(SKColor.FromHsv(i * 32, 100, 100)); - else - testColors.Add(SKColor.FromHsv(0, 100, 100)); - } - - var path = new SKPath(LayerShape.Path); - path.Transform(SKMatrix.MakeTranslation(x, y)); - path.Transform(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y)); - - - paint.Shader = SKShader.CreateSweepGradient(new SKPoint(path.Bounds.MidX, path.Bounds.MidY), testColors.ToArray()); - canvas.DrawPath(path, paint); + case LayerFillType.Stretch: + StretchRender(canvas, paint); + break; + case LayerFillType.Clip: + ClipRender(canvas, paint); + break; + case LayerFillType.Tile: + TileRender(canvas, paint); + break; + default: + throw new ArgumentOutOfRangeException(); } } - LayerBrush?.Render(canvas); canvas.Restore(); } + private void StretchRender(SKCanvas canvas, SKPaint paint) + { + // Apply transformations + var sizeProperty = ScaleProperty.CurrentValue; + var rotationProperty = RotationProperty.CurrentValue; + + var anchorPosition = GetLayerAnchorPosition(); + var anchorProperty = AnchorPointProperty.CurrentValue; + + // Translation originates from the unscaled center of the shape and is tied to the anchor + var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width; + var y = anchorPosition.Y - Bounds.MidY - anchorProperty.Y * Bounds.Height; + + // Apply these before translation because anchorPosition takes translation into account + canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y); + canvas.Scale(sizeProperty.Width, sizeProperty.Height, anchorPosition.X, anchorPosition.Y); + // Once the other transformations are done it is save to translate + canvas.Translate(x, y); + + LayerBrush?.Render(canvas, LayerShape.Path, paint); + } + + private void ClipRender(SKCanvas canvas, SKPaint paint) + { + // Apply transformations + var sizeProperty = ScaleProperty.CurrentValue; + var rotationProperty = RotationProperty.CurrentValue; + + var anchorPosition = GetLayerAnchorPosition(); + var anchorProperty = AnchorPointProperty.CurrentValue; + + // Translation originates from the unscaled center of the layer and is tied to the anchor + var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width; + var y = anchorPosition.Y - Bounds.MidY - anchorProperty.Y * Bounds.Height; + + // Rotation is always applied on the canvas + canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y); + + var path = new SKPath(LayerShape.Path); + path.Transform(SKMatrix.MakeTranslation(x, y)); + path.Transform(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y)); + + LayerBrush?.Render(canvas, path, paint); + } + + private void TileRender(SKCanvas canvas, SKPaint paint) + { + // TODO + // Apply transformations + var sizeProperty = ScaleProperty.CurrentValue; + var rotationProperty = RotationProperty.CurrentValue; + + var anchorPosition = GetLayerAnchorPosition(); + var anchorProperty = AnchorPointProperty.CurrentValue; + + // Translation originates from the unscaled center of the shape and is tied to the anchor + var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width; + var y = anchorPosition.Y - Bounds.MidY - anchorProperty.Y * Bounds.Height; + + // Apply these before translation because anchorPosition takes translation into account + canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y); + canvas.Scale(sizeProperty.Width, sizeProperty.Height, anchorPosition.X, anchorPosition.Y); + // Once the other transformations are done it is save to translate + canvas.Translate(x, y); + + LayerBrush?.Render(canvas, LayerShape.Path, paint); + } + private SKPoint GetLayerAnchorPosition() { var positionProperty = PositionProperty.CurrentValue; diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs index 95adbc215..f4bdd6a2e 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs @@ -41,7 +41,9 @@ namespace Artemis.Core.Plugins.LayerBrush /// Called during rendering, in the order configured on the layer /// /// The layer canvas - public virtual void Render(SKCanvas canvas) + /// The path to be filled, represents the shape + /// The paint to be used to fill the shape + public virtual void Render(SKCanvas canvas, SKPath path, SKPaint paint) { } } diff --git a/src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/UK.xml b/src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/UK.xml new file mode 100644 index 000000000..8d8902ec9 --- /dev/null +++ b/src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/UK.xml @@ -0,0 +1,753 @@ + + + Corsair K95 RGB PLATINUM XT - Physical UK + Physical UK-Layout of Corsairs K95 RGB PLATINUM (Logical: BE, CH, DE, ES, EU_Int, FR, IT, ND, MEX, PT, TR, UK) + Keyboard + Key + Corsair + K95 RGB Platinum XT + 465 + 169 + Images\Corsair\Keyboards + K95RGBPLATINUM.png + + + 91.5 + 8.333 + 14.5mm + 12mm + + + 14.5mm + 12mm + + + 382 + 8.333 + 12mm + + + 30 + 32 + + + +12.667 + + + + + + +12.667 + + + + + + +12.667 + + + + + + +5 + + + + + +5 + 31 + 17mm + + + 17mm + + + 17mm + + + 17mm + + + 30 + 53 + + + + + + + + + + + + + + + 2 + + + +5 + + + + + +5 + + + + + + 30 + + + 1.5 + + + + + + + + + + + + + + + M0,0 L0,0.5 L0.16666666666,0.5 L0.16666666666,1 L1,1 L1,0 Z + 1.5 + 2 + + + +5 + + + + + +5 + + + + + 2 + + + 30 + ~ + 1.75 + + + + + + + + + + + + + + + +90.75 + + + + + 30 + + + 1.25 + + + + + + + + + + + + + + 2.75 + + + +24 + + + +24 + + + + + 2 + + + 30 + ~ + 1.5 + + + + 1.25 + + + 6.5 + + + 1.25 + + + + + 1.5 + + + +5 + + + + + +5 + 2 + + + + 7 + 32 + + + 7 + + + + + 7 + +1 + + + 7 + + + + + 7 + +1 + + + 7 + + + + + 0 + 0 + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/US.xml b/src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/US.xml new file mode 100644 index 000000000..88fc36faa --- /dev/null +++ b/src/Artemis.Plugins.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGBPLATINUMXT/US.xml @@ -0,0 +1,464 @@ + + + Corsair K95 RGB PLATINUM XT - Physical US + Physical UK-Layout of Corsairs K95 RGB PLATINUM (Logical: NA) + Keyboard + Key + Corsair + K95 RGB Platinum XT + 465 + 169 + Images\Corsair\Keyboards + K95RGBPLATINUM.png + + + 91.5 + 8.333 + 14.5mm + 12mm + + + 14.5mm + 12mm + + + 382 + 8.333 + 12mm + + + 30 + 32 + + + +12.667 + + + + + + +12.667 + + + + + + +12.667 + + + + + + +5 + + + + + +5 + 31 + 17mm + + + 17mm + + + 17mm + + + 17mm + + + 30 + 53 + + + + + + + + + + + + + + + 2 + + + +5 + + + + + +5 + + + + + + 30 + + + 1.5 + + + + + + + + + + + + + + + 1.5 + 1 + + + +5 + + + + + +5 + + + + + 2 + + + 30 + ~ + 1.75 + + + + + + + + + + + + + + 2.25 + + + +67 + + + + + 30 + + + 2.25 + + + + + + + + + + + + + 2.75 + + + +24 + + + +24 + + + + + 2 + + + 30 + ~ + 1.5 + + + + 1.25 + + + 6.5 + + + 1.25 + + + + + 1.5 + + + +5 + + + + + +5 + 2 + + + + 7 + 32 + + + 7 + + + + + 7 + +1 + + + 7 + + + + + 7 + +1 + + + 7 + + + + + 0 + 0 + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + M0.2,1 L1,1 L1,0 L0,0z + 24.47368mm + 1 + + + 24.47368mm + 1 + + + M0,0 L0,1 L0.8,1 L1,0z + 24.47368mm + 1 + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + 24.47368mm + 4mm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs index c6245906d..b7475ca56 100644 --- a/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs +++ b/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs @@ -68,9 +68,10 @@ namespace Artemis.Plugins.LayerBrushes.Color return new ColorBrushViewModel(this); } - public override void Render(SKCanvas canvas) + public override void Render(SKCanvas canvas, SKPath path, SKPaint paint) { - canvas.DrawPath(Layer.LayerShape.Path, _paint); + paint.Shader = _shader; + canvas.DrawPath(path, paint); } } } \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs b/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs index 5c78af444..70a8939d0 100644 --- a/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs +++ b/src/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs @@ -23,7 +23,6 @@ namespace Artemis.Plugins.LayerBrushes.Noise public new NoiseBrushSettings Settings { get; } - public override void Update(double deltaTime) { // TODO: Come up with a better way to use deltaTime @@ -40,11 +39,11 @@ namespace Artemis.Plugins.LayerBrushes.Noise return new NoiseBrushViewModel(this); } - public override void Render(SKCanvas canvas) + public override void Render(SKCanvas canvas, SKPath path, SKPaint paint) { // Scale down the render path to avoid computing a value for every pixel - var width = (int) (Math.Max(Layer.Bounds.Width, Layer.Bounds.Height) / Scale); - var height = (int) (Math.Max(Layer.Bounds.Width, Layer.Bounds.Height) / Scale); + 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); using (var bitmap = new SKBitmap(new SKImageInfo(width, height))) { @@ -75,8 +74,8 @@ namespace Artemis.Plugins.LayerBrushes.Noise } using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(Scale, Scale))) - using (var paint = new SKPaint {Shader = sh, BlendMode = Settings.BlendMode}) { + paint.Shader = sh; canvas.DrawPath(Layer.LayerShape.Path, paint); } } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs index 72b88ddeb..aee0f9da9 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs @@ -178,6 +178,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools throw new ArgumentOutOfRangeException(); } + // Make the sides even if shift is held down + if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) && e.ShapeControlPoint < ShapeControlPoint.TopCenter) + { + var bounds = _layerEditorService.GetLayerBounds(layer); + var smallestSide = Math.Min(bounds.Width * width, bounds.Height * height); + width = (float) Math.Round(1.0 / bounds.Width * smallestSide, 2, MidpointRounding.AwayFromZero); + height = (float) Math.Round(1.0 / bounds.Height * smallestSide, 2, MidpointRounding.AwayFromZero); + } + layer.ScaleProperty.SetCurrentValue(new SKSize(width, height), ProfileEditorService.CurrentTime); ProfileEditorService.UpdateProfilePreview(); }