Esempio n. 1
0
        public static void Draw(Graphics graphics)
        {
            var generator = graphics.Generator;
            var image     = TestIcons.TestImage(generator);
            // lines
            var whitePen = Pens.White(generator);

            graphics.DrawLine(whitePen, 1, 1, 99, 99);
            graphics.DrawLine(whitePen, 50, 1, 50, 99);
            graphics.DrawLine(whitePen, 1, 51, 99, 51);

            graphics.DrawRectangle(Pens.White(generator), 101, 1, 100, 100);
            graphics.DrawRectangle(Pens.White(generator), 101, 1, 10, 10);

            graphics.DrawEllipse(Pens.Green(generator), 101, 1, 100, 100);

            graphics.DrawPolygon(Pens.White(generator), new PointF(203, 1), new PointF(253, 51), new Point(203, 101), new PointF(203, 1), new PointF(253, 1), new PointF(253, 101), new PointF(203, 101));

            var rect = new RectangleF(255, 1, 100, 100);

            graphics.DrawArc(Pens.LightGreen(generator), rect, 180, 90);
            graphics.DrawArc(Pens.SkyBlue(generator), rect, 0, 90);
            rect.Inflate(-15, 0);
            graphics.DrawArc(Pens.FloralWhite(generator), rect, -45, 90);
            rect.Inflate(-5, -20);
            graphics.DrawArc(Pens.SlateGray(generator), rect, -45, 270);
            rect.Inflate(-10, -10);
            graphics.DrawArc(Pens.SteelBlue(generator), rect, 180 + 45, 270);

            graphics.DrawImage(image, 100, 1, 100, 100);

            graphics.DrawText(Fonts.Sans(12 * graphics.PointsPerPixel, generator: generator), Colors.White, 0, 104, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

            // filled
            graphics.FillRectangle(Brushes.White(generator), 101, 120, 100, 100);
            graphics.FillRectangle(Brushes.Gray(generator), 101, 120, 10, 10);

            graphics.FillEllipse(Brushes.Green(generator), 101, 120, 100, 100);

            graphics.FillPolygon(Brushes.White(generator), new PointF(202, 120), new PointF(252, 170), new Point(202, 220), new PointF(202, 120));

            rect = new RectangleF(255, 120, 100, 100);
            graphics.FillPie(Brushes.LightGreen(generator), rect, 180, 90);
            graphics.FillPie(Brushes.SkyBlue(generator), rect, 0, 90);
            rect.Inflate(-15, 0);
            graphics.FillPie(Brushes.FloralWhite(generator), rect, -45, 90);
            rect.Inflate(-5, -20);
            graphics.FillPie(Brushes.SlateGray(generator), rect, -45, 270);
            rect.Inflate(-10, -10);
            graphics.FillPie(Brushes.SteelBlue(generator), rect, 180 + 45, 270);


            graphics.DrawImage(image, 101, 120, 100, 100);
        }
Esempio n. 2
0
        Control AntialiasOff()
        {
            var control = new Drawable {
                Size = new Size(100, 100), BackgroundColor = Colors.Black
            };

            var path = CreatePath();

            control.Paint += (sender, e) => {
                e.Graphics.Antialias = false;
                e.Graphics.DrawPath(Pens.White(), path);
            };

            return(control);
        }
Esempio n. 3
0
        Control LargeCanvas()
        {
            var control = new Drawable
            {
                Size            = new Size(1000, 1000),
                BackgroundColor = Colors.Blue
            };
            var image = TestIcons.TestImage;

            control.Paint += delegate(object sender, PaintEventArgs pe)
            {
                pe.Graphics.FillRectangle(Brushes.Black(), new Rectangle(150, 150, 100, 100));
                var whitePen = Pens.White();
                var inc      = 400;
                for (int i = 0; i <= control.Size.Width / inc; i++)
                {
                    var pos = i * inc;
                    pe.Graphics.DrawLine(whitePen, new Point(pos, 0), new Point(pos + control.Size.Width, control.Size.Height));
                    pe.Graphics.DrawLine(whitePen, new Point(pos, 0), new Point(pos - control.Size.Width, control.Size.Height));
                }
                var lpos = 100;
                pe.Graphics.DrawLine(whitePen, new Point(0, lpos), new Point(control.Size.Width, lpos));
                pe.Graphics.DrawLine(whitePen, new Point(lpos, 0), new Point(lpos, control.Size.Height));
                pe.Graphics.DrawImage(image, 100, 10);
                pe.Graphics.DrawImage(image, 250, 10, 80, 20);
            };
            LogEvents(control);

            var layout = new PixelLayout();

            layout.Add(control, 25, 25);
            return(new Scrollable
            {
                Size = new Size(250, 250),
                Content = layout
            });
        }
Esempio n. 4
0
        void MatrixTests(Graphics g)
        {
            // test matrix RotateAt
            DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) => {
                var m = Matrix.Create(Generator);
                m.RotateAt(angle, center);
                g.MultiplyTransform(m);
            });

            // test matrix scale/translate/rotate
            DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) => {
                var m = Matrix.Create(Generator);
                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(Generator);
                m.RotateAt(angle, center);
                g.MultiplyTransform(m);
            });

            // test transformed text
            DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) => {
                var m = Matrix.Create(Generator);
                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, generator: Generator));
                g.DrawImage(image, imageScaleLocation);

                var m = Matrix.Create(Generator);
                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(Generator);
                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(Generator), 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2);

                g.RestoreTransform();
            }

            // test more drawing operations
            {
                g.SaveTransform();
                var m = Matrix.Create(Generator);
                m.Translate(480, 20);
                m.Scale(0.4f);
                m.Rotate(90);
                g.MultiplyTransform(m);
                PixelOffsetSection.Draw(g);
                g.RestoreTransform();
            }
        }
Esempio n. 5
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, Generator));
            var textSize = g.MeasureString(font, "Skewed Text");

            g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text");
            g.DrawLine(Pens.White(Generator), 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);
            PixelOffsetSection.Draw(g);
            g.RestoreTransform();
        }