コード例 #1
0
ファイル: DXSprite.cs プロジェクト: Radviger/MultiV
        public void DrawString(int X, int Y, string text, System.Drawing.Color color, DXFont F)
        {
            Color4 blendFactor = new Color4(1.0f);
            Color4 backupBlendFactor;
            int    backupMask;

            using (var backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask))
            {
                _deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor);

                BeginBatch(F.GetFontSheetSRV());


                int length = text.Length;

                int posX = X;
                int posY = Y;

                Color4 color4 = ToColor4(color);

                for (int i = 0; i < length; ++i)
                {
                    char character = text[i];

                    if (character == ' ')
                    {
                        posX += F.GetSpaceWidth();
                    }
                    else if (character == '\n')
                    {
                        posX  = X;
                        posY += F.GetCharHeight();
                    }
                    else
                    {
                        Rectangle charRect = F.GetCharRect(character);

                        int width  = charRect.Right - charRect.Left;
                        int height = charRect.Bottom - charRect.Top;

                        Draw(new Rectangle(posX, posY, width, height), charRect, color4);

                        posX += width + 1;
                    }
                }

                EndBatch();
                _deviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask);
            }
        }