Update File selector to load/save palettes

Also "constify" the format array
This commit is contained in:
Thomas Bernard 2018-01-24 15:51:32 +01:00
parent 48ae5bf0d8
commit 4ffa389a90
6 changed files with 38 additions and 14 deletions

View File

@ -1174,6 +1174,8 @@ void Button_Settings(void)
Spare.selector.Offset=0;
Brush_selector.Position=0;
Brush_selector.Offset=0;
Palette_selector.Position=0;
Palette_selector.Offset=0;
}
if(Config.Allow_multi_shortcuts && !selected_config.Allow_multi_shortcuts)
{
@ -3135,7 +3137,7 @@ void Load_picture(enum CONTEXT_TYPE type)
Init_context_layered_image(&context, filename, directory);
context.Type = CONTEXT_PALETTE;
context.Format = FORMAT_PAL;
selector = &Main.selector;
selector = &Palette_selector;
break;
default:
return; // DO NOTHING
@ -3418,6 +3420,7 @@ void Save_picture(enum CONTEXT_TYPE type)
T_IO_Context save_context;
static char filename [MAX_PATH_CHARACTERS];
static char directory[MAX_PATH_CHARACTERS];
T_Selector_settings * selector;
if (type == CONTEXT_MAIN_IMAGE)
{
@ -3425,6 +3428,7 @@ void Save_picture(enum CONTEXT_TYPE type)
strcpy(directory, Main.backups->Pages->File_directory);
Init_context_layered_image(&save_context, filename, directory);
save_context.Format = Main.fileformat;
selector = &Main.selector;
}
else if (type == CONTEXT_BRUSH)
{
@ -3432,6 +3436,7 @@ void Save_picture(enum CONTEXT_TYPE type)
strcpy(directory, Brush_file_directory);
Init_context_brush(&save_context, filename, directory);
save_context.Format = Brush_fileformat;
selector = &Brush_selector;
}
else if (type == CONTEXT_PALETTE)
{
@ -3450,11 +3455,12 @@ void Save_picture(enum CONTEXT_TYPE type)
// Set format to PAL
save_context.Format = FORMAT_PAL;
selector = &Palette_selector;
}
else
return;
confirm=Button_Load_or_Save((type==CONTEXT_MAIN_IMAGE)?&Main.selector:&Brush_selector,0, &save_context);
confirm=Button_Load_or_Save(selector, 0, &save_context);
if (confirm && File_exists(save_context.File_name))
{
@ -3472,7 +3478,7 @@ void Save_picture(enum CONTEXT_TYPE type)
if (confirm)
{
T_Format * format;
const T_Format * format;
old_cursor_shape=Cursor_shape;
Hide_cursor();

View File

@ -1495,9 +1495,16 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
for (format=0; format < Nb_known_formats(); format++)
{
if (((context->Type == CONTEXT_PALETTE) == File_formats[format].Palette_only) &&
((load && (File_formats[format].Load || File_formats[format].Identifier <= FORMAT_ALL_FILES)) || (!load && File_formats[format].Save)))
Window_dropdown_add_item(formats_dropdown,File_formats[format].Identifier,File_formats[format].Label);
if (File_formats[format].Identifier > FORMAT_ALL_FILES)
{
if (load && !File_formats[format].Load) //filter out formats without Load function
continue;
if (!load && !File_formats[format].Save) // filter out formats without Save function
continue;
}
if (!load && ((context->Type == CONTEXT_PALETTE) != File_formats[format].Palette_only))
continue; // Only Palette only format when SAVING palette and not Palette only when saving image
Window_dropdown_add_item(formats_dropdown,File_formats[format].Identifier,File_formats[format].Label);
}
Print_in_window(70,18,"Format",MC_Dark,MC_Light);

View File

@ -303,6 +303,11 @@ GFX2_GLOBAL T_Document Spare;
/// Backup of the current screen, used during drawing when FX feedback is OFF.
GFX2_GLOBAL byte * Screen_backup;
// -- Palette load/Save selector
/// Fileselector settings
GFX2_GLOBAL T_Selector_settings Palette_selector;
// -- Brush data
/// Pixel data of the current brush (remapped).

View File

@ -162,9 +162,9 @@ void Save_PNG(T_IO_Context *);
void Load_SDL_Image(T_IO_Context *);
// ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts
T_Format File_formats[] = {
const T_Format File_formats[] = {
{FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;2bp;pcx;pkm;iff;lbm;ilbm;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;c64;koa;koala;fli;bml;cdu;prg;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico;ic2;cur;cm5;pph"},
{FORMAT_ALL_PALETTES, "(all)", NULL, NULL, NULL, 1, 0, 0, "", "kcf;pal;gpl"},
{FORMAT_ALL_PALETTES, "(pal)", NULL, NULL, NULL, 1, 0, 0, "", "kcf;pal;gpl"},
{FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, 0, "", "*"},
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 0, 1, 1, "gif", "gif"},
#ifndef __no_pnglib__
@ -602,7 +602,7 @@ void Set_file_error(int value)
void Load_image(T_IO_Context *context)
{
unsigned int index; // index de balayage des formats
T_Format *format = &(File_formats[FORMAT_ALL_FILES+1]); // Format du fichier à charger
const T_Format *format = &(File_formats[FORMAT_ALL_FILES+1]); // Format du fichier à charger
int i;
byte old_cursor_shape;
@ -996,7 +996,7 @@ void Load_image(T_IO_Context *context)
// -- Sauver n'importe quel type connu de fichier d'image (ou palette) ------
void Save_image(T_IO_Context *context)
{
T_Format *format;
const T_Format *format;
// On place par défaut File_error à vrai au cas où on ne sache pas
// sauver le format du fichier: (Est-ce vraiment utile??? Je ne crois pas!)
@ -1258,10 +1258,10 @@ void Image_emergency_backup()
Emergency_backup(SAFETYBACKUP_PREFIX_B "999999" BACKUP_FILE_EXTENSION,Spare.visible_image.Image, Spare.image_width, Spare.image_height, &Spare.palette);
}
T_Format * Get_fileformat(byte format)
const T_Format * Get_fileformat(byte format)
{
unsigned int i;
T_Format * safe_default = File_formats;
const T_Format * safe_default = File_formats;
for (i=0; i < Nb_known_formats(); i++)
{

View File

@ -173,7 +173,7 @@ typedef struct {
} T_Format;
/// Array of the known file formats
extern T_Format File_formats[];
extern const T_Format File_formats[];
///
/// Function which attempts to save backups of the images (main and spare),
@ -194,7 +194,7 @@ SDL_Surface * Load_surface(char *full_name, T_Gradient_array *gradients);
extern enum PIXEL_RATIO Ratio_of_loaded_image;
*/
T_Format * Get_fileformat(byte format);
const T_Format * Get_fileformat(byte format);
// -- File formats

View File

@ -517,6 +517,8 @@ int Init_program(int argc,char * argv[])
strcpy(Brush_filename ,"NO_NAME.GIF");
Brush_fileformat =DEFAULT_FILEFORMAT;
strcpy(Palette_selector.Directory,Main.selector.Directory);
// On initialise ce qu'il faut pour que les fileselects ne plantent pas:
Main.selector.Position=0; // Au début, le fileselect est en haut de la liste des fichiers
@ -537,6 +539,10 @@ int Init_program(int argc,char * argv[])
Brush_selector.Offset=0;
Brush_selector.Format_filter=FORMAT_ALL_IMAGES;
Palette_selector.Position=0;
Palette_selector.Offset=0;
Palette_selector.Format_filter=FORMAT_ALL_PALETTES;
// On initialise d'ot' trucs
Main.offset_X=0;
Main.offset_Y=0;