Layers - Allow the clip render mode to stretch if really needed

Core - Include the canvas' SKImageInfo in render calls
This commit is contained in:
SpoinkyNL committed 2020-02-16 01:56:45 +01:00
1 parent 97250e62bf
commit 4b1b0248f5
13 files changed
+107 -64

No files matched your search

+2 -2
View File
@@ -55,11 +55,11 @@ namespace Artemis.Core.Models.Profile
profileElement.Update(deltaTime);
}
public override void Render(double deltaTime, SKCanvas canvas)
public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
{
// Folders don't render but their children do
foreach (var profileElement in Children)
profileElement.Render(deltaTime, canvas);
profileElement.Render(deltaTime, canvas, canvasInfo);
}
public Folder AddFolder(string name)
+18 -11
View File
@@ -72,7 +72,7 @@ namespace Artemis.Core.Models.Profile
/// </summary>
public SKPath Path
{
get => _path;
get => _path != null ? new SKPath(_path) : null;
private set
{
_path = value;
@@ -231,7 +231,7 @@ namespace Artemis.Core.Models.Profile
LayerBrush?.Update(deltaTime);
}
public override void Render(double deltaTime, SKCanvas canvas)
public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
{
if (Path == null || LayerShape?.Path == null)
return;
@@ -247,10 +247,10 @@ namespace Artemis.Core.Models.Profile
switch (FillTypeProperty.CurrentValue)
{
case LayerFillType.Stretch:
StretchRender(canvas, paint);
StretchRender(canvas, canvasInfo, paint);
break;
case LayerFillType.Clip:
ClipRender(canvas, paint, true);
ClipRender(canvas, canvasInfo, paint);
break;
default:
throw new ArgumentOutOfRangeException();
@@ -260,7 +260,7 @@ namespace Artemis.Core.Models.Profile
canvas.Restore();
}
private void StretchRender(SKCanvas canvas, SKPaint paint)
private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
// Apply transformations
var sizeProperty = ScaleProperty.CurrentValue;
@@ -278,10 +278,10 @@ namespace Artemis.Core.Models.Profile
canvas.Scale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y);
canvas.Translate(x, y);
LayerBrush?.Render(canvas, new SKPath(LayerShape.Path), paint);
LayerBrush?.Render(canvas, canvasInfo, new SKPath(LayerShape.Path), paint);
}
private void ClipRender(SKCanvas canvas, SKPaint paint, bool rotatePath)
private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
// Apply transformations
var sizeProperty = ScaleProperty.CurrentValue;
@@ -303,10 +303,17 @@ namespace Artemis.Core.Models.Profile
canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y);
canvas.Translate(x, y);
// Render the entire layer, the clip will ensure the shape is matched
// Render the layer in the largest required bounds, this still creates stretching in some situations
// but the only alternative I see right now is always forcing brushes to render on the entire canvas
var boundsRect = new SKRect(
Math.Min(clipPath.Bounds.Left - x, Bounds.Left - x),
Math.Min(clipPath.Bounds.Top - y, Bounds.Top - y),
Math.Max(clipPath.Bounds.Right - x, Bounds.Right - x),
Math.Max(clipPath.Bounds.Bottom - y, Bounds.Bottom - y)
);
var renderPath = new SKPath();
renderPath.AddRect(Path.Bounds);
LayerBrush?.Render(canvas, renderPath, paint);
renderPath.AddRect(boundsRect);
LayerBrush?.Render(canvas, canvasInfo, renderPath, paint);
}
internal void CalculateRenderProperties()
@@ -332,7 +339,7 @@ namespace Artemis.Core.Models.Profile
OnRenderPropertiesUpdated();
}
private SKPoint GetLayerAnchorPosition()
internal SKPoint GetLayerAnchorPosition()
{
var positionProperty = PositionProperty.CurrentValue;
+2 -2
View File
@@ -57,7 +57,7 @@ namespace Artemis.Core.Models.Profile
}
}
public override void Render(double deltaTime, SKCanvas canvas)
public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
{
lock (this)
{
@@ -65,7 +65,7 @@ namespace Artemis.Core.Models.Profile
throw new ArtemisCoreException($"Cannot render inactive profile: {this}");
foreach (var profileElement in Children)
profileElement.Render(deltaTime, canvas);
profileElement.Render(deltaTime, canvas, canvasInfo);
}
}
@@ -44,7 +44,7 @@ namespace Artemis.Core.Models.Profile
/// <summary>
/// Renders the element
/// </summary>
public abstract void Render(double deltaTime, SKCanvas canvas);
public abstract void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo);
public List<Folder> GetAllFolders()
{