Beispiel #1
0
        private static GraphicsPath CreateTopRoundRectangle(Rectangle rectangle, int radius, RoundCornerStyle rcStyle)
        {
            GraphicsPath path = new GraphicsPath();
            int          l    = rectangle.Left;
            int          t    = rectangle.Top;
            int          w    = rectangle.Width;
            int          h    = rectangle.Height;

            if (radius <= 0)
            {
                path.AddLine(l, t, l + w, t);         // top
                path.AddLine(l + w, t, l + w, t + h); // right
                path.AddLine(l + w, t + h, l, t + h); // bottom
                path.AddLine(l, t + h, l, t);         // left
            }
            else
            {
                int d = radius << 1;

                int lefttop_eff  = 0;
                int righttop_eff = 0;
                int topleft_eff  = 0;
                int topright_eff = 0;

                if ((rcStyle & RoundCornerStyle.LeftTop) == RoundCornerStyle.LeftTop)
                {
                    lefttop_eff = radius;
                    topleft_eff = radius;
                }

                if ((rcStyle & RoundCornerStyle.RightTop) == RoundCornerStyle.RightTop)
                {
                    righttop_eff = radius;
                    topright_eff = radius;
                }

                if ((rcStyle & RoundCornerStyle.LeftTop) == RoundCornerStyle.LeftTop)
                {
                    path.AddArc(l, t, d, d, 180, 90);                      // topleft
                }
                path.AddLine(l + lefttop_eff, t, l + w - righttop_eff, t); // top
                if ((rcStyle & RoundCornerStyle.RightTop) == RoundCornerStyle.RightTop)
                {
                    path.AddArc(l + w - d, t, d, d, 270, 90);        // topright
                }
                path.AddLine(l + w, t + topright_eff, l + w, t + h); // right
                path.AddLine(l + w, t + h, l, t + h);                // bottom
                path.AddLine(l, t + h, l, t + topleft_eff);          // left
            }

            path.CloseFigure();
            return(path);
        }
Beispiel #2
0
        private static void DrawButtonBackground(Graphics g, Rectangle rectangle,
                                                 bool pressed, bool hovered, bool animating, bool enabled,
                                                 Color backColor, Color glowColor, Color shineColor,
                                                 Color borderColor, float glowOpacity, int rad, RoundCornerStyle rcStyle)
        {
            SmoothingMode sm = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            #region " outter border "
            Rectangle rect = rectangle;
            rect.Width--;
            rect.Height--;
            using (GraphicsPath bw = CreateRoundRectangle(rect, rad, rcStyle))
            {
                using (Pen p = new Pen(borderColor))
                {
                    g.DrawPath(p, bw);
                }
            }
            #endregion

            rect.X++;
            rect.Y++;
            rect.Width  -= 2;
            rect.Height -= 2;
            Rectangle rect2 = rect;
            rect2.Height >>= 1;

            #region " content "
            using (GraphicsPath bb = CreateRoundRectangle(rect, rad - 2, rcStyle))
            {
                /*
                 * int opacity = pressed ? 0x7f : 0xFF;
                 * using (Brush br = new SolidBrush(Color.FromArgb(opacity, backColor)))
                 * {
                 *  g.FillPath(br, bb);
                 * }
                 */

                int opacity = 0xbb;

                // pky
                if (!enabled)
                {
                    opacity = 0xdd;
                }
                else
                {
                    opacity = pressed ? 0x7f : 0xFF;
                    using (Brush br = new SolidBrush(Color.FromArgb(opacity, backColor)))
                    {
                        g.FillPath(br, bb);
                    }
                }

                using (Brush br = new SolidBrush(Color.FromArgb(opacity, backColor)))
                {
                    g.FillPath(br, bb);
                }
            }
            #endregion

            #region " glow "
            if ((hovered || animating) && !pressed)
            {
                using (GraphicsPath clip = CreateRoundRectangle(rect, rad - 2, rcStyle))
                {
                    g.SetClip(clip, CombineMode.Intersect);
                    using (GraphicsPath brad = CreateBottomRadialPath(rect))
                    {
                        using (PathGradientBrush pgr = new PathGradientBrush(brad))
                        {
                            unchecked
                            {
                                int        opacity = (int)(0xB2 * glowOpacity + .5f);
                                RectangleF bounds  = brad.GetBounds();
                                pgr.CenterPoint    = new PointF((bounds.Left + bounds.Right) / 2f, (bounds.Top + bounds.Bottom) / 2f);
                                pgr.CenterColor    = Color.FromArgb(opacity, glowColor);
                                pgr.SurroundColors = new Color[] { Color.FromArgb(0, glowColor) };
                            }
                            g.FillPath(pgr, brad);
                        }
                    }
                    g.ResetClip();
                }
            }
            #endregion

            #region " shine "
            if (rect2.Width > 0 && rect2.Height > 0)
            {
                rect2.Height++;
                using (GraphicsPath bh = CreateTopRoundRectangle(rect2, rad - 2, rcStyle))
                {
                    rect2.Height++;
                    int opacity = 0x99;


                    // Disable 버튼인 경우 들어간 느낌 주기 위해 - pky
                    if (pressed | !enabled)
                    //if (pressed)
                    {
                        // opacity = (int)(.4f * opacity + .5f);
                        // opacity = (int)(.9f * opacity + .9f);
                        opacity = 0x33;
                    }


                    using (LinearGradientBrush br = new LinearGradientBrush(rect2, Color.FromArgb(opacity, shineColor), Color.FromArgb(opacity / 3, shineColor), LinearGradientMode.Vertical))
                    {
                        g.FillPath(br, bh);
                    }
                }
                rect2.Height -= 2;
            }
            #endregion

            #region " inner border "
            using (GraphicsPath bb = CreateRoundRectangle(rect, rad - 1, rcStyle))
            {
                using (Pen p = new Pen(borderColor))
                {
                    g.DrawPath(p, bb);
                }
            }
            #endregion

            g.SmoothingMode = sm;
        }