Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
835 chris 1
package com.gebauz.bauzoid.graphics;
2
 
3
import java.util.HashMap;
4
import java.util.Map;
5
 
6
import com.badlogic.gdx.Gdx;
7
import com.gebauz.bauzoid.app.Consts;
8
import com.gebauz.bauzoid.file.FileUtil;
9
import com.gebauz.bauzoid.game.Game;
10
import com.gebauz.bauzoid.game.GameObject;
11
 
12
/** Manages the fonts currently loaded into the system.
13
 * Makes sure fonts don't get loaded multiple times.
14
 *
15
 * @author chris
16
 *
17
 */
18
public class FontCollection extends GameObject
19
{
20
 
21
        private HashMap<String, Font> mFonts = new HashMap<String, Font>();
22
        private Font mDefaultFont = null;
23
 
24
        public FontCollection(Game game)
25
        {
26
                super(game);
27
 
28
        }
29
 
30
        public void init()
31
        {
32
 
33
        }
34
 
35
        public void exit()
36
        {
37
                for (Map.Entry<String, Font> entry : mFonts.entrySet())
38
                {
39
                    entry.getValue().dispose();
40
                }
41
                mFonts.clear();
42
 
43
                mDefaultFont = null;
44
        }
45
 
46
        public Font loadFont(String filename)
47
        {
48
                String fontName = FileUtil.extractFilenameNoExt(filename);
49
 
50
                if (mFonts.containsKey(fontName))
51
                        return getFont(fontName);
52
 
53
                Font font = FontUtil.createFontFromBinaryFile(getGame().getGraphics(), Gdx.files.internal(filename));
54
                mFonts.put(fontName, font);
55
 
56
                if (mDefaultFont == null)
57
                {
58
                        mDefaultFont = font;
59
                }
60
 
61
                Gdx.app.log(Consts.LOG_TAG, "Font added: " + fontName);
62
 
63
                return font;
64
        }
65
 
66
        public Font getFont(String fontName)
67
        {
68
                return mFonts.get(fontName);
69
        }
70
 
71
        /** Just get the first font that was added to the map .*/
72
        public Font getDefaultFont()
73
        {
74
                return mDefaultFont;
75
        }
76
 
77
}
78
 
79