public void ResetTransform()
 {
     using (Matrix m = new Matrix(2, 0, 0, 2, 10, -10)) {
         using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) {
             pgb.Transform = m;
             Assert.IsFalse(pgb.Transform.IsIdentity, "Transform.IsIdentity");
             pgb.ResetTransform();
             Assert.IsTrue(pgb.Transform.IsIdentity, "Reset.IsIdentity");
         }
     }
 }
예제 #2
0
        /// <summary>
        /// 路径控件的颜色发生变化通知 [一般作用于示例图使用]
        /// </summary>
        /// <param name="cb"></param>
        /// <param name="angle"></param>
        private void Event_PathBrushControl(ColorBlend cb, float angle)
        {
            _pathGradientBrushExample.InterpolationColors = linearGradientUserControl2.LinearGradientBrushInfo.ColorBlend;
            _pathGradientBrushExample.ResetTransform();
            Point centpt = new Point(Location.X - 1 + Width / 2, Location.Y + Height / 2);

            Notify();
            //             Matrix matrix = new Matrix();
            //             matrix.Reset();
            //             matrix.RotateAt(0, centpt);
            //          _pathGradientBrushExample.Transform = matrix;
            Invalidate();
        }
    public void Transform_Operations ()
    {
        using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp))
        {
            Matrix clone = pgb.Transform.Clone ();
            Matrix mul = clone.Clone ();

            clone.Multiply (mul, MatrixOrder.Append);
            pgb.MultiplyTransform (mul, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Multiply/Append");

            clone.Multiply (mul, MatrixOrder.Prepend);
            pgb.MultiplyTransform (mul, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Multiply/Prepend");

            clone.Rotate (45, MatrixOrder.Append);
            pgb.RotateTransform (45, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Rotate/Append");

            clone.Rotate (45, MatrixOrder.Prepend);
            pgb.RotateTransform (45, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Rotate/Prepend");

            clone.Scale (0.25f, 2, MatrixOrder.Append);
            pgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Scale/Append");

            clone.Scale (0.25f, 2, MatrixOrder.Prepend);
            pgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Scale/Prepend");

            clone.Translate (10, 20, MatrixOrder.Append);
            pgb.TranslateTransform (10, 20, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Translate/Append");

            clone.Translate (30, 40, MatrixOrder.Prepend);
            pgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Translate/Prepend");

            clone.Reset ();
            pgb.ResetTransform ();
            Assert.AreEqual (pgb.Transform, clone, "Reset");
        }
    }
        public void Rectangle()
        {
            using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.TileFlipXY)) {
                CheckDefaultRectangle("Original", pgb.Rectangle);
                pgb.MultiplyTransform(new Matrix(2, 0, 0, 2, 2, 2));
                CheckDefaultRectangle("Multiply", pgb.Rectangle);
                pgb.ResetTransform();
                CheckDefaultRectangle("Reset", pgb.Rectangle);
                pgb.RotateTransform(90);
                CheckDefaultRectangle("Rotate", pgb.Rectangle);
                pgb.ScaleTransform(4, 0.25f);
                CheckDefaultRectangle("Scale", pgb.Rectangle);
                pgb.TranslateTransform(-10, -20);
                CheckDefaultRectangle("Translate", pgb.Rectangle);

                pgb.SetBlendTriangularShape(0.5f);
                CheckDefaultRectangle("SetBlendTriangularShape", pgb.Rectangle);
                pgb.SetSigmaBellShape(0.5f);
                CheckDefaultRectangle("SetSigmaBellShape", pgb.Rectangle);
            }
        }
예제 #5
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);
                        }
                    }
                }
            }
        }