mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Fixed a relative/absolute position problem with leds
This commit is contained in:
parent
6063f48cd4
commit
6fe54bd3ec
@ -49,6 +49,11 @@ namespace RGB.NET.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Rectangle LedRectangle { get; }
|
public Rectangle LedRectangle { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a rectangle representing the physical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>.
|
||||||
|
/// </summary>
|
||||||
|
public Rectangle AbsoluteLedRectangle => (LedRectangle.Location + Device.Location) + new Size(LedRectangle.Size.Width, LedRectangle.Size.Height);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether the <see cref="Led" /> is about to change it's color.
|
/// Indicates whether the <see cref="Led" /> is about to change it's color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -131,14 +131,14 @@ namespace RGB.NET.Core
|
|||||||
switch (brush.BrushCalculationMode)
|
switch (brush.BrushCalculationMode)
|
||||||
{
|
{
|
||||||
case BrushCalculationMode.Relative:
|
case BrushCalculationMode.Relative:
|
||||||
Rectangle brushRectangle = new Rectangle(leds.Select(GetDeviceLedLocation));
|
Rectangle brushRectangle = new Rectangle(leds.Select(led => led.AbsoluteLedRectangle));
|
||||||
Point offset = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y);
|
Point offset = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y);
|
||||||
brushRectangle.Location = new Point(0, 0);
|
brushRectangle.Location = new Point(0, 0);
|
||||||
brush.PerformRender(brushRectangle,
|
brush.PerformRender(brushRectangle,
|
||||||
leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x, offset))));
|
leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x, offset))));
|
||||||
break;
|
break;
|
||||||
case BrushCalculationMode.Absolute:
|
case BrushCalculationMode.Absolute:
|
||||||
brush.PerformRender(SurfaceRectangle, leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x))));
|
brush.PerformRender(SurfaceRectangle, leds.Select(x => new BrushRenderTarget(x, x.AbsoluteLedRectangle)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
@ -151,9 +151,11 @@ namespace RGB.NET.Core
|
|||||||
renders.Key.Led.Color = renders.Value;
|
renders.Key.Led.Color = renders.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rectangle GetDeviceLedLocation(Led led) => (led.LedRectangle.Location + led.Device.Location) + new Size(led.LedRectangle.Size.Width, led.LedRectangle.Size.Height);
|
private Rectangle GetDeviceLedLocation(Led led, Point extraOffset)
|
||||||
|
{
|
||||||
private Rectangle GetDeviceLedLocation(Led led, Point extraOffset) => (led.LedRectangle.Location + led.Device.Location + extraOffset) + new Size(led.LedRectangle.Size.Width, led.LedRectangle.Size.Height);
|
Rectangle absoluteRectangle = led.AbsoluteLedRectangle;
|
||||||
|
return (absoluteRectangle.Location + extraOffset) + absoluteRectangle.Size;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attaches the given <see cref="ILedGroup"/>.
|
/// Attaches the given <see cref="ILedGroup"/>.
|
||||||
|
|||||||
@ -117,7 +117,7 @@ namespace RGB.NET.Groups
|
|||||||
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.
|
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns>
|
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns>
|
||||||
public override IEnumerable<Led> GetLeds() => _ledCache ?? (_ledCache = RGBSurface.Instance.Leds.Where(x => x.LedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList());
|
public override IEnumerable<Led> GetLeds() => _ledCache ?? (_ledCache = RGBSurface.Instance.Leds.Where(x => x.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList());
|
||||||
|
|
||||||
private void InvalidateCache() => _ledCache = null;
|
private void InvalidateCache() => _ledCache = null;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user