mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added LastRender to layer to fix keypress wave stacking on inactive profile
This commit is contained in:
parent
21dbbe4eef
commit
ac7da4424b
@ -8,15 +8,13 @@ namespace Artemis.Profiles.Layers.Animations
|
||||
{
|
||||
public class GrowAnimation : ILayerAnimation
|
||||
{
|
||||
private DateTime _lastUpdate;
|
||||
public string Name { get; } = "Grow";
|
||||
|
||||
public void Update(LayerModel layerModel, bool updateAnimations)
|
||||
{
|
||||
// Reset animation progress if layer wasn't drawn for 100ms
|
||||
if (new TimeSpan(0, 0, 0, 0, 100) < DateTime.Now - _lastUpdate)
|
||||
if (new TimeSpan(0, 0, 0, 0, 100) < DateTime.Now - layerModel.LastRender)
|
||||
layerModel.Properties.AnimationProgress = 0;
|
||||
_lastUpdate = DateTime.Now;
|
||||
|
||||
var progress = layerModel.Properties.AnimationProgress;
|
||||
|
||||
|
||||
@ -8,15 +8,13 @@ namespace Artemis.Profiles.Layers.Animations
|
||||
{
|
||||
public class PulseAnimation : ILayerAnimation
|
||||
{
|
||||
private DateTime _lastUpdate;
|
||||
public string Name { get; } = "Pulse";
|
||||
|
||||
public void Update(LayerModel layerModel, bool updateAnimations)
|
||||
{
|
||||
// Reset animation progress if layer wasn't drawn for 100ms
|
||||
if (new TimeSpan(0, 0, 0, 0, 100) < DateTime.Now - _lastUpdate)
|
||||
if (new TimeSpan(0, 0, 0, 0, 100) > DateTime.Now - layerModel.LastRender)
|
||||
layerModel.Properties.AnimationProgress = 0;
|
||||
_lastUpdate = DateTime.Now;
|
||||
|
||||
var progress = layerModel.Properties.AnimationProgress;
|
||||
|
||||
|
||||
@ -53,6 +53,9 @@ namespace Artemis.Profiles.Layers.Models
|
||||
[JsonIgnore]
|
||||
public GifImage GifImage { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime LastRender { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether this layers conditions are met.
|
||||
/// If they are met and this layer is an event, this also triggers that event.
|
||||
@ -69,6 +72,9 @@ namespace Artemis.Profiles.Layers.Models
|
||||
{
|
||||
LayerType.Update(this, dataModel, preview);
|
||||
LayerAnimation?.Update(this, updateAnimations);
|
||||
|
||||
if (!preview)
|
||||
LastRender = DateTime.Now;
|
||||
}
|
||||
|
||||
public void Draw(IDataModel dataModel, DrawingContext c, bool preview, bool updateAnimations)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
@ -19,7 +20,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
||||
{
|
||||
private readonly MainManager _mainManager;
|
||||
private List<LayerModel> _keyPressLayers = new List<LayerModel>();
|
||||
private KeyPressPropertiesModel _properties;
|
||||
private LayerModel _layerModel;
|
||||
|
||||
public KeyPressType(MainManager mainManager)
|
||||
{
|
||||
@ -39,7 +40,9 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
||||
var thumbnailRect = new Rect(0, 0, 18, 18);
|
||||
var visual = new DrawingVisual();
|
||||
using (var c = visual.RenderOpen())
|
||||
{
|
||||
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.gif), thumbnailRect);
|
||||
}
|
||||
|
||||
var image = new DrawingImage(visual.Drawing);
|
||||
return image;
|
||||
@ -63,7 +66,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
||||
layerModel.Properties.Y = 0;
|
||||
layerModel.Properties.Contain = true;
|
||||
|
||||
_properties = (KeyPressPropertiesModel) layerModel.Properties;
|
||||
_layerModel = layerModel;
|
||||
|
||||
if (isPreview)
|
||||
return;
|
||||
@ -96,27 +99,38 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
||||
|
||||
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
||||
{
|
||||
if (_properties == null)
|
||||
if (_layerModel == null)
|
||||
return;
|
||||
|
||||
// Reset animation progress if layer wasn't drawn for 100ms
|
||||
if (new TimeSpan(0, 0, 0, 0, 100) < DateTime.Now - _layerModel.LastRender)
|
||||
return;
|
||||
|
||||
lock (_keyPressLayers)
|
||||
{
|
||||
if (_keyPressLayers.Count >= 25)
|
||||
return;
|
||||
}
|
||||
|
||||
var keyMatch = _mainManager.DeviceManager.ActiveKeyboard.GetKeyPosition(e.KeyCode);
|
||||
if (keyMatch == null)
|
||||
return;
|
||||
|
||||
lock (_keyPressLayers)
|
||||
{
|
||||
var properties = (KeyPressPropertiesModel) _layerModel.Properties;
|
||||
var layer = LayerModel.CreateLayer();
|
||||
layer.Properties.X = keyMatch.Value.X - _properties.Scale/2;
|
||||
layer.Properties.Y = keyMatch.Value.Y - _properties.Scale/2;
|
||||
layer.Properties.Width = _properties.Scale;
|
||||
layer.Properties.Height = _properties.Scale;
|
||||
layer.Properties.AnimationSpeed = _properties.AnimationSpeed;
|
||||
layer.Properties.X = keyMatch.Value.X - properties.Scale/2;
|
||||
layer.Properties.Y = keyMatch.Value.Y - properties.Scale/2;
|
||||
layer.Properties.Width = properties.Scale;
|
||||
layer.Properties.Height = properties.Scale;
|
||||
layer.Properties.AnimationSpeed = properties.AnimationSpeed;
|
||||
layer.LayerAnimation = new GrowAnimation();
|
||||
|
||||
// Setup the brush according to settings
|
||||
layer.Properties.Brush = _properties.RandomColor
|
||||
? ColorHelpers.RandomizeBrush(_properties.Brush)
|
||||
: _properties.Brush.CloneCurrentValue();
|
||||
layer.Properties.Brush = properties.RandomColor
|
||||
? ColorHelpers.RandomizeBrush(properties.Brush)
|
||||
: properties.Brush.CloneCurrentValue();
|
||||
|
||||
_keyPressLayers.Add(layer);
|
||||
}
|
||||
|
||||
@ -25,8 +25,13 @@ namespace Artemis.Profiles
|
||||
DrawingVisual = new DrawingVisual();
|
||||
}
|
||||
|
||||
public ChildItemCollection<ProfileModel, LayerModel> Layers { get; }
|
||||
/// <summary>
|
||||
/// Indicates whether the profile is actively being rendered
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public ChildItemCollection<ProfileModel, LayerModel> Layers { get; }
|
||||
public string Name { get; set; }
|
||||
public bool IsDefault { get; set; }
|
||||
public string KeyboardSlug { get; set; }
|
||||
@ -44,30 +49,6 @@ namespace Artemis.Profiles
|
||||
Layers[i].Order = i;
|
||||
}
|
||||
|
||||
public void DrawLayers(Graphics keyboard, Rect keyboardRect, IDataModel dataModel, bool preview,
|
||||
bool updateAnimations)
|
||||
{
|
||||
var visual = new DrawingVisual();
|
||||
using (var c = visual.RenderOpen())
|
||||
{
|
||||
// Setup the DrawingVisual's size
|
||||
c.PushClip(new RectangleGeometry(keyboardRect));
|
||||
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, keyboardRect);
|
||||
|
||||
// Draw the layers
|
||||
foreach (var layerModel in Layers.OrderByDescending(l => l.Order))
|
||||
{
|
||||
layerModel.Update(dataModel, preview, updateAnimations);
|
||||
layerModel.Draw(dataModel, c, preview, updateAnimations);
|
||||
}
|
||||
// Remove the clip
|
||||
c.Pop();
|
||||
}
|
||||
|
||||
using (var bmp = ImageUtilities.DrawingVisualToBitmap(visual, keyboardRect))
|
||||
keyboard.DrawImage(bmp, new PointF(0, 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives all the layers and their children in a flat list
|
||||
/// </summary>
|
||||
@ -97,14 +78,12 @@ namespace Artemis.Profiles
|
||||
var layers = new List<LayerModel>();
|
||||
foreach (var layerModel in Layers.OrderByDescending(l => l.Order))
|
||||
{
|
||||
if (!layerModel.Enabled || keyboardOnly && layerModel.LayerType.DrawType != DrawType.Keyboard)
|
||||
if (!layerModel.Enabled || (keyboardOnly && (layerModel.LayerType.DrawType != DrawType.Keyboard)))
|
||||
continue;
|
||||
|
||||
if (!ignoreConditions)
|
||||
{
|
||||
if (!layerModel.ConditionsMet(dataModel))
|
||||
continue;
|
||||
}
|
||||
|
||||
layers.Add(layerModel);
|
||||
layers.AddRange(layerModel.GetRenderLayers(dataModel, keyboardOnly, ignoreConditions));
|
||||
@ -144,7 +123,9 @@ namespace Artemis.Profiles
|
||||
}
|
||||
|
||||
using (var bmp = ImageUtilities.DrawingVisualToBitmap(visual, rect))
|
||||
{
|
||||
g.DrawImage(bmp, new PointF(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user