TranslateTransform() публичный Метод

public TranslateTransform ( float dx, float dy ) : void
dx float
dy float
Результат void
Пример #1
0
		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");
		}
Пример #2
0
        void PaintView2(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);

            // Rotate the LinearGradientBrush.
            myLGBrush.RotateTransform(45.0f, MatrixOrder.Prepend);

            // Rejustify the brush to start at the left edge of the ellipse.
            myLGBrush.TranslateTransform(-100.0f, 0.0f);

            // Draw a second ellipse to the screen using
            // the transformed brush.
            g.FillEllipse(myLGBrush, 20, 150, 200, 100);

            title = "PaintView2";
        }
Пример #3
0
		public void TranslateTransform_InvalidOrder ()
		{
			LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
			lgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
		}
Пример #4
0
		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");
		}
Пример #5
0
		public void TranslateTransform ()
		{
			LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
			lgb.TranslateTransform (1, 1);
			float[] elements = lgb.Transform.Elements;
			Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
			Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
			Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
			Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
			Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
			Assert.AreEqual (1, elements[5], 0.1, "matrix.5");

			lgb.TranslateTransform (-1, -1);
			// strangely lgb.Transform.IsIdentity is false
			elements = lgb.Transform.Elements;
			Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
			Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
			Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
			Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
			Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
			Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
		}
Пример #6
0
		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);
		}
Пример #7
0
        public static Bitmap DrawShadowBitmap(int width, int height, int borderRadius, int blur, int spread, Color color)
        {
            int ex = blur + spread;
            int w = width + ex * 2;
            int h = height + ex * 2;
            int solidW = width + spread * 2;
            int solidH = height + spread * 2;

            var bitmap = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(bitmap);
            // fill background
            g.FillRectangle(new SolidBrush(color)
                , blur, blur, width + spread * 2 + 1, height + spread * 2 + 1);
            // +1 to fill the gap

            if (blur > 0)
            {
                // four dir gradiant
                {
                    // left
                    var brush = new LinearGradientBrush(new Point(0, 0), new Point(blur, 0), Color.Transparent, color);
                    // will thorw ArgumentException
                    // brush.WrapMode = WrapMode.Clamp;

                    g.FillRectangle(brush, 0, blur, blur, solidH);
                    // up
                    brush.RotateTransform(90);
                    g.FillRectangle(brush, blur, 0, solidW, blur);

                    // right
                    // make sure parttern is currect
                    brush.ResetTransform();
                    brush.TranslateTransform(w % blur, h % blur);

                    brush.RotateTransform(180);
                    g.FillRectangle(brush, w - blur, blur, blur, solidH);
                    // down
                    brush.RotateTransform(90);
                    g.FillRectangle(brush, blur, h - blur, solidW, blur);
                }

                // four corner
                {
                    var gp = new GraphicsPath();
                    //gp.AddPie(0,0,blur*2,blur*2, 180, 90);
                    gp.AddEllipse(0, 0, blur * 2, blur * 2);

                    var pgb = new PathGradientBrush(gp);
                    pgb.CenterColor = color;
                    pgb.SurroundColors = new[] { Color.Transparent };
                    pgb.CenterPoint = new Point(blur, blur);

                    // lt
                    g.FillPie(pgb, 0, 0, blur * 2, blur * 2, 180, 90);
                    // rt
                    var matrix = new Matrix();
                    matrix.Translate(w - blur * 2, 0);

                    pgb.Transform = matrix;
                    //pgb.Transform.Translate(w-blur*2, 0);
                    g.FillPie(pgb, w - blur * 2, 0, blur * 2, blur * 2, 270, 90);
                    // rb
                    matrix.Translate(0, h - blur * 2);
                    pgb.Transform = matrix;
                    g.FillPie(pgb, w - blur * 2, h - blur * 2, blur * 2, blur * 2, 0, 90);
                    // lb
                    matrix.Reset();
                    matrix.Translate(0, h - blur * 2);
                    pgb.Transform = matrix;
                    g.FillPie(pgb, 0, h - blur * 2, blur * 2, blur * 2, 90, 90);
                }
            }

            //
            return bitmap;
        }
       // renders the overall gradient
       private void RenderBackgroundGradient(Graphics g, Control control, Color beginColor, Color endColor, Orientation orientation) {
       
          if (control.RightToLeft == RightToLeft.Yes) {
              Color temp = beginColor;
              beginColor = endColor;
              endColor = temp;
          }
 
          if (orientation == Orientation.Horizontal) {
              Control parent = control.ParentInternal;
              if (parent != null) {
                  Rectangle gradientBounds = new Rectangle(Point.Empty, parent.Size);
                  if (!LayoutUtils.IsZeroWidthOrHeight(gradientBounds)) {
                      using (LinearGradientBrush b = new LinearGradientBrush(gradientBounds, beginColor, endColor, LinearGradientMode.Horizontal)){
                          b.TranslateTransform(parent.Width - control.Location.X, parent.Height -control.Location.Y);
                          g.FillRectangle(b, new Rectangle(Point.Empty, control.Size));
                      }
                  }
              }
              else {
                  Rectangle gradientBounds = new Rectangle(Point.Empty, control.Size);
                  if (!LayoutUtils.IsZeroWidthOrHeight(gradientBounds)) {
                      // dont have a parent that we know about so go ahead and paint the gradient as if there wasnt another container.
                      using (LinearGradientBrush b = new LinearGradientBrush(gradientBounds, beginColor, endColor, LinearGradientMode.Horizontal)){
                          g.FillRectangle(b, gradientBounds);
                      }
                  }
              }
          }
          else {
              using (Brush b = new SolidBrush(beginColor)) {
                  g.FillRectangle(b, new Rectangle(Point.Empty, control.Size));
              }
          }
      }
Пример #9
0
 private void RenderBackgroundGradient( Graphics g, Control control, Color beginColor, Color endColor, Orientation orientation )
 {
     if ( control.RightToLeft == RightToLeft.Yes ) {
         Color color = beginColor;
         beginColor = endColor;
         endColor = color;
     }
     if ( orientation == Orientation.Horizontal ) {
         Control parent = control.Parent;
         if ( parent != null ) {
             Rectangle rectangle = new Rectangle ( Point.Empty, parent.Size );
             if ( rectangle.IsEmpty ) {
                 return;
             }
             using ( LinearGradientBrush brush = new LinearGradientBrush ( rectangle, beginColor, endColor, LinearGradientMode.Horizontal ) ) {
                 brush.TranslateTransform ( (float)( parent.Width - control.Location.X ), (float)( parent.Height - control.Location.Y ) );
                 g.FillRectangle ( brush, new Rectangle ( Point.Empty, control.Size ) );
                 return;
             }
         }
         Rectangle rectangle2 = new Rectangle ( Point.Empty, control.Size );
         if ( rectangle2.IsEmpty ) {
             return;
         }
         using ( LinearGradientBrush brush2 = new LinearGradientBrush ( rectangle2, beginColor, endColor, LinearGradientMode.Horizontal ) ) {
             g.FillRectangle ( brush2, rectangle2 );
             return;
         }
     }
     using ( Brush brush3 = new SolidBrush ( beginColor ) ) {
         g.FillRectangle ( brush3, new Rectangle ( Point.Empty, control.Size ) );
     }
 }