Profile - Blending mode fixes

Nodes editor - Adhere to cable display settings
Profile - Added focus layer option
This commit is contained in:
Robert committed 2022-08-14 10:18:17 +02:00
1 parent e401fdf964
commit 3f52279305
13 files changed
+115 -32

No files matched your search

+6 -2
View File
@@ -176,7 +176,7 @@ namespace Artemis.Core
#region Rendering
/// <inheritdoc />
public override void Render(SKCanvas canvas, SKPointI basePosition)
public override void Render(SKCanvas canvas, SKPointI basePosition, ProfileElement? editorFocus)
{
if (Disposed)
throw new ObjectDisposedException("Folder");
@@ -188,6 +188,10 @@ namespace Artemis.Core
// No point rendering if all children are disabled
if (!Children.Any(c => c is RenderProfileElement {Enabled: true}))
return;
// If the editor focus is on this folder, discard further focus for children to effectively focus the entire folder and all descendants
if (editorFocus == this)
editorFocus = null;
SKPaint layerPaint = new() {FilterQuality = SKFilterQuality.Low};
try
@@ -208,7 +212,7 @@ namespace Artemis.Core
// Iterate the children in reverse because the first layer must be rendered last to end up on top
for (int index = Children.Count - 1; index > -1; index--)
Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top), editorFocus);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
{
+24 -10
View File
@@ -416,11 +416,14 @@ namespace Artemis.Core
}
/// <inheritdoc />
public override void Render(SKCanvas canvas, SKPointI basePosition)
public override void Render(SKCanvas canvas, SKPointI basePosition, ProfileElement? editorFocus)
{
if (Disposed)
throw new ObjectDisposedException("Layer");
if (editorFocus != null && editorFocus != this)
return;
RenderLayer(canvas, basePosition);
RenderCopies(canvas, basePosition);
}
@@ -496,7 +499,7 @@ namespace Artemis.Core
private void RenderCopies(SKCanvas canvas, SKPointI basePosition)
{
for (int i = _renderCopies.Count - 1; i >= 0; i--)
_renderCopies[i].Render(canvas, basePosition);
_renderCopies[i].Render(canvas, basePosition, null);
}
/// <inheritdoc />
@@ -627,20 +630,31 @@ namespace Artemis.Core
if (LayerBrush == null)
throw new ArtemisCoreException("The layer is not yet ready for rendering");
using SKAutoCanvasRestore _ = new(canvas);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
{
if (!baseLayerEffect.Suspended)
baseLayerEffect.InternalPreProcess(canvas, bounds, layerPaint);
}
canvas.ClipPath(renderPath);
LayerBrush.InternalRender(canvas, bounds, layerPaint);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
try
{
if (!baseLayerEffect.Suspended)
baseLayerEffect.InternalPostProcess(canvas, bounds, layerPaint);
canvas.SaveLayer(layerPaint);
canvas.ClipPath(renderPath);
// Restore the blend mode before doing the actual render
layerPaint.BlendMode = SKBlendMode.SrcOver;
LayerBrush.InternalRender(canvas, bounds, layerPaint);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
{
if (!baseLayerEffect.Suspended)
baseLayerEffect.InternalPostProcess(canvas, bounds, layerPaint);
}
}
finally
{
canvas.Restore();
}
}
+2 -2
View File
@@ -101,7 +101,7 @@ namespace Artemis.Core
}
/// <inheritdoc />
public override void Render(SKCanvas canvas, SKPointI basePosition)
public override void Render(SKCanvas canvas, SKPointI basePosition, ProfileElement? editorFocus)
{
lock (_lock)
{
@@ -112,7 +112,7 @@ namespace Artemis.Core
profileScript.OnProfileRendering(canvas, canvas.LocalClipBounds);
foreach (ProfileElement profileElement in Children)
profileElement.Render(canvas, basePosition);
profileElement.Render(canvas, basePosition, editorFocus);
foreach (ProfileScript profileScript in Scripts)
profileScript.OnProfileRendered(canvas, canvas.LocalClipBounds);
@@ -105,9 +105,12 @@ namespace Artemis.Core
public abstract void Update(double deltaTime);
/// <summary>
/// Renders the element
/// Renders the element
/// </summary>
public abstract void Render(SKCanvas canvas, SKPointI basePosition);
/// <param name="canvas">The canvas to render upon.</param>
/// <param name="basePosition">The base position to use to translate relative positions to absolute positions.</param>
/// <param name="editorFocus">An optional element to focus on while rendering (other elements will not render).</param>
public abstract void Render(SKCanvas canvas, SKPointI basePosition, ProfileElement? editorFocus);
/// <summary>
/// Resets the internal state of the element
@@ -1,4 +1,5 @@
using SkiaSharp;
using System;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes
{
@@ -52,23 +53,24 @@ namespace Artemis.Core.LayerBrushes
TryOrBreak(() =>
{
for (int index = 0; index < Layer.Leds.Count; index++)
{
ArtemisLed artemisLed = Layer.Leds[index];
SKPoint renderPoint = points[index * 2 + 1];
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
continue;
// Let the brush determine the color
paint.Color = GetColor(artemisLed, renderPoint).WithAlpha(paint.Color.Alpha);
paint.Color = GetColor(artemisLed, renderPoint);
SKRect ledRectangle = SKRect.Create(
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
artemisLed.AbsoluteRectangle.Width,
artemisLed.AbsoluteRectangle.Height
);
canvas.DrawRect(ledRectangle, paint);
}
}, "Failed to render");
@@ -34,6 +34,11 @@ namespace Artemis.Core.Services
/// Gets or sets a boolean indicating whether rendering should only be done for profiles being edited
/// </summary>
bool RenderForEditor { get; set; }
/// <summary>
/// Gets or sets the profile element to focus on while rendering for the editor
/// </summary>
ProfileElement? EditorFocus { get; set; }
/// <summary>
/// Activates the profile of the given <see cref="ProfileConfiguration" /> with the currently active surface
@@ -190,6 +190,7 @@ namespace Artemis.Core.Services
public bool HotkeysEnabled { get; set; }
public bool RenderForEditor { get; set; }
public ProfileElement? EditorFocus { get; set; }
public void UpdateProfiles(double deltaTime)
{
@@ -247,7 +248,7 @@ namespace Artemis.Core.Services
ProfileConfiguration? editedProfileConfiguration = _profileCategories.SelectMany(c => c.ProfileConfigurations).FirstOrDefault(p => p.IsBeingEdited);
if (editedProfileConfiguration != null)
{
editedProfileConfiguration.Profile?.Render(canvas, SKPointI.Empty);
editedProfileConfiguration.Profile?.Render(canvas, SKPointI.Empty, RenderForEditor ? EditorFocus : null);
return;
}
@@ -265,7 +266,7 @@ namespace Artemis.Core.Services
ProfileConfiguration profileConfiguration = profileCategory.ProfileConfigurations[j];
// Ensure all criteria are met before rendering
if (!profileConfiguration.IsSuspended && !profileConfiguration.IsMissingModule && profileConfiguration.ActivationConditionMet)
profileConfiguration.Profile?.Render(canvas, SKPointI.Empty);
profileConfiguration.Profile?.Render(canvas, SKPointI.Empty, null);
}
catch (Exception e)
{