1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Fixed a calculation bug while calculating the parameters for the brush calculation

This commit is contained in:
Darth Affe 2016-03-16 21:11:10 +01:00
parent 855e850ce4
commit d3103dd646
3 changed files with 13 additions and 5 deletions

View File

@ -10,7 +10,8 @@
<licenseUrl>https://raw.githubusercontent.com/DarthAffe/CUE.NET/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Corsair HID SDK Wrapper</description>
<releaseNotes>Updated SDK to v1.15.28</releaseNotes>
<releaseNotes>Updated SDK to v1.15.28,
Fixed a calculation bug while calculating the parameters for the brush calculation (THIS MIGHT BREAK EXISTING IMPLEMENTATIONS AND WILL BE CHANGED AGAIN IN THE NEXT VERSION)</releaseNotes>
<summary>C# (.NET) Wrapper library around the Corsair CUE-SDK</summary>
<copyright>Copyright © Wyrez 2016</copyright>
<language>en-US</language>

View File

@ -179,8 +179,13 @@ namespace CUE.NET.Devices.Keyboard
try
{
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));
//TODO DarthAffe 16.03.2016: Rework brushes and replace this workaround with a proper selection of absolute/relative calculations
float offsetX = -brushRectangle.X;
float offsetY = -brushRectangle.Y;
brushRectangle.X = 0;
brushRectangle.Y = 0;
foreach (CorsairKey key in keys)
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter());
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter(offsetX, offsetY));
}
// ReSharper disable once CatchAllClause
catch (Exception ex) { ManageException(ex); }

View File

@ -10,13 +10,15 @@ namespace CUE.NET.Helper
public static class RectangleHelper
{
/// <summary>
/// Calculates the center-point of a rectangle.
/// Calculates the center-point of a rectangle adding a offset.
/// </summary>
/// <param name="rectangle">The rectangle.</param>
/// <param name="offsetX">The offset for the x-value</param>
/// <param name="offsetY">The offset for the y-value</param>
/// <returns>The center point of the rectangle.</returns>
public static PointF GetCenter(this RectangleF rectangle)
public static PointF GetCenter(this RectangleF rectangle, float offsetX = 0f, float offsetY = 0f)
{
return new PointF(rectangle.Left + rectangle.Width / 2f, rectangle.Top + rectangle.Height / 2f);
return new PointF((rectangle.Left + rectangle.Width / 2f) + offsetX, (rectangle.Top + rectangle.Height / 2f) + offsetY);
}
/// <summary>