diff --git a/src/buttons.c b/src/buttons.c index 28661e20..c8af5239 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -5056,7 +5056,7 @@ void Button_Text(int btn) Print_in_window_underscore(206,89,"Italic", MC_Dark, MC_Light,1); // Scroller des fontes - font_scroller = Window_set_scroller_button(165,35,NB_FONTS*8,Nb_fonts,NB_FONTS,list_start); // 5 + font_scroller = Window_set_scroller_button(165,35,NB_FONTS*8,Font_count(),NB_FONTS,list_start); // 5 // Liste des fontes disponibles font_list_button = Window_set_special_button(8,35,152,NB_FONTS*8,0); // 6 Window_display_frame_in(7, 33, 154, NB_FONTS*8+4); diff --git a/src/text.c b/src/text.c index 93815cfa..e1d59567 100644 --- a/src/text.c +++ b/src/text.c @@ -92,7 +92,6 @@ typedef struct T_Font * Head of the font linked list */ T_Font * font_list_start; -int Nb_fonts; // Inspiré par Allegro #define EXTID(a,b,c) ((((a)&255)<<16) | (((b)&255)<<8) | (((c)&255))) @@ -116,7 +115,6 @@ static void Insert_font(T_Font * font) { // Premiere (liste vide) font_list_start = font; - Nb_fonts++; } else { @@ -134,7 +132,6 @@ static void Insert_font(T_Font * font) // Avant la premiere font->Next=font_list_start; font_list_start=font; - Nb_fonts++; } else { @@ -152,7 +149,6 @@ static void Insert_font(T_Font * font) } font->Next=searched_font->Next; searched_font->Next=font; - Nb_fonts++; } } } @@ -248,36 +244,37 @@ static void Add_font(const char *name, const char * font_name) // Trouve le nom d'une fonte par son numéro -char * Font_name(int index) +const char * Font_name(int index) { T_Font *font = font_list_start; - if (index<0 ||index>=Nb_fonts) + if (index < 0 || font == NULL) return ""; while (index--) + { font = font->Next; + if (font == NULL) + return ""; + } return font->Name; } // Trouve le libellé d'affichage d'une fonte par son numéro // Renvoie un pointeur sur un buffer statique de 20 caracteres. -char * Font_label(int index) +const char * Font_label(int index) { - T_Font *font; - static char label[20]; + T_Font *font = font_list_start; - strcpy(label, " "); - - // Recherche de la fonte font = font_list_start; - if (index<0 ||index>=Nb_fonts) - return label; + if (index < 0 || font == NULL) + return " "; while (index--) + { font = font->Next; - - // Libellé - strcpy(label, font->Label); - return label; + if (font == NULL) + return " "; + } + return font->Label; } @@ -285,13 +282,30 @@ char * Font_label(int index) int TrueType_font(int index) { T_Font *font = font_list_start; - if (index<0 ||index>=Nb_fonts) + if (index < 0 || font == NULL) return 0; while (index--) + { font = font->Next; + if (font == NULL) + return 0; + } return font->Is_truetype; } +int Font_count(void) +{ + T_Font *font = font_list_start; + int count = 0; + + while (font != NULL) + { + count++; + font = font->Next; + } + return count; +} + #if defined(WIN32) && defined(NOTTF) static int CALLBACK EnumFontFamCallback(CONST LOGFONTA *lpelf, CONST TEXTMETRICA *lpntm, DWORD FontType, LPARAM lParam) { @@ -328,7 +342,6 @@ void Init_text(void) // Initialisation des fontes font_list_start = NULL; - Nb_fonts=0; // Parcours du répertoire "fonts" directory_name = Filepath_append_to_dir(Data_directory, FONTS_SUBDIRECTORY); For_each_file(directory_name, Add_font); @@ -793,11 +806,15 @@ byte *Render_text(const char *str, int font_number, int size, int antialias, int #endif // Verification type de la fonte - if (font_number<0 ||font_number>=Nb_fonts) + if (font_number < 0 || font == NULL) return NULL; while (index--) + { font = font->Next; + if (font == NULL) + return NULL; + } if (font->Is_truetype) { #if !defined(NOTTF) diff --git a/src/text.h b/src/text.h index 15b537a6..d7ee302b 100644 --- a/src/text.h +++ b/src/text.h @@ -48,12 +48,11 @@ void Add_font(const char *name); byte *Render_text(const char *str, int font_number, int size, int antialias, int bold, int italic, int *width, int *height, T_Palette palette); /// Finds a label to display for a font declared with ::Add_font(). -char * Font_label(int index); +const char * Font_label(int index); /// Finds the filename of a font declared with ::Add_font(). -char * Font_name(int index); +const char * Font_name(int index); /// Returns true if the font of this number is TrueType, false if it's a SFont bitmap. int TrueType_font(int index); /// -/// Number of fonts declared with a series of ::Add_font(). This is public for -/// convenience, but functionaly it is read-only. -extern int Nb_fonts; +/// Number of fonts declared with a series of ::Add_font() +int Font_count(void);