コード例 #1
0
        private void RefreshCache(FontState state, BitmapFontCache cache)
        {
            if (cache.NeedsRefresh == false)
            {
                return;
            }

            // this variable counts the number of rectangles actually used to display text.
            // It may be less then text.Length because carriage return characters
            // don't need any rects.
            GetRects(cache.SrcRects, cache.DestRects, out cache.DisplayTextLength,
                     state.Text, state.ScaleHeight, state.ScaleWidth);

            Vector2 dest = state.Location;

            if (state.TextAlignment != OriginAlignment.TopLeft)
            {
                Point value = Origin.Calc(state.TextAlignment,
                                          MeasureString(state, state.Text));

                dest.X -= value.X;
                dest.Y -= value.Y;
            }

            for (int i = 0; i < cache.DisplayTextLength; i++)
            {
                cache.DestRects[i].X += (int)dest.X;
                cache.DestRects[i].Y += (int)dest.Y;
            }

            cache.NeedsRefresh = false;
        }
コード例 #2
0
        public override void DrawText(Point dest_pt, string text)
        {
            if (mSprite == null)
            {
                mSprite = new Microsoft.DirectX.Direct3D.Sprite(mD3DFont.Device);
            }

            Point dest = Origin.Calc(DisplayAlignment, StringDisplaySize(text));


            dest_pt.X -= dest.X;
            dest_pt.Y -= dest.Y;

            double scalex, scaley;

            GetScale(out scalex, out scaley);

            mDisplay.D3D_Device.DrawBuffer.Flush();
            mDisplay.D3D_Device.SetFontRenderState();

            mSprite.Begin(SpriteFlags.AlphaBlend);
            mSprite.Transform = Matrix.Scaling((float)scalex, (float)scaley, 1.0f)
                                * Matrix.Translation(dest_pt.X, dest_pt.Y, 0);

            mD3DFont.DrawText(mSprite, text, new System.Drawing.Point(0, 0), Color.ToArgb());

            mSprite.End();
        }
コード例 #3
0
        private void DrawTextImpl(int destX, int destY, string text,
                                  RectangleF[] srcRects, RectangleF[] destRects)
        {
            // this variable counts the number of rectangles actually used to display text.
            // It may be less then text.Length because carriage return characters
            // don't need any rects.
            int displayTextLength;

            GetRects(text, srcRects, destRects, out displayTextLength);

            if (DisplayAlignment != OriginAlignment.TopLeft)
            {
                Point value = Origin.Calc(DisplayAlignment, StringDisplaySize(text));

                destX -= value.X;
                destY -= value.Y;
            }

            for (int i = 0; i < displayTextLength; i++)
            {
                destRects[i].X += destX;
                destRects[i].Y += destY;
            }

            mSurface.DrawRects(srcRects, destRects, 0, displayTextLength);
        }