Set() public méthode

public Set ( float x, float y, float w, float h, System.Color color, System.Vector2 texCoordTL, System.Vector2 texCoordBR ) : void
x float
y float
w float
h float
color System.Color
texCoordTL System.Vector2
texCoordBR System.Vector2
Résultat void
Exemple #1
0
        public void Draw(Texture2D texture,
                         Vector2 position,
                         Color color)
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            // texture 0 is the texture beeing draw
            graphicsDevice.Textures [0] = texture;

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = 0;
            item.TextureID = (int)texture.ID;

            tempRect.X      = 0;
            tempRect.Y      = 0;
            tempRect.Width  = texture.Width;
            tempRect.Height = texture.Height;

            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL.X = tempRect.X * texWidthRatio;
                //texCoordTL.Y = (tempRect.Y + tempRect.Height) * texHeightRatio;
                texCoordTL.Y = 1.0f - tempRect.Y * texHeightRatio;

                texCoordBR.X = (tempRect.X + tempRect.Width) * texWidthRatio;
                //texCoordBR.Y = tempRect.Y * texHeightRatio;
                texCoordBR.Y = 1.0f - (tempRect.Y + tempRect.Height) * texHeightRatio;
            }
            else
            {
                texCoordTL.X = texture.Image.GetTextureCoordX(tempRect.X);
                texCoordTL.Y = texture.Image.GetTextureCoordY(tempRect.Y);
                texCoordBR.X = texture.Image.GetTextureCoordX(tempRect.X + tempRect.Width);
                texCoordBR.Y = texture.Image.GetTextureCoordY(tempRect.Y + tempRect.Height);
            }

            item.Set(position.X,
                     position.Y,
                     tempRect.Width,
                     tempRect.Height,
                     color,
                     texCoordTL,
                     texCoordBR);
        }
Exemple #2
0
        public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle?sourceRectangle, Color color)
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = 0.0f;
            item.TextureID = (int)texture.ID;

            if (sourceRectangle.HasValue)
            {
                tempRect = sourceRectangle.Value;
            }
            else
            {
                tempRect.X      = 0;
                tempRect.Y      = 0;
                tempRect.Width  = texture.Width;
                tempRect.Height = texture.Height;
            }

            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL.X = tempRect.X * texWidthRatio;
                texCoordTL.Y = (tempRect.Y + tempRect.Height) * texHeightRatio;

                texCoordBR.X = (tempRect.X + tempRect.Width) * texWidthRatio;
                texCoordBR.Y = tempRect.Y * texHeightRatio;
            }
            else
            {
                texCoordTL.X = texture.Image.GetTextureCoordX(tempRect.X);
                texCoordTL.Y = texture.Image.GetTextureCoordY(tempRect.Y);
                texCoordBR.X = texture.Image.GetTextureCoordX(tempRect.X + tempRect.Width);
                texCoordBR.Y = texture.Image.GetTextureCoordY(tempRect.Y + tempRect.Height);
            }

            item.Set(destinationRectangle.X,
                     destinationRectangle.Y,
                     destinationRectangle.Width,
                     destinationRectangle.Height,
                     color,
                     texCoordTL,
                     texCoordBR);
        }
Exemple #3
0
        public void Draw
        (
            Texture2D texture,
            Vector2 position,
            Color color
        )
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = 0;
            item.TextureID = (int)texture.ID;

            Rectangle rect = new Rectangle(0, 0, texture.Width, texture.Height);

            Vector2 texCoordTL;            // = texture.Image.GetTextureCoord ( rect.X, rect.Y );
            Vector2 texCoordBR;            // = texture.Image.GetTextureCoord ( rect.X+rect.Width, rect.Y+rect.Height );


            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL = new Vector2(rect.X * texWidthRatio, (rect.Y + rect.Height) * texHeightRatio);
                texCoordBR = new Vector2((rect.X + rect.Width) * texWidthRatio,
                                         rect.Y * texHeightRatio);
            }
            else
            {
                texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
                texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);
            }

            item.Set
            (
                position.X,
                position.Y,
                rect.Width,
                rect.Height,
                color,
                texCoordTL,
                texCoordBR
            );
        }
Exemple #4
0
        public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color)
        {
            if (spriteFont == null)
            {
                throw new ArgumentException("spriteFont");
            }

            Vector2 p = position;

            foreach (char c in text)
            {
                if (c == '\n')
                {
                    p.Y += spriteFont.LineSpacing;
                    p.X  = position.X;
                    continue;
                }
                if (spriteFont.characterData.ContainsKey(c) == false)
                {
                    continue;
                }
                GlyphData g = spriteFont.characterData[c];

                SpriteBatchItem item = _batcher.CreateBatchItem();

                item.Depth     = 0.0f;
                item.TextureID = (int)spriteFont._texture.ID;

                texCoordTL.X = spriteFont._texture.Image.GetTextureCoordX(g.Glyph.X);
                texCoordTL.Y = spriteFont._texture.Image.GetTextureCoordY(g.Glyph.Y);
                texCoordBR.X = spriteFont._texture.Image.GetTextureCoordX(g.Glyph.X + g.Glyph.Width);
                texCoordBR.Y = spriteFont._texture.Image.GetTextureCoordY(g.Glyph.Y + g.Glyph.Height);

                item.Set
                (
                    p.X,
                    p.Y + g.Cropping.Y,
                    g.Glyph.Width,
                    g.Glyph.Height,
                    color,
                    texCoordTL,
                    texCoordBR
                );

                p.X += (g.Kerning.Y + g.Kerning.Z + spriteFont.Spacing);
            }
        }
Exemple #5
0
        internal void DrawInternal(Texture2D texture, Vector4 destinationRectangle, Rectangle?sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effect, float depth)
        {
            SpriteBatchItem batchItem = this._batcher.CreateBatchItem();

            batchItem.Depth   = depth;
            batchItem.Texture = texture;
            if (sourceRectangle.HasValue)
            {
                this._tempRect = sourceRectangle.Value;
            }
            else
            {
                this._tempRect.X      = 0;
                this._tempRect.Y      = 0;
                this._tempRect.Width  = texture.Width;
                this._tempRect.Height = texture.Height;
            }
            this._texCoordTL.X = (float)this._tempRect.X / (float)texture.Width;
            this._texCoordTL.Y = (float)this._tempRect.Y / (float)texture.Height;
            this._texCoordBR.X = (float)(this._tempRect.X + this._tempRect.Width) / (float)texture.Width;
            this._texCoordBR.Y = (float)(this._tempRect.Y + this._tempRect.Height) / (float)texture.Height;
            if ((effect & SpriteEffects.FlipVertically) != SpriteEffects.None)
            {
                float num = this._texCoordBR.Y;
                this._texCoordBR.Y = this._texCoordTL.Y;
                this._texCoordTL.Y = num;
            }
            if ((effect & SpriteEffects.FlipHorizontally) != SpriteEffects.None)
            {
                float num = this._texCoordBR.X;
                this._texCoordBR.X = this._texCoordTL.X;
                this._texCoordTL.X = num;
            }
            batchItem.Set(destinationRectangle.X, destinationRectangle.Y, -origin.X, -origin.Y, destinationRectangle.Z, destinationRectangle.W, (float)Math.Sin((double)rotation), (float)Math.Cos((double)rotation), color, this._texCoordTL, this._texCoordBR);
            if (this._sortMode != SpriteSortMode.Immediate)
            {
                return;
            }
            this._batcher.DrawBatch(this._sortMode);
        }
Exemple #6
0
        public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle?sourceRectangle, Color color)
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = 0.0f;
            item.TextureID = (int)texture.ID;

            Rectangle rect;

            if (sourceRectangle.HasValue)
            {
                rect = sourceRectangle.Value;
            }
            else
            {
                rect = new Rectangle(0, 0, texture.Image.ImageWidth, texture.Image.ImageHeight);
            }

            Vector2 texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
            Vector2 texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);

            item.Set
            (
                destinationRectangle.X,
                destinationRectangle.Y,
                destinationRectangle.Width,
                destinationRectangle.Height,
                color,
                texCoordTL,
                texCoordBR);
        }
Exemple #7
0
        public void Draw(Texture2D texture,
                         Rectangle destinationRectangle,
                         Nullable <Rectangle> sourceRectangle,
                         Color color,
                         float rotation,
                         Vector2 origin,
                         SpriteEffects effect,
                         float depth)
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            // texture 0 is the texture beeing draw
            graphicsDevice.Textures[0] = texture;

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            if (sourceRectangle.HasValue)
            {
                tempRect = sourceRectangle.Value;
            }
            else
            {
                tempRect.X      = 0;
                tempRect.Y      = 0;
                tempRect.Width  = texture.Width;
                tempRect.Height = texture.Height;
            }

            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL.X = tempRect.X * texWidthRatio;
                //texCoordTL.Y = (tempRect.Y + tempRect.Height) * texHeightRatio;
                texCoordTL.Y = 1.0f - tempRect.Y * texHeightRatio;

                texCoordBR.X = (tempRect.X + tempRect.Width) * texWidthRatio;
                //texCoordBR.Y = tempRect.Y * texHeightRatio;
                texCoordBR.Y = 1.0f - (tempRect.Y + tempRect.Height) * texHeightRatio;
            }
            else
            {
                texCoordTL.X = texture.Image.GetTextureCoordX(tempRect.X);
                texCoordTL.Y = texture.Image.GetTextureCoordY(tempRect.Y);
                texCoordBR.X = texture.Image.GetTextureCoordX(tempRect.X + tempRect.Width);
                texCoordBR.Y = texture.Image.GetTextureCoordY(tempRect.Y + tempRect.Height);
            }

            if ((effect & SpriteEffects.FlipVertically) != 0)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            if ((effect & SpriteEffects.FlipHorizontally) != 0)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set(destinationRectangle.X,
                     destinationRectangle.Y,
                     -origin.X,
                     -origin.Y,
                     destinationRectangle.Width,
                     destinationRectangle.Height,
                     (float)Math.Sin(rotation),
                     (float)Math.Cos(rotation),
                     color,
                     texCoordTL,
                     texCoordBR);
        }
Exemple #8
0
        public void DrawString
        (
            SpriteFont spriteFont,
            string text,
            Vector2 position,
            Color color,
            float rotation,
            Vector2 origin,
            Vector2 scale,
            SpriteEffects effects,
            float depth
        )
        {
            if (spriteFont == null)
            {
                throw new ArgumentException("spriteFont");
            }

            Vector2 p = new Vector2(-origin.X, -origin.Y);

            float sin = (float)Math.Sin(rotation);
            float cos = (float)Math.Cos(rotation);

            foreach (char c in text)
            {
                if (c == '\n')
                {
                    p.Y += spriteFont.LineSpacing;
                    p.X  = -origin.X;
                    continue;
                }
                if (spriteFont.characterData.ContainsKey(c) == false)
                {
                    continue;
                }
                GlyphData g = spriteFont.characterData[c];

                SpriteBatchItem item = _batcher.CreateBatchItem();

                item.Depth     = depth;
                item.TextureID = (int)spriteFont._texture.ID;

                Vector2 texCoordTL = spriteFont._texture.Image.GetTextureCoord(g.Glyph.X, g.Glyph.Y);
                Vector2 texCoordBR = spriteFont._texture.Image.GetTextureCoord(g.Glyph.X + g.Glyph.Width, g.Glyph.Y + g.Glyph.Height);

                if (effects == SpriteEffects.FlipVertically)
                {
                    float temp = texCoordBR.Y;
                    texCoordBR.Y = texCoordTL.Y;
                    texCoordTL.Y = temp;
                }
                else if (effects == SpriteEffects.FlipHorizontally)
                {
                    float temp = texCoordBR.X;
                    texCoordBR.X = texCoordTL.X;
                    texCoordTL.X = temp;
                }

                item.Set
                (
                    position.X,
                    position.Y,
                    p.X * scale.X,
                    (p.Y + g.Cropping.Y) * scale.Y,
                    g.Glyph.Width * scale.X,
                    g.Glyph.Height * scale.Y,
                    sin,
                    cos,
                    color,
                    texCoordTL,
                    texCoordBR
                );

                p.X += (g.Kerning.Y + g.Kerning.Z + spriteFont.Spacing);
            }
        }
Exemple #9
0
        public void Draw(
            Texture2D texture,
            Rectangle destinationRectangle,
            Nullable <Rectangle> sourceRectangle,
            Color color,
            float rotation,
            Vector2 origin,
            SpriteEffects effect,
            float depth
            )
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            Rectangle rect;

            if (sourceRectangle.HasValue)
            {
                rect = sourceRectangle.Value;
            }
            else
            {
                rect = new Rectangle(0, 0, texture.Image.ImageWidth, texture.Image.ImageHeight);
            }

            Vector2 texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
            Vector2 texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);

            if (effect == SpriteEffects.FlipVertically)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            else if (effect == SpriteEffects.FlipHorizontally)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set
            (
                destinationRectangle.X,
                destinationRectangle.Y,
                -origin.X,
                -origin.Y,
                destinationRectangle.Width,
                destinationRectangle.Height,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                texCoordTL,
                texCoordBR);
        }
Exemple #10
0
        internal void DrawInternal(
            Texture2D texture,
            Vector4 destinationRectangle,
            Rectangle?sourceRectangle,
            Color color,
            float rotation,
            Vector2 origin,
            SpriteEffects effect,
            float depth,
            bool autoFlush
            )
        {
            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth   = depth;
            item.Texture = texture;

            if (sourceRectangle.HasValue)
            {
                _tempRect = sourceRectangle.Value;
            }
            else
            {
                _tempRect.X      = 0;
                _tempRect.Y      = 0;
                _tempRect.Width  = texture.Width;
                _tempRect.Height = texture.Height;
            }

            _texCoordTL.X = _tempRect.X / (float)texture.Width;
            _texCoordTL.Y = _tempRect.Y / (float)texture.Height;
            _texCoordBR.X = (_tempRect.X + _tempRect.Width) / (float)texture.Width;
            _texCoordBR.Y = (_tempRect.Y + _tempRect.Height) / (float)texture.Height;

            if ((effect & SpriteEffects.FlipVertically) != 0)
            {
                float temp = _texCoordBR.Y;
                _texCoordBR.Y = _texCoordTL.Y;
                _texCoordTL.Y = temp;
            }
            if ((effect & SpriteEffects.FlipHorizontally) != 0)
            {
                float temp = _texCoordBR.X;
                _texCoordBR.X = _texCoordTL.X;
                _texCoordTL.X = temp;
            }

            item.Set(
                destinationRectangle.X,
                destinationRectangle.Y,
                -origin.X,
                -origin.Y,
                destinationRectangle.Z,
                destinationRectangle.W,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                _texCoordTL,
                _texCoordBR
                );

            if (autoFlush)
            {
                FlushIfNeeded();
            }
        }
Exemple #11
0
        public void Draw(
            Texture2D texture,
            Rectangle destinationRectangle,
            Nullable <Rectangle> sourceRectangle,
            Color color,
            float rotation,
            Vector2 origin,
            SpriteEffects effect,
            float depth
            )
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            Rectangle rect;

            if (sourceRectangle.HasValue)
            {
                rect = sourceRectangle.Value;
            }
            else
            {
                rect = new Rectangle(0, 0, texture.Width, texture.Height);
            }

            Vector2 texCoordTL;            // = texture.Image.GetTextureCoord ( rect.X, rect.Y );
            Vector2 texCoordBR;            // = texture.Image.GetTextureCoord ( rect.X+rect.Width, rect.Y+rect.Height );


            if (texture.Image == null)
            {
                float texWidthRatio  = 1.0f / (float)texture.Width;
                float texHeightRatio = 1.0f / (float)texture.Height;
                // We are initially flipped vertically so we need to flip the corners so that
                //  the image is bottom side up to display correctly
                texCoordTL = new Vector2(rect.X * texWidthRatio, (rect.Y + rect.Height) * texHeightRatio);
                texCoordBR = new Vector2((rect.X + rect.Width) * texWidthRatio,
                                         rect.Y * texHeightRatio);
            }
            else
            {
                texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
                texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);
            }
            if (effect == SpriteEffects.FlipVertically)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            else if (effect == SpriteEffects.FlipHorizontally)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set
            (
                destinationRectangle.X,
                destinationRectangle.Y,
                -origin.X,
                -origin.Y,
                destinationRectangle.Width,
                destinationRectangle.Height,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                texCoordTL,
                texCoordBR);
        }