mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Core - Implemented clipping modes
This commit is contained in:
parent
51a21b7a8a
commit
73115898de
@ -219,10 +219,7 @@ namespace Artemis.Core.Models.Profile
|
||||
StretchRender(canvas, paint);
|
||||
break;
|
||||
case LayerFillType.Clip:
|
||||
ClipRender(canvas, paint);
|
||||
break;
|
||||
case LayerFillType.Tile:
|
||||
TileRender(canvas, paint);
|
||||
ClipRender(canvas, paint, true);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@ -247,14 +244,13 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
// 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.Scale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y);
|
||||
canvas.Translate(x, y);
|
||||
|
||||
LayerBrush?.Render(canvas, LayerShape.Path, paint);
|
||||
LayerBrush?.Render(canvas, new SKPath(LayerShape.Path), paint);
|
||||
}
|
||||
|
||||
private void ClipRender(SKCanvas canvas, SKPaint paint)
|
||||
private void ClipRender(SKCanvas canvas, SKPaint paint, bool rotatePath)
|
||||
{
|
||||
// Apply transformations
|
||||
var sizeProperty = ScaleProperty.CurrentValue;
|
||||
@ -263,43 +259,25 @@ namespace Artemis.Core.Models.Profile
|
||||
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
|
||||
var clipPath = new SKPath(LayerShape.Path);
|
||||
clipPath.Transform(SKMatrix.MakeTranslation(x, y));
|
||||
clipPath.Transform(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y));
|
||||
clipPath.Transform(SKMatrix.MakeRotationDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y));
|
||||
canvas.ClipPath(clipPath);
|
||||
|
||||
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);
|
||||
// Render the entire layer, the clip will ensure the shape is matched
|
||||
var renderPath = new SKPath();
|
||||
renderPath.AddRect(Path.Bounds);
|
||||
LayerBrush?.Render(canvas, renderPath, paint);
|
||||
}
|
||||
|
||||
|
||||
internal void CalculateRenderProperties()
|
||||
{
|
||||
if (!Leds.Any())
|
||||
@ -582,7 +560,6 @@ namespace Artemis.Core.Models.Profile
|
||||
public enum LayerFillType
|
||||
{
|
||||
Stretch,
|
||||
Clip,
|
||||
Tile
|
||||
Clip
|
||||
}
|
||||
}
|
||||
@ -32,6 +32,7 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
||||
|
||||
CreateShader();
|
||||
Layer.RenderPropertiesUpdated += (sender, args) => CreateShader();
|
||||
GradientTypeProperty.ValueChanged += (sender, args) => CreateShader();
|
||||
}
|
||||
|
||||
public LayerProperty<SKColor> ColorProperty { get; set; }
|
||||
|
||||
@ -36,14 +36,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
_coreService = coreService;
|
||||
_settingsService = settingsService;
|
||||
_layerPropertyVmFactory = layerPropertyVmFactory;
|
||||
_layerPropertyViewModels = new List<LayerPropertyViewModel>();
|
||||
|
||||
PixelsPerSecond = 31;
|
||||
PropertyTree = propertyTreeVmFactory.Create(this);
|
||||
PropertyTimeline = propertyTimelineVmFactory.Create(this);
|
||||
|
||||
PopulateProperties(_profileEditorService.SelectedProfileElement, null);
|
||||
|
||||
_layerPropertyViewModels = new List<LayerPropertyViewModel>();
|
||||
_profileEditorService.SelectedProfileElementChanged += (sender, args) => PopulateProperties(args.ProfileElement, args.PreviousProfileElement);
|
||||
_profileEditorService.SelectedProfileChanged += (sender, args) => PopulateProperties(_profileEditorService.SelectedProfileElement, null);
|
||||
_profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user