コード例 #1
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);
            }

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

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

            return(Gradient.GetColor(offset));
        }
コード例 #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)
        {
            var centerX = rectangle.Width * Center.X;
            var centerY = rectangle.Height * Center.Y;

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

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

            return(Gradient.GetColor(offset));
        }
コード例 #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 (Image == null || Image.Width == 0 || Image.Height == 0)
            {
                return(CorsairColor.Transparent);
            }

            //TODO DarthAffe 16.03.2016: Refactor to allow more scale-/interpolation-modes
            var scaleX = Image.Width / rectangle.Width;
            var scaleY = Image.Height / rectangle.Height;

            var x = (int)(renderTarget.Point.X * scaleX);
            var 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));
        }
コード例 #4
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);
            }

            var 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 ...
            var 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));

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

            return(Gradient.GetColor(offset));
        }
コード例 #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) => ColorHelper.ColorFromHSV(
     (float)_random.NextDouble() * 360f, 1, 1);
コード例 #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 abstract CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget);