diff --git a/Makefile b/Makefile index 5ff25b5f..8929ec6a 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,8 @@ endif # This is the list of the objects we want to build. Dependancies are built by "make depend" automatically. OBJ = $(OBJDIR)/main.o $(OBJDIR)/init.o $(OBJDIR)/graph.o $(OBJDIR)/sdlscreen.o $(OBJDIR)/misc.o $(OBJDIR)/special.o $(OBJDIR)/buttons.o $(OBJDIR)/palette.o $(OBJDIR)/help.o $(OBJDIR)/operatio.o $(OBJDIR)/pages.o $(OBJDIR)/loadsave.o $(OBJDIR)/readline.o $(OBJDIR)/engine.o $(OBJDIR)/filesel.o $(OBJDIR)/op_c.o $(OBJDIR)/readini.o $(OBJDIR)/saveini.o $(OBJDIR)/shade.o $(OBJDIR)/keyboard.o $(OBJDIR)/io.o $(OBJDIR)/version.o $(OBJDIR)/text.o $(OBJDIR)/SFont.o $(OBJDIR)/setup.o $(OBJDIR)/pxsimple.o $(OBJDIR)/pxtall.o $(OBJDIR)/pxwide.o $(OBJDIR)/pxdouble.o $(OBJDIR)/pxtriple.o $(OBJDIR)/pxtall2.o $(OBJDIR)/pxwide2.o $(OBJDIR)/pxquad.o $(OBJDIR)/windows.o $(OBJDIR)/brush.o $(OBJDIR)/realpath.o $(OBJDIR)/mountlist.o $(OBJDIR)/input.o $(OBJDIR)/hotkeys.o $(OBJDIR)/transform.o $(OBJDIR)/pversion.o +SKIN_FILES = skins/skin_classic.png skins/skin_modern.png skins/font_Classic.png skins/font_Fun.png + all : $(BIN) debug : $(BIN) @@ -240,9 +242,9 @@ ziprelease: version $(BIN) release echo `sed "s/.*=\"\(.*\)\";/\1/" pversion.c`.`svnversion` | tr " :" "_-" | sed -e s/\\(wip\\)\\\\./\\1/I > $(OBJDIR)/versiontag tar cvzf "src-`cat $(OBJDIR)/versiontag`.tgz" --transform 's,^,src/,g' *.c *.h Makefile Makefile.dep gfx2.ico - $(ZIP) $(ZIPOPT) "grafx2-`cat $(OBJDIR)/versiontag`$(TTFLABEL)-$(PLATFORM).$(ZIP)" $(BIN) gfx2def.ini skins/modern.png skins/classic.png gfx2.gif doc/README.txt doc/COMPILING.txt doc/gpl-2.0.txt fonts/8pxfont.png doc/README-zlib1.txt doc/README-SDL.txt doc/README-SDL_image.txt doc/README-SDL_ttf.txt fonts/Tuffy.ttf src-`cat $(OBJDIR)/versiontag`.tgz $(PLATFORMFILES) + $(ZIP) $(ZIPOPT) "grafx2-`cat $(OBJDIR)/versiontag`$(TTFLABEL)-$(PLATFORM).$(ZIP)" $(BIN) gfx2def.ini $(SKIN_FILES) gfx2.gif doc/README.txt doc/COMPILING.txt doc/gpl-2.0.txt fonts/8pxfont.png doc/README-zlib1.txt doc/README-SDL.txt doc/README-SDL_image.txt doc/README-SDL_ttf.txt fonts/Tuffy.ttf src-`cat $(OBJDIR)/versiontag`.tgz $(PLATFORMFILES) $(DELCOMMAND) "src-`cat $(OBJDIR)/versiontag`.tgz" - tar cvzf "grafx2-`cat $(OBJDIR)/versiontag`$(TTFLABEL)-src.tgz" --transform 's,^,grafx2/,g' *.c *.h Makefile Makefile.dep gfx2def.ini skins/modern.png skins/classic.png gfx2.ico gfx2.gif doc/README.txt doc/COMPILING.txt doc/gpl-2.0.txt misc/grafx2.1 misc/grafx2.xpm misc/grafx2.desktop fonts/8pxfont.png fonts/Tuffy.ttf + tar cvzf "grafx2-`cat $(OBJDIR)/versiontag`$(TTFLABEL)-src.tgz" --transform 's,^,grafx2/,g' *.c *.h Makefile Makefile.dep gfx2def.ini $(SKIN_FILES) gfx2.ico gfx2.gif doc/README.txt doc/COMPILING.txt doc/gpl-2.0.txt misc/grafx2.1 misc/grafx2.xpm misc/grafx2.desktop fonts/8pxfont.png fonts/Tuffy.ttf $(DELCOMMAND) "$(OBJDIR)/versiontag" testsed : @@ -303,8 +305,7 @@ install : $(BIN) $(CP) gfx2def.ini $(DESTDIR)$(datadir)/grafx2/ $(CP) gfx2.gif $(DESTDIR)$(datadir)/grafx2/ $(CP) fonts/* $(DESTDIR)$(datadir)/grafx2/fonts/ - $(CP) skins/modern.png $(DESTDIR)$(datadir)/grafx2/skins/ - $(CP) skins/classic.png $(DESTDIR)$(datadir)/grafx2/skins/ + $(CP) $(SKIN_FILES) $(DESTDIR)$(datadir)/grafx2/skins/ # Icon and desktop file for debian $(CP) misc/grafx2.desktop $(DESTDIR)$(datadir)/applications/ $(CP) misc/grafx2.xpm $(DESTDIR)$(datadir)/icons/ @@ -318,8 +319,9 @@ uninstall : $(DELCOMMAND) $(DESTDIR)$(datadir)/grafx2/gfx2.gif $(DELCOMMAND) $(DESTDIR)$(datadir)/grafx2/fonts/* $(if $(wildcard $(DESTDIR)$(datadir)/grafx2/fonts),,$(RMDIR) $(DESTDIR)$(datadir)/grafx2/fonts) - $(DELCOMMAND) $(DESTDIR)$(datadir)/grafx2/skins/modern.png - $(DELCOMMAND) $(DESTDIR)$(datadir)/grafx2/skins/classic.png + cd $(DESTDIR)$(datadir)/grafx2 + $(DELCOMMAND) $(SKIN_FILES) + cd .. $(if $(wildcard $(DESTDIR)$(datadir)/grafx2/skins),,$(RMDIR) $(DESTDIR)$(datadir)/grafx2/skins) # Icon and desktop file for debian $(DELCOMMAND) $(DESTDIR)$(datadir)/applications/grafx2.desktop diff --git a/buttons.c b/buttons.c index c447dab5..2641de9d 100644 --- a/buttons.c +++ b/buttons.c @@ -962,16 +962,33 @@ void Button_Settings(void) // Data for skin selector T_Fileselector Skin_files_list; -/// Checks if the filename is a skin or a font. We avoid adding fonts to the -/// skin selector, and vice versa -char is_font(const char* name) + +// Data for font selector +T_Fileselector Font_files_list; + +// +char * Format_font_filename(const char * fname) { - return name[0]=='f' && name[1]=='o' && name[2]=='n' && name[3]=='t' - && name[4]=='_'; + static char result[12]; + int c; + int length; + + fname+=5; // Assume "font_" prefix + length=strlen(fname) - 4; // assume .png extension + + for (c=0;c<11 && c11) + result[10] = ELLIPSIS_CHARACTER; + + return result; } // Add a skin to the list -void Add_skin(const char *name) +void Add_font_or_skin(const char *name) { const char * fname; int namelength; @@ -983,7 +1000,7 @@ void Add_skin(const char *name) else fname=name; namelength = strlen(fname); - if (namelength>=5 && fname[0]!='_' && !is_font(fname) + if (namelength>=10 && fname[0]!='_' && !strncmp(fname, "skin_", 5) && (!strcasecmp(fname+namelength-4,".png") || !strcasecmp(fname+namelength-4,".gif"))) { @@ -992,12 +1009,25 @@ void Add_skin(const char *name) if (fname[0]=='\0') return; + // Remove directory from full name strcpy(Skin_files_list.First->Full_name, fname); // Reformat the short name differently strcpy(Skin_files_list.First->Short_name, Format_filename(Skin_files_list.First->Full_name, 0) ); } + else if (namelength>=10 && !strncmp(fname, "font_", 5) && (!strcasecmp(fname+namelength-4,".png"))) + { + Add_element_to_list(&Font_files_list, name, 0); + + if (fname[0]=='\0') + return; + + // Remove directory from full name + strcpy(Font_files_list.First->Full_name, fname); + // Reformat the short name differently + strcpy(Font_files_list.First->Short_name,Format_font_filename(Font_files_list.First->Full_name)); + } } @@ -1027,8 +1057,7 @@ void Button_Skins(void) T_Scroller_button * file_scroller; int selected_font=0; - char * fonts[] = {"Classic ", "Fun ", "Melon ", "Fairlight"}; - int nb_fonts = 4; + char * cursors[] = { "Solid", "Transparent", "Thin" }; #define FILESEL_Y 52 @@ -1037,13 +1066,17 @@ void Button_Skins(void) // Here we use the same data container as the fileselectors. // Reinitialize the list Free_fileselector_list(&Skin_files_list); + Free_fileselector_list(&Font_files_list); // Browse the "skins" directory strcpy(skinsdir,Data_directory); strcat(skinsdir,"skins"); // Add each found file to the list - For_each_file(skinsdir, Add_skin); + For_each_file(skinsdir, Add_font_or_skin); // Sort it Sort_list_of_files(&Skin_files_list); + Sort_list_of_files(&Font_files_list); + + //selected_font = Find_file_in_fileselector(&Font_files_list, Config_choisie.Font_name); // -------------------------------------------------------------- @@ -1068,35 +1101,19 @@ void Button_Skins(void) Skin_files_list.Nb_elements,10,selector_position)), // 3 Draw_one_skin_name); // 4 - // Font dropdown - font_dropdown = Window_set_dropdown_button(60,19,86,11,0, - fonts[selected_font],1,0,1,RIGHT_SIDE|LEFT_SIDE); // 5 - for (temp=0; tempShort_name,1,0,1,RIGHT_SIDE|LEFT_SIDE); // 5 + for (temp=0; tempShort_name); // Cancel Window_set_normal_button(62,136, 51,14,"Cancel",0,1,SDLK_ESCAPE); // 6 - // Button item du curseur - if(Config_choisie.Cursor==0) - cursor_dropdown = Window_set_dropdown_button(60,34,104,11,0,"Solid ",1,0,1,RIGHT_SIDE|LEFT_SIDE); // 7 - else if(Config_choisie.Cursor==1) - cursor_dropdown = Window_set_dropdown_button(60,34,104,11,0,"Transparent",1,0,1,RIGHT_SIDE|LEFT_SIDE); // 7 - else - cursor_dropdown = Window_set_dropdown_button(60,34,104,11,0,"Thin ",1,0,1,RIGHT_SIDE|LEFT_SIDE); // 7 - Window_dropdown_add_item(cursor_dropdown,0,"Solid "); - Window_dropdown_add_item(cursor_dropdown,1,"Transparent"); - Window_dropdown_add_item(cursor_dropdown,2,"Thin "); + // Dropdown list to choose cursor type + cursor_dropdown = Window_set_dropdown_button(60,34,104,11,0,cursors[Config_choisie.Cursor],1,0,1,RIGHT_SIDE|LEFT_SIDE); // 7 + for (temp=0; temp<3; temp++) + Window_dropdown_add_item(cursor_dropdown,temp,cursors[temp]); - // Select the current skin (we know it does exist, so no need to do a - // nearest match search) - //Highlight_file(Config_choisie.SkinFile); - // On efface les anciens noms de fichier: - //Window_rectangle(8-1,FILESEL_Y-1,144+2,80+2,MC_Black); - // On affiche les nouveaux: - //Display_skins_list(Main_fileselector_position,Main_fileselector_offset); Window_redraw_list(skin_list); Update_window_area(0,0,Window_width, Window_height); @@ -1242,13 +1259,8 @@ void Button_Skins(void) if(clicked_button == 1) { - char* tmp_font; - char* tmp_ptr; T_Gui_skin * gfx; - strcpy(skinsdir,"skins/"); - strcat( - skinsdir, - Get_item_by_index(&Skin_files_list, skin_list->List_start+skin_list->Cursor_position)->Full_name); + strcpy(skinsdir, Get_item_by_index(&Skin_files_list, skin_list->List_start+skin_list->Cursor_position)->Full_name); gfx=Load_graphics(skinsdir); if (gfx == NULL) // Error { @@ -1257,30 +1269,21 @@ void Button_Skins(void) else { byte * new_font; - free(Gfx); Gfx = gfx; // Font selection - tmp_font = strdup(fonts[selected_font]); - tmp_ptr=tmp_font; - while(*tmp_ptr!=' ' && *tmp_ptr!='\0') - tmp_ptr++; - *tmp_ptr='\0'; - new_font = Load_font(tmp_font); - free(tmp_font); + new_font = Load_font(Get_item_by_index(&Font_files_list,selected_font)->Full_name); if (new_font) { + const char * fname; free(Menu_font); Menu_font = new_font; free (Config_choisie.Font_name); - Config_choisie.Font_name = (char *)malloc(strlen(fonts[selected_font])+1); - if (Config_choisie.Font_name) - { - strcpy(Config_choisie.Font_name,fonts[selected_font]); - } + fname = Get_item_by_index(&Font_files_list,selected_font)->Full_name; + Config_choisie.Font_name = strdup(fname); } - strcpy(Config_choisie.SkinFile,skinsdir+6); + strcpy(Config_choisie.SkinFile,skinsdir); } Config = Config_choisie ; diff --git a/engine.c b/engine.c index e133065c..605cf0a3 100644 --- a/engine.c +++ b/engine.c @@ -2289,8 +2289,11 @@ short Window_dropdown_on_click(T_Dropdown_button *Button) Window_attribute2=item->Number; if (Button->Display_choice) { - // Mettre à jour automatiquement le libellé de la dropdown - Print_in_window(Button->Pos_X+2,Button->Pos_Y+(Button->Height-7)/2,item->Label,MC_Black,MC_Light); + // Automatically update the label of the dropdown list. + int text_length = (Button->Width-4-(Button->Display_arrow?8:0))/8; + // Clear original label area + Window_rectangle(Button->Pos_X+2,Button->Pos_Y+(Button->Height-7)/2,text_length*8,8,MC_Light); + Print_in_window_limited(Button->Pos_X+2,Button->Pos_Y+(Button->Height-7)/2,item->Label,text_length ,MC_Black,MC_Light); } return Button->Number; } diff --git a/filesel.c b/filesel.c index 16e6c3f0..4a449f2f 100644 --- a/filesel.c +++ b/filesel.c @@ -462,9 +462,8 @@ void Sort_list_of_files(T_Fileselector *list) T_Fileselector_item * next_item; T_Fileselector_item * next_to_next_item; - // Avant de trier quoi que ce soit, on vérifie qu'il y ait suffisamment - // d'éléments pour qu'il soit possibles qu'ils soient en désordre: - if (list->Nb_elements>1) + // Check there are at least two elements before sorting + if (list->First && list->First->Next) { do { diff --git a/filesel.h b/filesel.h index ed722a4a..1cbd2432 100644 --- a/filesel.h +++ b/filesel.h @@ -38,3 +38,5 @@ void Sort_list_of_files(T_Fileselector *list); void Recount_files(T_Fileselector *list); T_Fileselector_item * Get_item_by_index(T_Fileselector *list, short index); + +short Find_file_in_fileselector(T_Fileselector *list, char * fname); diff --git a/gfx2def.ini b/gfx2def.ini index 4f5382ef..7d42e54a 100644 --- a/gfx2def.ini +++ b/gfx2def.ini @@ -318,7 +318,7 @@ ; Name of the skinfile you want to | Nom du fichier skin que vous voulez ; use. | utiliser. - ; default 'modern.png' - Skin_file = modern.png + ; default 'skin_modern.png' + Skin_file = skin_modern.png ; end of configuration diff --git a/init.c b/init.c index c917b99e..16b993f1 100644 --- a/init.c +++ b/init.c @@ -772,6 +772,7 @@ T_Gui_skin * Load_graphics(const char * skin_file) // Read the "skin" file strcpy(filename,Data_directory); + strcat(filename,"skins" PATH_SEPARATOR); strcat(filename,skin_file); gui=IMG_Load(filename); @@ -848,7 +849,7 @@ byte * Load_font(const char * font_name) } // Read the file containing the image - sprintf(filename,"%sskins%sfont_%s.png", Data_directory, PATH_SEPARATOR, font_name); + sprintf(filename,"%sskins%s%s", Data_directory, PATH_SEPARATOR, font_name); image=IMG_Load(filename); if (!image) diff --git a/main.c b/main.c index ff8b3d06..dea075bd 100644 --- a/main.c +++ b/main.c @@ -76,7 +76,7 @@ #endif // filename for the current GUI skin file. -static char Gui_skin_file[MAX_PATH_CHARACTERS]= "skins" PATH_SEPARATOR ; +static char Gui_skin_file[MAX_PATH_CHARACTERS]; //--- Affichage de la syntaxe, et de la liste des modes vidéos disponibles --- void Display_syntax(void) @@ -534,12 +534,16 @@ int Init_program(int argc,char * argv[]) Analyze_command_line(argc,argv); // Load sprites, palette etc. - strcpy(Gui_skin_file+6,Config.SkinFile); + strcpy(Gui_skin_file,Config.SkinFile); Gfx = Load_graphics(Gui_skin_file); if (Gfx == NULL) { - printf("%s", Gui_loading_error_message); - Error(ERROR_GUI_MISSING); + Gfx = Load_graphics("skin_modern.png"); + if (Gfx == NULL) + { + printf("%s", Gui_loading_error_message); + Error(ERROR_GUI_MISSING); + } } // Infos sur les trames (Sieve) Sieve_mode=0; @@ -558,7 +562,7 @@ int Init_program(int argc,char * argv[]) // Font { byte *font; - font = Load_font("Classic"); + font = Load_font("font_Classic.png"); if (font) Menu_font=font; } diff --git a/readini.c b/readini.c index bef5316f..ccad626a 100644 --- a/readini.c +++ b/readini.c @@ -818,7 +818,7 @@ int Load_INI(T_Config * conf) if(!Load_INI_get_string(file,buffer,"Skin_file",value_label,1)) strcpy(conf->SkinFile,value_label); else - strcpy(conf->SkinFile,"modern.png"); + strcpy(conf->SkinFile,"skin_modern.png"); fclose(file); diff --git a/skins/classic.png b/skins/skin_classic.png similarity index 100% rename from skins/classic.png rename to skins/skin_classic.png diff --git a/skins/modern.png b/skins/skin_modern.png similarity index 100% rename from skins/modern.png rename to skins/skin_modern.png