public void MultiplyTransform2_Invalid () { using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) { pgb.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue); } }
public void MultiplyTransform2_Null () { using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) { pgb.MultiplyTransform (null, MatrixOrder.Append); } }
public void MultiplyTransform1_Null () { using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) { pgb.MultiplyTransform (null); } }
private static Brush NormalizeBrush(Brush brush, IRectangle layout) { if (brush is LinearGradientBrush) { LinearGradientBrush lgb = (LinearGradientBrush)brush.Clone(); lgb.MultiplyTransform( new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height), (float)layout.X, (float)layout.Y), MatrixOrder.Append); brush = lgb; } else if (brush is PathGradientBrush) { PathGradientBrush pgb = (PathGradientBrush)brush.Clone(); pgb.MultiplyTransform( new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height), (float)layout.X, (float)layout.Y), MatrixOrder.Append); brush = pgb; } else if (brush is TextureBrush) { TextureBrush tb = (TextureBrush)brush.Clone(); tb.MultiplyTransform( new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height), (float)layout.X, (float)layout.Y), MatrixOrder.Append); brush = tb; } return(brush); }
// Snippet for: M:System.Drawing.Drawing2D.PathGradientBrush.MultiplyTransform(System.Drawing.Drawing2D.Matrix,System.Drawing.Drawing2D.MatrixOrder) // <snippet1> public void MultiplyTransformExample(PaintEventArgs e) { // Create a graphics path and add an rectangle. GraphicsPath myPath = new GraphicsPath(); Rectangle rect = new Rectangle(20, 20, 100, 50); myPath.AddRectangle(rect); // Get the path's array of points. PointF[] myPathPointArray = myPath.PathPoints; // Create a path gradient brush. PathGradientBrush myPGBrush = new PathGradientBrush(myPathPointArray); // Set the color span. myPGBrush.CenterColor = Color.Red; Color[] mySurroundColor = { Color.Blue }; myPGBrush.SurroundColors = mySurroundColor; // Draw the brush to the screen prior to transformation. e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200); // Create a new matrix that rotates by 90 degrees, and // translates by 100 in each direction. Matrix myMatrix = new Matrix(0, 1, -1, 0, 100, 100); // Apply the transform to the brush. myPGBrush.MultiplyTransform(myMatrix, MatrixOrder.Append); // Draw the brush to the screen again after applying the // transform. e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300); }
public void MultiplyTransform_NonInvertible() { using (Matrix noninvertible = new Matrix(123, 24, 82, 16, 47, 30)) { using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) { Assert.Throws <ArgumentException> (() => pgb.MultiplyTransform(noninvertible)); } } }
public void MultiplyTransform_NonInvertible() { using (Matrix noninvertible = new Matrix(123, 24, 82, 16, 47, 30)) { using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) { pgb.MultiplyTransform(noninvertible); } } }
public void MultiplyTransform2_Null() { Assert.Throws <ArgumentNullException>(() => { using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) { pgb.MultiplyTransform(null, MatrixOrder.Append); } }); }
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); } }
private void PathGradientBrush_Click(object sender, System.EventArgs e) { Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); // Create a GraphicsPath object GraphicsPath path = new GraphicsPath(); // Create a rectangle and add it to path Rectangle rect = new Rectangle(20, 20, 200, 200); path.AddRectangle(rect); // Create a path gradient brush PathGradientBrush pgBrush = new PathGradientBrush(path.PathPoints); // Set its center and surrounding colors pgBrush.CenterColor = Color.Green; pgBrush.SurroundColors = new Color[] { Color.Blue }; // Create matrix Matrix M = new Matrix(); // Translate M.Translate(20.0f, 10.0f, MatrixOrder.Prepend); // Rotate M.Rotate(10.0f, MatrixOrder.Prepend); // Scale M.Scale(2, 1, MatrixOrder.Prepend); // shear M.Shear(.05f, 0.03f, MatrixOrder.Prepend); // Apply matrix to the brush pgBrush.MultiplyTransform(M); // Use brush after transformation // to fill a rectangle g.FillRectangle(pgBrush, 20, 100, 400, 400); // Dispose pgBrush.Dispose(); g.Dispose(); }
public void MultiplyTransform1_Null() { using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) { Assert.Throws <ArgumentNullException> (() => pgb.MultiplyTransform(null)); } }