예제 #1
0
        protected unsafe void addTex(char chr)
        {
            if (CharTiles.ContainsKey(chr))
            {
                return;
            }
            string text = chr.ToString();

            sizef = tempGr.MeasureString(text, Font, PointF.Empty, StringFormat.GenericTypographic);
            if (sizef.Width <= 0f)
            {
                sizef.Width = sizef.Height / 2f;
            }
            if (bitmap == null || (int)Math.Ceiling(sizef.Width) != bitmap.Width || (int)Math.Ceiling(sizef.Height) != bitmap.Height)
            {
                bitmap = new Bitmap((int)Math.Ceiling(sizef.Width), (int)Math.Ceiling(sizef.Height), PixelFormat.Format32bppArgb);
                gr     = Graphics.FromImage(bitmap);
            }
            else
            {
                gr.Clear(System.Drawing.Color.Empty);
            }
            gr.TextRenderingHint = textRenderingHint;
            gr.DrawString(text, Font, brush, 0f, 0f, StringFormat.GenericTypographic);
            if (bitmap.Height > CurrentMaxHeight)
            {
                CurrentMaxHeight = bitmap.Height;
            }
            if (CurrentLeft + bitmap.Width + 1 > CurrentTex2d.Width)
            {
                CurrentTop += CurrentMaxHeight + 1;
                CurrentLeft = 0;
            }
            if (CurrentTop + CurrentMaxHeight > CurrentTex2d.Height)
            {
                newTex();
            }
            CharTile charTile = new CharTile(CurrentTex2d, new Microsoft.Xna.Framework.Rectangle(CurrentLeft, CurrentTop, bitmap.Width, bitmap.Height));

            CharTiles.Add(chr, charTile);
            int[]      array      = new int[bitmap.Width * bitmap.Height];
            BitmapData bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            int *      ptr        = (int *)(void *)bitmapData.Scan0;

            for (int i = 0; i < array.Length; i++)
            {
                if (*ptr != 0)
                {
                    array[i] = *ptr;
                }
                ptr++;
            }
            bitmap.UnlockBits(bitmapData);
            GDS.GraphicsDevice.Textures[0] = null;
            CurrentTex2d.SetData(0, charTile.rect, array, 0, array.Length);
            CurrentLeft += charTile.rect.Width + 1;
        }
예제 #2
0
        public Vector2 Draw(SpriteBatch sb, string str, Vector2 position, Microsoft.Xna.Framework.Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            Vector2 maxBound = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 vector   = position;
            float   num      = 0f;
            float   num2     = 0f;

            foreach (char c in str)
            {
                addTex(c);
                CharTile charTile = CharTiles[c];
                if (c == '\r' || vector.X + (float)charTile.rect.Width * scale.X > maxBound.X)
                {
                    if (vector.X > num2)
                    {
                        num2 = vector.X;
                    }
                    vector.X  = position.X;
                    vector.Y += num * scale.Y + Spacing.Y * scale.X;
                    num       = 0f;
                }
                else
                {
                    if (c == '\n')
                    {
                        continue;
                    }
                    if ((float)charTile.rect.Height > num)
                    {
                        num = charTile.rect.Height;
                        if (vector.Y + num * scale.Y > maxBound.Y)
                        {
                            break;
                        }
                    }
                    sb?.Draw(charTile.tex, vector, charTile.rect, color, rotation, origin, scale, effects, layerDepth);
                    vector.X += (float)charTile.rect.Width * scale.X + Spacing.X * scale.X;
                }
            }
            if (vector.X > num2)
            {
                num2 = vector.X;
            }
            vector.X  = num2 - Spacing.X * scale.X;
            vector.Y += num * scale.Y;
            return(vector - position);
        }
예제 #3
0
        public Vector2 Draw(SpriteBatch sb, char[] str, Vector2 position, Vector2 maxBound, Vector2 scale, Microsoft.Xna.Framework.Color color)
        {
            if (maxBound.X == 0f)
            {
                maxBound.X = float.MaxValue;
            }
            else
            {
                maxBound.X += position.X;
            }
            if (maxBound.Y == 0f)
            {
                maxBound.Y = float.MaxValue;
            }
            else
            {
                maxBound.Y += position.Y;
            }
            Vector2 vector = position;
            float   num    = 0f;
            float   num2   = 0f;

            foreach (char c in str)
            {
                addTex(c);
                CharTile charTile = CharTiles[c];
                if (c == '\r' || vector.X + (float)charTile.rect.Width * scale.X > maxBound.X)
                {
                    if (vector.X > num2)
                    {
                        num2 = vector.X;
                    }
                    vector.X  = position.X;
                    vector.Y += num * scale.Y + Spacing.Y * scale.X;
                    num       = 0f;
                }
                else
                {
                    if (c == '\n')
                    {
                        continue;
                    }
                    if ((float)charTile.rect.Height > num)
                    {
                        num = charTile.rect.Height;
                        if (vector.Y + num * scale.Y > maxBound.Y)
                        {
                            break;
                        }
                    }
                    sb?.Draw(charTile.tex, vector, charTile.rect, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
                    vector.X += (float)charTile.rect.Width * scale.X + Spacing.X * scale.X;
                }
            }
            if (vector.X > num2)
            {
                num2 = vector.X;
            }
            vector.X  = num2 - Spacing.X * scale.X;
            vector.Y += num * scale.Y;
            return(vector - position);
        }