Ejemplo n.º 1
0
        private void AddNew(ShaderResourceView Texture, SpriteVertexLayout.Struct Data)
        {
            //Create new segment with initial values
            var NewSegment = new SpriteSegment();

            NewSegment.Texture = Texture;
            NewSegment.Sprites.Add(Data);
            Sprites.Add(NewSegment);

            //Create reference for segment in dictionary
            if (!TextureSprites.ContainsKey(Texture))
            {
                TextureSprites.Add(Texture, new List <SpriteSegment>());
            }

            TextureSprites[Texture].Add(NewSegment);
            CheckForFullBuffer();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws a region of a texture on the screen.
        /// </summary>
        /// <param name="Texture">The shader resource view of the texture to draw</param>
        /// <param name="Position">Position of the top left corner of the texture in the chosen coordinate system</param>
        /// <param name="Size">Size of the texture in the chosen coordinate system</param>
        /// <param name="CoordinateType">A custom coordinate system in which to draw the texture</param>
        /// <param name="Color">The color with which to multiply the texture</param>
        /// <param name="TexCoords">Texture coordinates for the top left corner</param>
        /// <param name="TexCoordsSize">Size of the region in texture coordinates</param>
        public void Draw(ShaderResourceView Texture, Vector2 Position, Vector2 Size, Vector2 TexCoords, Vector2 TexCoordsSize, Color4 Color, CoordinateType CoordinateType)
        {
            if (Texture == null)
            {
                return;
            }
            var Data = new SpriteVertexLayout.Struct();

            Data.Position     = ConvertCoordinate(Position, CoordinateType);
            Data.Size         = ConvertCoordinate(Position + Size, CoordinateType) - Data.Position;
            Data.Size.X       = Math.Abs(Data.Size.X);
            Data.Size.Y       = Math.Abs(Data.Size.Y);
            Data.TexCoord     = TexCoords;
            Data.TexCoordSize = TexCoordsSize;
            Data.Color        = Color.ToArgb();

            if (AllowReorder)
            {
                //Is there already a sprite for this texture?
                if (TextureSprites.ContainsKey(Texture))
                {
                    //Add the sprite to the last segment for this texture
                    var Segment = TextureSprites[Texture].Last();
                    AddIn(Segment, Data);
                }
                else
                {
                    //Add a new segment for this texture
                    AddNew(Texture, Data);
                }
            }
            else
            {
                //Add a new segment for this texture
                AddNew(Texture, Data);
            }
        }
Ejemplo n.º 3
0
 private void AddIn(SpriteSegment Segment, SpriteVertexLayout.Struct Data)
 {
     Segment.Sprites.Add(Data);
     CheckForFullBuffer();
 }