Represents a single target of a brush render.
Ejemplo n.º 1
0
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            //TODO DarthAffe 05.11.2016: The Key-Rectangle is missing in the render-target, I'll fix that with a future version of CUE.NET. Until then we consider the size of each key to be 10x10mm.
            float keyWidth = 10;

            int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth));

            int r = 0;
            int g = 0;
            int b = 0;
            int counter = 0;

            int widthOffset = Settings.FlipMode.HasFlag(FlipMode.Horizontal)
                ? (int)((SourceWidth - OffsetRight) - (KeyWidthProportion * (renderTarget.Point.X + (keyWidth / 2f))))
                : (int)(OffsetLeft + (KeyWidthProportion * (renderTarget.Point.X - (keyWidth / 2f))));
            int heightOffset = SourceHeight - OffsetBottom - EffectiveSourceHeight; // DarthAffe 05.11.2016: Vertical flipping doesn't mather in Extend-Mode

            // DarthAffe 06.11.2016: Validate offsets - rounding errors might cause problems (heightOffset is safe calculated -> no need to validate)
            widthOffset = Math.Max(0, Math.Min(SourceWidth - widthPixels, widthOffset));

            for (int y = 0; y < EffectiveSourceHeight; y += Increment)
                for (int x = 0; x < widthPixels; x += Increment)
                {
                    int offset = ((((heightOffset + y) * SourceWidth) + widthOffset + x) * 4);

                    b += ScreenPixelData[offset];
                    g += ScreenPixelData[offset + 1];
                    r += ScreenPixelData[offset + 2];
                    counter++;
                }

            return new CorsairColor((byte)(r / counter), (byte)(g / counter), (byte)(b / counter));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            CorsairLed led = CueSDK.KeyboardSDK[renderTarget.LedId];
            if (led == null) return CorsairColor.Transparent;

            CorsairColor color;
            return !_colors.TryGetValue(led.Id, out color) ? CorsairColor.Transparent : color;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if (Gradient == null) return CorsairColor.Transparent;

            PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
            PointF endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);

            float offset = GradientHelper.CalculateLinearGradientOffset(startPoint, endPoint, renderTarget.Point);
            return Gradient.GetColor(offset);
        }
Ejemplo n.º 4
0
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if (_soundDataProcessor?.BarValues == null) return CorsairColor.Transparent;

            // This logic is also stolen from AterialDawn
            int barSampleIndex = (int)Math.Floor(_soundDataProcessor.BarValues.Length * (renderTarget.Point.X / (rectangle.X + rectangle.Width))); // Calculate bar sampling index
            float curBarHeight = 1f - Utility.Clamp(_soundDataProcessor.BarValues[barSampleIndex], 0f, 1f); // Invert this value since the keyboard is laid out with topleft being point 0,0
            float verticalPos = (renderTarget.Point.Y / rectangle.Height);

            // If the barHeight is lower than the vertical pos currently calculated return the brush value. Otherwise do nothing by returning transparent.
            return curBarHeight <= verticalPos ? base.GetColorAtPoint(rectangle, renderTarget) : CorsairColor.Transparent;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            CorsairLed led = CueSDK.KeyboardSDK[renderTarget.LedId];

            if (led == null)
            {
                return(CorsairColor.Transparent);
            }

            CorsairColor color;

            return(!_colors.TryGetValue(led.Id, out color) ? CorsairColor.Transparent : color);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if (Gradient == null)
            {
                return(CorsairColor.Transparent);
            }

            PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
            PointF endPoint   = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);

            float offset = GradientHelper.CalculateLinearGradientOffset(startPoint, endPoint, renderTarget.Point);

            return(Gradient.GetColor(offset));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            float centerX = rectangle.Width * Center.X;
            float centerY = rectangle.Height * Center.Y;

            double angle = Math.Atan2(renderTarget.Point.Y - centerY, renderTarget.Point.X - centerX) - Origin;

            if (angle < 0)
            {
                angle += Math.PI * 2;
            }
            float offset = (float)(angle / (Math.PI * 2));

            return(Gradient.GetColor(offset));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if (Image == null || Image.Width == 0 || Image.Height == 0)
                return CorsairColor.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)(renderTarget.Point.X * scaleX);
            int y = (int)(renderTarget.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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if(Gradient == null) return CorsairColor.Transparent;

            PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y);

            // Calculate the distance to the farthest point from the center as reference (this has to be a corner)
            // ReSharper disable once RedundantCast - never trust this ...
            float refDistance = (float)Math.Max(Math.Max(Math.Max(GradientHelper.CalculateDistance(rectangle.Location, centerPoint),
                GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y), centerPoint)),
                GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)),
                GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), centerPoint));

            float distance = GradientHelper.CalculateDistance(renderTarget.Point, centerPoint);
            float offset = distance / refDistance;
            return Gradient.GetColor(offset);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if (Image == null || Image.Width == 0 || Image.Height == 0)
            {
                return(CorsairColor.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)(renderTarget.Point.X * scaleX);
            int y = (int)(renderTarget.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));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
        /// <returns>The color at the specified point.</returns>
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if (Gradient == null)
            {
                return(CorsairColor.Transparent);
            }

            PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y);

            // Calculate the distance to the farthest point from the center as reference (this has to be a corner)
            // ReSharper disable once RedundantCast - never trust this ...
            float refDistance = (float)Math.Max(Math.Max(Math.Max(GradientHelper.CalculateDistance(rectangle.Location, centerPoint),
                                                                  GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y), centerPoint)),
                                                         GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)),
                                                GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), centerPoint));

            float distance = GradientHelper.CalculateDistance(renderTarget.Point, centerPoint);
            float offset   = distance / refDistance;

            return(Gradient.GetColor(offset));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
 /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
 /// <returns>The color at the specified point.</returns>
 protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
 {
     return Color;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
 /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
 /// <returns>The color at the specified point.</returns>
 protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
 {
     return(ColorHelper.ColorFromHSV((float)_random.NextDouble() * 360f, 1, 1));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
 /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
 /// <returns>The color at the specified point.</returns>
 protected abstract CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget);
Ejemplo n.º 15
0
 /// <summary>
 /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
 /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
 /// <returns>The color at the specified point.</returns>
 protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
 {
     return ColorHelper.ColorFromHSV((float)_random.NextDouble() * 360f, 1, 1);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
 /// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
 /// <returns>The color at the specified point.</returns>
 protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
 {
     return(Color);
 }