Move static fonts to GLFont

This commit is contained in:
Charles J. Cliffe
2015-06-30 23:07:39 -04:00
parent 8ccb060237
commit b28c8dbc3e
8 changed files with 62 additions and 60 deletions
+38
View File
@@ -8,6 +8,9 @@
#define RES_FOLDER ""
#endif
GLFont GLFont::fonts[GLFONT_MAX];
GLFontChar::GLFontChar() :
id(0), x(0), y(0), width(0), height(0), xoffset(0), yoffset(0), xadvance(0), aspect(1), index(0) {
@@ -475,3 +478,38 @@ void GLFont::drawString(std::string str, float xpos, float ypos, int pxHeight, A
glDisable(GL_TEXTURE_2D);
}
GLFont &GLFont::getFont(GLFontSize esize) {
if (!fonts[esize].isLoaded()) {
std::string fontName;
switch (esize) {
case GLFONT_SIZE12:
fontName = "vera_sans_mono12.fnt";
break;
case GLFONT_SIZE16:
fontName = "vera_sans_mono16.fnt";
break;
case GLFONT_SIZE18:
fontName = "vera_sans_mono18.fnt";
break;
case GLFONT_SIZE24:
fontName = "vera_sans_mono24.fnt";
break;
case GLFONT_SIZE32:
fontName = "vera_sans_mono32.fnt";
break;
case GLFONT_SIZE48:
fontName = "vera_sans_mono48.fnt";
break;
default:
fontName = "vera_sans_mono12.fnt";
break;
}
fonts[esize].loadFont(fontName);
}
return fonts[esize];
}
+6
View File
@@ -56,6 +56,9 @@ public:
enum Align {
GLFONT_ALIGN_LEFT, GLFONT_ALIGN_RIGHT, GLFONT_ALIGN_CENTER, GLFONT_ALIGN_TOP, GLFONT_ALIGN_BOTTOM
};
enum GLFontSize {
GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX
};
GLFont();
~GLFont();
@@ -65,6 +68,9 @@ public:
float getStringWidth(std::string str, float size, float viewAspect);
void drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP);
static GLFont fonts[GLFONT_MAX];
static GLFont &getFont(GLFontSize esize);
private:
std::string nextParam(std::istringstream &str);
std::string getParamKey(std::string param_str);