mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +00:00
Added ImageBrush
This commit is contained in:
parent
d3103dd646
commit
3ade6dc0f3
81
Brushes/ImageBrush.cs
Normal file
81
Brushes/ImageBrush.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CUE.NET.Brushes
|
||||
{
|
||||
public class ImageBrush : AbstractBrush
|
||||
{
|
||||
#region Enums
|
||||
|
||||
/// <summary>
|
||||
/// Contains a list of available image-scale modes.
|
||||
/// </summary>
|
||||
public enum ScaleMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Stretches the image to fit inside the target rectangle.
|
||||
/// </summary>
|
||||
Stretch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains a list of available image-interpolation modes.
|
||||
/// </summary>
|
||||
public enum InterpolationMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Selects the pixel closest to the target point.
|
||||
/// </summary>
|
||||
PixelPerfect
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the image drawn by the brush. If null it will default to full transparent.
|
||||
/// </summary>
|
||||
public Bitmap Image { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ScaleMode" /> used to scale the image if needed.
|
||||
/// </summary>
|
||||
public ScaleMode ImageScaleMode { get; set; } = ScaleMode.Stretch;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="InterpolationMode" /> used to interpolate the image if needed.
|
||||
/// </summary>
|
||||
public InterpolationMode ImageInterpolationMode { get; set; } = InterpolationMode.PixelPerfect;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color at an specific point getting the color of the key at the given point.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
||||
/// <param name="point">The point from which the color should be taken.</param>
|
||||
/// <returns>The color of the key at the specified point.</returns>
|
||||
public override Color GetColorAtPoint(RectangleF rectangle, PointF point)
|
||||
{
|
||||
if (Image == null || Image.Width == 0 || Image.Height == 0)
|
||||
return Color.Transparent;
|
||||
|
||||
//TODO DarthAffe 16.03.2016: Refactor to allow more scale-/interpolation-modes
|
||||
float scaleX = Image.Width / rectangle.Width;
|
||||
float scaleY = Image.Height / rectangle.Height;
|
||||
|
||||
int x = (int)(point.X * scaleX);
|
||||
int y = (int)(point.Y * scaleY);
|
||||
|
||||
x = Math.Max(0, Math.Min(x, Image.Width - 1));
|
||||
y = Math.Max(0, Math.Min(y, Image.Height - 1));
|
||||
|
||||
return Image.GetPixel(x, y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -45,6 +45,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Brushes\ImageBrush.cs" />
|
||||
<Compile Include="Brushes\ProfileBrush.cs" />
|
||||
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
<requireLicenseAcceptance>true</requireLicenseAcceptance>
|
||||
<description>Corsair HID SDK Wrapper</description>
|
||||
<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>
|
||||
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),
|
||||
Added ImageBrush (this will most likely expand 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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user