Exemplo n.º 1
0
        /// <summary>
        /// Draws a rectangle using top left and bottom right point with specified colors for each corner.
        /// </summary>
        public static void Draw(float x1, float y1, float x2, float y2, bool isOutline, Color c1, Color c2, Color c3, Color c4)
        {
            GraphicsMode mode;

            short[] indices;
            if (isOutline)
            {
                mode    = GraphicsMode.LinePrimitives;
                indices = _rectangleIndices[1];
            }
            else
            {
                mode    = GraphicsMode.TrianglePrimitives;
                indices = _rectangleIndices[0];
            }

            var vertices = new List <VertexPositionColorTexture>
            {
                new VertexPositionColorTexture(new Vector3(x1, y1, 0), c1, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x2, y1, 0), c2, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x2, y2, 0), c3, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x1, y2, 0), c4, Vector2.Zero)
            };

            GraphicsMgr.AddVertices(mode, null, vertices, indices);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws text in specified coordinates with rotation, scale and origin.
        /// </summary>
        public static void Draw(string text, float x, float y, float scaleX, float scaleY, float originX = 0, float originY = 0, float rotation = 0)
        {
            if (CurrentFont == null)
            {
                throw new NullReferenceException("CurrentFont is null! Did you forgot to set a font?");
            }

            var transformMatrix =
                Matrix.CreateTranslation(new Vector3(-originX, -originY, 0)) *                 // Origin.
                Matrix.CreateRotationZ(MathHelper.ToRadians(-rotation)) *                      // Rotation.
                Matrix.CreateScale(new Vector3(scaleX, scaleY, 1)) *                           // Scale.
                Matrix.CreateTranslation(new Vector3(x, y, 0));                                // Position.

            GraphicsMgr.AddTransformMatrix(transformMatrix);

            /*
             * Font is a wrapper for MG's SpriteFont, which uses non-premultiplied alpha.
             * Using GraphicsMode.Sprites will result in black pixels everywhere.
             * TextureFont, on the other hand, is just regular sprites, so it's fine to
             * draw with sprite mode.
             */
            if (CurrentFont is Font)
            {
                GraphicsMgr.SwitchGraphicsMode(GraphicsMode.SpritesNonPremultiplied);
            }
            else
            {
                GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);
            }

            CurrentFont.Draw(GraphicsMgr.Batch, text, Vector2.Zero, HorAlign, VerAlign);

            GraphicsMgr.ResetTransformMatrix();
        }
Exemplo n.º 3
0
        public void Draw(Vector2 position, Vector2 origin, Vector2 scale, float rotation, Color color)
        {
            var mirroring = SpriteEffects.None;

            // Proper negative scaling.
            var scaleOffset = Vector2.Zero;

            if (scale.X < 0)
            {
                mirroring     = mirroring | SpriteEffects.FlipHorizontally;
                scale.X      *= -1;
                scaleOffset.X = Width;
            }

            if (scale.Y < 0)
            {
                mirroring     = mirroring | SpriteEffects.FlipVertically;
                scale.Y      *= -1;
                scaleOffset.Y = Height;
            }
            // Proper negative scaling.

            GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);
            GraphicsMgr.Batch.Draw(
                RenderTarget,
                position,
                RenderTarget.Bounds,
                color,
                MathHelper.ToRadians(rotation),
                scaleOffset + origin,
                scale,
                mirroring,
                0
                );
        }
Exemplo n.º 4
0
		public void Draw()
		{
			GraphicsMgr.AddVertices(
				_graphicsMode, 
				_texture, 
				GetConvertedVertices(), 
				GetIndices()
			);
		}
Exemplo n.º 5
0
        public void Draw(Rectangle destRect, Rectangle srcRect)
        {
            GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);

            srcRect.X += RenderTarget.Bounds.X;
            srcRect.Y += RenderTarget.Bounds.Y;

            GraphicsMgr.Batch.Draw(RenderTarget, destRect, srcRect, GraphicsMgr.CurrentColor);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draws a line with specified colors.
        /// </summary>
        public static void Draw(float x1, float y1, float x2, float y2, Color c1, Color c2)
        {
            var vertices = new List <VertexPositionColorTexture>
            {
                new VertexPositionColorTexture(new Vector3(x1, y1, 0), c1, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x2, y2, 0), c2, Vector2.Zero)
            };

            GraphicsMgr.AddVertices(GraphicsMode.LinePrimitives, null, vertices, new short[] { 0, 1 });
        }
Exemplo n.º 7
0
 public void Draw(Rectangle destRect, float rotation, Color color)
 {
     GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);
     GraphicsMgr.Batch.Draw(
         RenderTarget,
         destRect,
         RenderTarget.Bounds,
         color,
         rotation,
         Vector2.Zero,
         SpriteEffects.None,
         0
         );
 }
Exemplo n.º 8
0
        /// <summary>
        /// Draws a line with specified width and colors.
        /// </summary>
        public static void Draw(float x1, float y1, float x2, float y2, float thickness, Color c1, Color c2)
        {
            var normal2 = new Vector2(y2 - y1, x1 - x2);

            normal2  = normal2.GetSafeNormalize();            // The result is a unit vector rotated by 90 degrees.
            normal2 *= thickness / 2;

            var normal = normal2.ToVector3();

            var vertices = new List <VertexPositionColorTexture>
            {
                new VertexPositionColorTexture(new Vector3(x1, y1, 0) - normal, c1, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x1, y1, 0) + normal, c1, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x2, y2, 0) + normal, c2, Vector2.Zero),
                new VertexPositionColorTexture(new Vector3(x2, y2, 0) - normal, c2, Vector2.Zero)
            };

            // Thick line is in fact just a rotated rectangle.
            GraphicsMgr.AddVertices(GraphicsMode.TrianglePrimitives, null, vertices, _thickLineIndices);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Draws text in specified coordinates.
        /// </summary>
        public static void Draw(string text, Vector2 position)
        {
            if (CurrentFont == null)
            {
                throw new NullReferenceException("CurrentFont is null! Did you forgot to set a font?");
            }

            /*
             * Font is a wrapper for MG's SpriteFont, which uses non-premultiplied alpha.
             * Using GraphicsMode.Sprites will result in black pixels everywhere.
             * TextureFont, on the other hand, is just a bunch of regular sprites,
             * so it's fine to draw with sprite mode.
             */
            if (CurrentFont is Font)
            {
                GraphicsMgr.SwitchGraphicsMode(GraphicsMode.SpritesNonPremultiplied);
            }
            else
            {
                GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);
            }
            CurrentFont.Draw(GraphicsMgr.Batch, text, position, HorAlign, VerAlign);
        }
Exemplo n.º 10
0
        // Vectors.

        public void Draw(Vector2 position)
        {
            GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);
            GraphicsMgr.Batch.Draw(RenderTarget, position, GraphicsMgr.CurrentColor);
        }
Exemplo n.º 11
0
        // Vectors.

        // Rectangles.

        public void Draw(Rectangle destRect)
        {
            GraphicsMgr.SwitchGraphicsMode(GraphicsMode.Sprites);
            GraphicsMgr.Batch.Draw(RenderTarget, destRect, RenderTarget.Bounds, GraphicsMgr.CurrentColor);
        }