mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Merge pull request #744 from Artemis-RGB/feature/profile-fade
Core - Added fading in and out of profiles
This commit is contained in:
6 files changed
+82
-4
No files matched your search
@@ -23,7 +23,9 @@ public sealed class Profile : ProfileElement
|
||||
{
|
||||
_scripts = new ObservableCollection<ProfileScript>();
|
||||
_scriptConfigurations = new ObservableCollection<ScriptConfiguration>();
|
||||
|
||||
|
||||
Opacity = 0d;
|
||||
ShouldDisplay = true;
|
||||
Configuration = configuration;
|
||||
Profile = this;
|
||||
ProfileEntity = profileEntity;
|
||||
@@ -81,6 +83,10 @@ public sealed class Profile : ProfileElement
|
||||
|
||||
internal List<Exception> Exceptions { get; }
|
||||
|
||||
internal bool ShouldDisplay { get; set; }
|
||||
|
||||
internal double Opacity { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
@@ -97,6 +103,13 @@ public sealed class Profile : ProfileElement
|
||||
|
||||
foreach (ProfileScript profileScript in Scripts)
|
||||
profileScript.OnProfileUpdated(deltaTime);
|
||||
|
||||
const double OPACITY_PER_SECOND = 1;
|
||||
|
||||
if (ShouldDisplay && Opacity < 1)
|
||||
Opacity = Math.Clamp(Opacity + OPACITY_PER_SECOND * deltaTime, 0d, 1d);
|
||||
if (!ShouldDisplay && Opacity > 0)
|
||||
Opacity = Math.Clamp(Opacity - OPACITY_PER_SECOND * deltaTime, 0d, 1d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,10 +123,26 @@ public sealed class Profile : ProfileElement
|
||||
|
||||
foreach (ProfileScript profileScript in Scripts)
|
||||
profileScript.OnProfileRendering(canvas, canvas.LocalClipBounds);
|
||||
|
||||
SKPaint? opacityPaint = null;
|
||||
bool applyOpacityLayer = Configuration.FadeInAndOut && Opacity < 1;
|
||||
|
||||
if (applyOpacityLayer)
|
||||
{
|
||||
opacityPaint = new SKPaint();
|
||||
opacityPaint.Color = new SKColor(0, 0, 0, (byte)(255d * Easings.CubicEaseInOut(Opacity)));
|
||||
canvas.SaveLayer(opacityPaint);
|
||||
}
|
||||
|
||||
foreach (ProfileElement profileElement in Children)
|
||||
profileElement.Render(canvas, basePosition, editorFocus);
|
||||
|
||||
if (applyOpacityLayer)
|
||||
{
|
||||
canvas.Restore();
|
||||
opacityPaint?.Dispose();
|
||||
}
|
||||
|
||||
foreach (ProfileScript profileScript in Scripts)
|
||||
profileScript.OnProfileRendered(canvas, canvas.LocalClipBounds);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
private bool _isBeingEdited;
|
||||
private bool _isMissingModule;
|
||||
private bool _isSuspended;
|
||||
private bool _fadeInAndOut;
|
||||
private Module? _module;
|
||||
|
||||
private string _name;
|
||||
@@ -160,6 +161,15 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
internal set => SetAndNotify(ref _profile, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this profile should fade in and out when enabling or disabling
|
||||
/// </summary>
|
||||
public bool FadeInAndOut
|
||||
{
|
||||
get => _fadeInAndOut;
|
||||
set => SetAndNotify(ref _fadeInAndOut, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the module this profile uses
|
||||
/// </summary>
|
||||
@@ -272,6 +282,7 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
IsSuspended = Entity.IsSuspended;
|
||||
ActivationBehaviour = (ActivationBehaviour) Entity.ActivationBehaviour;
|
||||
HotkeyMode = (ProfileConfigurationHotkeyMode) Entity.HotkeyMode;
|
||||
FadeInAndOut = Entity.FadeInAndOut;
|
||||
Order = Entity.Order;
|
||||
|
||||
Icon.Load();
|
||||
@@ -294,6 +305,7 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
Entity.ActivationBehaviour = (int) ActivationBehaviour;
|
||||
Entity.HotkeyMode = (int) HotkeyMode;
|
||||
Entity.ProfileCategoryId = Category.Entity.Id;
|
||||
Entity.FadeInAndOut = FadeInAndOut;
|
||||
Entity.Order = Order;
|
||||
|
||||
Icon.Save();
|
||||
|
||||
Reference in new issue
Block a user