public static void RenderBorder(Graphics g, Rectangle rect, Color borderColor,
                                        ButtonBorderType borderType, int radius, RoundStyle roundType)
        {
            rect.Width--;
            rect.Height--;

            bool          simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2));
            SmoothingMode newMode    = simpleRect ? SmoothingMode.HighSpeed : SmoothingMode.AntiAlias;

            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode))
            {
                using (Pen p = new Pen(borderColor))
                {
                    if (simpleRect)
                    {
                        g.DrawRectangle(p, rect);
                    }
                    else if (borderType == ButtonBorderType.Ellipse)
                    {
                        g.DrawEllipse(p, rect);
                    }
                    else
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false))
                        {
                            g.DrawPath(p, path);
                        }
                    }
                }
            }
        }
        public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect,
                                                int ownerRadius, RoundStyle ownerRoundTye, RectangleGlassPosition position,
                                                float angle, float glassLengthFactor, Color glassColor, int alpha1, int alpha2)
        {
            if (!(glassLengthFactor > 0 && glassLengthFactor < 1))
            {
                throw new ArgumentException("glassLengthFactor must be between 0 and 1, but not include 0 and 1. ",
                                            "glassLengthFactor");
            }

            Rectangle  rect  = CalcGlassRect(ownerRect, position, glassLengthFactor);
            RoundStyle round = CalcRoundStyle(position, ownerRadius, ownerRoundTye);

            //if (angle == 0 || angle == 90 || angle == 180 || angle == 270)
            //    angle++;

            bool          simpleRect = (round == RoundStyle.None);
            SmoothingMode newMode;

            if (simpleRect)
            {
                newMode = SmoothingMode.HighSpeed;
            }
            else
            {
                newMode = SmoothingMode.AntiAlias;
                rect.Width--;
                rect.Height--;
            }

            if (rect.Width < 1 || rect.Height < 1)
            {
                return;
            }

            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode))
            {
                using (LinearGradientBrush lb = new LinearGradientBrush(rect,
                                                                        Color.FromArgb(alpha1, glassColor), Color.FromArgb(alpha2, glassColor), angle))
                {
                    if (simpleRect)
                    {
                        g.FillRectangle(lb, rect);
                    }
                    else
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect,
                                                                                        ownerRadius, round, false))
                        {
                            g.FillPath(lb, path);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static void RenderDefault(Graphics g, Rectangle rect, Color backColor, float startAngle,
                                         int radius1, int radius2, int spokeNum, float penWidth, Color[] colorArray)
        {
            if (spokeNum < 1)
            {
                throw new ArgumentException("spokeNum must bigger than 0", "spokeNum");
            }
            if (spokeNum > colorArray.Length)
            {
                throw new ArgumentException("spokeNum must NOT bigger than the length of colorArray. ", "spokeNum");
            }
            //using (SolidBrush sb = new SolidBrush(backColor))
            //{
            //    using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.HighSpeed))
            //    {
            //        g.FillRectangle(sb, rect);
            //    }
            //}
            Point  NYPD = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
            PointF p1, p2;

            p1 = new PointF(0f, 0f);
            p2 = p1;
            double cra = 2 * Math.PI / spokeNum;

            startAngle = (float)(startAngle * 2 * Math.PI / 360f);
            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias))
            {
                using (Pen p = new Pen(Color.White, penWidth))
                {
                    p.StartCap = LineCap.Round;
                    p.EndCap   = LineCap.Round;
                    for (int i = 0; i < spokeNum; i++)
                    {
                        double angle = startAngle + cra * i;
                        p1.X    = NYPD.X + (float)(radius1 / 2 * Math.Cos(angle));
                        p1.Y    = NYPD.Y + (float)(radius1 / 2 * Math.Sin(angle));
                        p2.X    = NYPD.X + (float)(radius2 / 2 * Math.Cos(angle));
                        p2.Y    = NYPD.Y + (float)(radius2 / 2 * Math.Sin(angle));
                        p.Color = colorArray[i];
                        g.DrawLine(p, p1, p2);
                    }
                }
            }
        }
        public static void RenderFlatBackground(Graphics g, Rectangle rect, Color backColor,
                                                ButtonBorderType borderType, int radius, RoundStyle roundType)
        {
            SmoothingMode newMode;
            bool          simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2));

            if (simpleRect)
            {
                newMode = SmoothingMode.HighSpeed;
            }
            else
            {
                newMode = SmoothingMode.AntiAlias;
                rect.Width--;
                rect.Height--;
            }
            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode))
            {
                using (SolidBrush sb = new SolidBrush(backColor))
                {
                    if (simpleRect)
                    {
                        g.FillRectangle(sb, rect);
                    }
                    else if (borderType == ButtonBorderType.Ellipse)
                    {
                        g.FillEllipse(sb, rect);
                    }
                    else
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false))
                        {
                            g.FillPath(sb, path);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public static void RenderChromeOneQuarter(Graphics g, Rectangle rect, Color backColor,
                                                  float startAngle, int radius, Color baseColor)
        {
            //using (SolidBrush sb = new SolidBrush(backColor))
            //{
            //    using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.HighSpeed))
            //    {
            //        g.FillRectangle(sb, rect);
            //    }
            //}
            Rectangle rectgc = new Rectangle(
                rect.X + (rect.Width - radius) / 2, rect.Y + (rect.Height - radius) / 2, radius, radius);

            using (Pen p = new Pen(baseColor, 3))
            {
                p.StartCap = LineCap.Round;
                p.EndCap   = LineCap.Round;
                using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias))
                {
                    g.DrawArc(p, rectgc, startAngle, 120);
                }
            }
        }
Esempio n. 6
0
        public static void RenderDiamondRing(Graphics g, Rectangle rect, Color backColor, float startAngle,
                                             int radius, Color baseColor, Color diamondColor)
        {
            //不要画背景,loading就行
            //using (SolidBrush sb = new SolidBrush(backColor))
            //{
            //    using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.HighSpeed))
            //    {
            //        g.FillRectangle(sb, rect);
            //    }
            //}

            Point NYPD = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            startAngle = (float)(startAngle * 2 * Math.PI / 360f);
            PointF pslute = PointF.Empty;

            pslute.X = NYPD.X + (float)(Math.Cos(startAngle) * radius / 2);
            pslute.Y = NYPD.Y + (float)(Math.Sin(startAngle) * radius / 2);

            Rectangle rectce = new Rectangle(
                rect.X + (rect.Width - radius) / 2, rect.Y + (rect.Height - radius) / 2, radius, radius);
            float      width  = 4f;
            RectangleF rectpf = new RectangleF(pslute.X - width / 2, pslute.Y - width / 2, width, width);

            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias))
            {
                using (Pen p = new Pen(baseColor))
                {
                    g.DrawEllipse(p, rectce);
                }
                using (SolidBrush sb = new SolidBrush(diamondColor))
                {
                    g.FillEllipse(sb, rectpf);
                }
            }
        }
Esempio n. 7
0
        public static void RenderTheseGuys(Graphics g, Rectangle rect, Color backColor, float startAngle,
                                           int radius, Color baseColor)
        {
            //using (SolidBrush sb = new SolidBrush(backColor))
            //{
            //    using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.HighSpeed))
            //    {
            //        g.FillRectangle(sb, rect);
            //    }
            //}

            Point NYPD = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            startAngle = (float)(startAngle * 2 * Math.PI / 360f);
            PointF     CIA = PointF.Empty;
            double     crs = 2 * Math.PI / 10;
            RectangleF FBI = RectangleF.Empty;

            float[] theFeds = new float[] { 5f, 4f, 3f, 2f, 2f };
            Color[] DoD     = ColorHelper.GetLighterArrayColors(baseColor, 5, 50f);
            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias))
            {
                using (SolidBrush sb = new SolidBrush(baseColor))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        CIA.X = NYPD.X + (float)(Math.Cos(startAngle - i * crs) * radius / 2);
                        CIA.Y = NYPD.Y + (float)(Math.Sin(startAngle - i * crs) * radius / 2);
                        FBI   = new RectangleF(
                            CIA.X - theFeds[i] / 2, CIA.Y - theFeds[i] / 2, theFeds[i], theFeds[i]);
                        sb.Color = DoD[4 - i];
                        g.FillEllipse(sb, FBI);
                    }
                }
            }
        }
Esempio n. 8
0
        public static void RenderCircleProgressBar(Graphics g, Rectangle rect, Color coveredColor, Color borderColor,
                                                   Color backColor, bool drawInnerBorder, int startAngle, int percentage, bool drawText, Font textFont)
        {
            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, SmoothingMode.AntiAlias))
            {
                Rectangle backup = rect;
                rect.Width--;
                rect.Height--;

                if (percentage < 0)
                {
                    percentage = 0;
                }
                if (percentage > 360)
                {
                    percentage = 360;
                }

                SolidBrush brushBack = new SolidBrush(backColor);
                Pen        penBorder = new Pen(borderColor);

                // fill background
                g.FillEllipse(brushBack, rect);

                // outter most circle
                g.DrawEllipse(penBorder, rect);

                // pie covered region
                rect.Inflate(-1, -1);
                if (drawInnerBorder)
                {
                    rect.Inflate(-1, -1);
                }
                using (SolidBrush sb = new SolidBrush(coveredColor))
                {
                    g.FillPie(sb, rect, startAngle, 360 * percentage / 100);
                }

                // inner circle background
                rect = backup;
                rect.Inflate(-rect.Width / 4, -rect.Width / 4);
                g.FillEllipse(brushBack, rect);

                // inner circle line
                rect.Inflate(-1, -1);
                if (drawInnerBorder)
                {
                    rect.Inflate(-1, -1);
                }
                g.DrawEllipse(penBorder, rect);

                // text
                if (drawText)
                {
                    string text = percentage.ToString() + "%";
                    TextRenderer.DrawText(g, text, textFont, backup, Color.Black,
                                          TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                }

                brushBack.Dispose();
                penBorder.Dispose();
            }
        }