Ejemplo n.º 1
0
        /// <summary>
        /// 用一个纹理绘制指定范围内的所有可见字符
        /// </summary>
        /// <param name="ttfFullname"></param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar"></param>
        /// <param name="lastChar"></param>
        /// <param name="maxTextureWidth">生成的纹理的最大宽度。</param>
        /// <returns></returns>
        public static IEnumerable <TTFTextureYeildingState> GetTTFTexture(
            string ttfFullname, int fontHeight, int maxTextureWidth, char firstChar, char lastChar)
        {
            FreeTypeLibrary library = new FreeTypeLibrary();

            FreeTypeFace face = new FreeTypeFace(library, ttfFullname);

            FullDictionary <char, CharacterInfo> charInfoDict = null;
            int textureWidth = 0, textureHeight = 0;

            System.Drawing.Bitmap bigBitmap = null;

            foreach (var item in GetTextureBlueprint(face, fontHeight, maxTextureWidth, firstChar, lastChar))
            {
                charInfoDict  = item.dict;
                textureWidth  = item.textureWidth;
                textureHeight = item.textureHeight;

                yield return(item);
            }

            if (textureWidth == 0)
            {
                textureWidth = 1;
            }
            if (textureHeight == 0)
            {
                textureHeight = 1;
            }

            foreach (var item in GetBigBitmap(face, fontHeight, maxTextureWidth,
                                              firstChar, lastChar, charInfoDict, textureWidth, textureHeight))
            {
                bigBitmap = item.bigBitmap;

                yield return(item);
            }

            face.Dispose();
            library.Dispose();

            var result = new FontTexture()
            {
                TtfFullname  = ttfFullname,
                FontHeight   = fontHeight,
                FirstChar    = firstChar,
                LastChar     = lastChar,
                BigBitmap    = bigBitmap,
                CharInfoDict = charInfoDict,
            };

            FileInfo fileInfo = new FileInfo(ttfFullname);

            yield return(new TTFTextureYeildingState()
            {
                percent = 100,
                ttfTexture = result,
                message = string.Format("got font texture for {0}", fileInfo.Name),
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 用一个纹理绘制指定范围内的所有可见字符
        /// </summary>
        /// <param name="ttfFullname"></param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar"></param>
        /// <param name="lastChar"></param>
        /// <param name="maxTextureWidth">生成的纹理的最大宽度。</param>
        /// <returns></returns>
        public static FontTexture GetTTFTexture(string ttfFullname, int fontHeight, int maxTextureWidth, char firstChar, char lastChar)
        {
            FreeTypeLibrary library = new FreeTypeLibrary();

            FreeTypeFace face = new FreeTypeFace(library, ttfFullname);

            FullDictionary <char, CharacterInfo> charInfoDict;
            int textureWidth, textureHeight;

            GetTextureBlueprint(face, fontHeight, maxTextureWidth, firstChar, lastChar, out charInfoDict, out textureWidth, out textureHeight);

            if (textureWidth == 0)
            {
                textureWidth = 1;
            }
            if (textureHeight == 0)
            {
                textureHeight = 1;
            }

            System.Drawing.Bitmap bigBitmap = GetBigBitmap(face, fontHeight, maxTextureWidth, firstChar, lastChar, charInfoDict, textureWidth, textureHeight);

            face.Dispose();
            library.Dispose();

            var result = new FontTexture()
            {
                TtfFullname = ttfFullname, FontHeight = fontHeight, FirstChar = firstChar, LastChar = lastChar, BigBitmap = bigBitmap, CharInfoDict = charInfoDict,
            };

            return(result);
        }
Ejemplo n.º 3
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            GameData    = new GamePersistance <GameData>(this);
            Pixel       = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            Pixel.SetData(new[] { Color.White });
            Textures.LoadContent(Content);
            Font = new FontTexture(Content.Load <Texture2D>(@"Images\EditSysLarge.png"), 58, 8, -10, new[]
            {
                26, 22, 36, 36, 50, 47, 40, 21, 28, 28, 29, 33, 26, 40, 22, 47,
                47, 33, 47, 47, 47, 47, 47, 47, 47, 47, 26, 26, 51, 40, 46, 47,
                47, 47, 47, 47, 47, 47, 47, 47, 47, 26, 47, 47, 47, 47, 47, 47,
                47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 29, 47, 29, 33, 47,
                26, 31, 33, 30, 33, 32, 28, 33, 31, 22, 26, 32, 21, 40, 31, 24,
                33, 33, 27, 29, 28, 31, 33, 40, 32, 33, 31, 33, 21, 33, 33, 31
            });
            Mouse          = new MouseInput();
            IsMouseVisible = false;

            Touch         = new TouchInput();
            UnifiedInput  = new UnifiedInput(this);
            KeyboardInput = new KeyboardInput(this);
            UnifiedInput.TapListeners.Add(Tap);
            Branding.BackgroundColor = Color.Black;
            Audio.Play(Cues.Music01, AudioChannels.Music, true);
            _currentComponent = new Intro(this, null);
        }
Ejemplo n.º 4
0
        void generateLyric(Lyric lyric)
        {
            var maroonColour = new Color4(128, 0, 0, 255);
            var startingRot  = ConvertToRadians(-15);
            var FontScale    = 0.35f;
            var lineWidth    = 0f;

            foreach (var character in lyric.sentence)
            {
                //var pos = new Vector2(lyric.posX,lyric.posY) + ;
                FontTexture texture = lyricFont.GetTexture(character.ToString());
                lineWidth += texture.BaseWidth * FontScale;
            }
            var letterX = lyric.posX - lineWidth * 0.5f;

            foreach (var character in lyric.sentence)
            {
                FontTexture texture = lyricFont.GetTexture(character.ToString());
                if (!texture.IsEmpty)
                {
                    var position = new Vector2((float)Math.Cos(startingRot) * letterX + lyric.posX,
                                               (float)Math.Sin(startingRot) * letterX + lyric.posY)
                                   + texture.OffsetFor(OsbOrigin.Centre) * FontScale;

                    //position = new Vector2(lyric.posX + (float)Math.Cos(letterX));
                    var sprite = GetLayer("").CreateSprite(texture.Path, OsbOrigin.Centre, position);
                    sprite.Rotate(lyric.startTime - 200, lyric.endTime, startingRot, ConvertToRadians(Random(-25, 0)));
                    sprite.Scale(lyric.startTime, FontScale);
                    sprite.Fade(lyric.startTime - 200, lyric.startTime, 0, 1);
                    sprite.Fade(lyric.endTime - 200, lyric.endTime, 1, 0);
                }
                letterX += texture.BaseWidth * FontScale;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 根据已经生成的贴图和附带的Xml配置文件得到一个<see cref="FontTexture"/>。
        /// <para>此贴图和Xml文件</para>
        /// </summary>
        /// <param name="textureFullname"></param>
        /// <param name="xmlFullname"></param>
        /// <returns></returns>
        public static FontTexture GetTTFTexture(string textureFullname, string xmlFullname)
        {
            XElement    ttfTextureElement = XElement.Load(xmlFullname); //new XElement(xmlFullname);
            FontTexture result            = Parse(ttfTextureElement);

            System.Drawing.Bitmap bigBitmap = new System.Drawing.Bitmap(textureFullname);
            result.BigBitmap = bigBitmap;

            return(result);
        }
Ejemplo n.º 6
0
 public void SetFont(Font value)
 {
     if (!this.fontTexes.ContainsKey(value))
     {
         var obj = new FontTexture();
         obj.Create(value);
         this.fontTexes.Add(value, obj);
     }
     this.fontTex = this.fontTexes[value];
 }
Ejemplo n.º 7
0
        public static XElement ToXElement(this FontTexture texture)
        {
            XElement result = new XElement(strTTFTexture,
                                           new XAttribute(strFontHeight, texture.FontHeight),
                                           new XAttribute(strFirstChar, (int)texture.FirstChar),
                                           new XAttribute(strLastChar, (int)texture.LastChar),
                                           texture.CharInfoDict.ToXElement());

            return(result);
        }
Ejemplo n.º 8
0
        private static FontTexture Parse(XElement xElement)
        {
            FontTexture result = new FontTexture();

            result.FontHeight   = int.Parse(xElement.Attribute(strFontHeight).Value);
            result.FirstChar    = (char)int.Parse(xElement.Attribute(strFirstChar).Value);
            result.LastChar     = (char)int.Parse(xElement.Attribute(strLastChar).Value);
            result.CharInfoDict = CharacterInfoDictHelper.Parse(
                xElement.Element(CharacterInfoDictHelper.strCharacterInfoDict));

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 用一个纹理绘制指定范围内的可见字符
        /// </summary>
        /// <param name="fontFilename">字体文件名</param>
        /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
        /// <param name="firstChar">要显示的第一个字符</param>
        /// <param name="lastChar">要显示的最后一个字符</param>
        public FontElement(string fontFilename, int fontHeight, char firstChar, char lastChar)
        {
            if (firstChar > lastChar)
            {
                throw new ArgumentException("first char should <= last char");
            }

            int[] maxTextureWidth = new int[1];
            //	Get the maximum texture size supported by GL.
            GL.GetInteger(GetTarget.MaxTextureSize, maxTextureWidth);

            this.ttfTexture = FontTextureHelper.GetTTFTexture(fontFilename, fontHeight, maxTextureWidth[0], firstChar, lastChar);
        }
Ejemplo n.º 10
0
 public ScoreParticle(int x, int y, int tx, int ty, int score, FontTexture font, Texture2D tex, Color c)
 {
     XDirection     = (int)(BaseGame.Random.Next(1) == 1 ? BaseGame.Random.NextDouble() * 5 : BaseGame.Random.NextDouble() * -5);
     X              = x;
     Y              = y;
     Tx             = tx;
     Ty             = ty;
     Score          = score;
     Font           = font;
     Explosion      = tex;
     Color          = c;
     ScoreFade      = new Tween(new TimeSpan(0, 0, 0, 8), 1f, 0f);
     ExplosionFade  = new Tween(new TimeSpan(0, 0, 0, 5), 1f, 0f);
     ExplosionScale = new Tween(new TimeSpan(0, 0, 0, 5), 0f, 4f);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets an instance of <see cref="FontTexture"/>.
        /// </summary>
        /// <param name="fontBitmap"></param>
        /// <returns></returns>
        public static FontTexture GetFontTexture(this FontBitmap fontBitmap)
        {
            var bmp     = fontBitmap.GlyphBitmap;
            var texture = new Texture(
                TextureTarget.Texture2D,
                new TexImage2D(TexImage2D.Target.Texture2D, 0, GL.GL_RGBA, bmp.Width, bmp.Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bmp)));

            texture.Initialize();
            var result = new FontTexture();

            result.GlyphFont           = fontBitmap.GlyphFont;
            result.GlyphHeight         = fontBitmap.GlyphHeight;
            result.TextureSize         = fontBitmap.GlyphBitmap.Size;
            result.GlyphInfoDictionary = fontBitmap.GlyphInfoDictionary;
            result.TextureObj          = texture;
            return(result);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets an instance of <see cref="FontTexture"/>.
 /// </summary>
 /// <param name="fontBitmap"></param>
 /// <param name="parameters"></param>
 /// <param name="mipmapFiltering"></param>
 /// <returns></returns>
 public static FontTexture GetFontTexture(this FontBitmap fontBitmap,
     SamplerParameters parameters = null,
     MipmapFilter mipmapFiltering = MipmapFilter.LinearMipmapLinear)
 {
     var texture = new Texture(
         TextureTarget.Texture2D,
         fontBitmap.GlyphBitmap,
         parameters, mipmapFiltering);
     texture.Initialize();
     var result = new FontTexture();
     result.GlyphFont = fontBitmap.GlyphFont;
     result.GlyphHeight = fontBitmap.GlyphHeight;
     result.TextureSize = fontBitmap.GlyphBitmap.Size;
     result.GlyphInfoDictionary = fontBitmap.GlyphInfoDictionary;
     result.TextureObj = texture;
     return result;
 }
Ejemplo n.º 13
0
        public Font(Frame frame)
        {
            CharWidth  = 8;
            CharHeight = 8;
            this.frame = frame;

            mapWidth  = 16;
            mapHeight = 16;

            texture = new FontTexture(Loader.LoadFontImage("0.png"));

            shader = new ShaderProgram(
                new Shader("font_vs.glsl", ShaderType.VertexShader),
                new Shader("font_fs.glsl", ShaderType.FragmentShader)
                );

            vao = GL.GenVertexArray();
            GL.BindVertexArray(vao);

            vbo = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);

            GL.BufferData(
                BufferTarget.ArrayBuffer,
                Marshal.SizeOf(typeof(Vertex4)) * 4,
                IntPtr.Zero,
                BufferUsageHint.DynamicDraw
                );

            Attribute attr = Vertex4.GetAttribute(shader, "vertex");

            GL.EnableVertexAttribArray(attr.Index);
            GL.VertexAttribPointer(
                attr.Index,
                attr.SizeOfElements,
                VertexAttribPointerType.Float,
                false,
                attr.StrideOfElements * sizeof(float),
                attr.OffsetOfElements * sizeof(float)
                );

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);
        }
Ejemplo n.º 14
0
        void generateCredit(StoryboardLayer layer, FontTexture topTexture, FontTexture bottomTexture, double start, double end)
        {
            var TopSprite = layer.CreateSprite(topTexture.Path);

            TopSprite.MoveY(start, 240 - (topTexture.BaseHeight * 0.3) * 0.7);
            TopSprite.Fade(start, start + 250, 0, 1);
            TopSprite.Fade(end - 250, end, 1, 0);
            TopSprite.Scale(start, 0.3);
            TopSprite.MoveX(start, start + 250, 400, 325);
            TopSprite.MoveX(start + 250, end - 250, 325, 300);
            TopSprite.MoveX(end - 250, end, 300, 250);

            // if(start != 16210)
            // {
            //     TopSprite.MoveX(start, start + 250, 400, 325);
            //     TopSprite.MoveX(start + 250, end - 250, 325, 300);
            //     TopSprite.MoveX(end - 250, end, 300, 250);
            // }else{
            //  TopSprite.MoveX(start, start + 250, 400, 340);
            //  TopSprite.MoveX(start + 250, 17260 , 340, 320);

            // }

            var BottomSprite = layer.CreateSprite(bottomTexture.Path);

            BottomSprite.MoveY(start, 240 + (bottomTexture.BaseHeight * 0.3) * 0.7);
            BottomSprite.Fade(start, start + 250, 0, 1);
            BottomSprite.Fade(end - 250, end, 1, 0);
            BottomSprite.Scale(start, 0.3);

            BottomSprite.MoveX(start, start + 250, 250, 300);
            BottomSprite.MoveX(start + 250, end - 250, 300, 325);
            BottomSprite.MoveX(end - 250, end, 325, 400);

            // if(start != 16210)
            // {
            //     BottomSprite.MoveX(start, start + 250, 250, 300);
            //     BottomSprite.MoveX(start + 250, end - 250, 300, 325);
            //     BottomSprite.MoveX(end - 250, end, 325, 400);
            // }else{
            //     BottomSprite.MoveX(start, start + 250, 250, 300);
            //     BottomSprite.MoveX(start + 250, 17260, 300, 320);
            // }
        }
Ejemplo n.º 15
0
    public void calculateLineHeight()
    {
        foreach (var line in lines)
        {
            float         lineHeight = 0f;
            FontTexture[] textures   = new FontTexture[line.Length];

            int t = 0;
            foreach (var letter in line)
            {
                var texture = font.GetTexture(letter.ToString());
                textures[t] = texture;
                lineHeight += texture.BaseHeight * this.textScale;
                t++;
            }

            this.lineHeight = Math.Max(this.lineHeight, lineHeight);
        }
    }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets an instance of <see cref="FontTexture"/>.
        /// </summary>
        /// <param name="fontBitmap"></param>
        /// <param name="parameters"></param>
        /// <param name="mipmapFiltering"></param>
        /// <returns></returns>
        public static FontTexture GetFontTexture(this FontBitmap fontBitmap,
                                                 SamplerParameters parameters = null,
                                                 MipmapFilter mipmapFiltering = MipmapFilter.LinearMipmapLinear)
        {
            var texture = new Texture(
                TextureTarget.Texture2D,
                fontBitmap.GlyphBitmap,
                parameters, mipmapFiltering);

            texture.Initialize();
            var result = new FontTexture();

            result.GlyphFont           = fontBitmap.GlyphFont;
            result.GlyphHeight         = fontBitmap.GlyphHeight;
            result.TextureSize         = fontBitmap.GlyphBitmap.Size;
            result.GlyphInfoDictionary = fontBitmap.GlyphInfoDictionary;
            result.TextureObj          = texture;
            return(result);
        }
Ejemplo n.º 17
0
    public long LoadFont(string filename, int width, int height, int count, bool lowerCase)
    {
        FontTexture Temp;

        Temp            = new FontTexture();
        Temp.FontImage  = (Texture)Resources.Load(filename);
        Temp.Width      = 1.0f / (Temp.FontImage.width / width);
        Temp.Height     = 1.0f / (Temp.FontImage.height / height);
        Temp.ID         = NextID;
        Temp.Characters = count;
        Temp.LowerCase  = lowerCase;
        Temp.xChars     = width;
        Temp.yChars     = height;
        LoadedFont.Add(Temp);
        NextID++;

        return(Temp.ID);
//		Debug.Log( "X:"+Temp.Width+" Y:"+Temp.Height );
    }
Ejemplo n.º 18
0
        void generateCredit(StoryboardLayer layer, FontTexture topTexture, FontTexture bottomTexture, double startMoveOut, double endMoveOut, double startMoveIn, double endMoveIn)
        {
            var top = layer.CreateSprite(topTexture.Path);

            top.Scale(startMoveOut, 0.25);
            top.MoveY(OsbEasing.OutExpo, startMoveOut, endMoveOut, 240, 240 - (topTexture.BaseHeight * 0.25));
            top.Fade(startMoveOut, endMoveOut, 0, 1);
            top.MoveY(endMoveOut, startMoveIn, 240 - (topTexture.BaseHeight * 0.25), 240 - (topTexture.BaseHeight * 0.2));
            top.MoveY(startMoveIn, endMoveIn, 240 - (topTexture.BaseHeight * 0.2), 240);
            top.Fade(startMoveIn, endMoveIn, 1, 0);

            var bottom = layer.CreateSprite(bottomTexture.Path);

            bottom.Scale(startMoveOut, 0.25);
            bottom.MoveY(OsbEasing.OutExpo, startMoveOut, endMoveOut, 240, 240 + (bottomTexture.BaseHeight * 0.25));
            bottom.Fade(startMoveOut, endMoveOut, 0, 1);
            bottom.MoveY(endMoveOut, startMoveIn, 240 + (bottomTexture.BaseHeight * 0.25), 240 + (bottomTexture.BaseHeight * 0.2));
            bottom.MoveY(startMoveIn, endMoveIn, 240 + (bottomTexture.BaseHeight * 0.2), 240);
            bottom.Fade(startMoveIn, endMoveIn, 1, 0);
        }
Ejemplo n.º 19
0
 private void CreateTextureObject(FontTexture ttfTexture)
 {
     this.texture = new Texture2D();
     this.texture.Initialize(ttfTexture.BigBitmap);
 }
Ejemplo n.º 20
0
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkerData data          = e.Argument as WorkerData;
            int        fontFileCount = data.selectedTTFFiles.Length;
            int        fontFileIndex = 1;
            const int  magicNumber   = 100;

            WorkerResult result = new WorkerResult(null, data);

            e.Result = result;

            StringBuilder builder = new StringBuilder();

            foreach (var fontFullname in this.selectedTTFFiles)
            {
                builder.Append(fontFileIndex); builder.Append("/"); builder.Append(fontFileCount);
                builder.Append(": "); builder.AppendLine(fontFullname);

                FileInfo fileInfo     = new FileInfo(fontFullname);
                string   fontName     = fileInfo.Name;
                string   destFullname = fontFullname + ".png";

                FontTexture ttfTexture = null;

                try
                {
                    {
                        int lastPercent = 0;
                        foreach (var progress in FontTextureYieldHelper.GetTTFTexture(
                                     fontFullname, data.fontHeight, data.maxTexturWidth, data.firstChar, data.lastChar))
                        {
                            ttfTexture = progress.ttfTexture;
                            if (progress.percent != lastPercent)
                            {
                                var singleFileProgress = new SingleFileProgress()
                                {
                                    fontName = fontName, progress = progress.percent, message = progress.message
                                };
                                bgWorker.ReportProgress(fontFileIndex * magicNumber / fontFileCount, singleFileProgress);
                                lastPercent = progress.percent;
                            }
                        }
                    }

                    System.Drawing.Bitmap bigBitmap = ttfTexture.BigBitmap;
                    if (data.drawBBox)
                    {
                        Graphics g = Graphics.FromImage(bigBitmap);
                        int      vertialLineIndex = 0;
                        int      characterCount   = ttfTexture.CharInfoDict.Values.Count;
                        int      lastPercent      = 0;
                        foreach (var item in ttfTexture.CharInfoDict.Values)
                        {
                            int     left   = item.xoffset;
                            int     right  = item.xoffset + item.width - 1;
                            int     top    = item.yoffset;
                            int     bottom = item.yoffset + ttfTexture.FontHeight - 1;
                            Point[] points = new Point[] { new Point(left, top), new Point(right, top), new Point(right, bottom), new Point(left, bottom), new Point(left, top) };
                            g.DrawLines(pen, points);

                            int percent = vertialLineIndex++ *100 / characterCount;
                            if (percent != lastPercent)
                            {
                                var singleFileProgress = new SingleFileProgress()
                                {
                                    fontName = fontName, progress = percent, message = "drawing bboxes"
                                };
                                bgWorker.ReportProgress(fontFileIndex * magicNumber / fontFileCount, singleFileProgress);
                                lastPercent = percent;
                            }
                        }
                        g.Dispose();
                        bigBitmap.Save(destFullname);
                    }

                    bigBitmap.Save(destFullname);

                    {
                        FontTextureXmlPrinter printer = new FontTextureXmlPrinter(ttfTexture);
                        printer.Print(fontFullname);
                    }

                    if (data.generateGlyphList)
                    {
                        FontTexturePNGPrinter printer = new FontTexturePNGPrinter(ttfTexture);
                        foreach (var progress in printer.Print(fontFullname, data.maxTexturWidth))
                        {
                            bgWorker.ReportProgress(fontFileIndex * magicNumber / fontFileCount, progress);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string message = string.Format("{0}", ex);
                    builder.AppendLine(message);
                    result.builder = builder;
                }

                if (ttfTexture != null)
                {
                    ttfTexture.Dispose();
                }

                if (result.builder != builder)
                {
                    builder.AppendLine("sucessfully done!");
                }
                builder.AppendLine();

                SingleFileProgress thisFileDone = new SingleFileProgress()
                {
                    fontName = fontName,
                    progress = magicNumber,
                    message  = string.Format("All is done for {0}", fileInfo.Name),
                };
                bgWorker.ReportProgress(fontFileIndex++ *magicNumber / fontFileCount, thisFileDone);
            }
        }
Ejemplo n.º 21
0
        // 0: no animation
        // 1: padding animation
        //public int SpawnAnimation;
        //private float paddingAnimationStep = 0.9f;

        private void Init()
        {
            if (lastDraw == null)
            {
                lastDraw = Tuple.Create("", Vector2.Zero, Color.White);
            }
            if (!initialized)
            {
                initialized = true;
                if ((Color != FontBaseColor && !StaticColor) || (Alpha >= 0 && Alpha < 255))
                {
                    for (var y = 0; y < FontTexture.Height; y++)
                    {
                        for (var x = 0; x < FontTexture.Width; x++)
                        {
                            var position = y * FontTexture.Width * 4 + x * 4;
                            if (!StaticColor && Color != FontBaseColor &&
                                FontTexture.Bitmap[position] == FontBaseColor.R && FontTexture.Bitmap[position + 1] == FontBaseColor.G &&
                                FontTexture.Bitmap[position + 2] == FontBaseColor.B &&
                                FontTexture.Bitmap[position + 3] == FontBaseColor.A)
                            {
                                FontTexture.Bitmap[position]     = Color.R;
                                FontTexture.Bitmap[position + 1] = Color.G;
                                FontTexture.Bitmap[position + 2] = Color.B;
                                FontTexture.Bitmap[position + 3] = Color.A;
                            }
                            if (Alpha >= 0 && Alpha < 255 && FontTexture.Bitmap[position + 3] > 20)
                            {
                                FontTexture.Bitmap[position + 3] = (byte)Alpha;
                            }
                        }
                    }
                    FontTexture.Update();
                }
            }
            ScaledPadding = Padding * Scale.X;

            if (lastDraw.Item1 != Text)
            {
                if (sprites != null)
                {
                    Dispose();
                }
                disposed = false;
                sprites  = new Sprite[Text.Length];
                for (var i = 0; i < Text.Length; i++)
                {
                    var c = Text[i];
                    if (c == ' ')
                    {
                        sprites[i] = null;
                        continue;
                    }
                    sprites[i] = new Sprite(
                        (int)CharToSprite[c].Item2.X,
                        (int)CharToSprite[c].Item2.Y
                        );
                }
            }
            lastDraw = Tuple.Create(Text, Scale, Color);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// 用一个纹理绘制指定范围内的可见字符
 /// </summary>
 /// <param name="fontFilename">字体文件名</param>
 /// <param name="fontHeight">此值越大,绘制文字的清晰度越高,但占用的纹理资源就越多。</param>
 /// <param name="firstChar">要显示的第一个字符</param>
 /// <param name="lastChar">要显示的最后一个字符</param>
 public WholeFontTextureElement(string textureFilename, string xmlFilename)
 {
     this.ttfTexture = FontTextureHelper.GetTTFTexture(textureFilename, xmlFilename);
 }
Ejemplo n.º 23
0
 public FontTextureXmlPrinter(FontTexture ttfTexture)
 {
     // TODO: Complete member initialization
     this.ttfTexture = ttfTexture;
 }
Ejemplo n.º 24
0
 public FontTexturePNGPrinter(FontTexture ttfTexture)
 {
     this.ttfTexture  = ttfTexture;
     this.font        = new Font("微软雅黑", ttfTexture.FontHeight / 2);
     this.outputWidth = ttfTexture.FontHeight * 40;
 }