Пример #1
0
        /// <summary>
        /// Instantiates this instance
        /// </summary>
        /// <param name="fontFile">The font file</param>
        /// <param name="fontTexture">The font texture</param>
        public BitmapFontRenderer(FontFile fontFile, Texture2D fontTexture)
        {
            _fontFile     = fontFile;
            _texture      = fontTexture;
            _characterMap = new Dictionary <char, FontChar>();

            foreach (var fontCharacter in _fontFile.Chars)
            {
                char c = (char)fontCharacter.ID;
                _characterMap.Add(c, fontCharacter);
            }
        }
Пример #2
0
        /// <summary>
        /// Instantiates this instance
        /// </summary>
        /// <param name="fontFile">The font file</param>
        /// <param name="fontTexture">The font texture</param>
        public BitmapFontRenderer(FontFile fontFile, Texture2D fontTexture)
        {
            _fontFile = fontFile;
            _texture = fontTexture;
            _characterMap = new Dictionary<char, FontChar>();

            foreach (var fontCharacter in _fontFile.Chars)
            {
                char c = (char)fontCharacter.ID;
                _characterMap.Add(c, fontCharacter);
            }
        }
Пример #3
0
 /// <summary>
 /// Loads a font from a stream
 /// </summary>
 /// <param name="stream">The stream</param>
 /// <returns>Loaded font file</returns>
 public static FontFile Load(Stream stream)
 {
     try
     {
         XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
         FontFile      file         = (FontFile)deserializer.Deserialize(stream);
         return(file);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         return(null);
     }
 }
Пример #4
0
        private void LoadData()
        {
            string _fntFilePath     = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fntFilePath);
            string _textureFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, textureFilePath);

#if WINDOWS
            if (File.Exists(_fntFilePath) && File.Exists(_textureFilePath))
#elif WINRT
            if (MetroHelper.AppDataFileExists(_fntFilePath) && MetroHelper.AppDataFileExists(_textureFilePath))
#endif
            {
                this.fontFile    = FontLoader.Load(_fntFilePath);
                this.fontTexture = TextureLoader.FromFile(_textureFilePath);

                this.fontRenderer = new BitmapFontRenderer(this.fontFile, this.fontTexture);
            }
        }
Пример #5
0
        /// <summary>
        /// Loads a font from a file path
        /// </summary>
        /// <param name="filename">The file path</param>
        /// <returns>Loaded font file</returns>
        public static FontFile Load(String filename)
        {
            try
            {
#if WINDOWS
                XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
                TextReader    textReader   = new StreamReader(filename);
                FontFile      file         = (FontFile)deserializer.Deserialize(textReader);
                textReader.Close();
                return(file);
#elif WINRT
                // TODO :
                return(null);
#endif
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #6
0
        private void LoadData()
        {
            string _fntFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, fntFilePath);
            string _textureFilePath = System.IO.Path.Combine(SceneManager.GameProject.ProjectPath, textureFilePath);

#if WINDOWS
            if (File.Exists(_fntFilePath) && File.Exists(_textureFilePath))
#elif WINRT
            if (MetroHelper.AppDataFileExists(_fntFilePath) && MetroHelper.AppDataFileExists(_textureFilePath))
#endif
            {
                this.fontFile = FontLoader.Load(_fntFilePath);
                this.fontTexture = TextureLoader.FromFile(_textureFilePath);

                this.fontRenderer = new BitmapFontRenderer(this.fontFile, this.fontTexture);
            }
        }