Beispiel #1
0
        void MatrixTests(Graphics g)
        {
            // test matrix RotateAt
            DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) =>
            {
                var m = Matrix.Create();
                m.RotateAt(angle, center);
                g.MultiplyTransform(m);
            });

            // test matrix scale/translate/rotate
            DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) =>
            {
                var m = Matrix.Create();
                m.Translate(center);
                m.Rotate(angle);
                m.Translate(-center);
                m.Scale(.4f);
                g.MultiplyTransform(m);
            });

            // test rotating arcs
            DrawRotatedArcs(g, Colors.LightBlue, rotatedLineCenter, (center, angle) =>
            {
                var m = Matrix.Create();
                m.RotateAt(angle, center);
                g.MultiplyTransform(m);
            });

            // test transformed text
            DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) =>
            {
                var m = Matrix.Create();
                m.RotateAt(angle, center - 40);
                g.MultiplyTransform(m);
            });

            // test image drawing
            {
                g.SaveTransform();
                g.MultiplyTransform(Matrix.FromScaleAt(new SizeF(1, -1), imageScaleLocation + image.Size / 2));
                g.DrawImage(image, imageScaleLocation);

                var m = Matrix.Create();
                m.Translate(0, -50);
                m.ScaleAt(0.3f, imageScaleLocation + image.Size / 2);
                g.MultiplyTransform(m);
                g.DrawImage(image, imageScaleLocation);
                g.RestoreTransform();
            }

            // test skewing
            {
                g.SaveTransform();
                var m = Matrix.Create();
                m.Skew(20, 20);
                g.MultiplyTransform(m);
                var textSize = g.MeasureString(font, "Skewed Text");
                g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text");
                g.DrawLine(Pens.White, 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2);

                g.RestoreTransform();
            }

            // test more drawing operations
            {
                g.SaveTransform();
                var m = Matrix.Create();
                m.Translate(480, 20);
                m.Scale(0.4f);
                m.Rotate(90);
                g.MultiplyTransform(m);
                PixelOffsetModeSection.Draw(g);
                g.RestoreTransform();
            }
        }
Beispiel #2
0
        void DirectTests(Graphics g)
        {
            // test translate/rotate
            DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) =>
            {
                g.TranslateTransform(center);
                g.RotateTransform(angle);
                g.TranslateTransform(-center);
            });

            // test translate/rotate/scale
            DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) =>
            {
                g.TranslateTransform(center);
                g.RotateTransform(angle);
                g.TranslateTransform(-center);
                g.ScaleTransform(.4f);
            });

            // test rotating arcs
            DrawRotatedArcs(g, Colors.LightBlue, rotatedLineCenter, (center, angle) =>
            {
                g.TranslateTransform(center);
                g.RotateTransform(angle);
                g.TranslateTransform(-center);
            });

            // test transformed text
            DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) =>
            {
                g.TranslateTransform(center - 40);
                g.RotateTransform(angle);
                g.TranslateTransform(-center + 40);
            });

            // Test image drawing
            g.SaveTransform();
            g.TranslateTransform(imageScaleLocation + image.Size / 2);
            g.ScaleTransform(1, -1);
            g.TranslateTransform(-imageScaleLocation - image.Size / 2);
            g.DrawImage(image, imageScaleLocation);

            g.TranslateTransform(0, -50);
            g.TranslateTransform(imageScaleLocation + image.Size / 2);
            g.ScaleTransform(0.3f);
            g.TranslateTransform(-imageScaleLocation - image.Size / 2);
            g.DrawImage(image, imageScaleLocation);
            g.RestoreTransform();

            // test skewing
            g.SaveTransform();
            g.MultiplyTransform(Matrix.FromSkew(20, 20));
            var textSize = g.MeasureString(font, "Skewed Text");

            g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text");
            g.DrawLine(Pens.White, 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2);

            g.RestoreTransform();

            // test more drawing operations
            g.SaveTransform();
            g.TranslateTransform(480, 20);
            g.ScaleTransform(0.4f);
            g.RotateTransform(90);
            PixelOffsetModeSection.Draw(g);
            g.RestoreTransform();
        }