示例#1
0
 public override void OnDraw(Graphics2D graphics2D)
 {
     graphics2D.Line(Width / 2, 0, Width / 2, Height, RGBA_Bytes.Red);
     graphics2D.Line(0, Height / 2, Width, Height / 2, RGBA_Bytes.Red);
     base.OnDraw(graphics2D);
 }
示例#2
0
        public static void Main(string[] args)
        {
            // first we will show how to use the simple drawing functions in graphics 2D
            {
                ImageBuffer simpleImage           = new ImageBuffer(640, 480, 32, new BlenderBGRA());
                Graphics2D  simpleImageGraphics2D = simpleImage.NewGraphics2D();
                // clear the image to white
                simpleImageGraphics2D.Clear(Color.White);
                // draw a circle
                simpleImageGraphics2D.Circle(50, 50, 30, Color.Blue);
                // draw a line
                simpleImageGraphics2D.Line(10, 100, 520, 50, new Color(20, 200, 200));
                // draw a filled box
                simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, Color.Yellow);
                // and an outline around it
                simpleImageGraphics2D.Rectangle(60, 260, 200, 280, Color.Magenta);
                // draw some text
                simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20);

                // and save this image out
                ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga");
            }

            // now we will we will show how to use the render function to draw more complex things
            {
                ImageBuffer lessSimpleImage           = new ImageBuffer(640, 480, 32, new BlenderBGRA());
                Graphics2D  lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D();
                // clear the image to white
                lessSimpleImageGraphics2D.Clear(Color.White);
                // draw a circle
                Ellipse ellipseTest = new Ellipse(0, 0, 100, 50);
                for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
                {
                    VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees)));
                    VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150));
                    lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, Color.Yellow);
                    Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3);
                    lessSimpleImageGraphics2D.Render(ellipseOutline, Color.Blue);
                }

                // and a little polygon
                VertexStorage littlePoly = new VertexStorage();
                littlePoly.MoveTo(50, 50);
                littlePoly.LineTo(150, 50);
                littlePoly.LineTo(200, 200);
                littlePoly.LineTo(50, 150);
                littlePoly.LineTo(50, 50);
                lessSimpleImageGraphics2D.Render(littlePoly, Color.Cyan);

                // draw some text
                TypeFacePrinter textPrinter    = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);
                IVertexSource   translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3)));
                lessSimpleImageGraphics2D.Render(translatedText, Color.Red);
                Stroke strokedText = new Stroke(translatedText);
                lessSimpleImageGraphics2D.Render(strokedText, Color.Black);

                IVertexSource rotatedText           = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90)));
                IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2)));
                lessSimpleImageGraphics2D.Render(rotatedTranslatedText, Color.Black);

                // and save this image out
                ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga");
            }
        }
示例#3
0
        public override void OnDraw(Graphics2D graphics2D)
		{
            graphics2D.PushTransform();

            int numLines = Text.Split('\n').Length - 1;
            if(Text.Contains("\r"))
            {
                throw new Exception("These should have be converted to \n.");
            }

            double yOffsetForText = Printer.TypeFaceStyle.EmSizeInPixels * numLines;
            double xOffsetForText = 0;
            switch (printer.Justification)
            {
                case Justification.Left:
                    break;

                case Justification.Center:
                    xOffsetForText = (Width - Printer.LocalBounds.Width) / 2;
                    break;

                case Justification.Right:
                    xOffsetForText = Width - Printer.LocalBounds.Width;
                    break;

                default:
                    throw new NotImplementedException();
            }
            graphics2D.SetTransform(graphics2D.GetTransform() * Affine.NewTranslation(xOffsetForText, yOffsetForText));

            RGBA_Bytes currentColor = this.textColor;

            if (EllipsisIfClipped && Printer.LocalBounds.Width > LocalBounds.Width) // only do this if it's static text
            {
                TypeFacePrinter shortTextPrinter = Printer;
                while (shortTextPrinter.LocalBounds.Width > LocalBounds.Width && shortTextPrinter.Text.Length > 4)
                {
                    shortTextPrinter = new TypeFacePrinter(shortTextPrinter.Text.Substring(0, shortTextPrinter.Text.Length - 4).TrimEnd(spaceTrim) + "...", Printer);
                }
                shortTextPrinter.Render(graphics2D, currentColor);
            }
            else
            {
                // it all fits or it's editable (if editable it will need to be offset/scrolled sometimes).
                Printer.Render(graphics2D, currentColor);
            }

            if (debugIt)
            {
                graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Blue);
                graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Blue);
            }

            graphics2D.PopTransform();

            if (debugIt)
            {
                graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Red);
                graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Red);
            }

			base.OnDraw(graphics2D);
		}
示例#4
0
        void EditorDraw(Graphics2D pDestFrame)
        {
            Vector2 WayPointPos = m_pCurWayPoint.GetPosition();
            if (m_pParent != null)
            {
                RGBA_Bytes LineColor = new RGBA_Bytes(128, 128, 128);
                Vector2 ParentPos = m_pParent.m_pCurWayPoint.GetPosition();
                // draw a line back to your parent
                pDestFrame.Line(WayPointPos.x, WayPointPos.y, ParentPos.x, ParentPos.y, LineColor);
            }

            // print out the stats for this point
            int LineSpacing = 12;
            int LineOffset = -LineSpacing;
            string Text = "";

            Text.FormatWith("G: {0:0.0}", m_AccumulatedCostFromStartG);
            pDestFrame.DrawString(Text, WayPointPos.x, WayPointPos.y + LineOffset, justification: Justification.Center);
            LineOffset += LineSpacing;

            Text.FormatWith("H: {0:0.0}", m_EstimatedCostToDestH);
            pDestFrame.DrawString(Text, WayPointPos.x, WayPointPos.y + LineOffset, justification: Justification.Center);
            LineOffset += LineSpacing;

            Text.FormatWith("F: {0:0.0}", m_TotalCostForThisNodeF);
            pDestFrame.DrawString(Text, WayPointPos.x, WayPointPos.y + LineOffset, justification: Justification.Center);
            LineOffset += LineSpacing;
        }
示例#5
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            // get the bounds of all the points
            var bounds = RectangleDouble.ZeroIntersection;

            foreach (var poly in Polygons)
            {
                foreach (var point in poly)
                {
                    bounds.ExpandToInclude(point);
                }
            }

            // prep for scaling
            var transform = Affine.NewTranslation(-bounds.Left, -bounds.Bottom);
            // scale to window
            var scale = Math.Min(Width / bounds.Width, Height / bounds.Height);

            transform *= Affine.NewScaling(scale);
            // scale for boarder
            transform *= Affine.NewScaling(.9);
            // move for boarder
            transform *= Affine.NewTranslation(Width / 20, Height / 20);

            // draw all the triangles
            var index = 0;

            foreach (var poly in Polygons)
            {
                var numPoints = poly.Count;
                if (numPoints > 2)
                {
                    var first         = true;
                    var vertexStorage = new VertexStorage();
                    for (int i = 0; i < numPoints; i++)
                    {
                        var p0 = poly[i];
                        if (first)
                        {
                            vertexStorage.MoveTo(p0);
                            first = false;
                        }
                        else
                        {
                            vertexStorage.LineTo(p0);
                        }
                    }

                    graphics2D.Render(new VertexSourceApplyTransform(vertexStorage, transform), 0, 0, colors[index].WithAlpha(190));
                }
                else if (numPoints > 1)
                {
                    var p0 = poly[numPoints - 1];
                    var p1 = poly[numPoints - 2];
                    graphics2D.Line(transform.Transform(p0), transform.Transform(p1), colors[index]);
                }

                index++;
            }

            base.OnDraw(graphics2D);
        }
示例#6
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			graphics2D.Line(Width / 2, 0, Width / 2, Height, RGBA_Bytes.Red);
			graphics2D.Line(0, Height / 2, Width, Height / 2, RGBA_Bytes.Red);
			base.OnDraw(graphics2D);
		}