MultiplyTransform() public méthode

public MultiplyTransform ( Matrix matrix ) : void
matrix Matrix
Résultat void
		public void Transform_Operations ()
		{
			LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
			Matrix clone = lgb.Transform.Clone ();
			Matrix mul = clone.Clone ();

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

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

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

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

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

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

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

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

			clone.Reset ();
			lgb.ResetTransform ();
			Assert.AreEqual (lgb.Transform, clone, "Reset");
		}
		public void Transform_Operations_OnScalableAngle ()
		{
			LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 360f, true);
			Matrix clone = lgb.Transform.Clone ();
			Matrix mul = clone.Clone ();
			Matrix m = new Matrix ();
			m.Scale (2, 1);
			m.Translate (rect.Width, rect.Height);
			m.Rotate (30f);

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

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

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

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

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

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

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

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

			clone.Reset ();
			lgb.ResetTransform ();
			Assert.AreEqual (lgb.Transform, clone, "Reset");
		}
		public void Rectangle ()
		{
			LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
			CheckDefaultRectangle ("Original", lgb.Rectangle);
			lgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2));
			CheckDefaultRectangle ("Multiply", lgb.Rectangle);
			lgb.ResetTransform ();
			CheckDefaultRectangle ("Reset", lgb.Rectangle);
			lgb.RotateTransform (90);
			CheckDefaultRectangle ("Rotate", lgb.Rectangle);
			lgb.ScaleTransform (4, 0.25f);
			CheckDefaultRectangle ("Scale", lgb.Rectangle);
			lgb.TranslateTransform (-10, -20);
			CheckDefaultRectangle ("Translate", lgb.Rectangle);

			lgb.SetBlendTriangularShape (0.5f);
			CheckDefaultRectangle ("SetBlendTriangularShape", lgb.Rectangle);
			lgb.SetSigmaBellShape (0.5f);
			CheckDefaultRectangle ("SetSigmaBellShape", lgb.Rectangle);
		}
Exemple #4
0
            public sd2.LinearGradientBrush GetBrush(RectangleF rect)
            {
                var start = StartPoint;
                var end   = EndPoint;

                if (wrapMode == GradientWrapMode.Pad)
                {
                    // winforms does not support pad, so extend to fill entire drawing region
                    if (transform != null)
                    {
                        start = transform.TransformPoint(start);
                        end   = transform.TransformPoint(end);
                    }
                    PointF min, max;
                    GradientHelper.GetLinearMinMax(start, end, rect, out min, out max, true);
                    var len = max.LengthTo(min);
                    // find start/end pos based on entire position
                    var startpos = min.LengthTo(start) / len;
                    var endpos   = min.LengthTo(end) / len;
                    if (brush == null || lastStartPos != startpos || lastEndPos > endpos)
                    {
                        lastStartPos = startpos;
                        lastEndPos   = endpos;
                        start        = min;
                        end          = max;
                        var diff = end - start;
                        // account for innacuracies in system.drawing when nearing horizontal or vertical
                        if (Math.Abs(diff.X) < 0.0001)
                        {
                            end.X = start.X;
                        }
                        if (Math.Abs(diff.Y) < 0.0001)
                        {
                            end.Y = start.Y;
                        }

                        brush                     = new sd2.LinearGradientBrush(start.ToSD(), end.ToSD(), StartColor, EndColor);
                        brush.WrapMode            = sd2.WrapMode.Tile;
                        brush.InterpolationColors = new sd2.ColorBlend
                        {
                            Colors = new[]
                            {
                                StartColor,
                                StartColor,
                                EndColor,
                                EndColor
                            },
                            Positions = new[]
                            {
                                0f,
                                startpos,
                                endpos,
                                1f,
                            }
                        };
                    }
                }
                else if (brush == null)
                {
                    brush          = new sd2.LinearGradientBrush(StartPoint.ToSD(), EndPoint.ToSD(), StartColor, EndColor);
                    brush.WrapMode = wrapMode.ToSD();
                    if (transform != null)
                    {
                        brush.MultiplyTransform(transform.ToSD());
                    }
                }
                return(brush);
            }
Exemple #5
0
		public static d.Brush ToGdiPlus(this LinearGradientBrush brush, Rect bounds) {
			var db = CheckDegenerate(brush);
			if (db != null) return db;
			var bt = new BrushTransform(brush, bounds);
			if (bt.DegenerateBrush != null) return bt.DegenerateBrush;

			var start = brush.StartPoint;
			var end = brush.EndPoint;
			if (brush.MappingMode == BrushMappingMode.RelativeToBoundingBox) {
				start = bt.ToAbsolute.Transform(start);
				end = bt.ToAbsolute.Transform(end);
			}

			var wm = brush.SpreadMethod.ToGdiPlus();
			if (wm == d2.WrapMode.Clamp) {
				wm = d2.WrapMode.TileFlipX;
				var delta = (bounds.BottomRight - bounds.TopLeft).Length 
					/ (bt.ToBrush.Transform(end) - bt.ToBrush.Transform(start)).Length;
				var diff = delta * (end - start);
				start -= diff; end += diff;
				brush = brush.Clone();
				var g = brush.GradientStops;
				g.Insert(0, new GradientStop(g[0].Color, -delta));
				g.Add(new GradientStop(g[g.Count - 1].Color, delta + 1));
			}

			var b = new d2.LinearGradientBrush(start.ToGdiPlus(), end.ToGdiPlus(), d.Color.Black, d.Color.White);
			b.InterpolationColors = ConvertGradient(brush);
			b.WrapMode = wm;
			b.MultiplyTransform(bt.ToBrush.ToGdiPlus(), d2.MatrixOrder.Append);
			return b;
		}
        void PaintView3(Graphics g)
        {
            // Create a LinearGradientBrush.
            Rectangle myRect = new Rectangle(20, 20, 200, 100);
            LinearGradientBrush myLGBrush = new LinearGradientBrush(
                myRect, Color.Blue, Color.Red,  0.0f, true);

            // Draw an ellipse to the screen using the LinearGradientBrush.
            g.FillEllipse(myLGBrush, myRect);

            // Transform the LinearGradientBrush.
            Point[] transformArray = { new Point(20, 150),
                new Point(400,150), new Point(20, 200) };

            Matrix myMatrix = new Matrix(myRect, transformArray);
            myLGBrush.MultiplyTransform(
                myMatrix,
                MatrixOrder.Prepend);

            RectangleF boundingRec = myLGBrush.Rectangle;
            var pennn = new Pen(Color.Green, 1);
            g.DrawRectangle(pennn, boundingRec.X, boundingRec.Y, boundingRec.Width, boundingRec.Height);
            // Draw a second ellipse to the screen using
            // the transformed brush.
            g.FillEllipse(myLGBrush, 20, 150, 380, 50);
        }
			public sd2.LinearGradientBrush GetBrush(RectangleF rect)
			{
				var start = StartPoint;
				var end = EndPoint;
				if (wrapMode == GradientWrapMode.Pad)
				{
					// winforms does not support pad, so extend to fill entire drawing region
					if (transform != null)
					{
						start = transform.TransformPoint(start);
						end = transform.TransformPoint(end);
					}
					PointF min, max;
					GradientHelper.GetLinearMinMax(start, end, rect, out min, out max, true);
					var len = max.LengthTo(min);
					// find start/end pos based on entire position
					var startpos = min.LengthTo(start) / len;
					var endpos = min.LengthTo(end) / len;
					if (brush == null || lastStartPos != startpos)
					{
						lastStartPos = startpos;
						start = min;
						end = max;
						var diff = end - start;
						// account for innacuracies in system.drawing when nearing horizontal or vertical
						if (Math.Abs(diff.X) < 0.0001)
							end.X = start.X;
						if (Math.Abs(diff.Y) < 0.0001)
							end.Y = start.Y;

						brush = new sd2.LinearGradientBrush(start.ToSD(), end.ToSD(), StartColor, EndColor);
						brush.WrapMode = sd2.WrapMode.Tile;
						brush.InterpolationColors = new sd2.ColorBlend
						{
							Colors = new[]
						{
							StartColor,
							StartColor,
							EndColor,
							EndColor
						},
							Positions = new[]
						{
							0f,
							startpos,
							endpos,
							1f,
						}
						};
					}
				}
				else if (brush == null)
				{
					brush = new sd2.LinearGradientBrush(StartPoint.ToSD(), EndPoint.ToSD(), StartColor, EndColor);
					brush.WrapMode = wrapMode.ToSD();
					if (transform != null)
						brush.MultiplyTransform(transform.ToSD());
				}
				return brush;
			}