From 2cbf4b98944ede6afa4a93513da22e303817d1c5 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 25 Mar 2016 18:15:59 +0100 Subject: [PATCH] Added caching to rectangle-keygroup --- Devices/Keyboard/Keys/RectangleKeyGroup.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Devices/Keyboard/Keys/RectangleKeyGroup.cs b/Devices/Keyboard/Keys/RectangleKeyGroup.cs index 4185a78..e02caba 100644 --- a/Devices/Keyboard/Keys/RectangleKeyGroup.cs +++ b/Devices/Keyboard/Keys/RectangleKeyGroup.cs @@ -17,10 +17,21 @@ namespace CUE.NET.Devices.Keyboard.Keys { #region Properties & Fields + private IList _keyCache; + + private RectangleF _rectangle; /// /// Gets or sets the rectangle the keys should be taken from. /// - public RectangleF Rectangle { get; set; } + public RectangleF Rectangle + { + get { return _rectangle; } + set + { + _rectangle = value; + _keyCache = null; + } + } /// /// Gets or sets the minimal percentage overlay a key must have with the to be taken into the keygroup. @@ -91,7 +102,7 @@ namespace CUE.NET.Devices.Keyboard.Keys /// The list containing the keys. protected override IList GetGroupKeys() { - return Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, Rectangle) >= MinOverlayPercentage).ToList(); + return _keyCache ?? (_keyCache = Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, Rectangle) >= MinOverlayPercentage).ToList()); } #endregion