-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathFontManager.java
More file actions
173 lines (143 loc) · 4.91 KB
/
FontManager.java
File metadata and controls
173 lines (143 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package org.andengine.opengl.font;
import java.util.ArrayList;
import java.util.HashMap;
import org.andengine.opengl.util.GLState;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 17:48:46 - 08.03.2010
*/
public class FontManager {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private final ArrayList<Font> mFontsManaged = new ArrayList<Font>();
private final ArrayList<BitmapFont> mBitmapFontsManaged = new ArrayList<BitmapFont>();
private final HashMap<String, IFont> mFontsMapped = new HashMap<String, IFont>();
private boolean mReloading;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public void onCreate() {
}
public synchronized void onDestroy() {
final ArrayList<Font> managedFonts = this.mFontsManaged;
for(int i = managedFonts.size() - 1; i >= 0; i--) {
managedFonts.get(i).invalidateLetters();
}
this.mFontsManaged.clear();
this.mBitmapFontsManaged.clear();
this.mFontsMapped.clear();
}
public synchronized boolean hasMappedFont(final String pID) {
if(pID == null) {
throw new IllegalArgumentException("pID must not be null!");
}
return this.mFontsMapped.containsKey(pID);
}
public synchronized IFont getMappedFont(final String pID) {
if(pID == null) {
throw new IllegalArgumentException("pID must not be null!");
}
return this.mFontsMapped.get(pID);
}
public synchronized void addMappedFont(final String pID, final IFont pFont) throws IllegalArgumentException {
if(pID == null) {
throw new IllegalArgumentException("pID must not be null!");
} else if(pFont == null) {
throw new IllegalArgumentException("pFont must not be null!");
} else if(this.mFontsMapped.containsKey(pID)) {
throw new IllegalArgumentException("Collision for pID: '" + pID + "'.");
}
this.mFontsMapped.put(pID, pFont);
}
public synchronized IFont removedMappedFont(final String pID) {
if(pID == null) {
throw new IllegalArgumentException("pID must not be null!");
}
return this.mFontsMapped.remove(pID);
}
public synchronized void loadFont(final Font pFont) {
if(pFont == null) {
throw new IllegalArgumentException("pFont must not be null!");
}
this.mFontsManaged.add(pFont);
}
public synchronized void loadFont(final BitmapFont pBitmapFont) {
if(pBitmapFont == null) {
throw new IllegalArgumentException("pBitmapFont must not be null!");
}
this.mBitmapFontsManaged.add(pBitmapFont);
}
public synchronized void loadFonts(final Font ... pFonts) {
for(int i = 0; i < pFonts.length; i++) {
this.loadFont(pFonts[i]);
}
}
public synchronized void loadFonts(final BitmapFont ... pBitmapFonts) {
for(int i = 0; i < pBitmapFonts.length; i++) {
this.loadFont(pBitmapFonts[i]);
}
}
public synchronized void unloadFont(final Font pFont) {
if(pFont == null) {
throw new IllegalArgumentException("pFont must not be null!");
}
this.mFontsManaged.remove(pFont);
}
public synchronized void unloadFont(final BitmapFont pBitmapFont) {
if(pBitmapFont == null) {
throw new IllegalArgumentException("pBitmapFont must not be null!");
}
this.mBitmapFontsManaged.remove(pBitmapFont);
}
public synchronized void unloadFonts(final Font ... pFonts) {
for(int i = 0; i < pFonts.length; i++) {
this.unloadFont(pFonts[i]);
}
}
public synchronized void unloadFonts(final BitmapFont ... pBitmapFonts) {
for(int i = 0; i < pBitmapFonts.length; i++) {
this.unloadFont(pBitmapFonts[i]);
}
}
public synchronized boolean updateFonts(final GLState pGLState) {
final ArrayList<Font> fonts = this.mFontsManaged;
final int fontCount = fonts.size();
if(fontCount > 0){
for(int i = fontCount - 1; i >= 0; i--){
fonts.get(i).update(pGLState);
}
}
if (this.mReloading) {
this.mReloading = false;
return true;
} else {
return false;
}
}
public synchronized void onReload() {
this.mReloading = true;
final ArrayList<Font> managedFonts = this.mFontsManaged;
for(int i = managedFonts.size() - 1; i >= 0; i--) {
managedFonts.get(i).invalidateLetters();
}
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}