Example #1
0
        private static void RenderTransforms(IGraphics ig)
        {
            ig.Clear(Color.Black);

            ig.RotateTransform(15);
            ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40);
            ig.ResetTransform();
            ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40);

            ig.TranslateTransform(15, -5);

            GraphicsContainer cnt = ig.BeginContainer();

            ig.SmoothingMode = SmoothingMode.HighQuality;

            ig.RotateTransform(5);
            ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40);
            ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40);

            GraphicsContainer cnt2 = ig.BeginContainer();

            ig.SmoothingMode = SmoothingMode.None;

            ig.RotateTransform(5);
            ig.ScaleTransform(1.1f, 1.5f);
            ig.TranslateTransform(5, 5);

            ig.DrawLines(new Pen(Color.Cyan, 2), new PointF[] { new PointF(0, 0), new PointF(50, 50), new PointF(0, 100) });

            ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40);
            ig.DrawRectangle(new Pen(Color.YellowGreen, 2.7f), 62, 80, 40, 40);

            GraphicsContainer cnt3 = ig.BeginContainer();

            ig.SmoothingMode = SmoothingMode.HighQuality;

            var mm = new Matrix();

            mm.Shear(0.3f, 0f);
            ig.Transform = mm;

            ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40);
            ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40);

            ig.EndContainer(cnt3);

            ig.EndContainer(cnt2);

            ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40);
            ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40);

            ig.EndContainer(cnt);

            ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40);
            ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40);

            ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
            ig.ResetTransform();
            ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
        }
Example #2
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(IGraphics g, Map map)
        {
            if (BaseLayer != null)
            {
                BaseLayer.Render(g, map);
            }

            var fds = new FeatureCollectionSet();
            var box = map.Envelope;

            ExecuteIntersectionQuery(box, fds);

            if (fds.Count == 0 || fds[0].Count == 0)
            {
                base.Render(g, map);
                return;
            }

            var zoomIndex = GetZoomIndex(map.Zoom);
            var dot       = _bitmaps[zoomIndex];
            var opacity   = _opacity[zoomIndex];

            using (var image = new Bitmap(map.Size.Width + dot.Width, map.Size.Height + dot.Height, PixelFormat.Format32bppArgb))
            {
                using (IGraphics gr = Graphics.FromImage(image).G())
                    gr.Clear(Color.White);

                DrawPoints(map, fds[0], dot, image);
                Colorize(image, HeatColorBlend, opacity);

                g.DrawImage(image, -dot.Width / 2, -dot.Height / 2);
            }
        }
Example #3
0
 public override void Draw(IGraphics g)
 {
     // draw the zone
     g.Clear(DangerColor);
     // add the safe zone (must be relative to Diameter - as it shifts)
     g.Ellipse(GroundColor, X - (Diameter / 2), Y - (Diameter / 2), Diameter, Diameter, true);
 }
Example #4
0
        /// <summary>
        /// Method to generate the base markers for different zoom levels
        /// </summary>
        /// <returns>An array of bitmaps</returns>
        private static Bitmap[] GenerateDots()
        {
            var res  = new Bitmap[32];
            var size = 6;

            for (var i = 0; i < 32; i++)
            {
                var bmp = new Bitmap(size, size, PixelFormat.Format24bppRgb);
                using (IGraphics g = Graphics.FromImage(bmp).G())
                {
                    g.Clear(Color.White);
                    using (var path = new GraphicsPath())
                    {
                        path.AddEllipse(0, 0, size - 1, size - 1);
                        var brush = new PathGradientBrush(path)
                        {
                            CenterColor    = Color.Gray,
                            SurroundColors = new[] { Color.White },
                        };
                        g.FillEllipse(brush, 0, 0, size - 1, size - 1);
                    }
                }
                res[i] = bmp;
                //bmp.Save("dot" + i + ".png");
                size += 3;
            }
            return(res);
        }
Example #5
0
        static NorthArrow()
        {
            lock (_lockObject)
            {
                DefaultNorthArrowBitmap = new Bitmap(120, 120);
                using (IGraphics g = Graphics.FromImage(DefaultNorthArrowBitmap).G())
                {
                    g.Clear(Color.Transparent);
                    var b = new SolidBrush(Color.Black);
                    var p = new Pen(new SolidBrush(Color.Black), 10)
                    {
                        LineJoin = LineJoin.Miter
                    };
                    g.FillEllipse(b, 50, 50, 20, 20);
                    g.DrawLines(p, new[] { new PointF(60, 110), new PointF(60, 40) });
                    var pts = new[] { new PointF(45, 40), new PointF(60, 10), new PointF(75, 40), new PointF(45, 40) };
                    g.FillPolygon(b, pts);
                    g.DrawPolygon(p, pts);

                    b = new SolidBrush(Color.White);
                    var          font = new Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel);
                    StringFormat sf   = new StringFormat {
                        LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center
                    };
                    g.DrawString("N", font, b, new RectangleF(50, 25, 20, 20), sf);
                }
            }
        }
Example #6
0
        private void RenderToImage(int layerIndex, ParallelLoopState pls)
        {
            if (pls.ShouldExitCurrentIteration)
            {
                return;
            }

            var layer = _layers[layerIndex];

            if (layer.Enabled)
            {
                if (layer.MaxVisible >= _map.Zoom && layer.MinVisible < _map.Zoom)
                {
                    var image = _images[layerIndex] = new Bitmap(_map.Size.Width, _map.Size.Height, PixelFormat.Format32bppArgb);
                    using (IGraphics g = Graphics.FromImage(image).G())
                    {
                        g.PageUnit = GraphicsUnitType.Pixel;
                        ApplyTransform(_transform, g);

                        g.Clear(Color.Transparent);
                        layer.Render(g, _map);
                    }
                }
            }
        }
Example #7
0
        private static void RenderClipping(IGraphics ig)
        {
            var pn  = new Pen(Color.LightGray, 5.6f);
            var pn2 = new Pen(Color.Yellow, 1.2f);

            ig.Clear(Color.Black);

            GraphicsContainer cnt = ig.BeginContainer();

            ig.SmoothingMode = SmoothingMode.HighQuality;

            ig.SetClip(new Rectangle(35, 35, 120, 120));

            ig.DrawRectangle(pn, 5, 5, 45, 70);
            ig.DrawRectangle(pn, 15, 25, 90, 120);
            ig.DrawRectangle(pn, 50, 30, 100, 170);
            ig.DrawRectangle(pn, 5, 80, 180, 30);
            ig.DrawRectangle(pn, 75, 10, 40, 160);

            ig.EndContainer(cnt);

            ig.DrawRectangle(pn2, 5, 5, 45, 70);
            ig.DrawRectangle(pn2, 15, 25, 90, 120);
            ig.DrawRectangle(pn2, 50, 30, 100, 170);
            ig.DrawRectangle(pn2, 5, 80, 180, 30);
            ig.DrawRectangle(pn2, 75, 10, 40, 160);
        }
Example #8
0
 public override void Draw(IGraphics g)
 {
     //base.Draw(g);
     // draw the zone
     g.Clear(DangerColor);
     // add the safe zone
     g.Ellipse(GroundColor, X - (Diameter / 2), Y - (Diameter / 2), Diameter, Diameter, true);
 }
Example #9
0
        private void Render()
        {
            _graphics.Clear();

            var viewport = _cameraHandler.GetViewport();

            _mapHandler.Render(viewport, _graphics);
            _unitHandler.Render(viewport, _graphics);

            _graphics.Render();
        }
Example #10
0
            private static Image ColoredArrow(Brush c)
            {
                Bitmap bmp = new Bitmap(13, 36);

                using (IGraphics g = Graphics.FromImage(bmp).G())
                {
                    g.Clear(Color.Wheat);
                    g.FillPolygon(c, ArrowPoints);
                    g.DrawPolygon(Pens.Black, ArrowPoints);
                }

                bmp.MakeTransparent(Color.Wheat);
                return(bmp);
            }
Example #11
0
 protected virtual void Render(IGraphics g)
 {
     // Start the drawing process
     g.BeginDraw();
     // Clear buffer to background color
     g.Clear(BackColor);
     // Render Scene Objects
     _sm.Render(g);
     // Call Render Metrics
     RenderMetrics(g);
     // Done drawing so tell graphics engine we are done
     g.EndDraw();
     // Invalide form so it will redraw
     Invalidate();
 }
Example #12
0
        private void WriteProbabilityImage(IGraphics gfx)
        {
            var proba2Da = ProbabilityMatrix;
            var bsize = _charMap.Count * 24 + 24;

            var font = new Font("Consolas", 20, FontStyle.Regular, GraphicsUnit.Pixel);
            var cm2 = _charMap.ToList();
            cm2.Sort();
            var format = new StringFormat { Alignment = StringAlignment.Center };

            gfx.CompositingQuality = CompositingQuality.HighQuality;
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
            gfx.SmoothingMode = SmoothingMode.HighQuality;
            gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            gfx.Clear(Color.White);
            var ver = Assembly.GetEntryAssembly()?.GetName().Version ?? new Version(0, 0);
            gfx.DrawString($"twm {ver.Major}.{ver.Minor}", font, Brushes.Black, new RectangleF(0, 0, bsize, 24),
                format);
            gfx.DrawString("P", font, Brushes.Black, new RectangleF(0, 24, 24, 24), format);
            gfx.DrawString("=", font, Brushes.Black, new RectangleF(24, 24, 24, 24), format);
            gfx.DrawString("0", font, Brushes.Black, new RectangleF(48, 24, 24, 24), format);
            gfx.FillRectangle(Brushes.Black, 72, 24, 24, 24);
            for (var i = 0; i < bsize - 120; i++)
                gfx.FillRectangle(new SolidBrush(Utils.HsvToRgb((1 - i / (double)(bsize - 120)) * 240, 1, 1)), 96 + i,
                    24, 1, 24);

            gfx.DrawString("1", font, Brushes.Black, new RectangleF(bsize - 24, 24, 24, 24), format);
            for (var i = 0; i < _charMap.Count; i++)
            {
                gfx.DrawString((i == 0 ? '␂' : _charMap[i]).ToString(), font, new SolidBrush(Color.Black),
                    new RectangleF(0, 24 * (3 + cm2.IndexOf(_charMap[i])), 24, 24), format);
                gfx.DrawString((i == 0 ? '␃' : _charMap[i]).ToString(), font, new SolidBrush(Color.Black),
                    new RectangleF(24 * (1 + cm2.IndexOf(_charMap[i])), 48, 24, 24), format);

                for (var j = 0; j < _charMap.Count; j++)
                {
                    var prob = proba2Da[i][j];
                    var color = Color.Black;
                    // probability is explicitely set to zero iff it never happens
                    // ReSharper disable once CompareOfFloatsByEqualityOperator
                    if (prob != 0) color = Utils.HsvToRgb((1 - prob) * 240, 1, 1);
                    gfx.FillRectangle(new SolidBrush(color), 24 * (1 + cm2.IndexOf(_charMap[j])),
                        24 * (3 + cm2.IndexOf(_charMap[i])), 24, 24);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Utility function to transform any <see cref="IPointSymbolizer"/> into an unscaled <see cref="RasterPointSymbolizer"/>. This may bring performance benefits.
        /// </summary>
        /// <returns></returns>
        public virtual IPointSymbolizer ToRasterPointSymbolizer()
        {
            var bitmap = new Bitmap(Size.Width, Size.Height);

            using (IGraphics g = Graphics.FromImage(bitmap).G())
            {
                g.Clear(Color.Transparent);
                OnRenderInternal(new PointF(Size.Width * 0.5f, Size.Height * 0.5f), g);
            }

            return(new RasterPointSymbolizer
            {
                Offset = Offset,
                Rotation = Rotation,
                Scale = Scale,
                //ImageAttributes = new ImageAttributes(),
                Symbol = bitmap
            });
        }
Example #14
0
        /// <summary>
        /// Generates a random symbol.
        /// </summary>
        /// <returns></returns>
        public static Bitmap GetRandomSymbol()
        {
            int    s   = Rnd.Next(4, 12);
            Font   f   = new Font("WingDings", 2 * s, GraphicsUnit.Pixel);
            Bitmap bmp = new Bitmap(2 * s + 2, 2 * s + 2, PixelFormat.Format32bppArgb);

            using (IGraphics g = Graphics.FromImage(bmp).G())
            {
                g.Clear(Color.Transparent);
                string       text  = new string(Convert.ToChar((byte)Rnd.Next(15, 127)), 1);
                Brush        brush = GetRandomBrush();
                StringFormat sf    = new StringFormat {
                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                };
                g.DrawString(text, f, brush, s, s, sf);
            }

            return(bmp);
        }
Example #15
0
 private void Clear()
 {
     _graphics.Clear();
 }
Example #16
0
 public static void RenderRectAlignedText(IGraphics ig, float width, float height, Font baseFont)
 {
     ig.Clear(Color.White);
     ig.ScaleTransform(width / CanvasSize, height / CanvasSize);
     DrawTest(ig, baseFont);
 }
Example #17
0
        /// <summary>
        /// Draws the sprites
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="renderer">Graphics</param>
        public void Draw(GameTime gameTime, IGraphics renderer)
        {
            // Draw the walls to the map buffer
            this.mapGraphics.DrawImage(this.mapImage, 0, 0, this.mapImage.Width, this.mapImage.Height);

            // Draw all objects to the map buffer
            foreach (Sprite sprite in this.allObjects)
            {
                sprite.Draw(this.mapGraphics, gameTime);
            }

            // Clear the screen background (because it is larger than the map)
            renderer.Clear(Color.Black);

            // Draw the map to the screen buffer
            renderer.DrawImage(this.mapBuffer, MapXoffset, MapYoffset, this.mapBuffer.Width, this.mapBuffer.Height);

            // Draw the text messages to the screen buffer
            this.DrawMessages(gameTime, renderer);
        }
Example #18
0
        // paint callbacks
        private void Paint(IGraphics graphics)
        {
            // pre-load images
            if (Preloading)
            {
                if (AllResources == null)
                {
                    // clear
                    graphics.Clear(RGBA.White);

                    // get all the image resources
                    AllResources         = Cat.GetImagesFromResources();
                    CurrentResourceIndex = 0;
                    PreloadItemCount     = Platform.IsType(PlatformType.Blazor) ? (AllResources.Count() / 2) - 1 : AllResources.Count() - 1;
                }

                if (CurrentResourceIndex < AllResources.Count())
                {
                    // load one image from a resource at a time
                    var kvp  = AllResources.ElementAt(CurrentResourceIndex++);
                    var name = kvp.Key;
                    if (Platform.IsType(PlatformType.Blazor))
                    {
                        if (!name.StartsWith("t_", StringComparison.OrdinalIgnoreCase))
                        {
                            return;
                        }
                        // remove the 't_'
                        name = name.Substring(2);
                    }
                    var img = new ImageSource(name, kvp.Value);
                    // load image
                    graphics.Image(img.Image, x: 0, y: 0, width: 1, height: 1);
                }

                // display the loading bar
                if (PreloadCurrent > 0)
                {
                    graphics.Rectangle(new RGBA()
                    {
                        B = 255, A = 255
                    }, x: 0, y: 100, width: (300 * ((float)PreloadCurrent / (float)PreloadItemCount)), 50, fill: true, border: false);
                }
                graphics.Rectangle(RGBA.Black, 0, 100, 300, 50, fill: false, border: true);

                PreloadCurrent++;

                // exit condition
                if (CurrentResourceIndex >= AllResources.Count())
                {
                    Preloading   = false;
                    AllResources = null;
                }

                return;
            }

            // clear
            graphics.Clear(RGBA.White);

            // paint the board
            try
            {
                LibraryLock.EnterReadLock();

                // draw the title (relative to the typing text)
                var titleX = TextXStart;
                var titleY = TextYStart;
                graphics.Rectangle(new RGBA()
                {
                    R = 200, G = 200, B = 200, A = 255
                }, titleX, titleY, width: Board.Width - (TextXStart * 2) - 20f, height: 90, fill: true, border: false);
                graphics.Text(RGBA.Black, titleX, titleY + (TextSpacing * 0f), string.Format($"{CurrentBook.Title} by {CurrentBook.Author}"), TitleFontSize, TitleFontName);
                graphics.Text(RGBA.Black, titleX, titleY + (TextSpacing * 1.2f), CurrentPoem.Section, TitleFontSize, TitleFontName);
                graphics.Text(RGBA.Black, titleX, titleY + (TextSpacing * 2.4f), CurrentPoem.Title, TitleFontSize, TitleFontName);

                // draw the stats (based on the window height
                var statsX = TextXStart;
                var statsY = Board.Height - 150f;
                graphics.Rectangle(RGBA.Black, statsX, statsY, width: Board.Width - (TextXStart * 2) - 20f, height: 100, fill: true, border: true, thickness: 1f);
                graphics.Text(RGBA.White, statsX + 10f, statsY + (TextSpacing * 0.35f), string.Format($"Round {Stats.Round}"), TitleFontSize, TitleFontName);
                graphics.Text(RGBA.White, statsX + 10f, statsY + (TextSpacing * 2f), string.Format($"Words per minute {Stats.WordsPerMinute:f2} :: Wins {Stats.Wins} :: Losses {Stats.Losses}"), FontSize, FontName);
                graphics.Text(RGBA.White, statsX + 10f, statsY + (TextSpacing * 3f), string.Format($"Correct characters {Stats.CorrectCharacters} :: Wrong characters {Stats.WrongCharacters}"), FontSize, FontName);

                // add the cursor
                if (CurrentLine < Lines.Length)
                {
                    var cursor = "_";
                    var x      = TextXStart + (Lines[CurrentLine].Input.Length * FontWidth);
                    graphics.Text(new RGBA()
                    {
                        R = 255, A = 255
                    }, x, TextYStart + (TextSpacing * (CurrentLine + 5)), cursor, FontSize, FontName);
                }

                // draw all the strings on the board
                for (int i = 0; i < Lines.Length; i++)
                {
                    graphics.Text(RGBA.Black, TextXStart, TextYStart + (TextSpacing * (i + 5)), Lines[i].Text, FontSize, FontName);
                    if (Lines[i].Input.Length > 0)
                    {
                        graphics.Text(RGBA.White, TextXStart, TextYStart + (TextSpacing * (i + 5)), Lines[i].Input.ToString(), FontSize, FontName);
                    }
                }
            }
            finally
            {
                LibraryLock.ExitReadLock();
            }

            // draw the cat
            if (Stats.IsRunning)
            {
                Cat.Draw(graphics);
            }

            // draw any ephemerial elements
            lock (Ephemerials)
            {
                Ephemerial active = null;
                if (Ephemerials.Count > 0)
                {
                    active = Ephemerials[0];
                    active.Duration--;
                    // check if it should be removed
                    if (active.Duration <= 0)
                    {
                        Ephemerials.RemoveAt(0);
                        if (active is NextRoundEphemerial)
                        {
                            ReadyToStartNextRound = true;
                        }
                    }
                }
                else
                {
                    // show a message to start typing
                    if (!IsDone && !Stats.IsRunning)
                    {
                        active = TypeToStart;
                    }
                }

                if (active != null)
                {
                    graphics.Text(active.Color, x: Board.Width - 400, y: Board.Height - 200, active.Text, fontsize: 12f);
                    if (active is NextRoundEphemerial)
                    {
                        graphics.Text(RGBA.Black, x: Board.Width - 400, y: Board.Height - 200 + TextSpacing, string.Format($"Next round starts in {(active.Duration / 10) + 1}"), fontsize: 12f);
                    }
                }
            }
        }
Example #19
0
        private void Render(IGraphics ig)
        {
            string s = cbWhat.Text;

            if (s == "Clipping")
            {
                Pen pn = new Pen(Color.LightGray, 5);
                Pen pn2 = new Pen(Color.Yellow);

                ig.Clear(Color.Black);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.SetClip(new Rectangle(35,35,120,120));

                ig.DrawRectangle(pn, 5,5,45,70);
                ig.DrawRectangle(pn, 15,25,90,120);
                ig.DrawRectangle(pn, 50,30,100,170);
                ig.DrawRectangle(pn, 5,80,180,30);
                ig.DrawRectangle(pn, 75,10,40,160);

                ig.EndContainer(cnt);

                ig.DrawRectangle(pn2, 5,5,45,70);
                ig.DrawRectangle(pn2, 15,25,90,120);
                ig.DrawRectangle(pn2, 50,30,100,170);
                ig.DrawRectangle(pn2, 5,80,180,30);
                ig.DrawRectangle(pn2, 75,10,40,160);
            }
            else if (s == "Transforms")
            {

                ig.Clear(Color.Black);

                ig.RotateTransform(15);
                ig.DrawRectangle(new Pen(Color.Red,2), 260,80,50,40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.Red,2), 260,80,50,40);

                ig.TranslateTransform(15,-5);

                GraphicsContainer cnt = ig.BeginContainer();

                    ig.SmoothingMode = SmoothingMode.HighQuality;

                    ig.RotateTransform(5);
                    ig.FillEllipse(new SolidBrush(Color.Orange), 100,100,80,40);
                    ig.DrawRectangle(new Pen(Color.Orange,2), 60,80,40,40);

                    GraphicsContainer cnt2  = ig.BeginContainer();

                        ig.SmoothingMode = SmoothingMode.None;

                        ig.RotateTransform(5);
                        ig.ScaleTransform(1.1f, 1.2f);

                        ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130,180,80,40);
                        ig.DrawRectangle(new Pen(Color.YellowGreen,2), 62,80,40,40);

                        GraphicsContainer cnt3  = ig.BeginContainer();

                            ig.SmoothingMode = SmoothingMode.HighQuality;

                            Matrix mm = new Matrix();
                            mm.Shear(0.3f, 0f);
                            ig.Transform = mm;

                            ig.FillEllipse(new SolidBrush(Color.Green), 180,120,80,40);
                            ig.DrawRectangle(new Pen(Color.Green,2), 62,84,40,40);

                        ig.EndContainer(cnt3);

                    ig.EndContainer(cnt2);

                    ig.FillEllipse(new SolidBrush(Color.Blue), 120,150,80,40);
                    ig.DrawRectangle(new Pen(Color.Blue,2), 64,80,40,40);

                ig.EndContainer(cnt);

                ig.FillEllipse(new SolidBrush(Color.Indigo), 80,210,80,40);
                ig.DrawRectangle(new Pen(Color.Indigo,2), 66,80,40,40);

                ig.DrawRectangle(new Pen(Color.White,2), 270,30,50,40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.White,2), 270,30,50,40);

            }
            else if (s == "Lines")
            {
                ig.SmoothingMode = SmoothingMode.AntiAlias;

                Pen ow = new Pen(Color.Purple, 12);
                ow.EndCap = LineCap.Round;
                ow.StartCap = LineCap.Round;
                ow.MiterLimit = 6f;
                ow.LineJoin = LineJoin.Miter;

                ig.SmoothingMode = SmoothingMode.None;

                Pen tp = new Pen(Color.Red, 2);
                tp.DashStyle = DashStyle.DashDot;

                ig.DrawLine(tp, 70,20,190,20);

                tp.DashStyle = DashStyle.Dash;

                ig.DrawLine(tp, 70,30,190,30);

                tp.DashStyle = DashStyle.Custom;
                tp.DashPattern = new float[] {1,8,2,2};

                ig.DrawLine(tp, 70,40,190,40);

                ig.SmoothingMode = SmoothingMode.AntiAlias;

                PointF[] pts = new PointF[4];
                pts[0] = new PointF(20,50);
                pts[1] = new PointF(30,90);
                pts[2] = new PointF(65,60);
                pts[3] = new PointF(50,40);
                ig.DrawLines(ow, pts);

                Point[] polly = new Point[]
                {
                new Point(200, 40),
                new Point(220, 140),
                new Point(240, 100),
                new Point(290, 70),
                new Point(230, 10)
                };

                ig.DrawPolygon(tp, polly);

                //arrows
                Pen arr = new Pen(Color.DarkGoldenrod, 5);
                AdjustableArrowCap aac = new AdjustableArrowCap(5,3, false);
                arr.EndCap = LineCap.Custom;
                arr.CustomEndCap = aac;
                arr.StartCap = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 50,120, 150,200);

                arr.Width = 7f;
                arr.EndCap = LineCap.RoundAnchor;
                arr.StartCap = LineCap.SquareAnchor;
                ig.DrawLine(arr, 100,120, 200,200);

                arr.Width = 9;
                arr.EndCap = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 150,120, 250,200);

                Point[] al = new Point[]
                {
                    new Point(200, 100),
                    new Point(300, 200),
                    new Point(300, 150)
                };

                arr.EndCap = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.DiamondAnchor;
                ig.DrawLines(arr, al);

            }
            else if (s == "Curves")
            {

                PointF[] bezzie = new PointF[]
            {
                new PointF(20, 150),

                new PointF(110, 190),
                new PointF(120, 200),
                new PointF(50, 220),

                new PointF(60, 200),
                new PointF(140, 180),
                new PointF(100, 160),

                new PointF(180, 260),
                new PointF(200, 210),
                new PointF(190, 210)
            };

                Pen bpn = new Pen(Color.MediumSeaGreen, 2);
                bpn.DashStyle = DashStyle.Custom;
                bpn.DashPattern = new float[]{6,1,5,2,4,3,3,4,2,5,6,1};
                ig.DrawBeziers(bpn, bezzie);

                PointF[] curvy = new PointF[]
            {
                new PointF(130, 40),
                new PointF(70, 70),
                new PointF(50, 20),
                new PointF(120, 120),
                new PointF(150, 80),
                new PointF(80, 150),
                new PointF(80, 110)
            };

                ig.DrawCurve(new Pen(Color.Blue, 5), curvy);
                ig.DrawCurve(new Pen(Color.Red, 2), curvy, 2, 3);
                ig.DrawCurve(new Pen(Color.Yellow, 1), curvy, 1f);

                Point[] ccurvy = new Point[]
            {
                new Point(280, 30),
                new Point(260, 60),
                new Point(200, 20),
                new Point(290, 120),
                new Point(290, 80),
                new Point(230, 150),
                new Point(150, 50)
            };
                ig.DrawClosedCurve(new Pen(Color.Green, 3), ccurvy, 1f, FillMode.Alternate);
                ig.DrawClosedCurve(new Pen(Color.Purple, 1), ccurvy, 0f, FillMode.Alternate);

                Point[] fcc = new Point[]
            {
                new Point(160, 350),
                new Point(190, 370),
                new Point(130, 390),
                new Point(190, 400),
                new Point(195, 410),
                new Point(100, 430),
                new Point(160, 450)
            };
                ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f);
                ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f);

            }
            else if (s == "Transparency")
            {
                Point[] fillpoly = new Point[]
                {
                    new Point(20, 130),
                    new Point(60, 90),
                    new Point(30, 20),
                    new Point(80, 20),
                    new Point(15, 90),
                    new Point(100, 50),
                    new Point(0, 50)
                };

                Color col = Color.FromArgb(96,255,0,0);

                ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding);

                ig.TranslateTransform(10,10);
                ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate);
                ig.ResetTransform();

                ig.FillPie(new SolidBrush(Color.FromArgb(100,255,0,0)), 10, 200, 200, 80, 315, 90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100,128,128,0)), 10, 200, 200, 80, 250, -90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100,128,0,128)), 15, 205, 190, 70, 180, 270);
                ig.FillPie(new SolidBrush(Color.FromArgb(100,200,60,60)), 20, 210, 180, 60, 45, -270);

            }
            else if (s == "Fills")
            {

                LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0,0), new Point(30,20), Color.Blue, Color.Plum);

                ColorBlend blend = new ColorBlend(3);
                blend.Colors =  new Color[] {Color.Red, Color.Yellow, Color.MediumSlateBlue};
                blend.Positions = new float[] {0, .3f, 1f};
                gbr1.InterpolationColors = blend;

                Point[] sp = new Point[]
                {
                    new Point(145, 145),
                    new Point(305, 250),
                    new Point(220, 250),
                    new Point(180, 250)
                };
                ig.FillPolygon(gbr1, sp);

                LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0,0), new Point(10,20), Color.WhiteSmoke, Color.CornflowerBlue);
                gbr2.WrapMode = WrapMode.TileFlipXY;
                Point[] sp2 = new Point[]
                {
                    new Point(25, 205),
                    new Point(75, 150),
                    new Point(110, 110),
                    new Point(40, 80)
                };
                ig.FillPolygon(gbr2, sp2);

                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140,5,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160,5,20,20);

                ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200,30,20,20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220,30,20,20);

            }
            else if (s == "Arcs/Pies")
            {
                //GDI does not seem to draw arcs correctly except when the ellipse is a circle.
                //These arcs demonstrate the problem.  SVGGraphics calculates arcs correctly.
                ig.DrawArc(new Pen(Color.Black, 2), 120+5*3, 120, 110*3, 110, 0, 240);
                ig.DrawArc(new Pen(Color.Black, 2), 120+10*3, 125, 100*3, 100, 0, 210);
                ig.DrawArc(new Pen(Color.Black, 2), 120+15*3, 130, 90*3, 90, 0, 180);
                ig.DrawArc(new Pen(Color.Black, 2), 120+20*3, 135, 80*3, 80, 0, 150);
                ig.DrawArc(new Pen(Color.Black, 2), 120+25*3, 140, 70*3, 70, 0, 120);
                ig.DrawArc(new Pen(Color.Black, 2), 120+30*3, 145, 60*3, 60, 0, 90);
                ig.DrawArc(new Pen(Color.Black, 2), 120+35*3, 150, 50*3, 50, 0, 60);
                ig.DrawArc(new Pen(Color.Black, 2), 120+40*3, 155, 40*3, 40, 0, 270);

                ig.DrawPie(new Pen(Color.Pink, 2), 110, 50, 100, 100, 315, 90);
                ig.DrawPie(new Pen(Color.Purple, 2), 110, 50, 100, 100, 250, -90);
                ig.DrawPie(new Pen(Color.DarkRed, 2), 115, 55, 90, 90, 180, 270);
                ig.DrawPie(new Pen(Color.Red, 2), 120, 60, 80, 80, 45, -270);

            }
            else if (s == "Text")
            {

                Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold);
                Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold);
                Font fnt3 = new Font("", 40, FontStyle.Underline);

                Rectangle rc1 = new Rectangle(30, 30, 220,20);
                StringFormat fmt1= new StringFormat();
                fmt1.Alignment = StringAlignment.Near;

                ig.DrawRectangle(new Pen(Color.Blue),  rc1);
                ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1);

                Rectangle rc2 = new Rectangle(0,0, 120,20);
                StringFormat fmt2= new StringFormat();
                fmt2.Alignment = StringAlignment.Center;

                ig.TranslateTransform(30,160);
                ig.RotateTransform(90);

                ig.DrawRectangle(new Pen(Color.Blue),  rc2);
                ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2);

                ig.ResetTransform();

                Rectangle rc3 = new Rectangle(30, 90, 300,30);
                StringFormat fmt3= new StringFormat();
                fmt3.Alignment = StringAlignment.Far;

                ig.DrawRectangle(new Pen(Color.Blue),  rc3);
                ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3);

                //measurestring
                string mme = "MeasureString Is Impossible To Emulate";
                SizeF siz = ig.MeasureString(mme, fnt1);
                ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, 150);
                ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1,  new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical));
                ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height);

            }
            else if (s == "Images")
            {

                Icon ike = new Icon(GetType(), "App.ico");
                ig.DrawIcon(ike, 10,10);
                //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40));

                Bitmap bmp = new Bitmap(GetType(), "test.bmp");
                ig.DrawImage(bmp, 100f, 150f);
                GraphicsContainer cnt = ig.BeginContainer();
                ig.RotateTransform(5);
                ig.DrawImage(bmp, 160f, 50f, 120f, 70f);
                ig.EndContainer(cnt);
                //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20);

            }
            else
            {

            }
        }
Example #20
0
        /// <summary>
        /// Renders the map using the provided <see cref="IGraphics"/> object.
        /// </summary>
        /// <param name="g">the <see cref="IGraphics"/> object to use</param>
        /// <exception cref="ArgumentNullException">if <see cref="IGraphics"/> object is null.</exception>
        /// <exception cref="InvalidOperationException">if there are no layers to render.</exception>
        public void RenderMap(IGraphics g)
        {
            OnMapRendering(g);

            if (g == null)
                throw new ArgumentNullException("g", "Cannot render map with null graphics object!");

            //Pauses the timer for VariableLayer
            VariableLayerCollection.Pause = true;

            if ((Layers == null || Layers.Count == 0) && (BackgroundLayer == null || BackgroundLayer.Count == 0) && (_variableLayers == null || _variableLayers.Count == 0))
                throw new InvalidOperationException("No layers to render");

            lock (MapTransform)
            {
                g.Transform = MapTransform.Clone();
            }
            g.Clear(BackColor);
            g.PageUnit = GraphicsUnitType.Pixel;


            //int srid = (Layers.Count > 0 ? Layers[0].SRID : -1); //Get the SRID of the first layer
            ILayer[] layerList;
            if (_backgroundLayers != null && _backgroundLayers.Count > 0)
            {
                layerList = new ILayer[_backgroundLayers.Count];
                _backgroundLayers.CopyTo(layerList, 0);
                foreach (ILayer layer in layerList)
                {
                    OnLayerRendering(layer, LayerCollectionType.Background);
                    if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                        layer.Render(g, this);
                    OnLayerRendered(layer, LayerCollectionType.Background);
                }
            }

            if (_layers != null && _layers.Count > 0)
            {
                layerList = new ILayer[_layers.Count];
                _layers.CopyTo(layerList, 0);

                //int srid = (Layers.Count > 0 ? Layers[0].SRID : -1); //Get the SRID of the first layer
                foreach (ILayer layer in layerList)
                {
                    OnLayerRendering(layer, LayerCollectionType.Static);
                    if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                        layer.Render(g, this);
                    OnLayerRendered(layer, LayerCollectionType.Static);
                }
            }

            if (_variableLayers != null && _variableLayers.Count > 0)
            {
                layerList = new ILayer[_variableLayers.Count];
                _variableLayers.CopyTo(layerList, 0);
                foreach (ILayer layer in layerList)
                {
                    if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                        layer.Render(g, this);
                }
            }

#pragma warning disable 612,618
            RenderDisclaimer(g);
#pragma warning restore 612,618

            // Render all map decorations
            foreach (var mapDecoration in _decorations)
            {
                mapDecoration.Render(g, this);
            }
            //Resets the timer for VariableLayer
            VariableLayerCollection.Pause = false;

            OnMapRendered(g);
        }
Example #21
0
        /// <summary>
        /// Renders the map using the provided <see cref="IGraphics"/> object.
        /// </summary>
        /// <param name="g">the <see cref="IGraphics"/> object to use</param>
        /// <param name="layerCollectionType">the <see cref="LayerCollectionType"/> to use</param>
        /// <param name="drawMapDecorations">Set whether to draw map decorations on the map (if such are set)</param>
        /// <param name="drawTransparent">Set wether to draw with transparent background or with BackColor as background</param>
        /// <exception cref="ArgumentNullException">if <see cref="IGraphics"/> object is null.</exception>
        /// <exception cref="InvalidOperationException">if there are no layers to render.</exception>
        public void RenderMap(IGraphics g, LayerCollectionType layerCollectionType, bool drawMapDecorations, bool drawTransparent)
        {
            if (g == null)
                throw new ArgumentNullException("g", "Cannot render map with null graphics object!");

            VariableLayerCollection.Pause = true;

            LayerCollection lc = null;
            switch (layerCollectionType)
            {
                case LayerCollectionType.Static:
                    lc = Layers;
                    break;
                case LayerCollectionType.Variable:
                    lc = VariableLayers;
                    break;
                case LayerCollectionType.Background:
                    lc = BackgroundLayer;
                    break;
            }

            if (lc == null || lc.Count == 0)
                throw new InvalidOperationException("No layers to render");

            Matrix transform = g.Transform;
            lock (MapTransform)
            {
                g.Transform = MapTransform.Clone();
            }
            if (!drawTransparent)
                g.Clear(BackColor);

            g.PageUnit = GraphicsUnitType.Pixel;

            LayerCollectionRenderer.AllowParallel = true;
            using (var lcr = new LayerCollectionRenderer(lc))
            {
                lcr.Render(g, this);
            }

            /*
            var layerList = new ILayer[lc.Count];
            lc.CopyTo(layerList, 0);

            foreach (ILayer layer in layerList)
            {
                if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                    layer.Render(g, this);
            }

             */

            if (drawTransparent)


                g.Transform = transform;
            if (layerCollectionType == LayerCollectionType.Static)
            {
#pragma warning disable 612,618
                RenderDisclaimer(g);
#pragma warning restore 612,618
                if (drawMapDecorations)
                {
                    foreach (var mapDecoration in Decorations)
                    {
                        mapDecoration.Render(g, this);
                    }
                }
            }



            VariableLayerCollection.Pause = false;

        }
Example #22
0
        private void Render(IGraphics ig)
        {
            string s = cbWhat.Text;

            if (s == "Clipping")
            {
                Pen pn  = new Pen(Color.LightGray, 5);
                Pen pn2 = new Pen(Color.Yellow);

                ig.Clear(Color.Black);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.SetClip(new Rectangle(35, 35, 120, 120));

                ig.DrawRectangle(pn, 5, 5, 45, 70);
                ig.DrawRectangle(pn, 15, 25, 90, 120);
                ig.DrawRectangle(pn, 50, 30, 100, 170);
                ig.DrawRectangle(pn, 5, 80, 180, 30);
                ig.DrawRectangle(pn, 75, 10, 40, 160);

                ig.EndContainer(cnt);

                ig.DrawRectangle(pn2, 5, 5, 45, 70);
                ig.DrawRectangle(pn2, 15, 25, 90, 120);
                ig.DrawRectangle(pn2, 50, 30, 100, 170);
                ig.DrawRectangle(pn2, 5, 80, 180, 30);
                ig.DrawRectangle(pn2, 75, 10, 40, 160);
            }
            else if (s == "Transforms")
            {
                ig.Clear(Color.Black);

                ig.RotateTransform(15);
                ig.DrawRectangle(new Pen(Color.Red, 2), 260, 80, 50, 40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.Red, 2), 260, 80, 50, 40);

                ig.TranslateTransform(15, -5);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.RotateTransform(5);
                ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40);
                ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40);


                GraphicsContainer cnt2 = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.None;

                ig.RotateTransform(5);
                ig.ScaleTransform(1.1f, 1.2f);

                ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40);
                ig.DrawRectangle(new Pen(Color.YellowGreen, 2), 62, 80, 40, 40);

                GraphicsContainer cnt3 = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                Matrix mm = new Matrix();
                mm.Shear(0.3f, 0f);
                ig.Transform = mm;

                ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40);
                ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40);

                ig.EndContainer(cnt3);

                ig.EndContainer(cnt2);

                ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40);
                ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40);

                ig.EndContainer(cnt);

                ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40);
                ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40);

                ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
            }
            else if (s == "Lines")
            {
                ig.SmoothingMode = SmoothingMode.AntiAlias;

                Pen ow = new Pen(Color.Purple, 12);
                ow.EndCap     = LineCap.Round;
                ow.StartCap   = LineCap.Round;
                ow.MiterLimit = 6f;
                ow.LineJoin   = LineJoin.Miter;

                ig.SmoothingMode = SmoothingMode.None;

                Pen tp = new Pen(Color.Red, 2);
                tp.DashStyle = DashStyle.DashDot;

                ig.DrawLine(tp, 70, 20, 190, 20);

                tp.DashStyle = DashStyle.Dash;

                ig.DrawLine(tp, 70, 30, 190, 30);

                tp.DashStyle   = DashStyle.Custom;
                tp.DashPattern = new float[] { 1, 8, 2, 2 };

                ig.DrawLine(tp, 70, 40, 190, 40);

                ig.SmoothingMode = SmoothingMode.AntiAlias;

                PointF[] pts = new PointF[4];
                pts[0] = new PointF(20, 50);
                pts[1] = new PointF(30, 90);
                pts[2] = new PointF(65, 60);
                pts[3] = new PointF(50, 40);
                ig.DrawLines(ow, pts);

                Point[] polly = new Point[]
                {
                    new Point(200, 40),
                    new Point(220, 140),
                    new Point(240, 100),
                    new Point(290, 70),
                    new Point(230, 10)
                };

                ig.DrawPolygon(tp, polly);

                //arrows
                Pen arr = new Pen(Color.DarkGoldenrod, 5);
                AdjustableArrowCap aac = new AdjustableArrowCap(5, 3, false);
                arr.EndCap       = LineCap.Custom;
                arr.CustomEndCap = aac;
                arr.StartCap     = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 50, 120, 150, 200);

                arr.Width    = 7f;
                arr.EndCap   = LineCap.RoundAnchor;
                arr.StartCap = LineCap.SquareAnchor;
                ig.DrawLine(arr, 100, 120, 200, 200);

                arr.Width    = 9;
                arr.EndCap   = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 150, 120, 250, 200);

                Point[] al = new Point[]
                {
                    new Point(200, 100),
                    new Point(300, 200),
                    new Point(300, 150)
                };

                arr.EndCap   = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.DiamondAnchor;
                ig.DrawLines(arr, al);
            }
            else if (s == "Curves")
            {
                PointF[] bezzie = new PointF[]
                {
                    new PointF(20, 150),

                    new PointF(110, 190),
                    new PointF(120, 200),
                    new PointF(50, 220),

                    new PointF(60, 200),
                    new PointF(140, 180),
                    new PointF(100, 160),

                    new PointF(180, 260),
                    new PointF(200, 210),
                    new PointF(190, 210)
                };

                Pen bpn = new Pen(Color.MediumSeaGreen, 2);
                bpn.DashStyle   = DashStyle.Custom;
                bpn.DashPattern = new float[] { 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 6, 1 };
                ig.DrawBeziers(bpn, bezzie);



                PointF[] curvy = new PointF[]
                {
                    new PointF(130, 40),
                    new PointF(70, 70),
                    new PointF(50, 20),
                    new PointF(120, 120),
                    new PointF(150, 80),
                    new PointF(80, 150),
                    new PointF(80, 110)
                };

                ig.DrawCurve(new Pen(Color.Blue, 5), curvy);
                ig.DrawCurve(new Pen(Color.Red, 2), curvy, 2, 3);
                ig.DrawCurve(new Pen(Color.Yellow, 1), curvy, 1f);

                Point[] ccurvy = new Point[]
                {
                    new Point(280, 30),
                    new Point(260, 60),
                    new Point(200, 20),
                    new Point(290, 120),
                    new Point(290, 80),
                    new Point(230, 150),
                    new Point(150, 50)
                };
                ig.DrawClosedCurve(new Pen(Color.Green, 3), ccurvy, 1f, FillMode.Alternate);
                ig.DrawClosedCurve(new Pen(Color.Purple, 1), ccurvy, 0f, FillMode.Alternate);



                Point[] fcc = new Point[]
                {
                    new Point(160, 350),
                    new Point(190, 370),
                    new Point(130, 390),
                    new Point(190, 400),
                    new Point(195, 410),
                    new Point(100, 430),
                    new Point(160, 450)
                };
                ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f);
                ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f);
            }
            else if (s == "Transparency")
            {
                Point[] fillpoly = new Point[]
                {
                    new Point(20, 130),
                    new Point(60, 90),
                    new Point(30, 20),
                    new Point(80, 20),
                    new Point(15, 90),
                    new Point(100, 50),
                    new Point(0, 50)
                };

                Color col = Color.FromArgb(96, 255, 0, 0);

                ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding);

                ig.TranslateTransform(10, 10);
                ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate);
                ig.ResetTransform();

                ig.FillPie(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), 10, 200, 200, 80, 315, 90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 128, 0)), 10, 200, 200, 80, 250, -90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 0, 128)), 15, 205, 190, 70, 180, 270);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 200, 60, 60)), 20, 210, 180, 60, 45, -270);
            }
            else if (s == "Fills")
            {
                LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0, 0), new Point(30, 20), Color.Blue, Color.Plum);

                ColorBlend blend = new ColorBlend(3);
                blend.Colors             = new Color[] { Color.Red, Color.Yellow, Color.MediumSlateBlue };
                blend.Positions          = new float[] { 0, .3f, 1f };
                gbr1.InterpolationColors = blend;


                Point[] sp = new Point[]
                {
                    new Point(145, 145),
                    new Point(305, 250),
                    new Point(220, 250),
                    new Point(180, 250)
                };
                ig.FillPolygon(gbr1, sp);

                LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue);
                gbr2.WrapMode = WrapMode.TileFlipXY;
                Point[] sp2 = new Point[]
                {
                    new Point(25, 205),
                    new Point(75, 150),
                    new Point(110, 110),
                    new Point(40, 80)
                };
                ig.FillPolygon(gbr2, sp2);

                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160, 5, 20, 20);

                ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220, 30, 20, 20);
            }
            else if (s == "Arcs/Pies")
            {
                //GDI does not seem to draw arcs correctly except when the ellipse is a circle.
                //These arcs demonstrate the problem.  SVGGraphics calculates arcs correctly.
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 5 * 3, 120, 110 * 3, 110, 0, 240);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 10 * 3, 125, 100 * 3, 100, 0, 210);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 15 * 3, 130, 90 * 3, 90, 0, 180);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 20 * 3, 135, 80 * 3, 80, 0, 150);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 25 * 3, 140, 70 * 3, 70, 0, 120);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 30 * 3, 145, 60 * 3, 60, 0, 90);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 35 * 3, 150, 50 * 3, 50, 0, 60);
                ig.DrawArc(new Pen(Color.Black, 2), 120 + 40 * 3, 155, 40 * 3, 40, 0, 270);

                ig.DrawPie(new Pen(Color.Pink, 2), 110, 50, 100, 100, 315, 90);
                ig.DrawPie(new Pen(Color.Purple, 2), 110, 50, 100, 100, 250, -90);
                ig.DrawPie(new Pen(Color.DarkRed, 2), 115, 55, 90, 90, 180, 270);
                ig.DrawPie(new Pen(Color.Red, 2), 120, 60, 80, 80, 45, -270);
            }
            else if (s == "Text")
            {
                Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold);
                Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold);
                Font fnt3 = new Font("", 40, FontStyle.Underline);

                Rectangle    rc1  = new Rectangle(30, 30, 220, 20);
                StringFormat fmt1 = new StringFormat();
                fmt1.Alignment = StringAlignment.Near;

                ig.DrawRectangle(new Pen(Color.Blue), rc1);
                ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1);

                Rectangle    rc2  = new Rectangle(0, 0, 120, 20);
                StringFormat fmt2 = new StringFormat();
                fmt2.Alignment = StringAlignment.Center;

                ig.TranslateTransform(30, 160);
                ig.RotateTransform(90);

                ig.DrawRectangle(new Pen(Color.Blue), rc2);
                ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2);

                ig.ResetTransform();

                Rectangle    rc3  = new Rectangle(30, 90, 300, 30);
                StringFormat fmt3 = new StringFormat();
                fmt3.Alignment = StringAlignment.Far;

                ig.DrawRectangle(new Pen(Color.Blue), rc3);
                ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3);

                //measurestring
                string mme = "MeasureString Is Impossible To Emulate";
                SizeF  siz = ig.MeasureString(mme, fnt1);
                ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, 150);
                ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical));
                ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height);
            }
            else if (s == "Images")
            {
                Icon ike = new Icon(GetType(), "App.ico");
                ig.DrawIcon(ike, 10, 10);
                //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40));

                Bitmap bmp = new Bitmap(GetType(), "test.bmp");
                ig.DrawImage(bmp, 100f, 150f);
                GraphicsContainer cnt = ig.BeginContainer();
                ig.RotateTransform(5);
                ig.DrawImage(bmp, 160f, 50f, 120f, 70f);
                ig.EndContainer(cnt);
                //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20);
            }
            else
            {
            }
        }
Example #23
0
        void Draw(IGraphics g, DrawingMode mode)
        {
            g.SmoothingMode = checkBoxAntialiasing.Checked ? SmoothingMode.HighQuality : SmoothingMode.None;
            g.Clear(Color.White);

            DrawMillimeterGridInPixels(g, tabControl1.SelectedTab.Controls[0].ClientRectangle);

            g.PageUnit = GraphicsUnit.Millimeter;

            var points = _noisePoints;

            DrawLines(g, points, mode);

            g.ResetTransform();

            var path = CreateRoundedRectanglePath(new RectangleF(10, 10, 100, 40), 10);

            g.FillPath(new SolidBrush(Color.FromArgb(120, Color.LightSlateGray)), path);
            g.DrawPath(new Pen(Color.LightSlateGray, 0.0f), path);

            g.FillPie(new SolidBrush(Color.FromArgb(120, Color.CadetBlue)), new Rectangle(30, 20, 100, 100), 45.0f, 90.0f);
            g.DrawPie(new Pen(Color.CadetBlue, 0.0f), new Rectangle(30, 20, 100, 100), 45.0f, 90.0f);

            //GLGraphics gl = g as GLGraphics;
            //if (gl != null)
            //    gl.FillTextBackground = gl.FillTextBackground_glReadPixels;

            g.PageUnit = GraphicsUnit.Pixel;
            RectangleF rect = new RectangleF(30.0f, 15.0f, _testImage.Width, _testImage.Height);
            g.DrawImage(_testImage, rect);
            g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height);

            g.PageUnit = GraphicsUnit.Millimeter;

            g.HintTextBackgroundAction((gdi, textLocation, textRect) =>
            {
                _millimeterGridBrush.ResetTransform();
                _millimeterGridBrush.TranslateTransform(-textLocation.X, -textLocation.Y);
                gdi.FillRectangle(_millimeterGridBrush, textRect);
            });

            g.DrawString("Testovací řetězec pro odzkoušení správné implementace IGraphics - metody DrawString.",
                new Font("Arial", 12.0f), Brushes.Black, new PointF(100.0f, 58.0f));
        }
Example #24
0
 public override void Draw(IGraphics g)
 {
     g.Clear(GroundColor);
     base.Draw(g);
 }
Example #25
0
        private void Render(IGraphics ig)
        {
            string s = cbWhat.Text;

            if (string.IsNullOrEmpty(s))
            {
            }
            else if (s == "Clipping")
            {
                Pen pn  = new Pen(Color.LightGray, 5.6f);
                Pen pn2 = new Pen(Color.Yellow, 1.2f);

                ig.Clear(Color.Black);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.SetClip(new Rectangle(35, 35, 120, 120));

                ig.DrawRectangle(pn, 5, 5, 45, 70);
                ig.DrawRectangle(pn, 15, 25, 90, 120);
                ig.DrawRectangle(pn, 50, 30, 100, 170);
                ig.DrawRectangle(pn, 5, 80, 180, 30);
                ig.DrawRectangle(pn, 75, 10, 40, 160);

                ig.EndContainer(cnt);

                ig.DrawRectangle(pn2, 5, 5, 45, 70);
                ig.DrawRectangle(pn2, 15, 25, 90, 120);
                ig.DrawRectangle(pn2, 50, 30, 100, 170);
                ig.DrawRectangle(pn2, 5, 80, 180, 30);
                ig.DrawRectangle(pn2, 75, 10, 40, 160);
            }
            else if (s == "Transforms")
            {
                ig.Clear(Color.Black);

                ig.RotateTransform(15);
                ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40);

                ig.TranslateTransform(15, -5);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.RotateTransform(5);
                ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40);
                ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40);

                GraphicsContainer cnt2 = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.None;

                ig.RotateTransform(5);
                ig.ScaleTransform(1.1f, 1.2f);

                ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40);
                ig.DrawRectangle(new Pen(Color.YellowGreen, 2.7f), 62, 80, 40, 40);

                GraphicsContainer cnt3 = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                Matrix mm = new Matrix();
                mm.Shear(0.3f, 0f);
                ig.Transform = mm;

                ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40);
                ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40);

                ig.EndContainer(cnt3);

                ig.EndContainer(cnt2);

                ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40);
                ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40);

                ig.EndContainer(cnt);

                ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40);
                ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40);

                ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
            }
            else if (s == "Lines")
            {
                ig.SmoothingMode = SmoothingMode.AntiAlias;

                Pen ow = new Pen(Color.Purple, 12.6f);
                ow.EndCap     = LineCap.Round;
                ow.StartCap   = LineCap.Round;
                ow.MiterLimit = 6f;
                ow.LineJoin   = LineJoin.Miter;

                ig.SmoothingMode = SmoothingMode.None;

                Pen tp = new Pen(Color.Red, 2.7f);
                tp.DashStyle = DashStyle.DashDot;

                ig.DrawLine(tp, 70, 20, 190, 20);

                tp.DashStyle = DashStyle.Dash;

                ig.DrawLine(tp, 70, 30, 190, 30);

                tp.DashStyle   = DashStyle.Custom;
                tp.DashPattern = new float[] { 1, 8, 2, 2 };

                ig.DrawLine(tp, 70, 40, 190, 40);

                ig.SmoothingMode = SmoothingMode.AntiAlias;

                PointF[] pts = new PointF[4];
                pts[0] = new PointF(20, 50);
                pts[1] = new PointF(30, 90);
                pts[2] = new PointF(65, 60);
                pts[3] = new PointF(50, 40);
                ig.DrawLines(ow, pts);

                Point[] polly = new Point[]
                {
                    new Point(200, 40),
                    new Point(220, 140),
                    new Point(240, 100),
                    new Point(290, 70),
                    new Point(230, 10)
                };

                ig.DrawPolygon(tp, polly);

                //arrows
                Pen arr = new Pen(Color.DarkGoldenrod, 5.7f);

                {
                    arr.Width    = 2;
                    arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                    const float arrowWidth   = 11.0f; // TUNE:
                    const float arrowHeight  = 14f;   // TUNE:
                    var         arrowOutline = new System.Drawing.Drawing2D.GraphicsPath();
                    arrowOutline.AddLines(new PointF[] {
                        new PointF(-(arrowWidth / 2), -arrowHeight),
                        new PointF(0, 0),
                        new PointF((arrowWidth / 2), -arrowHeight),
                        new PointF(-(arrowWidth / 2), -arrowHeight)
                    });
                    var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline);
                    generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round);
                    generalizationArrow.BaseInset = arrowHeight;
                    arr.CustomEndCap = generalizationArrow;
                    ig.DrawLine(arr, 0, 120, 100, 200);
                }

                arr.Width = 5;
                AdjustableArrowCap aac = new AdjustableArrowCap(5, 3, false);
                arr.EndCap       = LineCap.Custom;
                arr.CustomEndCap = aac;
                arr.StartCap     = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 50, 120, 150, 200);

                arr.Width    = 7f;
                arr.EndCap   = LineCap.RoundAnchor;
                arr.StartCap = LineCap.SquareAnchor;
                ig.DrawLine(arr, 100, 120, 200, 200);

                arr.Width    = 9;
                arr.EndCap   = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 150, 120, 250, 200);

                Point[] al = new Point[]
                {
                    new Point(200, 100),
                    new Point(300, 200),
                    new Point(300, 150)
                };

                arr.Width    = 9;
                arr.EndCap   = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.DiamondAnchor;
                ig.DrawLines(arr, al);
            }
            else if (s == "Curves")
            {
                PointF[] bezzie = new PointF[]
                {
                    new PointF(20, 150),

                    new PointF(110, 190),
                    new PointF(120, 200),
                    new PointF(50, 220),

                    new PointF(60, 200),
                    new PointF(140, 180),
                    new PointF(100, 160),

                    new PointF(180, 260),
                    new PointF(200, 210),
                    new PointF(190, 210)
                };

                Pen bpn = new Pen(Color.MediumSeaGreen, 2.3f);
                bpn.DashStyle   = DashStyle.Custom;
                bpn.DashPattern = new float[] { 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 6, 1 };
                ig.DrawBeziers(bpn, bezzie);

                PointF[] curvy = new PointF[]
                {
                    new PointF(130, 40),
                    new PointF(70, 70),
                    new PointF(50, 20),
                    new PointF(120, 120),
                    new PointF(150, 80),
                    new PointF(80, 150),
                    new PointF(80, 110)
                };

                ig.DrawCurve(new Pen(Color.Blue, 5.7f), curvy);
                ig.DrawCurve(new Pen(Color.Red, 2.7f), curvy, 2, 3);
                ig.DrawCurve(new Pen(Color.Yellow, 1.7f), curvy, 1f);

                Point[] ccurvy = new Point[]
                {
                    new Point(280, 30),
                    new Point(260, 60),
                    new Point(200, 20),
                    new Point(290, 120),
                    new Point(290, 80),
                    new Point(230, 150),
                    new Point(150, 50)
                };
                ig.DrawClosedCurve(new Pen(Color.Green, 3.7f), ccurvy, 1f, FillMode.Alternate);
                ig.DrawClosedCurve(new Pen(Color.Purple, 1.7f), ccurvy, 0f, FillMode.Alternate);

                Point[] fcc = new Point[]
                {
                    new Point(160, 350),
                    new Point(190, 370),
                    new Point(130, 390),
                    new Point(190, 400),
                    new Point(195, 410),
                    new Point(100, 430),
                    new Point(160, 450)
                };
                ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f);
                ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f);
            }
            else if (s == "Transparency")
            {
                Point[] fillpoly = new Point[]
                {
                    new Point(20, 130),
                    new Point(60, 90),
                    new Point(30, 20),
                    new Point(80, 20),
                    new Point(15, 90),
                    new Point(100, 50),
                    new Point(0, 50)
                };

                Color col = Color.FromArgb(96, 255, 0, 0);

                ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding);

                ig.TranslateTransform(10, 10);
                ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate);
                ig.ResetTransform();

                ig.FillPie(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), 10, 200, 200, 80, 315, 90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 128, 0)), 10, 200, 200, 80, 250, -90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 0, 128)), 15, 205, 190, 70, 180, 270);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 200, 60, 60)), 20, 210, 180, 60, 45, -270);
            }
            else if (s == "Fills")
            {
                LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0, 0), new Point(30, 20), Color.Blue, Color.Plum);

                ColorBlend blend = new ColorBlend(3);
                blend.Colors             = new Color[] { Color.Red, Color.Yellow, Color.MediumSlateBlue };
                blend.Positions          = new float[] { 0, .3f, 1f };
                gbr1.InterpolationColors = blend;

                Point[] sp = new Point[]
                {
                    new Point(145, 145),
                    new Point(305, 250),
                    new Point(220, 250),
                    new Point(180, 250)
                };
                ig.FillPolygon(gbr1, sp);

                LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue);
                gbr2.WrapMode = WrapMode.TileFlipXY;
                Point[] sp2 = new Point[]
                {
                    new Point(25, 205),
                    new Point(75, 150),
                    new Point(110, 110),
                    new Point(40, 80)
                };
                ig.FillPolygon(gbr2, sp2);

                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160, 5, 20, 20);
                ig.FillRectangle(gbr1, 200, 5, 20, 20);
                ig.FillRectangle(gbr2, 220, 5, 20, 20);

                ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220, 30, 20, 20);
            }
            else if (s == "Arcs/Pies")
            {
                //GDI does not seem to draw arcs correctly except when the ellipse is a circle.
                //These arcs demonstrate the problem.  SVGGraphics calculates arcs correctly.
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 5 * 3, 120, 110 * 3, 110, 0, 240);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 10 * 3, 125, 100 * 3, 100, 0, 210);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 15 * 3, 130, 90 * 3, 90, 0, 180);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 20 * 3, 135, 80 * 3, 80, 0, 150);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 25 * 3, 140, 70 * 3, 70, 0, 120);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 30 * 3, 145, 60 * 3, 60, 0, 90);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 35 * 3, 150, 50 * 3, 50, 0, 60);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 40 * 3, 155, 40 * 3, 40, 0, 270);

                ig.DrawPie(new Pen(Color.Pink, 2.7f), 110, 50, 100, 100, 315, 90);
                ig.DrawPie(new Pen(Color.Purple, 2.7f), 110, 50, 100, 100, 250, -90);
                ig.DrawPie(new Pen(Color.DarkRed, 2.7f), 115, 55, 90, 90, 180, 270);
                ig.DrawPie(new Pen(Color.Red, 2.7f), 120, 60, 80, 80, 45, -270);
            }
            else if (s == "Text")
            {
                Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold);
                Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold);
                Font fnt3 = new Font("", 40, FontStyle.Underline);

                Rectangle    rc1  = new Rectangle(30, 30, 220, 20);
                StringFormat fmt1 = new StringFormat();
                fmt1.Alignment = StringAlignment.Near;

                ig.DrawRectangle(new Pen(Color.Blue), rc1);
                ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1);

                Rectangle    rc2  = new Rectangle(0, 0, 120, 20);
                StringFormat fmt2 = new StringFormat();
                fmt2.Alignment = StringAlignment.Center;

                ig.TranslateTransform(30, 160);
                ig.RotateTransform(90);

                ig.DrawRectangle(new Pen(Color.Blue), rc2);
                ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2);

                ig.ResetTransform();

                Rectangle    rc3  = new Rectangle(30, 90, 300, 30);
                StringFormat fmt3 = new StringFormat();
                fmt3.Alignment = StringAlignment.Far;

                ig.DrawRectangle(new Pen(Color.Blue), rc3);
                ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3);

                //measurestring
                const string mme = "MeasureString Is Impossible To Emulate";
                SizeF        siz = ig.MeasureString(mme, fnt1);
                ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, 150);
                ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical));
                ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height);
            }
            else if (s == "Rect-aligned Text")
            {
                ig.Clear(Color.White);
                ig.ScaleTransform(
                    (float)panel1.ClientSize.Width / RectAlignedTextTest.CanvasSize,
                    (float)panel1.ClientSize.Height / RectAlignedTextTest.CanvasSize);
                RectAlignedTextTest.DrawTest(ig);
            }
            else if (s == "Images")
            {
                Icon ike = new Icon(GetType(), "App.ico");
                ig.DrawIcon(ike, 10, 10);
                //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40));

                Bitmap bmp = new Bitmap(GetType(), "test.bmp");
                ig.DrawImage(bmp, 100f, 150f);
                GraphicsContainer cnt = ig.BeginContainer();
                ig.RotateTransform(5);
                ig.DrawImage(bmp, 160f, 50f, 120f, 70f);
                ig.EndContainer(cnt);
                //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20);
            }
            else if (s == "Path")
            {
                /* The following example GraphicsPath code comes from the MSDN docs on the GraphicsPathIterator class
                 * https://msdn.microsoft.com/en-us/library/79k451ts.aspx
                 *
                 */
                // Create a graphics path.
                GraphicsPath myPath = new GraphicsPath();

                // Set up primitives to add to myPath.
                Point[]   myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) };
                Rectangle myRect   = new Rectangle(120, 120, 100, 100);

                // Add 3 lines, a rectangle, an ellipse, and 2 markers.
                myPath.AddLines(myPoints);
                myPath.SetMarkers();
                myPath.AddRectangle(myRect);
                myPath.SetMarkers();
                myPath.AddEllipse(220, 220, 100, 100);
                ig.DrawPath(new Pen(Color.Black, 1.7f), myPath);
                LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue);
                gbr2.WrapMode = WrapMode.TileFlipXY;
                ig.FillPath(gbr2, myPath);

                GraphicsPath myPath2 = new GraphicsPath();
                myPath2.AddLine(100, 100, 130, 120);
                myPath2.AddEllipse(120, 120, 120, 140);
                myPath2.AddBezier(130, 160, 170, 160, 150, 130, 200, 110);
                ig.DrawPath(new Pen(Color.Blue, 1.7f), myPath2);
            }
            else if (s == "Path 2 (Slow)")
            {
                SolidBrush   mySolidBrush   = new SolidBrush(Color.Aqua);
                GraphicsPath myGraphicsPath = new GraphicsPath();

                Point[] myPointArray =
                {
                    new Point(15, 20),
                    new Point(20, 40),
                    new Point(50, 30)
                };

                FontFamily   myFontFamily   = new FontFamily("Times New Roman");
                PointF       myPointF       = new PointF(50, 20);
                StringFormat myStringFormat = new StringFormat();

                myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
                myGraphicsPath.AddCurve(myPointArray);
                myGraphicsPath.AddString("a string in a path filled", myFontFamily,
                                         0, 24, myPointF, myStringFormat);
                myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
                ig.FillPath(mySolidBrush, myGraphicsPath);
                ig.DrawPath(new Pen(Color.Green, 1.7f), myGraphicsPath);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #26
0
        public CharInfo[] Buffer => graphics.Buffer; // todo: fix, this is currently returning whole buffer

        public void Clear(ConsoleColor color = ConsoleColor.Black)
        {
            graphics.Clear(xOffset, yOffset, Width, Height, color);
        }