/// <summary>
        /// Paints the specified g.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="rClient">The r client.</param>
        public override void Paint(Graphics g, Region rClient)
        {
            base.Paint(g, rClient);

            if (!Bar.DrawBar)
            {
                return;
            }

            RectangleF bounds = rClient.GetBounds(g);
            float      ratio  = CalculateRatio();

            if (!Bar.Vertical)
            {
                float xPeriod = bounds.Width / BlockCount;
                float xOffset = bounds.Width * ratio;
                float xValue  = bounds.Left + xOffset;
                float yMiddle = bounds.Top + (bounds.Height / 2);

                RectangleF r2 = bounds;
                r2.Inflate(xPeriod, 0);

                ZeroitBusyBarBlockLines blocks = new ZeroitBusyBarBlockLines();

                blocks.BlockWidth     = xPeriod / 2f;
                blocks.BlockLineWidth = xPeriod / 2f;
                blocks.BlockScroll    = false;
                blocks.Bounds         = bounds;
                blocks.R1             = RectangleF.Empty;
                blocks.R2             = r2;
                blocks.R3             = RectangleF.Empty;
                blocks.XValue         = 0;

                ArrayList lines = blocks.HorizontalLines;

                // back
                float xBackSpace = xPeriod - BackBlockWidth;

                RectangleF[] rectsBack = new RectangleF[lines.Count];

                int iRectBack = 0;
                foreach (float line in lines)
                {
                    rectsBack[iRectBack++] = new RectangleF(
                        line + (xBackSpace / 2f),
                        bounds.Top + ((bounds.Height - BackBlockHeight) / 2f),
                        BackBlockWidth,
                        BackBlockHeight);
                }

                if (BackOutlineWidth > 0)
                {
                    using (Brush brushBackOutline = new SolidBrush(BackOutlineColor))
                        if (_BackShape == Shapes.Rectangle)
                        {
                            g.FillRectangles(brushBackOutline, rectsBack);
                        }
                        else if (_BackShape == Shapes.Ellipse)
                        {
                            foreach (RectangleF rectBack in rectsBack)
                            {
                                g.FillEllipse(brushBackOutline, rectBack);
                            }
                        }
                        else
                        {
                            Debug.Assert(false);
                        }

                    for (iRectBack = 0; iRectBack < rectsBack.Length; iRectBack++)
                    {
                        rectsBack[iRectBack].Inflate(-BackOutlineWidth, -BackOutlineWidth);
                    }
                }

                using (Brush brushBack = new SolidBrush(BackColor))
                    if (_BackShape == Shapes.Rectangle)
                    {
                        g.FillRectangles(brushBack, rectsBack);
                    }
                    else if (_BackShape == Shapes.Ellipse)
                    {
                        foreach (RectangleF rectBack in rectsBack)
                        {
                            g.FillEllipse(brushBack, rectBack);
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                // fore
                float xForeSpace = xPeriod - ForeBlockWidth;

                RectangleF[] rectsFore = new RectangleF[lines.Count];

                int iRectFore = 0;
                foreach (float line in lines)
                {
                    rectsFore[iRectFore++] = new RectangleF(
                        line + (xForeSpace / 2f),
                        bounds.Top + ((bounds.Height - ForeBlockHeight) / 2f),
                        ForeBlockWidth,
                        ForeBlockHeight);
                }

                foreach (RectangleF rectFore in rectsFore)
                {
                    RectangleF rectBig = rectFore;
                    rectBig.Inflate(xForeSpace / 2f, 0);

                    if (rectBig.Contains(xValue, yMiddle))
                    {
                        float ratioFore = (xValue - rectBig.Left) / rectBig.Width;

                        int alpha = 255;

                        switch (Bar.Pin)
                        {
                        case ZeroitBusyBar.Pins.None:
                            if (ratioFore < 0.5)
                            {
                                alpha = (int)(ratioFore * 255 * 2);
                            }
                            if (ratioFore > 0.5)
                            {
                                alpha = (int)((1f - ratioFore) * 255 * 2);
                            }
                            break;

                        case ZeroitBusyBar.Pins.Start:
                            alpha = (int)(ratioFore * 255);
                            break;

                        case ZeroitBusyBar.Pins.End:
                            alpha = (int)((1f - ratioFore) * 255);
                            break;

                        default: Debug.Assert(false); break;
                        }

                        if (ForeOutlineWidth > 0)
                        {
                            using (Brush brushForeOutline = new SolidBrush(Color.FromArgb(alpha, ForeOutlineColor)))
                                if (_ForeShape == Shapes.Rectangle)
                                {
                                    g.FillRectangle(brushForeOutline, rectFore);
                                }
                                else if (_ForeShape == Shapes.Ellipse)
                                {
                                    g.FillEllipse(brushForeOutline, rectFore);
                                }
                                else
                                {
                                    Debug.Assert(false);
                                }

                            rectFore.Inflate(-ForeOutlineWidth, -ForeOutlineWidth);
                        }

                        using (Brush brushFore = new SolidBrush(Color.FromArgb(alpha, ForeColor)))
                            if (_ForeShape == Shapes.Rectangle)
                            {
                                g.FillRectangle(brushFore, rectFore);
                            }
                            else if (_ForeShape == Shapes.Ellipse)
                            {
                                g.FillEllipse(brushFore, rectFore);
                            }
                            else
                            {
                                Debug.Assert(false);
                            }
                    }
                    else
                    {
                        if (
                            (xValue > rectFore.Right && Bar.Pin == ZeroitBusyBar.Pins.Start) ||
                            (xValue < rectFore.Left && Bar.Pin == ZeroitBusyBar.Pins.End))
                        {
                            if (ForeOutlineWidth > 0)
                            {
                                using (Brush brushForeOutline = new SolidBrush(ForeOutlineColor))
                                    if (_ForeShape == Shapes.Rectangle)
                                    {
                                        g.FillRectangle(brushForeOutline, rectFore);
                                    }
                                    else if (_ForeShape == Shapes.Ellipse)
                                    {
                                        g.FillEllipse(brushForeOutline, rectFore);
                                    }
                                    else
                                    {
                                        Debug.Assert(false);
                                    }

                                rectFore.Inflate(-ForeOutlineWidth, -ForeOutlineWidth);
                            }

                            using (Brush brushFore = new SolidBrush(ForeColor))
                                if (_ForeShape == Shapes.Rectangle)
                                {
                                    g.FillRectangle(brushFore, rectFore);
                                }
                                else if (_ForeShape == Shapes.Ellipse)
                                {
                                    g.FillEllipse(brushFore, rectFore);
                                }
                                else
                                {
                                    Debug.Assert(false);
                                }
                        }
                    }
                }
            }
            else // Vertical
            {
                float yPeriod = bounds.Height / BlockCount;
                float yOffset = bounds.Height * ratio;
                float yValue  = bounds.Top + yOffset;
                float xMiddle = bounds.Left + (bounds.Width / 2f);

                RectangleF r2 = bounds;
                r2.Inflate(0, yPeriod);

                ZeroitBusyBarBlockLines blocks = new ZeroitBusyBarBlockLines();

                blocks.BlockWidth     = yPeriod / 2f;
                blocks.BlockLineWidth = yPeriod / 2f;
                blocks.BlockScroll    = false;
                blocks.Bounds         = bounds;
                blocks.R1             = RectangleF.Empty;
                blocks.R2             = r2;
                blocks.R3             = RectangleF.Empty;
                blocks.XValue         = 0;

                ArrayList lines = blocks.VerticalLines;

                // back
                float yBackSpace = yPeriod - BackBlockHeight;

                RectangleF[] rectsBack = new RectangleF[lines.Count];

                int iRectBack = 0;
                foreach (float line in lines)
                {
                    rectsBack[iRectBack++] = new RectangleF(
                        bounds.Left + ((bounds.Width - BackBlockWidth) / 2f),
                        line + (yBackSpace / 2f),
                        BackBlockWidth,
                        BackBlockHeight);
                }

                if (BackOutlineWidth > 0)
                {
                    using (Brush brushBackOutline = new SolidBrush(BackOutlineColor))
                        if (_BackShape == Shapes.Rectangle)
                        {
                            g.FillRectangles(brushBackOutline, rectsBack);
                        }
                        else if (_BackShape == Shapes.Ellipse)
                        {
                            foreach (RectangleF rectBack in rectsBack)
                            {
                                g.FillEllipse(brushBackOutline, rectBack);
                            }
                        }
                        else
                        {
                            Debug.Assert(false);
                        }

                    for (iRectBack = 0; iRectBack < rectsBack.Length; iRectBack++)
                    {
                        rectsBack[iRectBack].Inflate(-BackOutlineWidth, -BackOutlineWidth);
                    }
                }

                using (Brush brushBack = new SolidBrush(BackColor))
                    if (_BackShape == Shapes.Rectangle)
                    {
                        g.FillRectangles(brushBack, rectsBack);
                    }
                    else if (_BackShape == Shapes.Ellipse)
                    {
                        foreach (RectangleF rectBack in rectsBack)
                        {
                            g.FillEllipse(brushBack, rectBack);
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                // fore
                float yForeSpace = yPeriod - ForeBlockHeight;

                RectangleF[] rectsFore = new RectangleF[lines.Count];

                int iRectFore = 0;
                foreach (float line in lines)
                {
                    rectsFore[iRectFore++] = new RectangleF(
                        bounds.Left + ((bounds.Width - ForeBlockWidth) / 2f),
                        line + (yForeSpace / 2f),
                        ForeBlockWidth,
                        ForeBlockHeight);
                }

                foreach (RectangleF rectFore in rectsFore)
                {
                    RectangleF rectBig = rectFore;
                    rectBig.Inflate(0, yForeSpace / 2f);

                    if (rectBig.Contains(xMiddle, yValue))
                    {
                        float ratioFore = (yValue - rectBig.Top) / rectBig.Height;

                        int alpha = 255;

                        switch (Bar.Pin)
                        {
                        case ZeroitBusyBar.Pins.None:
                            if (ratioFore < 0.5)
                            {
                                alpha = (int)(ratioFore * 255 * 2);
                            }
                            if (ratioFore > 0.5)
                            {
                                alpha = (int)((1f - ratioFore) * 255 * 2);
                            }
                            break;

                        case ZeroitBusyBar.Pins.Start:
                            alpha = (int)(ratioFore * 255);
                            break;

                        case ZeroitBusyBar.Pins.End:
                            alpha = (int)((1f - ratioFore) * 255);
                            break;

                        default: Debug.Assert(false); break;
                        }

                        if (ForeOutlineWidth > 0)
                        {
                            using (Brush brushForeOutline = new SolidBrush(Color.FromArgb(alpha, ForeOutlineColor)))
                                if (_ForeShape == Shapes.Rectangle)
                                {
                                    g.FillRectangle(brushForeOutline, rectFore);
                                }
                                else if (_ForeShape == Shapes.Ellipse)
                                {
                                    g.FillEllipse(brushForeOutline, rectFore);
                                }
                                else
                                {
                                    Debug.Assert(false);
                                }

                            rectFore.Inflate(-ForeOutlineWidth, -ForeOutlineWidth);
                        }

                        using (Brush brushFore = new SolidBrush(Color.FromArgb(alpha, ForeColor)))
                            if (_ForeShape == Shapes.Rectangle)
                            {
                                g.FillRectangle(brushFore, rectFore);
                            }
                            else if (_ForeShape == Shapes.Ellipse)
                            {
                                g.FillEllipse(brushFore, rectFore);
                            }
                            else
                            {
                                Debug.Assert(false);
                            }
                    }
                    else
                    {
                        if (
                            (yValue > rectFore.Bottom && Bar.Pin == ZeroitBusyBar.Pins.Start) ||
                            (yValue < rectFore.Top && Bar.Pin == ZeroitBusyBar.Pins.End))
                        {
                            if (ForeOutlineWidth > 0)
                            {
                                using (Brush brushForeOutline = new SolidBrush(ForeOutlineColor))
                                    if (_ForeShape == Shapes.Rectangle)
                                    {
                                        g.FillRectangle(brushForeOutline, rectFore);
                                    }
                                    else if (_ForeShape == Shapes.Ellipse)
                                    {
                                        g.FillEllipse(brushForeOutline, rectFore);
                                    }
                                    else
                                    {
                                        Debug.Assert(false);
                                    }

                                rectFore.Inflate(-ForeOutlineWidth, -ForeOutlineWidth);
                            }

                            using (Brush brushFore = new SolidBrush(ForeColor))
                                if (_ForeShape == Shapes.Rectangle)
                                {
                                    g.FillRectangle(brushFore, rectFore);
                                }
                                else if (_ForeShape == Shapes.Ellipse)
                                {
                                    g.FillEllipse(brushFore, rectFore);
                                }
                                else
                                {
                                    Debug.Assert(false);
                                }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Paints the specified g.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="r">The r.</param>
        public override void Paint(Graphics g, Region r)
        {
            base.Paint(g, r);

            if (!Bar.DrawBar)
            {
                return;
            }

            RectangleF bounds = r.GetBounds(g);
            float      ratio  = CalculateRatio();

            if (!Bar.Vertical)
            {
                float xOffset = bounds.Width * ratio;

                if (!BlockSmooth && Bar.Pin != ZeroitBusyBar.Pins.None)
                {
                    int xPeriod     = BlockWidth + BlockLineWidth;
                    int xIntPeriods = (int)System.Math.Floor(bounds.Width / xPeriod);

                    float xWholeWidth = (1 + xIntPeriods) * xPeriod;
                    float xFudge      = xWholeWidth / bounds.Width;

                    xOffset *= xFudge;
                }

                float xValue  = bounds.Left + xOffset;
                float b       = bounds.Width * BlockPercent / 100f;
                float xLeft   = xValue - (b / 2);
                float xRight  = xValue + (b / 2);
                float yMiddle = bounds.Top + (bounds.Height / 2);

                RectangleF r2 = RectangleF.Empty;
                RectangleF r1 = RectangleF.Empty;
                RectangleF r3 = RectangleF.Empty;

                switch (Bar.Pin)
                {
                case ZeroitBusyBar.Pins.None:
                {
                    r2 = new RectangleF(xLeft, bounds.Top, b, bounds.Height);
                    r1 = r2; r1.Offset(-bounds.Width, 0);
                    r3 = r2; r3.Offset(+bounds.Width, 0);
                    break;
                }

                case ZeroitBusyBar.Pins.Start:
                {
                    r2 = new RectangleF(
                        bounds.Left,
                        bounds.Top,
                        xOffset,
                        bounds.Height);

                    break;
                }

                case ZeroitBusyBar.Pins.End:
                {
                    r2 = new RectangleF(
                        xValue,
                        bounds.Top,
                        bounds.Width - xOffset,
                        bounds.Height);

                    break;
                }

                default:
                    Debug.Assert(false);
                    return;
                }

                if (r2.Width <= 0 || r2.Height <= 0)
                {
                    return;
                }

                if (r2.Left > bounds.Left)
                {
                    _Wrap = Bar.Wrap;
                }

                ZeroitBusyBarBlockLines blocks = new ZeroitBusyBarBlockLines();

                blocks.BlockWidth     = BlockWidth;
                blocks.BlockLineWidth = BlockLineWidth;
                blocks.BlockScroll    = BlockScroll;
                blocks.Bounds         = bounds;
                blocks.R1             = r1;
                blocks.R2             = r2;
                blocks.R3             = r3;
                blocks.XValue         = xValue;

                ArrayList lines = blocks.HorizontalLines;

                if (!BlockSmooth)
                {
                    r1.X = blocks.R1Left;
                    r2.X = blocks.R2Left;
                    r3.X = blocks.R3Left;

                    r1.Width = blocks.R1Right - r1.Left;
                    r2.Width = blocks.R2Right - r2.Left;
                    r3.Width = blocks.R3Right - r3.Left;

                    if (Bar.Pin == ZeroitBusyBar.Pins.Start && lines.Count > 0)
                    {
                        r2.X     -= BlockWidth + BlockLineWidth;
                        r2.Width += BlockWidth + BlockLineWidth;
                    }

                    if (Bar.Pin == ZeroitBusyBar.Pins.End && lines.Count > 0)
                    {
                        r2.Width += BlockWidth + BlockLineWidth;
                    }
                }

                GraphicsPath path    = null;
                Color[]      colours = null;

                switch (_Shape)
                {
                case Shapes.Rectangle:
                {
                    PointF[] points = null;

                    if (Bar.Pin == ZeroitBusyBar.Pins.None)
                    {
                        points = new PointF[]
                        {
                            new PointF(xLeft, bounds.Top),
                            new PointF(xValue, bounds.Top),
                            new PointF(xRight, bounds.Top),
                            new PointF(xRight, yMiddle),
                            new PointF(xRight, bounds.Bottom),
                            new PointF(xValue, bounds.Bottom),
                            new PointF(xLeft, bounds.Bottom),
                            new PointF(xLeft, yMiddle),
                        };
                    }
                    else
                    {
                        if (r2.Width < 1)
                        {
                            return;
                        }

                        float xMiddle = (r2.Left + r2.Right) / 2;

                        points = new PointF[]
                        {
                            new PointF(r2.Left, bounds.Top),
                            new PointF(xMiddle, bounds.Top),
                            new PointF(r2.Right, bounds.Top),
                            new PointF(r2.Right, yMiddle),
                            new PointF(r2.Right, bounds.Bottom),
                            new PointF(xMiddle, bounds.Bottom),
                            new PointF(r2.Left, bounds.Bottom),
                            new PointF(r2.Left, yMiddle),
                        };
                    }

                    path = new GraphicsPath();
                    path.AddLines(points);
                    path.CloseFigure();

                    colours = new Color[]
                    {
                        _ColorCorner,
                        _ColorVertical,
                        _ColorCorner,
                        _ColorHorizontal,
                        _ColorCorner,
                        _ColorVertical,
                        _ColorCorner,
                        _ColorHorizontal
                    };

                    break;
                }

                case Shapes.Diamond:
                {
                    PointF[] points = null;

                    if (Bar.Pin == ZeroitBusyBar.Pins.None)
                    {
                        points = new PointF[]
                        {
                            new PointF(xValue, bounds.Top),
                            new PointF(xRight, yMiddle),
                            new PointF(xValue, bounds.Bottom),
                            new PointF(xLeft, yMiddle),
                        };
                    }
                    else
                    {
                        if (r2.Width < 1)
                        {
                            return;
                        }

                        float xMiddle = (r2.Left + r2.Right) / 2;

                        points = new PointF[]
                        {
                            new PointF(xMiddle, bounds.Top),
                            new PointF(r2.Right, yMiddle),
                            new PointF(xMiddle, bounds.Bottom),
                            new PointF(r2.Left, yMiddle),
                        };
                    }
                    path = new GraphicsPath();
                    path.AddLines(points);
                    path.CloseFigure();

                    colours = new Color[]
                    {
                        _ColorVertical,
                        _ColorHorizontal,
                        _ColorVertical,
                        _ColorHorizontal
                    };

                    break;
                }

                case Shapes.Circle:
                {
                    path = new GraphicsPath();

                    if (Bar.Pin == ZeroitBusyBar.Pins.None)
                    {
                        path.AddEllipse(xLeft, bounds.Top, b, bounds.Height);
                    }
                    else
                    {
                        if (r2.Width < 1)
                        {
                            return;
                        }

                        path.AddEllipse(r2.Left, bounds.Top, r2.Width, bounds.Height);
                    }

                    colours = new Color[]
                    {
                        _ColorCorner,
                    };

                    break;
                }

                default:
                    Debug.Assert(false);
                    return;
                }

                using (PathGradientBrush brush = new PathGradientBrush(path))
                {
                    brush.CenterColor    = _ColorCentre;
                    brush.SurroundColors = colours;

                    bool bOther = _Wrap && (Bar.Pin == ZeroitBusyBar.Pins.None);

                    if (bOther)
                    {
                        brush.TranslateTransform(-bounds.Width, 0);
                        g.FillRectangle(brush, r1);
                        brush.ResetTransform();
                    }

                    g.FillRectangle(brush, r2);

                    if (bOther)
                    {
                        brush.TranslateTransform(+bounds.Width, 0);
                        g.FillRectangle(brush, r3);
                        brush.ResetTransform();
                    }
                }

                if (BlockLineWidth > 0)
                {
                    using (Pen pen2 = new Pen(BlockLineColor, BlockLineWidth))
                    {
                        foreach (float xLine in lines)
                        {
                            g.DrawLine(pen2, xLine, bounds.Top, xLine, bounds.Bottom);
                        }
                    }
                }
            }
            // Vertical
            else
            {
                float yOffset = bounds.Height * ratio;

                if (!BlockSmooth && Bar.Pin != ZeroitBusyBar.Pins.None)
                {
                    int yPeriod     = BlockWidth + BlockLineWidth;
                    int yIntPeriods = (int)System.Math.Floor(bounds.Height / yPeriod);

                    float yWholeWidth = (1 + yIntPeriods) * yPeriod;
                    float yFudge      = yWholeWidth / bounds.Height;

                    yOffset *= yFudge;
                }

                float yValue  = bounds.Top + yOffset;
                float b       = bounds.Height * BlockPercent / 100f;
                float yTop    = yValue - (b / 2);
                float yBottom = yValue + (b / 2);
                float xMiddle = bounds.Left + (bounds.Width / 2);

                RectangleF r2 = RectangleF.Empty;
                RectangleF r1 = RectangleF.Empty;
                RectangleF r3 = RectangleF.Empty;

                switch (Bar.Pin)
                {
                case ZeroitBusyBar.Pins.None:
                {
                    r2 = new RectangleF(bounds.Left, yTop, bounds.Width, b);
                    r1 = r2; r1.Offset(0, -bounds.Height);
                    r3 = r2; r3.Offset(0, +bounds.Height);
                    break;
                }

                case ZeroitBusyBar.Pins.Start:
                {
                    r2 = new RectangleF(
                        bounds.Left,
                        bounds.Top,
                        bounds.Width,
                        yOffset);

                    break;
                }

                case ZeroitBusyBar.Pins.End:
                {
                    r2 = new RectangleF(
                        bounds.Left,
                        yValue,
                        bounds.Width,
                        bounds.Height - yOffset);

                    break;
                }

                default:
                    Debug.Assert(false);
                    return;
                }

                if (r2.Width <= 0 || r2.Height <= 0)
                {
                    return;
                }

                if (r2.Top > bounds.Top)
                {
                    _Wrap = Bar.Wrap;
                }

                ZeroitBusyBarBlockLines blocks = new ZeroitBusyBarBlockLines();

                blocks.BlockWidth     = BlockWidth;
                blocks.BlockLineWidth = BlockLineWidth;
                blocks.BlockScroll    = BlockScroll;
                blocks.Bounds         = bounds;
                blocks.R1             = r1;
                blocks.R2             = r2;
                blocks.R3             = r3;
                blocks.YValue         = yValue;

                ArrayList lines = blocks.VerticalLines;

                if (!BlockSmooth)
                {
                    r1.Y = blocks.R1Top;
                    r2.Y = blocks.R2Top;
                    r3.Y = blocks.R3Top;

                    r1.Height = blocks.R1Bottom - r1.Top;
                    r2.Height = blocks.R2Bottom - r2.Top;
                    r3.Height = blocks.R3Bottom - r3.Top;

                    if (Bar.Pin == ZeroitBusyBar.Pins.Start && lines.Count > 0)
                    {
                        r2.Y      -= BlockWidth + BlockLineWidth;
                        r2.Height += BlockWidth + BlockLineWidth;
                    }

                    if (Bar.Pin == ZeroitBusyBar.Pins.End && lines.Count > 0)
                    {
                        r2.Height += BlockWidth + BlockLineWidth;
                    }
                }

                GraphicsPath path    = null;
                Color[]      colours = null;

                switch (_Shape)
                {
                case Shapes.Rectangle:
                {
                    PointF[] points = null;

                    if (Bar.Pin == ZeroitBusyBar.Pins.None)
                    {
                        points = new PointF[]
                        {
                            new PointF(bounds.Left, yTop),
                            new PointF(xMiddle, yTop),
                            new PointF(bounds.Right, yTop),
                            new PointF(bounds.Right, yValue),
                            new PointF(bounds.Right, yBottom),
                            new PointF(xMiddle, yBottom),
                            new PointF(bounds.Left, yBottom),
                            new PointF(bounds.Left, yValue),
                        };
                    }
                    else
                    {
                        if (r2.Height < 1)
                        {
                            return;
                        }

                        float yMiddle = (r2.Top + r2.Bottom) / 2;

                        points = new PointF[]
                        {
                            new PointF(bounds.Left, r2.Top),
                            new PointF(xMiddle, r2.Top),
                            new PointF(bounds.Right, r2.Top),
                            new PointF(bounds.Right, yMiddle),
                            new PointF(bounds.Right, r2.Bottom),
                            new PointF(xMiddle, r2.Bottom),
                            new PointF(bounds.Left, r2.Bottom),
                            new PointF(bounds.Left, yMiddle),
                        };
                    }

                    path = new GraphicsPath();
                    path.AddLines(points);
                    path.CloseFigure();

                    colours = new Color[]
                    {
                        _ColorCorner,
                        _ColorVertical,
                        _ColorCorner,
                        _ColorHorizontal,
                        _ColorCorner,
                        _ColorVertical,
                        _ColorCorner,
                        _ColorHorizontal
                    };

                    break;
                }

                case Shapes.Diamond:
                {
                    PointF[] points = null;

                    if (Bar.Pin == ZeroitBusyBar.Pins.None)
                    {
                        points = new PointF[]
                        {
                            new PointF(xMiddle, yTop),
                            new PointF(bounds.Right, yValue),
                            new PointF(xMiddle, yBottom),
                            new PointF(bounds.Left, yValue),
                        };
                    }
                    else
                    {
                        if (r2.Height < 1)
                        {
                            return;
                        }

                        float yMiddle = (r2.Top + r2.Bottom) / 2;

                        points = new PointF[]
                        {
                            new PointF(xMiddle, r2.Top),
                            new PointF(bounds.Right, yMiddle),
                            new PointF(xMiddle, r2.Bottom),
                            new PointF(bounds.Left, yMiddle),
                        };
                    }

                    path = new GraphicsPath();
                    path.AddLines(points);
                    path.CloseFigure();

                    colours = new Color[]
                    {
                        _ColorVertical,
                        _ColorHorizontal,
                        _ColorVertical,
                        _ColorHorizontal
                    };

                    break;
                }

                case Shapes.Circle:
                {
                    path = new GraphicsPath();

                    if (Bar.Pin == ZeroitBusyBar.Pins.None)
                    {
                        path.AddEllipse(bounds.Left, yTop, bounds.Width, b);
                    }
                    else
                    {
                        if (r2.Height < 1)
                        {
                            return;
                        }

                        path.AddEllipse(bounds.Left, r2.Top, bounds.Width, r2.Height);
                    }

                    colours = new Color[]
                    {
                        _ColorCorner,
                    };

                    break;
                }

                default:
                    Debug.Assert(false);
                    return;
                }

                using (PathGradientBrush brush = new PathGradientBrush(path))
                {
                    brush.CenterColor    = _ColorCentre;
                    brush.SurroundColors = colours;

                    bool bOther = _Wrap && (Bar.Pin == ZeroitBusyBar.Pins.None);

                    if (bOther)
                    {
                        brush.TranslateTransform(0, -bounds.Height);
                        g.FillRectangle(brush, r1);
                        brush.ResetTransform();
                    }

                    g.FillRectangle(brush, r2);

                    if (bOther)
                    {
                        brush.TranslateTransform(0, +bounds.Height);
                        g.FillRectangle(brush, r3);
                        brush.ResetTransform();
                    }
                }

                if (BlockLineWidth > 0)
                {
                    using (Pen pen2 = new Pen(BlockLineColor, BlockLineWidth))
                    {
                        foreach (float yLine in lines)
                        {
                            g.DrawLine(pen2, bounds.Left, yLine, bounds.Right, yLine);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Paints the specified g.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="r">The r.</param>
        public override void Paint(Graphics g, Region r)
        {
            //			g.ResetClip();

            base.Paint(g, r);

            if (!Bar.DrawBar)
            {
                return;
            }

            RectangleF bounds = r.GetBounds(g);
            float      ratio  = CalculateRatio();

            if (!Bar.Vertical)
            {
                float xOffset = bounds.Width * ratio;

                if (!BlockSmooth && Bar.Pin != ZeroitBusyBar.Pins.None)
                {
                    int xPeriod     = BlockWidth + BlockLineWidth;
                    int xIntPeriods = (int)System.Math.Floor(bounds.Width / xPeriod);

                    float xWholeWidth = (1 + xIntPeriods) * xPeriod;
                    float xFudge      = xWholeWidth / bounds.Width;

                    xOffset *= xFudge;
                }

                float xValue = bounds.Left + xOffset;

                float b     = bounds.Width * BlockPercent / 100f;
                float xLeft = xValue - (b / 2f);

                RectangleF r2 = RectangleF.Empty;
                RectangleF r1 = RectangleF.Empty;
                RectangleF r3 = RectangleF.Empty;

                switch (Bar.Pin)
                {
                case ZeroitBusyBar.Pins.None:
                {
                    r2 = new RectangleF(xLeft, bounds.Top, b, bounds.Height);
                    r1 = r2; r1.Offset(-bounds.Width, 0);
                    r3 = r2; r3.Offset(+bounds.Width, 0);
                    break;
                }

                case ZeroitBusyBar.Pins.Start:
                {
                    r2 = new RectangleF(
                        bounds.Left,
                        bounds.Top,
                        xOffset,
                        bounds.Height);

                    break;
                }

                case ZeroitBusyBar.Pins.End:
                {
                    r2 = new RectangleF(
                        xValue,
                        bounds.Top,
                        bounds.Width - xOffset,
                        bounds.Height);

                    break;
                }

                default:
                    Debug.Assert(false);
                    return;
                }

                if (r1.Right < bounds.Left && r3.Left > bounds.Right)
                {
                    _Wrap = Bar.Wrap;
                }

                ZeroitBusyBarBlockLines blocks = new ZeroitBusyBarBlockLines();

                blocks.BlockWidth     = BlockWidth;
                blocks.BlockLineWidth = BlockLineWidth;
                blocks.BlockScroll    = BlockScroll;
                blocks.Bounds         = bounds;
                blocks.R1             = r1;
                blocks.R2             = r2;
                blocks.R3             = r3;
                blocks.XValue         = xValue;

                ArrayList lines = blocks.HorizontalLines;

                if (!BlockSmooth)
                {
                    r1.X = blocks.R1Left;
                    r2.X = blocks.R2Left;
                    r3.X = blocks.R3Left;

                    r1.Width = blocks.R1Right - r1.Left;
                    r2.Width = blocks.R2Right - r2.Left;
                    r3.Width = blocks.R3Right - r3.Left;

                    if (Bar.Pin == ZeroitBusyBar.Pins.Start && lines.Count > 0)
                    {
                        r2.X     -= BlockWidth + BlockLineWidth;
                        r2.Width += BlockWidth + BlockLineWidth;
                    }

                    if (Bar.Pin == ZeroitBusyBar.Pins.End && lines.Count > 0)
                    {
                        r2.Width += BlockWidth + BlockLineWidth;
                    }
                }

                if (r2.Width <= 0 || r2.Height <= 0)
                {
                    return;
                }

                //				g.DrawRectangle( pen, r2.X, r2.Y, r2.Width, r2.Height );

                Blend blend = new Blend(5);
                blend.Positions = new float[] { 0f, 0.2f, 0.3f, 0.8f, 1f };
                blend.Factors   = new float[] { 0f, 1f, 0f, 0f, 0.8f };

                ColorBlend colourBlend = new ColorBlend(5);
                colourBlend.Colors    = new Color[] { _ColorDark, _ColorLight, _ColorDark, _ColorDark, _ColorLight };
                colourBlend.Positions = new float[] { 0f, 0.2f, 0.3f, 0.8f, 1f };

                using (LinearGradientBrush brush = new LinearGradientBrush(
                           //							r2, Color.Empty, Color.Empty, LinearGradientMode.Vertical ) )
                           //							bounds, _ColorDark, _ColorLight, LinearGradientMode.Vertical ) )
                           r2, _ColorDark, _ColorLight, LinearGradientMode.Vertical))
                {
                    brush.Blend = blend;
                    //					brush.InterpolationColors = colourBlend;
                    brush.GammaCorrection = true;
                    //					brush.WrapMode = WrapMode.Tile;

                    bool bOther = _Wrap && (Bar.Pin == ZeroitBusyBar.Pins.None);

                    if (bOther)
                    {
                        g.FillRectangle(brush, r1);
                    }
                    if (1 == 1)
                    {
                        g.FillRectangle(brush, r2);
                    }
                    //					if ( 1 == 1 ) g.FillRectangle( Brushes.Red, r2 );
                    if (bOther)
                    {
                        g.FillRectangle(brush, r3);
                    }
                }

                if (BlockLineWidth > 0)
                {
                    using (Pen pen2 = new Pen(BlockLineColor, BlockLineWidth))
                    {
                        foreach (float xLine in lines)
                        {
                            g.DrawLine(pen2, xLine, bounds.Top, xLine, bounds.Bottom);
                        }
                    }
                }

                //				g.DrawLine( Pens.Red, blocks.R1Left, bounds.Top, blocks.R1Left, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R1Right, bounds.Top, blocks.R1Right, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R2Left, bounds.Top, blocks.R2Left, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R2Right, bounds.Top, blocks.R2Right, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R3Left, bounds.Top, blocks.R3Left, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R3Right, bounds.Top, blocks.R3Right, bounds.Bottom );
            }
            // Vertical
            else
            {
                float yOffset = bounds.Height * ratio;

                if (!BlockSmooth && Bar.Pin != ZeroitBusyBar.Pins.None)
                {
                    int yPeriod     = BlockWidth + BlockLineWidth;
                    int yIntPeriods = (int)System.Math.Floor(bounds.Height / yPeriod);

                    float yWholeHeight = (1 + yIntPeriods) * yPeriod;
                    float yFudge       = yWholeHeight / bounds.Height;

                    yOffset *= yFudge;
                    //					yOffset += yPeriod;
                }

                float yValue = bounds.Top + yOffset;

                float b    = bounds.Height * BlockPercent / 100f;
                float yTop = yValue - (b / 2f);

                RectangleF r2 = RectangleF.Empty;
                RectangleF r1 = RectangleF.Empty;
                RectangleF r3 = RectangleF.Empty;

                switch (Bar.Pin)
                {
                case ZeroitBusyBar.Pins.None:
                {
                    r2 = new RectangleF(bounds.Left, yTop, bounds.Width, b);
                    r1 = r2; r1.Offset(0, -bounds.Height);
                    r3 = r2; r3.Offset(0, +bounds.Height);
                    break;
                }

                case ZeroitBusyBar.Pins.Start:
                {
                    r2 = new RectangleF(
                        bounds.Left,
                        bounds.Top,
                        bounds.Width,
                        yOffset);

                    break;
                }

                case ZeroitBusyBar.Pins.End:
                {
                    r2 = new RectangleF(
                        bounds.Top,
                        yValue,
                        bounds.Width,
                        bounds.Height - yOffset);

                    break;
                }

                default:
                    Debug.Assert(false);
                    return;
                }

                if (r1.Bottom < bounds.Top && r3.Top > bounds.Bottom)
                {
                    _Wrap = Bar.Wrap;
                }

                ZeroitBusyBarBlockLines blocks = new ZeroitBusyBarBlockLines();

                blocks.BlockWidth     = BlockWidth;
                blocks.BlockLineWidth = BlockLineWidth;
                blocks.BlockScroll    = BlockScroll;
                blocks.Bounds         = bounds;
                blocks.R1             = r1;
                blocks.R2             = r2;
                blocks.R3             = r3;
                blocks.YValue         = yValue;

                ArrayList lines = blocks.VerticalLines;

                if (!BlockSmooth)
                {
                    r1.Y = blocks.R1Top;
                    r2.Y = blocks.R2Top;
                    r3.Y = blocks.R3Top;

                    r1.Height = blocks.R1Bottom - r1.Top;
                    r2.Height = blocks.R2Bottom - r2.Top;
                    r3.Height = blocks.R3Bottom - r3.Top;

                    if (Bar.Pin == ZeroitBusyBar.Pins.Start && lines.Count > 0)
                    {
                        r2.Y      -= BlockWidth + BlockLineWidth;
                        r2.Height += BlockWidth + BlockLineWidth;
                    }

                    if (Bar.Pin == ZeroitBusyBar.Pins.End && lines.Count > 0)
                    {
                        r2.Height += BlockWidth + BlockLineWidth;
                    }
                }

                if (r2.Width <= 0 || r2.Height <= 0)
                {
                    return;
                }

                //				g.DrawRectangle( pen, r2.X, r2.Y, r2.Width, r2.Height );

                Blend blend = new Blend(5);
                blend.Positions = new float[] { 0f, 0.2f, 0.3f, 0.8f, 1f };
                blend.Factors   = new float[] { 0f, 1f, 0f, 0f, 0.8f };

                ColorBlend colourBlend = new ColorBlend(5);
                colourBlend.Colors    = new Color[] { _ColorDark, _ColorLight, _ColorDark, _ColorDark, _ColorLight };
                colourBlend.Positions = new float[] { 0f, 0.2f, 0.3f, 0.8f, 1f };

                using (LinearGradientBrush brush = new LinearGradientBrush(
                           //							r2, Color.Empty, Color.Empty, LinearGradientMode.Vertical ) )
                           //							bounds, _ColorDark, _ColorLight, LinearGradientMode.Vertical ) )
                           r2, _ColorDark, _ColorLight, LinearGradientMode.Horizontal))
                {
                    brush.Blend = blend;
                    //					brush.InterpolationColors = colourBlend;
                    brush.GammaCorrection = true;
                    //					brush.WrapMode = WrapMode.Tile;

                    bool bOther = _Wrap && (Bar.Pin == ZeroitBusyBar.Pins.None);

                    if (bOther)
                    {
                        g.FillRectangle(brush, r1);
                    }
                    if (1 == 1)
                    {
                        g.FillRectangle(brush, r2);
                    }
                    //					if ( 1 == 1 ) g.FillRectangle( Brushes.Red, r2 );
                    if (bOther)
                    {
                        g.FillRectangle(brush, r3);
                    }
                }

                if (BlockLineWidth > 0)
                {
                    using (Pen pen2 = new Pen(BlockLineColor, BlockLineWidth))
                    {
                        foreach (float yLine in lines)
                        {
                            g.DrawLine(pen2, bounds.Left, yLine, bounds.Right, yLine);
                        }
                    }
                }

                //				g.DrawLine( Pens.Red, blocks.R1Left, bounds.Top, blocks.R1Left, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R1Right, bounds.Top, blocks.R1Right, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R2Left, bounds.Top, blocks.R2Left, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R2Right, bounds.Top, blocks.R2Right, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R3Left, bounds.Top, blocks.R3Left, bounds.Bottom );
                //				g.DrawLine( Pens.Red, blocks.R3Right, bounds.Top, blocks.R3Right, bounds.Bottom );
            }
        }