Subversion Repositories AndroidProjects

Rev

Blame | Last modification | View Log | RSS feed

package com.gebauz.bauzoid.graphics;

import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.Gdx;
import com.gebauz.bauzoid.app.Consts;
import com.gebauz.bauzoid.file.FileUtil;
import com.gebauz.bauzoid.game.Game;
import com.gebauz.bauzoid.game.GameObject;

/** Manages the fonts currently loaded into the system.
 * Makes sure fonts don't get loaded multiple times.
 *
 * @author chris
 *
 */

public class FontCollection extends GameObject
{
       
        private HashMap<String, Font> mFonts = new HashMap<String, Font>();
        private Font mDefaultFont = null;

        public FontCollection(Game game)
        {
                super(game);
               
        }
       
        public void init()
        {
               
        }
       
        public void exit()
        {
                for (Map.Entry<String, Font> entry : mFonts.entrySet())
                {
                    entry.getValue().dispose();
                }
                mFonts.clear();
               
                mDefaultFont = null;
        }
       
        public Font loadFont(String filename)
        {
                String fontName = FileUtil.extractFilenameNoExt(filename);
               
                if (mFonts.containsKey(fontName))
                        return getFont(fontName);
               
                Font font = FontUtil.createFontFromBinaryFile(getGame().getGraphics(), Gdx.files.internal(filename));
                mFonts.put(fontName, font);
               
                if (mDefaultFont == null)
                {
                        mDefaultFont = font;
                }
               
                Gdx.app.log(Consts.LOG_TAG, "Font added: " + fontName);
               
                return font;
        }
       
        public Font getFont(String fontName)
        {
                return mFonts.get(fontName);
        }
       
        /** Just get the first font that was added to the map .*/
        public Font getDefaultFont()
        {
                return mDefaultFont;
        }
       
}