コード例 #1
0
ファイル: Font.cs プロジェクト: jrs1498/GDDGame1
        public void Draw(string text, SpriteBatch spriteBatch, Vector2 position, Color color, Rectangle scissor)
        {
            bool      newLine         = true;
            Vector2   overallPosition = Vector2.Zero;
            Rectangle source;
            Rectangle destination;
            Vector2   charPosition;

            for (int i = 0; i < text.Length; i++)
            {
                // Work out current character
                char character      = text[i];
                int  characterIndex = this.GetCharacterIndex(character);

                Vector3 charKerning = this.kerning[characterIndex];

                if (newLine)
                {
                    charKerning.X = Math.Max(charKerning.X, 0f);
                }
                else
                {
                    overallPosition.X += this.spacing;
                }

                overallPosition.X += charKerning.X;

                source = this.glyphData[characterIndex];

                charPosition    = overallPosition;
                charPosition.X += this.croppingData[characterIndex].X;
                charPosition.Y += this.croppingData[characterIndex].Y;

                charPosition += position;

                destination = new Rectangle((int)charPosition.X, (int)charPosition.Y, source.Width, source.Height);

                if (GUIManager.PerformClipping(ref scissor, ref source, ref destination))
                {
                    spriteBatch.Draw(this.textureValue, destination, source, Color.Black);
                }

                newLine            = false;
                overallPosition.X += charKerning.Y + charKerning.Z;
            }
        }
コード例 #2
0
        /// <summary>
        /// Draws all skins associated with control, after clipping them to the
        /// parent control area.
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch to draw with.</param>
        /// <param name="parentScissor">The scissor region of the parent control.</param>
        protected override void DrawControl(SpriteBatch spriteBatch, Rectangle scissor)
        {
            ComponentSkin skin = GetSkin(this.currentSkin);

            if (skin != null)
            {
                Texture2D texture;

                // Should the default GUI skin be used?
                if (skin.UseCustomSkin)
                {
                    texture = skin.Skin;
                }
                else
                {
                    texture = GUIManager.SkinTexture;
                }

                Rectangle source;
                Rectangle destination;

                foreach (GUIRect rect in skin.Rects)
                {
                    source = rect.Source;

                    // Convert to absolute position
                    destination    = rect.Destination;
                    destination.X += AbsolutePosition.X;
                    destination.Y += AbsolutePosition.Y;

                    if (GUIManager.PerformClipping(ref scissor, ref source, ref destination))
                    {
                        // Actually draw!
                        spriteBatch.Draw(
                            texture,
                            destination,
                            source,
                            Color.White
                            );
                    }
                }
            }
        }