diff --git a/src/buttons.c b/src/buttons.c index 324b24f6..663c8b54 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -3433,32 +3433,52 @@ void Backup_existing_file(void) } -void Save_picture(byte image) - // image=1 => On charge/sauve une image - // image=0 => On charge/sauve une brosse +void Save_picture(enum CONTEXT_TYPE type) { byte confirm; byte old_cursor_shape; T_IO_Context save_context; static char filename [MAX_PATH_CHARACTERS]; static char directory[MAX_PATH_CHARACTERS]; - - if (image) + + if (type == CONTEXT_MAIN_IMAGE) { strcpy(filename, Main_backups->Pages->Filename); strcpy(directory, Main_backups->Pages->File_directory); Init_context_layered_image(&save_context, filename, directory); save_context.Format = Main_fileformat; } - else + else if (type == CONTEXT_BRUSH) { strcpy(filename, Brush_filename); strcpy(directory, Brush_file_directory); Init_context_brush(&save_context, filename, directory); save_context.Format = Brush_fileformat; } + else if (type == CONTEXT_PALETTE) + { + char* dotpos; + strcpy(filename, Main_backups->Pages->Filename); - confirm=Button_Load_or_Save(image?&Main_selector:&Brush_selector,0, &save_context); + // Replace extension with PAL + dotpos = strrchr(filename, '.'); + if (dotpos == NULL) + dotpos = filename + strlen(filename); + strcpy(dotpos, ".pal"); + + printf("FILEN %s\n", filename); + + strcpy(directory, Main_backups->Pages->File_directory); + Init_context_layered_image(&save_context, filename, directory); + save_context.Type = CONTEXT_PALETTE; + + // Set format to PAL + save_context.Format = FORMAT_PAL; + } + else + return; + + confirm=Button_Load_or_Save((type==CONTEXT_MAIN_IMAGE)?&Main_selector:&Brush_selector,0, &save_context); if (confirm && File_exists(save_context.File_name)) { @@ -3486,14 +3506,14 @@ void Save_picture(byte image) Save_image(&save_context); format=Get_fileformat(save_context.Format); - if (!File_error && image && !format->Palette_only && (Main_backups->Pages->Nb_layers==1 || format->Supports_layers)) + if (!File_error && type == CONTEXT_MAIN_IMAGE && !format->Palette_only && (Main_backups->Pages->Nb_layers==1 || format->Supports_layers)) { Main_image_is_modified=0; Main_fileformat=save_context.Format; strcpy(Main_backups->Pages->Filename, save_context.File_name); strcpy(Main_backups->Pages->File_directory, save_context.File_directory); } - if (!image) + if (type == CONTEXT_BRUSH) { Brush_fileformat=save_context.Format; strcpy(Brush_filename, save_context.File_name); @@ -3512,7 +3532,7 @@ void Save_picture(byte image) void Button_Save(void) { - Save_picture(1); + Save_picture(CONTEXT_MAIN_IMAGE); } /// Save main image over existing file (no fileselector) @@ -4037,7 +4057,7 @@ void Button_Brush_FX(void) break; case 19 : // Save Display_cursor(); - Save_picture(0); + Save_picture(CONTEXT_BRUSH); Hide_cursor(); break; } diff --git a/src/buttons.h b/src/buttons.h index ac1b7c3b..c613e072 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -28,6 +28,7 @@ #define __BOUTONS_H_ #include "struct.h" +#include "loadsave.h" void Stencil_update_color(byte color); void Stencil_tag_color(byte color, byte tag_color); @@ -654,7 +655,7 @@ void Load_picture(byte image); /*! Save picture to file. */ -void Save_picture(byte image); +void Save_picture(enum CONTEXT_TYPE type); /*! diff --git a/src/engine.c b/src/engine.c index 378d38c4..9561b2e9 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1027,7 +1027,7 @@ void Main_handler(void) action++; break; case SPECIAL_SAVE_BRUSH : - Save_picture(0); + Save_picture(CONTEXT_BRUSH); action++; break; case SPECIAL_ZOOM_IN : // Zoom in diff --git a/src/filesel.c b/src/filesel.c index 7c4fa8fd..9a3e6486 100644 --- a/src/filesel.c +++ b/src/filesel.c @@ -41,6 +41,7 @@ #include #endif +#include #include #include #include @@ -1397,12 +1398,16 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context { if (context->Type == CONTEXT_MAIN_IMAGE) Open_window(310,200,"Save picture"); - else + else if (context->Type == CONTEXT_BRUSH) Open_window(310,200,"Save brush"); + else if (context->Type == CONTEXT_PALETTE) + Open_window(310,200,"Save palette"); + else + assert(false); Window_set_normal_button(198,180,51,14,"Save",0,1,SDLK_RETURN); // 1 if (Selector->Format_filter<=FORMAT_ALL_FILES) // Correction du *.* { - Selector->Format_filter=Main_fileformat; + Selector->Format_filter=context->Format; Selector->Position=0; Selector->Offset=0; } diff --git a/src/loadsave.h b/src/loadsave.h index ab46643b..fa84ddbb 100644 --- a/src/loadsave.h +++ b/src/loadsave.h @@ -35,6 +35,7 @@ enum CONTEXT_TYPE { CONTEXT_BRUSH, CONTEXT_PREVIEW, CONTEXT_SURFACE, + CONTEXT_PALETTE }; /// Data for a cycling color series. Heavily cloned from T_Gradient_array. diff --git a/src/palette.c b/src/palette.c index c45fb93a..2bada347 100644 --- a/src/palette.c +++ b/src/palette.c @@ -2576,6 +2576,13 @@ void Button_Palette(void) Wait_end_of_click(); break; } + + case 26: // Load palette (TODO) + break; + + case 27: // Save palette + Save_picture(CONTEXT_PALETTE); + break; }