diff --git a/Brushes/ImageBrush.cs b/Brushes/ImageBrush.cs new file mode 100644 index 0000000..612c1da --- /dev/null +++ b/Brushes/ImageBrush.cs @@ -0,0 +1,81 @@ +using System; +using System.Drawing; + +namespace CUE.NET.Brushes +{ + public class ImageBrush : AbstractBrush + { + #region Enums + + /// + /// Contains a list of available image-scale modes. + /// + public enum ScaleMode + { + /// + /// Stretches the image to fit inside the target rectangle. + /// + Stretch + } + + /// + /// Contains a list of available image-interpolation modes. + /// + public enum InterpolationMode + { + /// + /// Selects the pixel closest to the target point. + /// + PixelPerfect + } + + #endregion + + #region Properties & Fields + + /// + /// Gets or sets the image drawn by the brush. If null it will default to full transparent. + /// + public Bitmap Image { get; set; } + + /// + /// Gets or sets the used to scale the image if needed. + /// + public ScaleMode ImageScaleMode { get; set; } = ScaleMode.Stretch; + + /// + /// Gets or sets the used to interpolate the image if needed. + /// + public InterpolationMode ImageInterpolationMode { get; set; } = InterpolationMode.PixelPerfect; + + #endregion + + #region Methods + + /// + /// Gets the color at an specific point getting the color of the key at the given point. + /// + /// The rectangle in which the brush should be drawn. + /// The point from which the color should be taken. + /// The color of the key at the specified point. + 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 + } +} diff --git a/CUE.NET.csproj b/CUE.NET.csproj index 299d8a2..beda141 100644 --- a/CUE.NET.csproj +++ b/CUE.NET.csproj @@ -45,6 +45,7 @@ + diff --git a/CUE.NET.nuspec b/CUE.NET.nuspec index f9381f7..da80755 100644 --- a/CUE.NET.nuspec +++ b/CUE.NET.nuspec @@ -11,7 +11,8 @@ true Corsair HID SDK Wrapper 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) + 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) C# (.NET) Wrapper library around the Corsair CUE-SDK Copyright © Wyrez 2016 en-US