summaryrefslogtreecommitdiff
path: root/lib/font.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/font.cc')
-rw-r--r--lib/font.cc69
1 files changed, 62 insertions, 7 deletions
diff --git a/lib/font.cc b/lib/font.cc
index 93588bf..d878399 100644
--- a/lib/font.cc
+++ b/lib/font.cc
@@ -79,8 +79,27 @@ nbT = number of textures
*/
+mogltk::ColorP colorcached[16] = {
+ DOS_BLACK,
+ DOS_BLUE,
+ DOS_GREEN,
+ DOS_CYAN,
+ DOS_RED,
+ DOS_MAGENTA,
+ DOS_BRAWN,
+ DOS_WHITE,
+ DOS_GRAY,
+ DOS_HIGH_BLUE,
+ DOS_HIGH_GREEN,
+ DOS_HIGH_CYAN,
+ DOS_HIGH_RED,
+ DOS_HIGH_MAGENTA,
+ DOS_YELLOW,
+ DOS_HIGH_WHITE
+};
+
mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), wspace(0) {
- int i;
+ int i, j;
nbentries = ffont->readU16();
flags = ffont->readU8();
@@ -104,9 +123,16 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w
printm(M_INFO, "Which makes %i texture(s), with %i char by texture, %i on X, and %i on Y\n", nbT, nbcT, nbcU, nbcV);
fonttex = (texture **) malloc(nbT * sizeof(texture *));
+ for (i = 0; i < 16; i++) {
+ fontcache[i] = (texture **) malloc(nbT * sizeof(texture *));
+ }
for (i = 0; i < nbT; i++) {
fonttex[i] = alloctexture();
+ for (j = 0; j < 15; j++) {
+ fontcache[j][i] = 0;
+ }
+ fontcache[15][i] = fonttex[i];
}
sizes = (Uint8 *) malloc(nbentries * sizeof(Uint8));
@@ -155,10 +181,14 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w
}
mogltk::font::~font() {
- int i;
- for (i = 0; i < nbT; i++) {
- delete fonttex[i];
- }
+ int i, j;
+ for (i = 0; i < nbT; i++)
+ for (j = 0; j < 16; j++)
+ if (fontcache[j][i])
+ delete fontcache[j][i];
+
+ for (i = 0; i < 16; i++)
+ free((void *&) fontcache[i]);
free((void *&) fonttex);
free(sizes);
@@ -174,7 +204,6 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {
SDL_LockSurface(mogltk::engine::base_o->getsurface());
}
-#if 0
if (shadow) {
int os = shadow;
shadow = 0;
@@ -183,7 +212,8 @@ void mogltk::font::drawentry(Uint16 entry, int x, int y, ColorP c) {
shadow = os;
}
-#endif
+
+ checknbind(entry / nbcT, c);
y -= base;
@@ -321,3 +351,28 @@ mogltk::texture * mogltk::font::alloctexture() {
void mogltk::font::Bind(int f) {
fonttex[f]->Bind();
}
+
+void mogltk::font::checknbind(int index, ColorP c) {
+ int i, x, y;
+ ColorP oldmax = ColorP::Max, t;
+ ColorP::Max = c.c;
+ SDL_PixelFormat * f = fonttex[0]->GetSurface()->format;
+
+ for (i = 0; i < 15; i++)
+ if (c == colorcached[i])
+ break;
+
+ if (!fontcache[i][index]) {
+ fontcache[i][index] = alloctexture();
+ for (y = 0; y < 256; y++) {
+ for (x = 0; x < 256; x++) {
+ t.fromSDL(fontcache[15][index]->GetPixels()[(y << 8) + x], f);
+ fontcache[i][index]->GetPixels()[(y << 8) + x] = t.toSDL(f);
+ }
+ }
+ }
+
+ fonttex[index] = fontcache[i][index];
+
+ ColorP::Max = oldmax.c;
+}