Separated font graphics from skin graphics. WIP, a lot is still hard-coded (font list) or not coded at all (save/load in ini, and match in skin selection screen).

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@885 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-06-23 21:04:58 +00:00
parent 77c87dcc24
commit ab9671b286
15 changed files with 124 additions and 83 deletions

View File

@ -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; temp<nb_fonts; temp++)
Window_dropdown_add_item(font_dropdown,temp,fonts[temp]);
// Cancel
Window_set_normal_button(62,136, 51,14,"Cancel",0,1,SDLK_ESCAPE); // 6
@ -1121,7 +1127,7 @@ void Button_Skins(void)
case 4 : // a file is selected
break;
case 5 : // Font dropdown
Config_choisie.Font=Window_attribute2; // récupère le numéro de l'item selectionné
selected_font=Window_attribute2; // Get the index of the chosen font.
break;
// 5: Cancel
case 7 : // Cursor
@ -1257,13 +1263,27 @@ void Button_Skins(void)
}
else
{
byte * new_font;
free(Gfx);
Gfx = gfx;
// Font selection
if (Config_choisie.Font)
Menu_font=Gfx->Fun_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);
}

View File

@ -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

View File

@ -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.

120
init.c
View File

@ -475,50 +475,6 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
}
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:

8
init.h
View File

@ -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);

13
main.c
View File

@ -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));

View File

@ -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;

View File

@ -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;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -240,7 +240,7 @@ 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 *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.
@ -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;