示例#1
0
        /// <summary>
        /// Draws a gradient around the specified polygon. Fades from 'inner' to 'outer' over a distance of 'width' pixels.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="poly"></param>
        /// <param name="inner"></param>
        /// <param name="outer"></param>
        /// <param name="width"></param>
        public static void DrawOuterGradient(Graphics g, PointF[] poly, Color inner, Color outer, float width)
        {
            PointF[,] corners = PolygonMath.GetCorners(poly, width);
            PointF[,] sides   = PolygonMath.GetSides(poly, width);
            //Overlapping these causes darker areas... Don't use InflatePoly

            //Paint corners
            for (int i = 0; i <= corners.GetUpperBound(0); i++)
            {
                PointF[] pts = PolygonMath.GetSubArray(corners, i);
                using (Brush b = PolygonMath.GenerateRadialBrush(inner, outer, pts[0], width + 1)) {
                    g.FillPolygon(b, pts);
                }
            }
            //Paint sides
            for (int i = 0; i <= sides.GetUpperBound(0); i++)
            {
                PointF[] pts = PolygonMath.GetSubArray(sides, i);
                using (LinearGradientBrush b = new LinearGradientBrush(pts[3], pts[0], inner, outer)) {
                    b.SetSigmaBellShape(1);
                    b.WrapMode = WrapMode.TileFlipXY;
                    g.FillPolygon(b, pts);
                }
            }
        }