00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00036 #ifdef WIN32
00037
00038 #include <windows.h>
00039 #endif
00040
00041 #include <vector>
00042 #include <GL/gl.h>
00043 #include "fonts.h"
00044
00045 _GLICTFONTVECTOR glictFonts;
00046
00061 glictFont* glictCreateFont(const char* name) {
00062
00063 if (glictFindFont(name)) return NULL;
00064
00065
00066 glictFont* fnt = new glictFont;
00067 if (!fnt) return NULL;
00068
00069
00070 glictFonts.insert(glictFonts.end(), fnt);
00071 fnt->SetName(name);
00072 return fnt;
00073 }
00074
00075 glictFont* glictFindFont(const char* name) {
00076
00077 _GLICTFONTVECTORITERATOR it;
00078 for (it = glictFonts.begin(); it<glictFonts.end() && strcmp((*it)->GetName().c_str(), name); it++);
00079 if (it!=glictFonts.end()) return *it;
00080 return NULL;
00081 }
00082
00083 bool glictDeleteFont(const char* name) {
00084 _GLICTFONTVECTORITERATOR it;
00085
00086 for (it = glictFonts.begin(); it!=glictFonts.end() && strcmp((*it)->GetName().c_str(), name); it++);
00087 if (it!=glictFonts.end()) {
00088 delete *it;
00089 glictFonts.erase(it);
00090 return true;
00091
00092 }
00093 return false;
00094 }
00095
00119 bool glictFontRender(const char* text, const char* fontname, float x, float y) {
00120 return glictFontRender(text, fontname, 10, x, y);
00121 }
00122
00123
00148 #ifdef NO_GL
00149 #define glMatrixMode(x)
00150 #define glScalef(x,y,z)
00151
00152 #endif
00153 bool glictFontRender(const char* text, const char* fontname, float fontsize, float x, float y) {
00154
00155 glictFont* fnt;
00156 glMatrixMode(GL_MODELVIEW);
00157
00158 fnt = glictFindFont(fontname);
00159 if (!fnt) {
00160 printf("*** glictFontRender: Font %s not loaded\n", fontname);
00161 return false;
00162 }
00163 if (strcmp(fnt->GetName().c_str(), fontname)) printf("*** glictFontRender: Font name different from what we searched for\n");
00164
00165
00166 if (fnt->RenderBoolSize) {
00167 return fnt->RenderBoolSize(text, fnt->fontparam, fontsize, x, y);
00168 }
00169 if (fnt->RenderBoolNoSize) {
00170
00171
00172 glScalef(fontsize, fontsize, fontsize);
00173
00174 bool r = fnt->RenderBoolNoSize(text, fnt->fontparam, x/fontsize, y/fontsize);
00175 glScalef(1./fontsize, 1./fontsize, 1./fontsize);
00176
00177 return r;
00178 }
00179 if (fnt->RenderVoidSize) {
00180 fnt->RenderVoidSize(text, fnt->fontparam, fontsize, x, y);
00181 return true;
00182 }
00183 if (fnt->RenderVoidNoSize) {
00184
00185 glScalef(fontsize, fontsize, fontsize);
00186 fnt->RenderVoidNoSize(text, fnt->fontparam, x/fontsize, y/fontsize);
00187 glScalef(1./fontsize, 1./fontsize, 1./fontsize);
00188
00189 return true;
00190 }
00191
00192 printf("*** glictFontRender: Font %s not renderable\n", fontname);
00193 return false;
00194 }
00195
00196 float glictFontSize(const char* text, const char* font) {
00197 return glictFontSize(text, font, 10);
00198 }
00199
00200 float glictFontSize(const char* text, const char* font, float size) {
00201
00202 glictFont* fnt = glictFindFont(font);
00203 if (!fnt) printf("*** glictFontSize: Font %s not found\n", font);
00204 if (!fnt) return false;
00205 if (fnt->SizeSize) {
00206 return fnt->SizeSize(text, fnt->fontparam, size);
00207 }
00208 if (fnt->SizeNoSize) {
00209 return fnt->SizeNoSize(text, fnt->fontparam)*size;
00210 }
00211 return 0;
00212 }
00213
00214 int glictFontNumberOfLines(const char* txt) {
00215 int count=1;
00216 for (unsigned int i=0;i<strlen(txt);i++) {
00217 if (txt[i]=='\n') {
00218 count++;
00219 }
00220 }
00221
00222 return count;
00223 }
00224
00226
00227
00228 glictFont::glictFont() {
00229
00230 }
00231
00232 glictFont::~glictFont() {
00233
00234 }
00235
00236 void glictFont::SetName(const char* name) {
00237 this->name = name;
00238 }
00239 std::string glictFont::GetName() {
00240 return this->name;
00241 }
00242
00244 void glictFont::SetRenderFunc(_glictFontRenderFuncBoolSize funcpointer) {
00245 this->RenderBoolNoSize = NULL;
00246 this->RenderBoolSize = funcpointer;
00247 this->RenderVoidNoSize = NULL;
00248 this->RenderVoidSize = NULL;
00249 }
00250
00252 void glictFont::SetRenderFunc(_glictFontRenderFuncBoolNoSize funcpointer) {
00253 this->RenderBoolNoSize = funcpointer;
00254 this->RenderBoolSize = NULL;
00255 this->RenderVoidNoSize = NULL;
00256 this->RenderVoidSize = NULL;
00257 }
00258
00260 void glictFont::SetRenderFunc(_glictFontRenderFuncVoidSize funcpointer) {
00261 this->RenderBoolNoSize = NULL;
00262 this->RenderBoolSize = NULL;
00263 this->RenderVoidNoSize = NULL;
00264 this->RenderVoidSize = funcpointer;
00265 }
00266
00268 void glictFont::SetRenderFunc(_glictFontRenderFuncVoidNoSize funcpointer) {
00269 this->RenderBoolNoSize = NULL;
00270 this->RenderBoolSize = NULL;
00271 this->RenderVoidNoSize = funcpointer;
00272 this->RenderVoidSize = NULL;
00273 }
00274
00276 void glictFont::SetSizeFunc(_glictFontSizeFuncSize funcpointer) {
00277 this->SizeNoSize = NULL;
00278 this->SizeSize = funcpointer;
00279 }
00280
00282 void glictFont::SetSizeFunc(_glictFontSizeFuncNoSize funcpointer) {
00283 this->SizeNoSize = funcpointer;
00284 this->SizeSize = NULL;
00285 }
00286
00287 void glictFont::SetFontParam(void* fp) {
00288 this->fontparam = fp;
00289 }
00290