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
|
public class GrowAnimation : ILayerAnimation
|
||||||
{
|
{
|
||||||
private DateTime _lastUpdate;
|
|
||||||
public string Name { get; } = "Grow";
|
public string Name { get; } = "Grow";
|
||||||
|
|
||||||
public void Update(LayerModel layerModel, bool updateAnimations)
|
public void Update(LayerModel layerModel, bool updateAnimations)
|
||||||
{
|
{
|
||||||
// Reset animation progress if layer wasn't drawn for 100ms
|
// 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;
|
layerModel.Properties.AnimationProgress = 0;
|
||||||
_lastUpdate = DateTime.Now;
|
|
||||||
|
|
||||||
var progress = layerModel.Properties.AnimationProgress;
|
var progress = layerModel.Properties.AnimationProgress;
|
||||||
|
|
||||||
|
|||||||
@ -8,15 +8,13 @@ namespace Artemis.Profiles.Layers.Animations
|
|||||||
{
|
{
|
||||||
public class PulseAnimation : ILayerAnimation
|
public class PulseAnimation : ILayerAnimation
|
||||||
{
|
{
|
||||||
private DateTime _lastUpdate;
|
|
||||||
public string Name { get; } = "Pulse";
|
public string Name { get; } = "Pulse";
|
||||||
|
|
||||||
public void Update(LayerModel layerModel, bool updateAnimations)
|
public void Update(LayerModel layerModel, bool updateAnimations)
|
||||||
{
|
{
|
||||||
// Reset animation progress if layer wasn't drawn for 100ms
|
// 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;
|
layerModel.Properties.AnimationProgress = 0;
|
||||||
_lastUpdate = DateTime.Now;
|
|
||||||
|
|
||||||
var progress = layerModel.Properties.AnimationProgress;
|
var progress = layerModel.Properties.AnimationProgress;
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,9 @@ namespace Artemis.Profiles.Layers.Models
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public GifImage GifImage { get; set; }
|
public GifImage GifImage { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public DateTime LastRender { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether this layers conditions are met.
|
/// Checks whether this layers conditions are met.
|
||||||
/// If they are met and this layer is an event, this also triggers that event.
|
/// 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);
|
LayerType.Update(this, dataModel, preview);
|
||||||
LayerAnimation?.Update(this, updateAnimations);
|
LayerAnimation?.Update(this, updateAnimations);
|
||||||
|
|
||||||
|
if (!preview)
|
||||||
|
LastRender = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(IDataModel dataModel, DrawingContext c, bool preview, bool updateAnimations)
|
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.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -19,7 +20,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
|||||||
{
|
{
|
||||||
private readonly MainManager _mainManager;
|
private readonly MainManager _mainManager;
|
||||||
private List<LayerModel> _keyPressLayers = new List<LayerModel>();
|
private List<LayerModel> _keyPressLayers = new List<LayerModel>();
|
||||||
private KeyPressPropertiesModel _properties;
|
private LayerModel _layerModel;
|
||||||
|
|
||||||
public KeyPressType(MainManager mainManager)
|
public KeyPressType(MainManager mainManager)
|
||||||
{
|
{
|
||||||
@ -39,7 +40,9 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
|||||||
var thumbnailRect = new Rect(0, 0, 18, 18);
|
var thumbnailRect = new Rect(0, 0, 18, 18);
|
||||||
var visual = new DrawingVisual();
|
var visual = new DrawingVisual();
|
||||||
using (var c = visual.RenderOpen())
|
using (var c = visual.RenderOpen())
|
||||||
|
{
|
||||||
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.gif), thumbnailRect);
|
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.gif), thumbnailRect);
|
||||||
|
}
|
||||||
|
|
||||||
var image = new DrawingImage(visual.Drawing);
|
var image = new DrawingImage(visual.Drawing);
|
||||||
return image;
|
return image;
|
||||||
@ -63,7 +66,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
|||||||
layerModel.Properties.Y = 0;
|
layerModel.Properties.Y = 0;
|
||||||
layerModel.Properties.Contain = true;
|
layerModel.Properties.Contain = true;
|
||||||
|
|
||||||
_properties = (KeyPressPropertiesModel) layerModel.Properties;
|
_layerModel = layerModel;
|
||||||
|
|
||||||
if (isPreview)
|
if (isPreview)
|
||||||
return;
|
return;
|
||||||
@ -96,27 +99,38 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
|
|||||||
|
|
||||||
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (_properties == null)
|
if (_layerModel == null)
|
||||||
return;
|
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);
|
var keyMatch = _mainManager.DeviceManager.ActiveKeyboard.GetKeyPosition(e.KeyCode);
|
||||||
if (keyMatch == null)
|
if (keyMatch == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (_keyPressLayers)
|
lock (_keyPressLayers)
|
||||||
{
|
{
|
||||||
|
var properties = (KeyPressPropertiesModel) _layerModel.Properties;
|
||||||
var layer = LayerModel.CreateLayer();
|
var layer = LayerModel.CreateLayer();
|
||||||
layer.Properties.X = keyMatch.Value.X - _properties.Scale/2;
|
layer.Properties.X = keyMatch.Value.X - properties.Scale/2;
|
||||||
layer.Properties.Y = keyMatch.Value.Y - _properties.Scale/2;
|
layer.Properties.Y = keyMatch.Value.Y - properties.Scale/2;
|
||||||
layer.Properties.Width = _properties.Scale;
|
layer.Properties.Width = properties.Scale;
|
||||||
layer.Properties.Height = _properties.Scale;
|
layer.Properties.Height = properties.Scale;
|
||||||
layer.Properties.AnimationSpeed = _properties.AnimationSpeed;
|
layer.Properties.AnimationSpeed = properties.AnimationSpeed;
|
||||||
layer.LayerAnimation = new GrowAnimation();
|
layer.LayerAnimation = new GrowAnimation();
|
||||||
|
|
||||||
// Setup the brush according to settings
|
// Setup the brush according to settings
|
||||||
layer.Properties.Brush = _properties.RandomColor
|
layer.Properties.Brush = properties.RandomColor
|
||||||
? ColorHelpers.RandomizeBrush(_properties.Brush)
|
? ColorHelpers.RandomizeBrush(properties.Brush)
|
||||||
: _properties.Brush.CloneCurrentValue();
|
: properties.Brush.CloneCurrentValue();
|
||||||
|
|
||||||
_keyPressLayers.Add(layer);
|
_keyPressLayers.Add(layer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,8 +25,13 @@ namespace Artemis.Profiles
|
|||||||
DrawingVisual = new DrawingVisual();
|
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 string Name { get; set; }
|
||||||
public bool IsDefault { get; set; }
|
public bool IsDefault { get; set; }
|
||||||
public string KeyboardSlug { get; set; }
|
public string KeyboardSlug { get; set; }
|
||||||
@ -44,30 +49,6 @@ namespace Artemis.Profiles
|
|||||||
Layers[i].Order = i;
|
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>
|
/// <summary>
|
||||||
/// Gives all the layers and their children in a flat list
|
/// Gives all the layers and their children in a flat list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -97,14 +78,12 @@ namespace Artemis.Profiles
|
|||||||
var layers = new List<LayerModel>();
|
var layers = new List<LayerModel>();
|
||||||
foreach (var layerModel in Layers.OrderByDescending(l => l.Order))
|
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;
|
continue;
|
||||||
|
|
||||||
if (!ignoreConditions)
|
if (!ignoreConditions)
|
||||||
{
|
|
||||||
if (!layerModel.ConditionsMet(dataModel))
|
if (!layerModel.ConditionsMet(dataModel))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
layers.Add(layerModel);
|
layers.Add(layerModel);
|
||||||
layers.AddRange(layerModel.GetRenderLayers(dataModel, keyboardOnly, ignoreConditions));
|
layers.AddRange(layerModel.GetRenderLayers(dataModel, keyboardOnly, ignoreConditions));
|
||||||
@ -144,8 +123,10 @@ namespace Artemis.Profiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
using (var bmp = ImageUtilities.DrawingVisualToBitmap(visual, rect))
|
using (var bmp = ImageUtilities.DrawingVisualToBitmap(visual, rect))
|
||||||
|
{
|
||||||
g.DrawImage(bmp, new PointF(0, 0));
|
g.DrawImage(bmp, new PointF(0, 0));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks at all the layers wthin the profile and makes sure they are within boundaries of the given rectangle
|
/// Looks at all the layers wthin the profile and makes sure they are within boundaries of the given rectangle
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user