* fix for theme font handling (when switching back to the default theme, the language...
authorHominem te esse <[email protected]>
Fri, 23 Mar 2012 23:21:03 +0000 (24 00:21 +0100)
committerHominem te esse <[email protected]>
Fri, 23 Mar 2012 23:21:03 +0000 (24 00:21 +0100)
* font code factorization

include/fntsys.h
lng/lang_Italian.lng
src/dia.c
src/fntsys.c
src/gui.c
src/lang.c
src/menusys.c
src/themes.c
thirdparty/font_Hungarian.ttf
thirdparty/font_Italian.ttf [copied from thirdparty/font_Hungarian.ttf with 100% similarity]

index bb040e0..b24aa8e 100644 (file)
@@ -9,28 +9,18 @@
 #define FNT_ERROR (-1)
 
 /** Initializes the font subsystem */
-void fntInit(void);
+void fntInit();
 
 /** Terminates the font subsystem */
-void fntEnd(void);
-
-/** Loads a font
-  * @param buffer The memory buffer containing the font
-  * @param bufferSize Size of the buffer
-  * @param takeover Set to nonzero
-  * @return font slot id (negative value means error happened) */
-int fntLoad(void* buffer, int bufferSize, int takeover);
+void fntEnd();
 
 /** Loads a font from a file path
   * @param path The path to the font file
   * @return font slot id (negative value means error happened) */
 int fntLoadFile(char* path);
 
-/** Replaces the given font slot with the defined font */
-void fntReplace(int id, void* buffer, int bufferSize, int takeover, int asDefault);
-
-/** Reloads the default font into the given font slot */
-void fntSetDefault(int id);
+/** Reloads the default font */
+void fntLoadDefault(char* path);
 
 /** Releases a font slot */
 void fntRelease(int id);
@@ -40,15 +30,15 @@ void fntRelease(int id);
 void fntSetAspectRatio(float aw, float ah);
 
 /** Renders a text with specified window dimensions */
-int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour);
+int fntRenderString(int id, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour);
 
 /** replaces spaces with newlines so that the text fits into the specified width.
   * @note A destrutive operation - modifies the given string!
   */
-void fntFitString(int font, unsigned char *string, size_t width);
+void fntFitString(int id, unsigned char *string, size_t width);
 
 /** Calculates the width of the given text string
 * We can't use the height for alignment, as the horizontal center would depends of the contained text itself */
-int fntCalcDimensions(int font, const unsigned char* str);
+int fntCalcDimensions(int id, const unsigned char* str);
 
 #endif
index 6cdd320..a67dbb5 100644 (file)
-# translation by 0NullChAr0\r
-Italian\r
-               WELCOME TO OPEN PS2 LOADER. MAIN CODE BASED ON SOURCE CODE OF HD PROJECT <http://psx-scene.com> ADAPTATION TO USB ADVANCE FORMAT AND INITIAL GUI BY IFCARO <http://ps2dev.ifcaro.net> MOST OF LOADER CORE IS MADE BY JIMMIKAELKAEL. ALL THE GUI IMPROVEMENTS ARE MADE BY VOLCA. THANKS FOR USING OUR PROGRAM ^^\r
-Open PS2 Loader %s\r
-Salva cambiamenti\r
-O Indietro\r
-Configura Network\r
-<nessun valore>\r
-Impostazioni salvate...\r
-Errore scrittura impostazioni!\r
-Esci\r
-Impostazioni\r
-Giochi USB\r
-Giochi HDD\r
-Giochi Network\r
-Applicazioni\r
-Tema\r
-Lingua\r
-Errore avvio Network: %d\r
-Attivato\r
-Disattivato\r
-OK\r
-Impostazioni Gioco\r
-Rimuovi tutte le impostazioni\r
-Tutte le impostazioni del gioco sono state rimosse\r
-Scorrimento\r
-Lento\r
-Medio\r
-Veloce\r
-Menu Predefinito\r
-Carica dal disco\r
-Per favore attendere\r
-Errore caricamento ID del Gioco\r
-Ordinamento Automatico\r
-Errore caricamento file linguaggio\r
-Disabilita Colori di Debug\r
-Nessun controller rilevato, attendere...\r
-Abilita Cover Art\r
-Schermo ampio\r
-Spegni\r
-Caricamento Configurazioni\r
-Salvataggio Configurazioni\r
-Avvia Periferica\r
-Avviamento periferica USB\r
-Avviamento periferica HDD\r
-Avviamento periferica ETH\r
-Avviamento Applicazioni\r
-Automatico\r
-Manuale\r
-Avvia HDL Server\r
-Avviamento HDL Server...\r
-Caricamento HDL Server... [O] Per Fermare\r
-Premi [X] per fermare HDL...\r
-Scaricamento HDL Server...\r
-Esci per\r
-Colore dello Sfondo\r
-Colore del Testo\r
-IP\r
-Maschera\r
-Ingresso\r
-Porta\r
-Titolo\r
-Utente\r
-Parola d'ordine\r
-<non impostato>\r
-X Accetta\r
-L'oggetto sara' cancellato definitivamente, continuare?\r
-Rinomina\r
-Cancella\r
-Avvia\r
-Impostazioni Schermo\r
-Abilita operazioni di Elimina e Rinomina\r
-Controlla frammentazione Gioco USB\r
-Ricorda ultimo gioco Avviato\r
-Errore, il gioco e' frammentato\r
-Errore, impossibile avviare l'oggetto\r
-Testa\r
-Lasciare vuoto per Autorizzazioni GUEST\r
-Carica Nucleo Alternativo\r
-Metodo lettura data alternativo\r
-Sgancia chiamate Sistema\r
-PSS Disabilitati\r
-Disabilita DVD-DL\r
-Disabilita IGR\r
-Riduci buffer cdvdfsv\r
-Nascondi modulo dev9\r
-Combo IGR alternato\r
-Cambiare le dimensioni della VMC\r
-Creare\r
-Modifica\r
-Annulla\r
-Resetta\r
-Usa generico\r
-Configura VMC\r
-Nome\r
-Dimensione\r
-Stato\r
-Progresso\r
-File VMC esiste\r
-File VMC invalido, la dimensione non e' corretta\r
-File VMC deve essere creato\r
-Errore con il File VMC, continuare con MC fisica ?\r
-Aggiornamento automatico\r
-Informazioni\r
-Sviluppatori
\ No newline at end of file
+# translation by 0NullChAr0
+Italian
+               WELCOME TO OPEN PS2 LOADER. MAIN CODE BASED ON SOURCE CODE OF HD PROJECT <http://psx-scene.com> ADAPTATION TO USB ADVANCE FORMAT AND INITIAL GUI BY IFCARO <http://ps2dev.ifcaro.net> MOST OF LOADER CORE IS MADE BY JIMMIKAELKAEL. ALL THE GUI IMPROVEMENTS ARE MADE BY VOLCA. THANKS FOR USING OUR PROGRAM ^^
+Open PS2 Loader %s
+Salva cambiamenti
+Indietro
+Configura Network
+<nessun valore>
+Impostazioni salvate...
+Errore scrittura impostazioni!
+Esci
+Impostazioni
+Giochi USB
+Giochi HDD
+Giochi Network
+Applicazioni
+Tema
+Lingua
+Avvio Network Errore: %d
+Attivato
+Disattivato
+Ok
+Impostazioni Gioco
+Rimuovi tutte le impostazioni
+Tutte le impostazioni del gioco sono state rimosse
+Scorrimento
+Lento
+Medio
+Veloce
+Menu Predefinito
+Carica dal disco
+Per favore attendere
+Errore caricamento ID del Gioco
+Ordinamento Automatico
+Errore caricamento file linguaggio
+Disabilita Colori di Debug
+Nessun controller rilevato, attendere...
+Abilita Cover Art
+Schermo ampio
+Spegni
+Caricamento Configurazioni
+Salvataggio Configurazioni
+Avvia Periferica
+Avviamento periferica USB
+Avviamento periferica HDD
+Avviamento periferica ETH
+Avviamento Applicazioni
+Automatico
+Manuale
+Avvia HDL Server
+Avviamento HDL Server...
+Caricamento HDL Server... [O] Per Fermare
+Premi [X] per fermare HDL...
+Scaricamento HDL Server...
+Esci per
+Colore dello Sfondo
+Colore del Testo
+IP
+Maschera
+Ingresso
+Porta
+Titolo
+Utente
+Parola d'ordine
+<non impostato>
+Accetta
+L'oggetto sarà cancellato definitivamente, continuare ?
+Rinomina
+Cancella
+Avvia
+Impostazioni Schermo
+Abilita operazioni di Elimina e Rinomina
+Controlla frammentazione Gioco USB
+Ricorda ultimo gioco Avviato
+Errore, il gioco è frammentato
+Errore, impossibile avviare l'oggetto
+Testa
+Lasciare vuoto per Autorizzazioni GUEST
+Carica Nucleo Alternativo
+Metodo lettura data Alternativo
+Sgancia chiamate Sistema
+PSS Disabilitati
+Disabilita DVD-DL
+Disabilita IGR
+Non utilizzato
+Nascondi modulo dev9
+Combo IGR Alternato
+Cambia le dimensioni della VMC
+Creare
+Modifica
+Annulla
+Resetta
+Usa generico
+Configura VMC
+Nome
+Dimensione
+Stato
+Progresso
+File VMC esistente
+File VMC invalido, la dimensione non è corretta
+File VMC ancora da creare
+Errore con il File VMC %s, continuare con MC fisica (slot %d) ?
+Aggiornamento automatico
+Informazioni
+Sviluppatori
+Ritardo USB
+Prefisso Percorso USB
+Lasciare vuoto per uscire al Browser
+Valore in minuti, 0 per disabilitare spin down
+Spin down HDD automatico
+Modo Video
+Colore Dialogo
+Colore Selezionato
+Mostra pagina info
+Info
+ELF Personalizzato
+Colore Selezione
+Riconnetti
+Lasciare vuoto per la lista condivisioni
+Prefisso Percorso ETH
+Backspace
+Spazio
+Invio
+Modo
+VMC Slot 1
+VMC Slot 2
+ID Gioco
+Modo DMA
+V-Sync
+Modo 1
+Modo 2
+Modo 3
+Modo 4
+Modo 5
+Modo 6
+Modo 7
+Modo 8
+Modo 9
+Cronometro Chiamata
+Applica un ritardo alle funzioni CDVD (0 è Predefinito)
\ No newline at end of file
index 7594969..f6b00e4 100644 (file)
--- a/src/dia.c
+++ b/src/dia.c
@@ -76,7 +76,7 @@ int diaShowKeyb(char* text, int maxLen) {
                rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);
 
                //Text
-               fntRenderString(FNT_DEFAULT, 50, 120, ALIGN_NONE, 0, 0, text, gTheme->textColor);
+               fntRenderString(gTheme->fonts[0], 50, 120, ALIGN_NONE, 0, 0, text, gTheme->textColor);
                
                // separating line for simpler orientation
                rmDrawLine(25, 138, 615, 138, gColWhite);
@@ -87,7 +87,7 @@ int diaShowKeyb(char* text, int maxLen) {
                                c[0] = keyb[i + j * KEYB_WIDTH];
 
                                x = 50 + i * 31;
-                               w = fntRenderString(FNT_DEFAULT, x, 170 + 3 * UI_SPACING_H * j, ALIGN_NONE, 0, 0, c, gTheme->uiTextColor) - x;
+                               w = fntRenderString(gTheme->fonts[0], x, 170 + 3 * UI_SPACING_H * j, ALIGN_NONE, 0, 0, c, gTheme->uiTextColor) - x;
                                if ((i + j * KEYB_WIDTH) == selchar)
                                        diaDrawBoundingBox(x, 170 + 3 * UI_SPACING_H * j, w, UI_SPACING_H, 0);
                        }
@@ -99,7 +99,7 @@ int diaShowKeyb(char* text, int maxLen) {
                                rmDrawPixmap(cmdicons[i], 436, 170 + 3 * UI_SPACING_H * i, ALIGN_NONE, cmdicons[i]->Width, cmdicons[i]->Height, SCALING_RATIO, gDefaultCol);
                        
                        x = 477;
-                       w = fntRenderString(FNT_DEFAULT, x, 170 + 3 * UI_SPACING_H * i, ALIGN_NONE, 0, 0, commands[i], gTheme->uiTextColor) - x;
+                       w = fntRenderString(gTheme->fonts[0], x, 170 + 3 * UI_SPACING_H * i, ALIGN_NONE, 0, 0, commands[i], gTheme->uiTextColor) - x;
                        if (i == selcommand)
                                diaDrawBoundingBox(x, 170 + 3 * UI_SPACING_H * i, w, UI_SPACING_H, 0);
                }
@@ -214,7 +214,7 @@ static int diaShowColSel(unsigned char *r, unsigned char *g, unsigned char *b) {
                rmDrawRect(0, 0,  screenWidth, screenHeight, gColDarker);
                
                // "Color selection"
-               fntRenderString(FNT_DEFAULT, 50, 50, ALIGN_NONE, 0, 0, _l(_STR_COLOR_SELECTION), GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
+               fntRenderString(gTheme->fonts[0], 50, 50, ALIGN_NONE, 0, 0, _l(_STR_COLOR_SELECTION), GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
 
                // 3 bars representing the colors...
                size_t co;
@@ -308,12 +308,12 @@ static void diaDrawHint(int text_id) {
        
        char* text = _l(text_id);
        
-       x = screenWidth - fntCalcDimensions(FNT_DEFAULT, text) - 10;
+       x = screenWidth - fntCalcDimensions(gTheme->fonts[0], text) - 10;
        y = gTheme->usedHeight - 40;
        
        // render hint on the lower side of the screen.
        rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
-       fntRenderString(FNT_DEFAULT, x + 5, y + 5, ALIGN_NONE, 0, 0, text, gTheme->textColor);
+       fntRenderString(gTheme->fonts[0], x + 5, y + 5, ALIGN_NONE, 0, 0, text, gTheme->textColor);
 }
 
 /// renders an ui item (either selected or not)
@@ -339,9 +339,9 @@ static void diaRenderItem(int x, int y, struct UIItem *item, int selected, int h
                        // width is text length in pixels...
                        const char *txt = diaGetLocalisedText(item->label.text, item->label.stringId);
                        if(txt && strlen(txt))
-                               *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
+                               *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
                        else
-                               *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
+                               *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
 
                        break;
                }
@@ -379,7 +379,7 @@ static void diaRenderItem(int x, int y, struct UIItem *item, int selected, int h
 
                case UI_OK: {
                        const char *txt = _l(_STR_OK);
-                       *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
+                       *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, txt, txtcol) - x;
                        break;
                }
 
@@ -387,15 +387,15 @@ static void diaRenderItem(int x, int y, struct UIItem *item, int selected, int h
                        char tmp[10];
 
                        snprintf(tmp, 10, "%d", item->intvalue.current);
-                       *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, tmp, txtcol) - x;
+                       *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, tmp, txtcol) - x;
                        break;
                }
 
                case UI_STRING: {
                        if(strlen(item->stringvalue.text))
-                               *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, item->stringvalue.text, txtcol) - x;
+                               *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, item->stringvalue.text, txtcol) - x;
                        else
-                               *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
+                               *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, _l(_STR_NOT_SET), txtcol) - x;
                        break;
                }
 
@@ -408,13 +408,13 @@ static void diaRenderItem(int x, int y, struct UIItem *item, int selected, int h
                                stars[i] = '*';
 
                        stars[i] = '\0';
-                       *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, stars, txtcol) - x;
+                       *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, stars, txtcol) - x;
                        break;
                }
 
                case UI_BOOL: {
                        const char *txtval = _l((item->intvalue.current) ? _STR_ON : _STR_OFF);
-                       *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, txtval, txtcol) - x;
+                       *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, txtval, txtcol) - x;
                        break;
                }
 
@@ -424,7 +424,7 @@ static void diaRenderItem(int x, int y, struct UIItem *item, int selected, int h
                        if (!tv)
                                tv = _l(_STR_NO_ITEMS);
 
-                       *w = fntRenderString(FNT_DEFAULT, x, y, ALIGN_NONE, 0, 0, tv, txtcol) - x;
+                       *w = fntRenderString(gTheme->fonts[0], x, y, ALIGN_NONE, 0, 0, tv, txtcol) - x;
                        break;
                }
 
index 722b058..c963d6b 100644 (file)
@@ -30,7 +30,7 @@ extern int size_freesansfont_raw;
 // freetype vars
 static FT_Library font_library;
 
-static int gCharHeight;
+static int gCharHeight = 16;
 
 static s32 gFontSemaId;
 static ee_sema_t gFontSema;
@@ -72,9 +72,6 @@ typedef struct {
        /// Nonzero if font is used
        int isValid;
 
-       /// Nonzero for custom fonts
-       int isDefault;
-
        /// Texture atlases (default to NULL)
        atlas_t *atlases[ATLAS_MAX];
        
@@ -98,6 +95,40 @@ static FT_Vector delta;
 
 #define GLYPH_PAGE_OK(font,page) ((pageid <= font->cacheMaxPageID) && (font->glyphCache[page]))
 
+static void fntCacheFlushPage(fnt_glyph_cache_entry_t *page) {
+       int i;
+
+       for (i = 0; i < GLYPH_CACHE_PAGE_SIZE; ++i, ++page) {
+               page->isValid = 0;
+               // we're not doing any atlasFree or such - atlas has to be rebuild
+               page->allocation = NULL;
+               page->atlas = NULL;
+       }
+}
+
+static void fntCacheFlush(font_t *font) {
+       // Release all the glyphs from the cache
+       int i;
+       for (i = 0; i <= font->cacheMaxPageID; ++i) {
+               if (font->glyphCache[i]) {
+                       fntCacheFlushPage(font->glyphCache[i]);
+                       free(font->glyphCache[i]);
+                       font->glyphCache[i] = NULL;
+               }
+       }
+
+       free(font->glyphCache);
+       font->glyphCache = NULL;
+       font->cacheMaxPageID = -1;
+
+       // free all atlasses too, they're invalid now anyway
+       int aid;
+       for(aid = 0; aid < ATLAS_MAX; ++aid) {
+               atlasFree(font->atlases[aid]);
+               font->atlases[aid] = NULL;
+       }
+}
+
 static int fntPrepareGlyphCachePage(font_t *font, int pageid) {
        if (pageid > font->cacheMaxPageID) {
                fnt_glyph_cache_entry_t **np = realloc(font->glyphCache, (pageid + 1) * sizeof(fnt_glyph_cache_entry_t *));
@@ -131,33 +162,20 @@ static int fntPrepareGlyphCachePage(font_t *font, int pageid) {
        return 1;
 }
 
-static void fntResetFontDef(font_t *fnt) {
-       fnt->glyphCache = NULL;
-       fnt->cacheMaxPageID = -1;
-       fnt->isValid = 0;
-       fnt->isDefault = 0;
-       
-       int aid;
-       for(aid = 0; aid < ATLAS_MAX; ++aid)
-               fnt->atlases[aid] = NULL;
-               
-       fnt->dataPtr = NULL;
-}
-
 static void fntPrepareCLUT() {
        fontClut.PSM = GS_PSM_T8;
        fontClut.ClutPSM = GS_PSM_CT32;
        fontClut.Clut = memalign(128, 256 * 4);
        fontClut.VramClut = 0;
-       
+
        // generate the clut table
        size_t i;
        u32 *clut = fontClut.Clut;
        for (i = 0; i < 256; ++i) {
                u8 alpha =  i > 0x080 ? 0x080 : i;
-               
+
                *clut = alpha << 24 | i << 16 | i << 8 | i;
-               clut++; 
+               clut++;
        }
 }
 
@@ -166,87 +184,24 @@ static void fntDestroyCLUT() {
        fontClut.Clut = NULL;
 }
 
-void fntInit(void) {
-       LOG("FNTSYS Init\n");
-       int error = FT_Init_FreeType(&font_library);
-
-       if (error) {
-               // just report over the ps2link
-               LOG("FNTSYS Freetype init failed with %x!\n", error);
-               // SleepThread();
-       }
-
-       fntPrepareCLUT();
-
-       gFontSema.init_count = 1;
-       gFontSema.max_count = 1;
-       gFontSema.option = 0;
-       gFontSemaId = CreateSema(&gFontSema);
-
-       int i;
-       for (i = 0; i < FNT_MAX_COUNT; ++i)
-               fntResetFontDef(&fonts[i]);
-
-       // load the default font (will be id=0)
-       fntLoad(NULL, -1, 0);
-}
-
-static void fntCacheFlushPage(fnt_glyph_cache_entry_t *page) {
-       int i;
-
-       for (i = 0; i < GLYPH_CACHE_PAGE_SIZE; ++i, ++page) {
-               page->isValid = 0;
-               // we're not doing any atlasFree or such - atlas has to be rebuild
-               page->allocation = NULL;
-               page->atlas = NULL;
-       }
-}
-
-static void fntCacheFlush(font_t *fnt) {
-       int i;
-
-       // Release all the glyphs from the cache
-       for (i = 0; i <= fnt->cacheMaxPageID; ++i) {
-               if (fnt->glyphCache[i]) {
-                       fntCacheFlushPage(fnt->glyphCache[i]);
-                       free(fnt->glyphCache[i]);
-                       fnt->glyphCache[i] = NULL;
-               }
-       }
-
-       free(fnt->glyphCache);
-       fnt->glyphCache = NULL;
-       fnt->cacheMaxPageID = -1;
-       
-       // free all atlasses too, they're invalid now anyway
-       int aid;
-       for(aid = 0; aid < ATLAS_MAX; ++aid) {
-               atlasFree(fnt->atlases[aid]);
-               fnt->atlases[aid] = NULL;
-       }
-}
-
-static int fntNewFont() {
-       int i;
-       for (i = 0; i < FNT_MAX_COUNT; ++i) {
-               if (fonts[i].isValid == 0) {
-                       fntResetFontDef(&fonts[i]);
-                       return i;
-               }
-       }
+static void fntInitSlot(font_t *font) {
+       font->face = NULL;
+       font->glyphCache = NULL;
+       font->cacheMaxPageID = -1;
+       font->dataPtr = NULL;
+       font->isValid = 0;
 
-       return FNT_ERROR;
+       int aid = 0;
+       for(; aid < ATLAS_MAX; ++aid)
+               font->atlases[aid] = NULL;
 }
 
-void fntDeleteFont(font_t *font) {
-       // skip already deleted fonts
-       if (!font->isValid)
-               return;
-
+static void fntDeleteSlot(font_t *font) {
        // free the glyph cache, atlases, unload the font
        fntCacheFlush(font);
 
        FT_Done_Face(font->face);
+       font->face = NULL;
 
        if (font->dataPtr) {
                free(font->dataPtr);
@@ -256,85 +211,110 @@ void fntDeleteFont(font_t *font) {
        font->isValid = 0;
 }
 
-int fntLoadSlot(font_t *fnt, void* buffer, int bufferSize) {
-       if (!buffer) {
+void fntRelease(int id) {
+       if (id > FNT_DEFAULT && id < FNT_MAX_COUNT)
+               fntDeleteSlot(&fonts[id]);
+}
+
+static int fntLoadSlot(font_t *font, char* path) {
+       void* buffer = NULL;
+       int bufferSize = -1;
+
+       fntInitSlot(font);
+
+       if (path) {
+               buffer = readFile(path, -1, &bufferSize);
+               if (!buffer) {
+                       LOG("FNTSYS Font file loading failed: %s\n", path);
+                       return FNT_ERROR;
+               }
+               font->dataPtr = buffer;
+       } else {
                buffer = &freesansfont_raw;
                bufferSize = size_freesansfont_raw;
-               fnt->isDefault = 1;
        }
 
        // load the font via memory handle
-       int error = FT_New_Memory_Face(font_library, (FT_Byte*) buffer, bufferSize, 0, &fnt->face);
-
+       int error = FT_New_Memory_Face(font_library, (FT_Byte*) buffer, bufferSize, 0, &font->face);
        if (error) {
-               // just report over the ps2link
                LOG("FNTSYS Freetype font loading failed with %x!\n", error);
-               // SleepThread();
-               return -1;
+               fntDeleteSlot(font);
+               return FNT_ERROR;
        }
 
-       gCharHeight = 16;
-
-       error = FT_Set_Char_Size(fnt->face, 0, gCharHeight * 16, 300, 300);
-       /*error = FT_Set_Pixel_Sizes( face,
-        0, // pixel_width
-        gCharHeight ); // pixel_height*/
-
+       error = FT_Set_Char_Size(font->face, 0, gCharHeight * 16, 300, 300);
+       /*error = FT_Set_Pixel_Sizes( face, 0, // pixel_width gCharHeight ); // pixel_height */
        if (error) {
-               // just report over the ps2link
                LOG("FNTSYS Freetype error setting font pixel size with %x!\n", error);
-               // SleepThread();
-               return -1;
+               fntDeleteSlot(font);
+               return FNT_ERROR;
        }
 
-       fnt->isValid = 1;
+       font->isValid = 1;
        return 0;
 }
 
-int fntLoad(void* buffer, int bufferSize, int takeover) {
-       // we need a new slot in the font array
-       int fontID = fntNewFont();
-
-       if (fontID == FNT_ERROR)
-               return FNT_ERROR;
+void fntInit() {
+       LOG("FNTSYS Init\n");
+       int error = FT_Init_FreeType(&font_library);
+       if (error) {
+               // just report over the ps2link
+               LOG("FNTSYS Freetype init failed with %x!\n", error);
+               // SleepThread();
+       }
 
-       font_t *fnt = &fonts[fontID];
+       fntPrepareCLUT();
 
-       if (fntLoadSlot(fnt, buffer, bufferSize) == FNT_ERROR)
-               return FNT_ERROR;
+       gFontSema.init_count = 1;
+       gFontSema.max_count = 1;
+       gFontSema.option = 0;
+       gFontSemaId = CreateSema(&gFontSema);
 
-       if (takeover)
-               fnt->dataPtr = buffer;
+       int i = 0;
+       for (; i < FNT_MAX_COUNT; ++i)
+               fntInitSlot(&fonts[i]);
 
-       return fontID;
+       fntLoadDefault(NULL);
 }
 
 int fntLoadFile(char* path) {
-       LOG("FNTSYS LoadFile: %s\n", path);
-       // load the buffer with font
-       int size = -1;
-       void* customFont = readFile(path, -1, &size);
+       font_t *font;
+       int i = 1;
+       for (; i < FNT_MAX_COUNT; i++) {
+               font = &fonts[i];
+               if (!font->isValid) {
+                       if (fntLoadSlot(font, path) != FNT_ERROR)
+                               return i;
+                       break;
+               }
+       }
 
-       if (!customFont)
-               return FNT_ERROR;
+       return FNT_ERROR;
+}
 
-       int fontID = fntLoad(customFont, size, 1);
+void fntLoadDefault(char* path) {
+       font_t newFont, oldFont;
 
-       return fontID;
-}
+       if (fntLoadSlot(&newFont, path) != FNT_ERROR) {
+               // copy over the new font definition
+               // we have to lock this phase, as the old font may still be used
+               // Note: No check for concurrency is done here, which is kinda funky!
+               WaitSema(gFontSemaId);
+               memcpy(&oldFont, &fonts[FNT_DEFAULT], sizeof(font_t));
+               memcpy(&fonts[FNT_DEFAULT], &newFont, sizeof(font_t));
+               SignalSema(gFontSemaId);
 
-void fntRelease(int id) {
-       if (id < FNT_MAX_COUNT)
-               fntDeleteFont(&fonts[id]);
+               // delete the old font
+               fntDeleteSlot(&oldFont);
+       }
 }
 
-/** Terminates the font rendering system */
-void fntEnd(void) {
+void fntEnd() {
        LOG("FNTSYS End\n");
        // release all the fonts
        int id;
        for (id = 0; id < FNT_MAX_COUNT; ++id)
-               fntDeleteFont(&fonts[id]);
+               fntDeleteSlot(&fonts[id]);
 
        // deinit freetype system
        FT_Done_FreeType(font_library);
@@ -353,8 +333,8 @@ static atlas_t *fntNewAtlas() {
        return atl;
 }
 
-static int fntGlyphAtlasPlace(font_t *fnt, fnt_glyph_cache_entry_t* glyph) {
-       FT_GlyphSlot slot = fnt->face->glyph;
+static int fntGlyphAtlasPlace(font_t *font, fnt_glyph_cache_entry_t* glyph) {
+       FT_GlyphSlot slot = font->face->glyph;
        
        //LOG("FNTSYS GlyphAtlasPlace: Placing the glyph... %d x %d\n", slot->bitmap.width, slot->bitmap.rows);
        
@@ -363,19 +343,16 @@ static int fntGlyphAtlasPlace(font_t *fnt, fnt_glyph_cache_entry_t* glyph) {
                return 1;
        }
        
-       int aid;
-       
-       for (aid = 0; aid < ATLAS_MAX; ++aid) {
+       int aid = 0;
+       for (; aid < ATLAS_MAX; aid++) {
                //LOG("FNTSYS Placing aid %d...\n", aid);
-               atlas_t **atl = &fnt->atlases[aid];
+               atlas_t **atl = &font->atlases[aid];
                if (!*atl) { // atlas slot not yet used
                        //LOG("FNTSYS aid %d is new...\n", aid);
                        *atl = fntNewAtlas();
                }
                
-               glyph->allocation = 
-                       atlasPlace(*atl, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.buffer);
-                       
+               glyph->allocation =     atlasPlace(*atl, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.buffer);
                if (glyph->allocation) {
                        //LOG("FNTSYS Found placement\n", aid);
                        glyph->atlas = *atl;
@@ -389,45 +366,42 @@ static int fntGlyphAtlasPlace(font_t *fnt, fnt_glyph_cache_entry_t* glyph) {
 }
 
 /** Internal method. Makes sure the bitmap data for particular character are pre-rendered to the glyph cache */
-static fnt_glyph_cache_entry_t* fntCacheGlyph(font_t *fnt, uint32_t gid) {
+static fnt_glyph_cache_entry_t* fntCacheGlyph(font_t *font, uint32_t gid) {
        // calc page id and in-page index from glyph id
        int pageid = gid / GLYPH_CACHE_PAGE_SIZE;
        int idx = gid % GLYPH_CACHE_PAGE_SIZE;
 
        // do not call on every char of every font rendering call
-       if (!GLYPH_PAGE_OK(fnt,pageid))
-               if (!fntPrepareGlyphCachePage(fnt, pageid)) // failed to prepare the page...
+       if (!GLYPH_PAGE_OK(font, pageid))
+               if (!fntPrepareGlyphCachePage(font, pageid)) // failed to prepare the page...
                        return NULL;
 
-       fnt_glyph_cache_entry_t *page = fnt->glyphCache[pageid];
-
+       fnt_glyph_cache_entry_t *page = font->glyphCache[pageid];
        /* Should never happen. 
        if (!page) // safeguard
                return NULL;
        */
 
        fnt_glyph_cache_entry_t* glyph = &page[idx];
-
        if (glyph->isValid)
                return glyph;
 
        // not cached but valid. Cache
-       if (!fnt->face) {
+       if (!font->face) {
                LOG("FNTSYS Face is NULL!\n");
        }
 
-       int error = FT_Load_Char(fnt->face, gid, FT_LOAD_RENDER);
-
+       int error = FT_Load_Char(font->face, gid, FT_LOAD_RENDER);
        if (error) {
                LOG("FNTSYS Error loading glyph - %d\n", error);
                return NULL;
        }
 
        // find atlas placement for the glyph
-       if  (!fntGlyphAtlasPlace(fnt, glyph))
+       if  (!fntGlyphAtlasPlace(font, glyph))
                return NULL;
 
-       FT_GlyphSlot slot = fnt->face->glyph;
+       FT_GlyphSlot slot = font->face->glyph;
        glyph->width = slot->bitmap.width;
        glyph->height = slot->bitmap.rows;
        glyph->shx = slot->advance.x;
@@ -442,15 +416,14 @@ static fnt_glyph_cache_entry_t* fntCacheGlyph(font_t *fnt, uint32_t gid) {
 
 void fntSetAspectRatio(float aw, float ah) {
        // flush cache - it will be invalid after the setting
-       int i;
-
-       for (i = 0; i < FNT_MAX_COUNT; ++i) {
+       int i = 0;
+       for (; i < FNT_MAX_COUNT; i++) {
                if (fonts[i].isValid)
                        fntCacheFlush(&fonts[i]);
        }
 
-       // set new aspect ratio (Is this correct, I wonder?)
-       // TODO: error = FT_Set_Char_Size(face, 0, gCharHeight*64, ah*300, aw*300);
+       // TODO: set new aspect ratio (Is this correct, I wonder?)
+       // error = FT_Set_Char_Size(face, 0, gCharHeight*64, ah*300, aw*300);
 }
 
 static void fntRenderGlyph(fnt_glyph_cache_entry_t* glyph, int pen_x, int pen_y) {
@@ -461,8 +434,8 @@ static void fntRenderGlyph(fnt_glyph_cache_entry_t* glyph, int pen_x, int pen_y)
                 *
                 * 2. GS_SETREG_TEX0 for every quad - why? gsKit should only set texture if demanded
                 *    We should prepare a special fnt render method that would step over most of the
-                *    performance problems under - begining with rmSetupQuad and continuing into gsKit
-                *    - this method would handle the preparetion of the quads and GS upload itself,
+                *    performance problems under - beginning with rmSetupQuad and continuing into gsKit
+                *    - this method would handle the preparation of the quads and GS upload itself,
                 *    without the use of prim_quad_texture and rmSetupQuad...
                 *
                 * 3. We should use clut to keep the memory allocations sane - we're linear in the 32bit buffers
@@ -485,17 +458,17 @@ static void fntRenderGlyph(fnt_glyph_cache_entry_t* glyph, int pen_x, int pen_y)
 }
 
 #ifndef __RTL
-int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
+int fntRenderString(int id, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
        // wait for font lock to unlock
        WaitSema(gFontSemaId);
-       font_t *fnt = &fonts[font];
+       font_t *font = &fonts[id];
        SignalSema(gFontSemaId);
 
        if (aligned) {
                if (width) {
-                       x -= min(fntCalcDimensions(font, string), width) >> 1;
+                       x -= min(fntCalcDimensions(id, string), width) >> 1;
                } else {
-                       x -= fntCalcDimensions(font, string) >> 1;
+                       x -= fntCalcDimensions(id, string) >> 1;
                }
                y -= MENU_ITEM_HEIGHT >> 1;
        }
@@ -507,7 +480,7 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
        int xmax = x + width;
        int ymax = y + height;
 
-       use_kerning = FT_HAS_KERNING(fnt->face);
+       use_kerning = FT_HAS_KERNING(font->face);
        state = UTF8_ACCEPT;
        previous = 0;
 
@@ -523,15 +496,15 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
                if (utf8Decode(&state, &codepoint, *string)) // accumulate the codepoint value
                        continue;
 
-               glyph = fntCacheGlyph(fnt, codepoint);
+               glyph = fntCacheGlyph(font, codepoint);
                if (!glyph)
                        continue;
 
                // kerning
                if (use_kerning && previous) {
-                       glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+                       glyph_index = FT_Get_Char_Index(font->face, codepoint);
                        if (glyph_index) {
-                               FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+                               FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
                                pen_x += delta.x >> 6;
                        }
                        previous = glyph_index;
@@ -561,7 +534,7 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
 }
 
 #else
-static void fntRenderSubRTL(font_t *fnt, const unsigned char* startRTL, const unsigned char* string, fnt_glyph_cache_entry_t* glyph, int x, int y) {
+static void fntRenderSubRTL(font_t *font, const unsigned char* startRTL, const unsigned char* string, fnt_glyph_cache_entry_t* glyph, int x, int y) {
        if (glyph) {
                x -= glyph->shx >> 6;
                fntRenderGlyph(glyph, x, y);
@@ -571,14 +544,14 @@ static void fntRenderSubRTL(font_t *fnt, const unsigned char* startRTL, const un
                if (utf8Decode(&state, &codepoint, *startRTL))
                        continue;
 
-               glyph = fntCacheGlyph(fnt, codepoint);
+               glyph = fntCacheGlyph(font, codepoint);
                if (!glyph)
                        continue;
 
                if (use_kerning && previous) {
-                       glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+                       glyph_index = FT_Get_Char_Index(font->face, codepoint);
                        if (glyph_index) {
-                               FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+                               FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
                                x -= delta.x >> 6;
                        }
                        previous = glyph_index;
@@ -589,17 +562,17 @@ static void fntRenderSubRTL(font_t *fnt, const unsigned char* startRTL, const un
        }
 }
 
-int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
+int fntRenderString(int id, int x, int y, short aligned, size_t width, size_t height, const unsigned char* string, u64 colour) {
        // wait for font lock to unlock
        WaitSema(gFontSemaId);
-       font_t *fnt = &fonts[font];
+       font_t *font = &fonts[id];
        SignalSema(gFontSemaId);
 
        if (aligned) {
                if (width) {
-                       x -= min(fntCalcDimensions(font, string), width) >> 1;
+                       x -= min(fntCalcDimensions(id, string), width) >> 1;
                } else {
-                       x -= fntCalcDimensions(font, string) >> 1;
+                       x -= fntCalcDimensions(id, string) >> 1;
                }
                y -= MENU_ITEM_HEIGHT >> 1;
        }
@@ -611,7 +584,7 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
        /*int xmax = x + width;
        int ymax = y + height;*/
 
-       use_kerning = FT_HAS_KERNING(fnt->face);
+       use_kerning = FT_HAS_KERNING(font->face);
        state = UTF8_ACCEPT;
        previous = 0;
 
@@ -625,16 +598,16 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
                if (utf8Decode(&state, &codepoint, *string)) // accumulate the codepoint value
                        continue;
 
-               glyph = fntCacheGlyph(fnt, codepoint);
+               glyph = fntCacheGlyph(font, codepoint);
                if (!glyph)
                        continue;
 
                // kerning
                delta_x = 0;
                if (use_kerning && previous) {
-                       glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+                       glyph_index = FT_Get_Char_Index(font->face, codepoint);
                        if (glyph_index) {
-                               FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+                               FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
                                delta_x = delta.x >> 6;
                        }
                        previous = glyph_index;
@@ -663,7 +636,7 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
                        if (inRTL) { // render RTL
                                inRTL = 0;
                                pen_x = pen_xRTL;
-                               fntRenderSubRTL(fnt, startRTL, string, glyphRTL, pen_xRTL, y);
+                               fntRenderSubRTL(font, startRTL, string, glyphRTL, pen_xRTL, y);
                        }
                }
 
@@ -679,17 +652,17 @@ int fntRenderString(int font, int x, int y, short aligned, size_t width, size_t
 
        if (inRTL) {
                pen_x = pen_xRTL;
-               fntRenderSubRTL(fnt, startRTL, string, glyphRTL, pen_xRTL, y);
+               fntRenderSubRTL(font, startRTL, string, glyphRTL, pen_xRTL, y);
        }
 
        return pen_x;
 }
 #endif
 
-void fntFitString(int font, unsigned char *string, size_t width) {
+void fntFitString(int id, unsigned char *string, size_t width) {
        size_t cw = 0;
        unsigned char *str = string;
-       size_t spacewidth = fntCalcDimensions(font, " ");
+       size_t spacewidth = fntCalcDimensions(id, " ");
        unsigned char *psp = NULL;
        
        while (*str) {
@@ -714,7 +687,7 @@ void fntFitString(int font, unsigned char *string, size_t width) {
                // Calc the font's width...
                // NOTE: The word was terminated, so we're seeing a single word
                // on that position
-               size_t ww = fntCalcDimensions(font, str);
+               size_t ww = fntCalcDimensions(id, str);
                
                if (cw + ww > width) {
                        if (psp) {
@@ -740,16 +713,16 @@ void fntFitString(int font, unsigned char *string, size_t width) {
        }
 }
 
-int fntCalcDimensions(int font, const unsigned char* str) {
+int fntCalcDimensions(int id, const unsigned char* str) {
        int w = 0;
 
        WaitSema(gFontSemaId);
-       font_t *fnt = &fonts[font];
+       font_t *font = &fonts[id];
        SignalSema(gFontSemaId);
 
        uint32_t codepoint;
        uint32_t state = UTF8_ACCEPT;
-       FT_Bool use_kerning = FT_HAS_KERNING(fnt->face);
+       FT_Bool use_kerning = FT_HAS_KERNING(font->face);
        FT_UInt glyph_index, previous = 0;
        FT_Vector delta;
 
@@ -760,15 +733,15 @@ int fntCalcDimensions(int font, const unsigned char* str) {
 
                // Could just as well only get the glyph dimensions
                // but it is probable the glyphs will be needed anyway
-               fnt_glyph_cache_entry_t* glyph = fntCacheGlyph(fnt, codepoint);
+               fnt_glyph_cache_entry_t* glyph = fntCacheGlyph(font, codepoint);
                if (!glyph)
                        continue;
 
                // kerning
                if (use_kerning && previous) {
-                       glyph_index = FT_Get_Char_Index(fnt->face, codepoint);
+                       glyph_index = FT_Get_Char_Index(font->face, codepoint);
                        if (glyph_index) {
-                               FT_Get_Kerning(fnt->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+                               FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
                                w += delta.x >> 6;
                        }
                        previous = glyph_index;
@@ -779,49 +752,3 @@ int fntCalcDimensions(int font, const unsigned char* str) {
 
        return w;
 }
-
-void fntReplace(int id, void* buffer, int bufferSize, int takeover, int asDefault) {
-       font_t *fnt = &fonts[id];
-
-       font_t ndefault, old;
-       fntResetFontDef(&ndefault);
-       fntLoadSlot(&ndefault, buffer, bufferSize);
-       ndefault.isDefault = asDefault;
-
-       // copy over the new font definition
-       // we have to lock this phase, as the old font may still be used
-       WaitSema(gFontSemaId);
-       memcpy(&old, fnt, sizeof(font_t));
-       memcpy(fnt, &ndefault, sizeof(font_t));
-
-       if (takeover)
-               fnt->dataPtr = buffer;
-
-       SignalSema(gFontSemaId);
-
-       // delete the old font
-       fntDeleteFont(&old);
-}
-
-void fntSetDefault(int id) {
-       font_t *fnt = &fonts[id];
-
-       // already default
-       if (fnt->isDefault)
-               return;
-
-       font_t ndefault, old;
-       fntResetFontDef(&ndefault);
-       fntLoadSlot(&ndefault, NULL, -1);
-
-       // copy over the new font definition
-       // we have to lock this phase, as the old font may still be used
-       // Note: No check for concurrency is done here, which is kinda funky!
-       WaitSema(gFontSemaId);
-       memcpy(&old, fnt, sizeof(font_t));
-       memcpy(fnt, &ndefault, sizeof(font_t));
-       SignalSema(gFontSemaId);
-
-       // delete the old font
-       fntDeleteFont(&old);
-}
index c8957f7..2b5ebd6 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -1111,7 +1111,7 @@ static void guiDrawOverlays() {
        else
                snprintf(fps, 20, "%3d ms ----- FPS", time_render);
 
-       fntRenderString(FNT_DEFAULT, screenWidth - 90, 30, ALIGN_CENTER, 0, 0, fps, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
+       fntRenderString(gTheme->fonts[0], screenWidth - 90, 30, ALIGN_CENTER, 0, 0, fps, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
 #endif
 }
 
@@ -1287,10 +1287,10 @@ int guiMsgBox(const char* text, int addAccept, struct UIItem *ui) {
                rmDrawLine(50, 75, screenWidth - 50, 75, gColWhite);
                rmDrawLine(50, 410, screenWidth - 50, 410, gColWhite);
 
-               fntRenderString(FNT_DEFAULT, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, text, gTheme->textColor);
-               guiDrawIconAndText(CIRCLE_ICON, _STR_O_BACK, FNT_DEFAULT, 500, 417, gTheme->selTextColor);
+               fntRenderString(gTheme->fonts[0], screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, text, gTheme->textColor);
+               guiDrawIconAndText(CIRCLE_ICON, _STR_O_BACK, gTheme->fonts[0], 500, 417, gTheme->selTextColor);
                if (addAccept)
-                       guiDrawIconAndText(CROSS_ICON, _STR_X_ACCEPT, FNT_DEFAULT, 70, 417, gTheme->selTextColor);
+                       guiDrawIconAndText(CROSS_ICON, _STR_X_ACCEPT, gTheme->fonts[0], 70, 417, gTheme->selTextColor);
 
                guiEndFrame();
        }
@@ -1312,7 +1312,7 @@ void guiRenderTextScreen(const unsigned char* message) {
 
        rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);
 
-       fntRenderString(FNT_DEFAULT, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, message, gTheme->textColor);
+       fntRenderString(gTheme->fonts[0], screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, message, gTheme->textColor);
 
        guiDrawOverlays();
 
index 2cb11ad..11322a1 100644 (file)
@@ -197,17 +197,10 @@ static int lngLoadFromFile(char* path, char *name) {
                        strId++;
                }
 
-               int size = -1;
                char path[255];
                snprintf(path, 255, "%s/font_%s.ttf", gBaseMCDir, name);
-               
                LOG("LANG Custom font path: %s\n", path);
-               
-               void* customFont = readFile(path, -1, &size);
-               if (customFont)
-                       fntReplace(FNT_DEFAULT, customFont, size, 1, 1);  // consider fonts loaded through language as default, so they won't be reset-ed when changing themes
-               else
-                       fntSetDefault(FNT_DEFAULT);
+               fntLoadDefault(path);
 
                return 1;
        }
index 7e8c2cd..42fa49c 100644 (file)
@@ -518,7 +518,7 @@ void menuRenderMenu() {
        int cp = 0; // current position
        for (it = mainMenu; it; it = it->next, cp++) {
                // render, advance
-               fntRenderString(gTheme->itemsList->font, 320, y, ALIGN_CENTER, 0, 0, submenuItemGetText(&it->item), (cp == sitem) ? gTheme->selTextColor : gTheme->textColor);
+               fntRenderString(gTheme->fonts[0], 320, y, ALIGN_CENTER, 0, 0, submenuItemGetText(&it->item), (cp == sitem) ? gTheme->selTextColor : gTheme->textColor);
                y += spacing;
        }
 }
index 86bf7e7..6707f3d 100644 (file)
@@ -589,13 +589,12 @@ static theme_element_t* initBasic(char* themePath, config_set_t* themeConfig, th
        else
                elem->color = color;
 
+       elem->font = font;
        snprintf(elemProp, 64, "%s_font", name);
-       if (configGetInt(themeConfig, elemProp, &intValue))
-               font = intValue;
-       if (font >= 0 && font < THM_MAX_FONTS)
-               elem->font = theme->fonts[font];
-       else
-               elem->font = FNT_DEFAULT;
+       if (configGetInt(themeConfig, elemProp, &intValue)) {
+               if (intValue > 0 && intValue < THM_MAX_FONTS)
+                       elem->font = theme->fonts[intValue];
+       }
 
        return elem;
 }
@@ -747,7 +746,7 @@ static void validateGUIElems(char* themePath, config_set_t* themeConfig, theme_t
        // 1. check we have a valid Background elements
        if ( !theme->mainElems.first || (theme->mainElems.first->type != TYPE_BACKGROUND) ) {
                LOG("THEMES No valid background found for main, add default BG_ART\n");
-               theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, FNT_DEFAULT);
+               theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, theme->fonts[0]);
                if (themePath)
                        initBackground(themePath, themeConfig, theme, backgroundElem, "bg", "BG", 1, "background");
                else
@@ -759,7 +758,7 @@ static void validateGUIElems(char* themePath, config_set_t* themeConfig, theme_t
        if (theme->infoElems.first) {
                if (theme->infoElems.first->type != TYPE_BACKGROUND) {
                        LOG("THEMES No valid background found for info, add default BG_ART\n");
-                       theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, FNT_DEFAULT);
+                       theme_element_t* backgroundElem = initBasic(themePath, themeConfig, theme, "bg", TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, theme->fonts[0]);
                        if (themePath)
                                initBackground(themePath, themeConfig, theme, backgroundElem, "bg", "BG", 1, "background");
                        else
@@ -792,7 +791,7 @@ static void validateGUIElems(char* themePath, config_set_t* themeConfig, theme_t
                }
        } else {
                LOG("THEMES No itemsList found, adding a default one\n");
-               theme->itemsList = initBasic(themePath, themeConfig, theme, "il", TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+               theme->itemsList = initBasic(themePath, themeConfig, theme, "il", TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                initItemsList(themePath, themeConfig, theme, theme->itemsList, "il", NULL);
                theme->itemsList->next = theme->mainElems.first->next; // Position the itemsList as second element (right after the Background)
                theme->mainElems.first->next = theme->itemsList;
@@ -813,55 +812,55 @@ static int addGUIElem(char* themePath, config_set_t* themeConfig, theme_t* theme
                configGetStr(themeConfig, elemProp, &type);
                if (type) {
                        if (!strcmp(elementsType[TYPE_ATTRIBUTE_TEXT], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                initAttributeText(themePath, themeConfig, theme, elem, name, NULL);
                        } else if (!strcmp(elementsType[TYPE_STATIC_TEXT], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                initStaticText(themePath, themeConfig, theme, elem, name, NULL);
                        } else if (!strcmp(elementsType[TYPE_ATTRIBUTE_IMAGE], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_ATTRIBUTE_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                                initAttributeImage(themePath, themeConfig, theme, elem, name);
                        } else if (!strcmp(elementsType[TYPE_GAME_IMAGE], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                                initGameImage(themePath, themeConfig, theme, elem, name, NULL, 1, NULL, NULL);
                        } else if (!strcmp(elementsType[TYPE_STATIC_IMAGE], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_STATIC_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                                initStaticImage(themePath, themeConfig, theme, elem, name, NULL);
                        } else if (!strcmp(elementsType[TYPE_BACKGROUND], type)) {
                                if (!elems->first) { // Background elem can only be the first one
-                                       elem = initBasic(themePath, themeConfig, theme, name, TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, FNT_DEFAULT);
+                                       elem = initBasic(themePath, themeConfig, theme, name, TYPE_BACKGROUND, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol, theme->fonts[0]);
                                        initBackground(themePath, themeConfig, theme, elem, name, NULL, 1, NULL);
                                }
                        } else if (!strcmp(elementsType[TYPE_MENU_ICON], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_ICON, 40, 40, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_ICON, 40, 40, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                                elem->drawElem = &drawMenuIcon;
                        } else if (!strcmp(elementsType[TYPE_MENU_TEXT], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_TEXT, screenWidth >> 1, 20, ALIGN_CENTER, 200, 20, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_MENU_TEXT, screenWidth >> 1, 20, ALIGN_CENTER, 200, 20, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                elem->drawElem = &drawMenuText;
                        } else if (!strcmp(elementsType[TYPE_ITEMS_LIST], type)) {
                                if (!theme->itemsList) {
-                                       elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                                       elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEMS_LIST, 150, MENU_POS_V, ALIGN_NONE, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                        initItemsList(themePath, themeConfig, theme, elem, name, NULL);
                                        theme->itemsList = elem;
                                }
                        } else if (!strcmp(elementsType[TYPE_ITEM_ICON], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 80, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 80, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                                initGameImage(themePath, themeConfig, theme, elem, name, "ICO", 20, NULL, NULL);
                        } else if (!strcmp(elementsType[TYPE_ITEM_COVER], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 520, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_GAME_IMAGE, 520, theme->usedHeight >> 1, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                                initGameImage(themePath, themeConfig, theme, elem, name, "COV", 10, NULL, NULL);
                        } else if (!strcmp(elementsType[TYPE_ITEM_TEXT], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEM_TEXT, 520, 370, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_ITEM_TEXT, 520, 370, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                elem->drawElem = &drawItemText;
                        } else if (!strcmp(elementsType[TYPE_HINT_TEXT], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                elem->drawElem = &drawHintText;
                        } else if (!strcmp(elementsType[TYPE_INFO_HINT_TEXT], type)) {
-                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_INFO_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, FNT_DEFAULT);
+                               elem = initBasic(themePath, themeConfig, theme, name, TYPE_INFO_HINT_TEXT, 16, -HINT_HEIGHT, ALIGN_NONE, 12, 20, SCALING_RATIO, theme->textColor, theme->fonts[0]);
                                elem->drawElem = &drawInfoHintText;
                        } else if (!strcmp(elementsType[TYPE_LOADING_ICON], type)) {
                                if (!theme->loadingIcon)
-                                       theme->loadingIcon = initBasic(themePath, themeConfig, theme, name, TYPE_LOADING_ICON, -40, -60, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, FNT_DEFAULT);
+                                       theme->loadingIcon = initBasic(themePath, themeConfig, theme, name, TYPE_LOADING_ICON, -40, -60, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]);
                        }
 
                        if (elem) {
@@ -926,12 +925,8 @@ static void thmFree(theme_t* theme) {
                }
 
                // free fonts
-               for (id = 0; id < THM_MAX_FONTS; ++id) {
-                       int fntid = theme->fonts[id];
-
-                       if (fntid != FNT_DEFAULT)
-                               fntRelease(fntid);
-               }
+               for (id = 0; id < THM_MAX_FONTS; ++id)
+                       fntRelease(theme->fonts[id]);
 
                free(theme);
                theme = NULL;
@@ -987,49 +982,29 @@ static void thmSetColors(theme_t* theme) {
 
 static void thmLoadFonts(config_set_t* themeConfig, const char* themePath, theme_t* theme) {
     int fntID; // theme side font id, not the fntSys handle
-       for (fntID = -1; fntID < THM_MAX_FONTS; ++fntID) {
+       for (fntID = 0; fntID < THM_MAX_FONTS; ++fntID) {
                // does the font by the key exist?
                char fntKey[16];
 
-               // -1 is a placeholder for default font...
-               if (fntID >= 0) {
-                       // Default font handle...
-                       theme->fonts[fntID] = FNT_DEFAULT;
-                       snprintf(fntKey, 16, "font%d", fntID);
-               } else {
+               if (fntID == 0) {
                        snprintf(fntKey, 16, "default_font");
+                       theme->fonts[0] = FNT_DEFAULT;
+               } else {
+                       snprintf(fntKey, 16, "font%d", fntID);
+                       theme->fonts[fntID] = theme->fonts[0];
                }
 
-               char *fntFile;
-               int cfgKeyOK = configGetStr(themeConfig, fntKey, &fntFile);
-               if (!cfgKeyOK && (fntID >= 0))
-                       continue;
-
                char fullPath[128];
-
-               if (fntID < 0) {
-                       // replace the default font
-                       if (cfgKeyOK) {
-                               snprintf(fullPath, 128, "%s%s", themePath, fntFile);
-
-                               int size = -1;
-                               void* customFont = readFile(fullPath, -1, &size);
-
-                               if (customFont)
-                                       fntReplace(FNT_DEFAULT, customFont, size, 1, 0);
-                       } else {
-                               // TODO reload the language font file
-                               fntSetDefault(FNT_DEFAULT);
-                       }
-               } else {
+               char *fntFile;
+               if (configGetStr(themeConfig, fntKey, &fntFile)) {
                        snprintf(fullPath, 128, "%s%s", themePath, fntFile);
                        int fntHandle = fntLoadFile(fullPath);
 
                        // Do we have a valid font? Assign the font handle to the theme font slot
                        if (fntHandle != FNT_ERROR)
                                theme->fonts[fntID] = fntHandle;
-               };
-       };
+               }
+       }
 }
 
 static void thmLoad(char* themePath) {
@@ -1061,9 +1036,6 @@ static void thmLoad(char* themePath) {
                addGUIElem(themePath, themeConfig, newT, &newT->mainElems, elementsType[TYPE_ITEM_TEXT], "_");
                addGUIElem(themePath, themeConfig, newT, &newT->mainElems, elementsType[TYPE_HINT_TEXT], "_");
                addGUIElem(themePath, themeConfig, newT, &newT->mainElems, elementsType[TYPE_LOADING_ICON], "_");
-
-               // reset the default font to be sure
-               fntSetDefault(FNT_DEFAULT);
        } else {
                char path[255];
                snprintf(path, 255, "%sconf_theme.cfg", themePath);
index 3a2e5a9..49d4ff0 100644 (file)
Binary files a/thirdparty/font_Hungarian.ttf and b/thirdparty/font_Hungarian.ttf differ