diff --git a/buttons.c b/buttons.c index a68c76af..f530a3a2 100644 --- a/buttons.c +++ b/buttons.c @@ -1035,6 +1035,10 @@ void Button_Skins(void) T_Dropdown_button * cursor_dropdown; T_List_button * skin_list; T_Scroller_button * file_scroller; + int selected_font=0; + + char * fonts[] = {"Classic", "Fun", "Melon", "Fairlight"}; + int nb_fonts = 4; #define FILESEL_Y 52 @@ -1075,9 +1079,11 @@ void Button_Skins(void) Draw_one_skin_name); // 4 // Boutons de fontes - font_dropdown = Window_set_dropdown_button(60,19,70,11,0,(Config_choisie.Font==0)?"Classic":"Fun ",1,0,1,RIGHT_SIDE|LEFT_SIDE); // 5 - Window_dropdown_add_item(font_dropdown,0,"Classic"); - Window_dropdown_add_item(font_dropdown,1,"Fun "); + font_dropdown = Window_set_dropdown_button(60,19,70,11,0, fonts[selected_font],1,0,1,RIGHT_SIDE|LEFT_SIDE); // 5 + for (temp=0; tempFun_font; - else - Menu_font=Gfx->System_font; + new_font = Load_font(fonts[selected_font]); + if (new_font) + { + free(Menu_font); + Menu_font = new_font; + if (Config_choisie.Font_name) + { + free (Config_choisie.Font_name); + Config_choisie.Font_name = NULL; + } + Config_choisie.Font_name = (char *)malloc(strlen(fonts[selected_font])+1); + if (Config_choisie.Font_name) + { + strcpy(Config_choisie.Font_name,fonts[selected_font]); + } + } strcpy(Config_choisie.SkinFile,skinsdir+6); } diff --git a/gfx2def.ini b/gfx2def.ini index 752096b8..4f5382ef 100644 --- a/gfx2def.ini +++ b/gfx2def.ini @@ -76,11 +76,6 @@ ; the menus and tool-bar | des menus et de la barre d'outils Menu_ratio = 1 ; (default 1) - ; Font: | Police de caractères (fonte): - ; 1: Classic | 1: Classique - ; 2: Fun | 2: Fun - Font = 1 ; (default 1) - [FILE_SELECTOR] # [SELECTEUR_DE_FICHIERS] ; Show hidden files and | Afficher les fichiers et répertoires diff --git a/global.h b/global.h index 3980a64b..0542ea6b 100644 --- a/global.h +++ b/global.h @@ -794,7 +794,7 @@ GFX2_GLOBAL byte Resolution_in_command_line; // - Graphic -/// Pointer to the font selected for menus. It's either ::Gfx->System_font or ::Gfx->Fun_font +/// Pointer to the font selected for menus. GFX2_GLOBAL byte * Menu_font; /// Pointer to the current active skin. diff --git a/init.c b/init.c index 9f3470c4..c917b99e 100644 --- a/init.c +++ b/init.c @@ -474,50 +474,6 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx) cursor_x+=16; } cursor_y+=16; - - // Font Système - for (i=0; i<256; i++) - { - // Rangés par ligne de 32 - if ((i%32)==0) - { - if (i!=0) - cursor_y+=8; - if (GUI_seek_down(gui, &cursor_x, &cursor_y, neutral_color, "system font")) - return 1; - } - else - { - if (GUI_seek_right(gui, &cursor_x, cursor_y, neutral_color, "system font")) - return 1; - } - if (Read_GUI_block(gui, cursor_x, cursor_y, &gfx->System_font[i*64], 8, 8, "system font",2)) - return 1; - cursor_x+=8; - } - cursor_y+=8; - - // Font Fun - for (i=0; i<256; i++) - { - // Rangés par ligne de 32 - if ((i%32)==0) - { - if (i!=0) - cursor_y+=8; - if (GUI_seek_down(gui, &cursor_x, &cursor_y, neutral_color, "fun font")) - return 1; - } - else - { - if (GUI_seek_right(gui, &cursor_x, cursor_y, neutral_color, "fun font")) - return 1; - } - if (Read_GUI_block(gui, cursor_x, cursor_y, &gfx->Fun_font[i*64], 8, 8, "fun font",2)) - return 1; - cursor_x+=8; - } - cursor_y+=8; // Font help normale for (i=0; i<256; i++) @@ -835,6 +791,82 @@ T_Gui_skin * Load_graphics(const char * skin_file) return gfx; } +// ---- font loading ----- + +byte Parse_font(SDL_Surface * image, byte * font) +{ + int character; + byte color; + int x, y; + int chars_per_line; + + // Check image size + if (image->w % 8) + { + sprintf(Gui_loading_error_message, "Error in font file: Image width is not a multiple of 8.\n"); + return 1; + } + if (image->w * image->h < 8*8*256) + { + sprintf(Gui_loading_error_message, "Error in font file: Image is too small to be a 256-character 8x8 font.\n"); + return 1; + } + chars_per_line = image->w/8; + + for (character=0; character < 256; character++) + { + for (y=0; y<8; y++) + { + for (x=0;x<8; x++) + { + // Pick pixel + color = Get_SDL_pixel_8(image, (character % chars_per_line)*8+x, (character / chars_per_line)*8+y); + if (color > 1) + { + sprintf(Gui_loading_error_message, "Error in font file: Only colors 0 and 1 can be used for the font.\n"); + return 1; + } + // Put it in font. 0 = BG, 1 = FG. + font[character*64 + y*8 + x]=color; + } + } + } + return 0; +} + +byte * Load_font(const char * font_name) +{ + byte * font; + char filename[MAX_PATH_CHARACTERS]; + SDL_Surface * image; + + font = (byte *)malloc(8*8*256); + if (font == NULL) + { + sprintf(Gui_loading_error_message, "Not enough memory to read font file\n"); + return NULL; + } + + // Read the file containing the image + sprintf(filename,"%sskins%sfont_%s.png", Data_directory, PATH_SEPARATOR, font_name); + + image=IMG_Load(filename); + if (!image) + { + sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?)\n"); + free(font); + return NULL; + } + if (Parse_font(image, font)) + { + SDL_FreeSurface(image); + free(font); + return NULL; + } + SDL_FreeSurface(image); + return font; +} + // Initialisation des boutons: diff --git a/init.h b/init.h index 6a28c728..86053986 100644 --- a/init.h +++ b/init.h @@ -32,3 +32,11 @@ void Set_config_defaults(void); void Init_sighandler(void); extern char Gui_loading_error_message[512]; + +/// +/// Loads a 8x8 monochrome font, the kind used in all menus and screens. +/// This function allocates the memory, and returns a pointer to it when +/// successful. +/// If an error is encountered, it frees what needs it, prints an error message +/// in ::Gui_loading_error_message, and returns NULL. +byte * Load_font(const char * font_name); diff --git a/main.c b/main.c index 956d09c7..c76df867 100644 --- a/main.c +++ b/main.c @@ -555,11 +555,14 @@ int Init_program(int argc,char * argv[]) Fore_color=MC_White; Back_color=MC_Black; - // Prise en compte de la fonte - if (Config.Font) - Menu_font=Gfx->Fun_font; - else - Menu_font=Gfx->System_font; + // Font + { + byte *font; + font = Load_font("Classic"); + if (font) + Menu_font=font; + } + memcpy(Main_palette, Gfx->Default_palette, sizeof(T_Palette)); diff --git a/readini.c b/readini.c index f1594c1d..bef5316f 100644 --- a/readini.c +++ b/readini.c @@ -523,12 +523,6 @@ int Load_INI(T_Config * conf) goto Erreur_ERREUR_INI_CORROMPU; conf->Ratio=values[0]; - if ((return_code=Load_INI_get_values (file,buffer,"Font",1,values))) - goto Erreur_Retour; - if ((values[0]<1) || (values[0]>2)) - goto Erreur_ERREUR_INI_CORROMPU; - conf->Font=values[0]-1; - if ((return_code=Load_INI_reach_group(file,buffer,"[FILE_SELECTOR]"))) goto Erreur_Retour; diff --git a/saveini.c b/saveini.c index 4130624a..2bf95c04 100644 --- a/saveini.c +++ b/saveini.c @@ -476,10 +476,6 @@ int Save_INI(T_Config * conf) if ((return_code=Save_INI_set_values (Ancien_fichier,Nouveau_fichier,buffer,"Menu_ratio",1,values,0))) goto Erreur_Retour; - values[0]=(conf->Font)+1; - if ((return_code=Save_INI_set_values (Ancien_fichier,Nouveau_fichier,buffer,"Font",1,values,0))) - goto Erreur_Retour; - if ((return_code=Save_INI_reach_group(Ancien_fichier,Nouveau_fichier,buffer,"[FILE_SELECTOR]"))) goto Erreur_Retour; diff --git a/skins/classic.png b/skins/classic.png index 8de524a2..6ce4c024 100644 Binary files a/skins/classic.png and b/skins/classic.png differ diff --git a/skins/_classic.png b/skins/font_Classic.png similarity index 100% rename from skins/_classic.png rename to skins/font_Classic.png diff --git a/skins/_fairlight.png b/skins/font_Fairlight.png similarity index 100% rename from skins/_fairlight.png rename to skins/font_Fairlight.png diff --git a/skins/_fun.png b/skins/font_Fun.png similarity index 100% rename from skins/_fun.png rename to skins/font_Fun.png diff --git a/skins/_melon.png b/skins/font_Melon.png similarity index 100% rename from skins/_melon.png rename to skins/font_Melon.png diff --git a/skins/modern.png b/skins/modern.png index d0f72fa0..4247fc14 100644 Binary files a/skins/modern.png and b/skins/modern.png differ diff --git a/struct.h b/struct.h index ad0a107d..38f9ab6d 100644 --- a/struct.h +++ b/struct.h @@ -240,8 +240,8 @@ typedef struct /// This structure holds all the settings which are saved and loaded as gfx2.ini. typedef struct { - byte Font; ///< Boolean, true to use the "fun" font in menus, false to use the classic one. - char SkinFile[64]; ///< String, name of the file where all the graphic data is stored + char *Font_name; ///< Name of the font used in the menus. Matches file skins/font_*.png (Case-sensitive on some filesystems) + char SkinFile[64]; ///< String, name of the file where all the graphic data is stored int Show_hidden_files; ///< Boolean, true to show hidden files in fileselectors. int Show_hidden_directories; ///< Boolean, true to show hidden directories in fileselectors. // int Show_system_directories; ///< (removed when converted from DOS) @@ -380,13 +380,6 @@ typedef struct /// Bitmap data for the small 8x8 icons. byte Icon_sprite[NB_ICON_SPRITES][ICON_SPRITE_HEIGHT][ICON_SPRITE_WIDTH]; - // 8x8 fonts - - /// Bitmap data for the classic 8x8 font used in menus etc. - byte System_font[256*8*8]; - /// Bitmap data for the "fun" 8x8 font used in menus etc. - byte Fun_font [256*8*8]; - /// A default 256-color palette. T_Palette Default_palette;