mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 04:56:44 +00:00
First attempt to rewrite Effects
This commit is contained in:
1 parent
5a296dd048
commit
ba80ef9848
32 files changed
+353
-325
No files matched your search
@@ -106,18 +106,6 @@ namespace CUE.NET.Devices.Keyboard
|
||||
/// </summary>
|
||||
public int ZIndex { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating if the keyboard has an active effect to deal with or not.
|
||||
/// </summary>
|
||||
protected override bool HasEffect
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (Effects)
|
||||
return Effects.Any();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -156,13 +144,9 @@ namespace CUE.NET.Devices.Keyboard
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ApplyEffect(IEffect effect)
|
||||
protected override void DeviceUpdateEffects()
|
||||
{
|
||||
if (effect == null) return;
|
||||
|
||||
//TODO DarthAffe 18.10.2015: This is really dirty and might have a really negative performance impact - find a better solution.
|
||||
IEnumerable<CorsairKey> keys = effect.LedList?.Select(x => this.FirstOrDefault(y => y.Led == x));
|
||||
ApplyBrush((keys ?? this).ToList(), effect.EffectBrush);
|
||||
UpdateEffects();
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Local - idc
|
||||
@@ -200,6 +184,30 @@ namespace CUE.NET.Devices.Keyboard
|
||||
|
||||
#endregion
|
||||
|
||||
public void UpdateEffects()
|
||||
{
|
||||
lock (_keyGroups)
|
||||
{
|
||||
foreach (IKeyGroup keyGroup in _keyGroups)
|
||||
{
|
||||
keyGroup.UpdateEffects();
|
||||
keyGroup.Brush.UpdateEffects();
|
||||
}
|
||||
}
|
||||
|
||||
Brush.UpdateEffects();
|
||||
}
|
||||
|
||||
public void AddEffect(IEffect<IKeyGroup> effect)
|
||||
{
|
||||
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
|
||||
}
|
||||
|
||||
public void RemoveEffect(IEffect<IKeyGroup> effect)
|
||||
{
|
||||
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the given keygroup.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace CUE.NET.Devices.Keyboard.Extensions
|
||||
public static class KeyGroupExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the given <see cref="BaseKeyGroup" /> to a <see cref="ListKeyGroup" />.
|
||||
/// Converts the given <see cref="AbstractKeyGroup" /> to a <see cref="ListKeyGroup" />.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The <see cref="BaseKeyGroup" /> to convert.</param>
|
||||
/// <param name="keyGroup">The <see cref="AbstractKeyGroup" /> to convert.</param>
|
||||
/// <returns>The converted <see cref="ListKeyGroup" />.</returns>
|
||||
public static ListKeyGroup ToSimpleKeyGroup(this BaseKeyGroup keyGroup)
|
||||
public static ListKeyGroup ToSimpleKeyGroup(this AbstractKeyGroup keyGroup)
|
||||
{
|
||||
ListKeyGroup simpleKeyGroup = keyGroup as ListKeyGroup;
|
||||
if (simpleKeyGroup == null)
|
||||
@@ -34,7 +34,7 @@ namespace CUE.NET.Devices.Keyboard.Extensions
|
||||
/// <param name="keyGroup">The base keygroup.</param>
|
||||
/// <param name="keyIds">The ids of the keys to exclude.</param>
|
||||
/// <returns>The new <see cref="ListKeyGroup" />.</returns>
|
||||
public static ListKeyGroup Exclude(this BaseKeyGroup keyGroup, params CorsairKeyboardKeyId[] keyIds)
|
||||
public static ListKeyGroup Exclude(this AbstractKeyGroup keyGroup, params CorsairKeyboardKeyId[] keyIds)
|
||||
{
|
||||
ListKeyGroup simpleKeyGroup = keyGroup.ToSimpleKeyGroup();
|
||||
foreach (CorsairKeyboardKeyId keyId in keyIds)
|
||||
@@ -48,7 +48,7 @@ namespace CUE.NET.Devices.Keyboard.Extensions
|
||||
/// <param name="keyGroup">The base keygroup.</param>
|
||||
/// <param name="keyIds">The keys to exclude.</param>
|
||||
/// <returns>The new <see cref="ListKeyGroup" />.</returns>
|
||||
public static ListKeyGroup Exclude(this BaseKeyGroup keyGroup, params CorsairKey[] keyIds)
|
||||
public static ListKeyGroup Exclude(this AbstractKeyGroup keyGroup, params CorsairKey[] keyIds)
|
||||
{
|
||||
ListKeyGroup simpleKeyGroup = keyGroup.ToSimpleKeyGroup();
|
||||
foreach (CorsairKey key in keyIds)
|
||||
@@ -62,7 +62,7 @@ namespace CUE.NET.Devices.Keyboard.Extensions
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The keygroup to attach.</param>
|
||||
/// <returns><c>true</c> if the keygroup could be attached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Attach(this BaseKeyGroup keyGroup)
|
||||
public static bool Attach(this AbstractKeyGroup keyGroup)
|
||||
{
|
||||
return keyGroup.Keyboard?.AttachKeyGroup(keyGroup) ?? false;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ namespace CUE.NET.Devices.Keyboard.Extensions
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The keygroup to attach.</param>
|
||||
/// <returns><c>true</c> if the keygroup could be detached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Detach(this BaseKeyGroup keyGroup)
|
||||
public static bool Detach(this AbstractKeyGroup keyGroup)
|
||||
{
|
||||
return keyGroup.Keyboard?.DetachKeyGroup(keyGroup) ?? false;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ using System.Linq;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Keyboard.Extensions;
|
||||
using CUE.NET.Effects;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a basic keygroup.
|
||||
/// </summary>
|
||||
public abstract class BaseKeyGroup : IKeyGroup
|
||||
public abstract class AbstractKeyGroup : AbstractEffectTarget<IKeyGroup>, IKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -39,11 +40,11 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BaseKeyGroup"/> class.
|
||||
/// Initializes a new instance of the <see cref="AbstractKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this group should be automatically attached or not.</param>
|
||||
protected BaseKeyGroup(CorsairKeyboard keyboard, bool autoAttach = true)
|
||||
protected AbstractKeyGroup(CorsairKeyboard keyboard, bool autoAttach = true)
|
||||
{
|
||||
this.Keyboard = keyboard;
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
using System.Collections.Generic;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Effects;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
public interface IKeyGroup
|
||||
public interface IKeyGroup : IEffectTarget<IKeyGroup>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing the keys from this group.
|
||||
|
||||
@@ -9,10 +9,12 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
/// <summary>
|
||||
/// Represents a keygroup containing arbitrary keys.
|
||||
/// </summary>
|
||||
public class ListKeyGroup : BaseKeyGroup
|
||||
public class ListKeyGroup : AbstractKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
protected override IKeyGroup EffectTarget => this;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list containing the keys of this keygroup.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,10 +13,12 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
/// <summary>
|
||||
/// Represents a keygroup containing keys which physically lay inside a rectangle.
|
||||
/// </summary>
|
||||
public class RectangleKeyGroup : BaseKeyGroup
|
||||
public class RectangleKeyGroup : AbstractKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
protected override IKeyGroup EffectTarget => this;
|
||||
|
||||
private IList<CorsairKey> _keyCache;
|
||||
|
||||
private RectangleF _rectangle;
|
||||
|
||||
Reference in new issue
Block a user