Fix issue 46 : part 2

in Error(0) the palette was not properly restored
as it was always restored to the Main_palette.
Now we really restore the right palette !

Also clarified/simplified the change directory code in case of error.

http://pulkomandy.tk/projects/GrafX2/ticket/46
This commit is contained in:
Thomas Bernard 2018-01-20 23:59:41 +01:00
parent e078b3afe1
commit 08e3c6bebf
4 changed files with 42 additions and 28 deletions

View File

@ -2061,47 +2061,49 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
Hide_cursor();
has_clicked_ok=0;
// On mémorise le répertoire dans lequel on était
if (strcmp(Selector_filename,PARENT_DIR))
{
strcpy(previous_directory,PARENT_DIR);
}
else
{
Extract_filename(previous_directory, Selector->Directory);
}
// On doit rentrer dans le répertoire:
// We must enter the directory
if (!chdir(Selector_filename))
{
#if defined (__MINT__)
static char path[1024]={0};
char currentDrive='A';
#endif
// save the previous current directory
if (strcmp(Selector_filename,PARENT_DIR) != 0)
{
strcpy(previous_directory,PARENT_DIR);
}
else
{
Extract_filename(previous_directory, Selector->Directory);
}
#if defined (__MINT__)
currentDrive=currentDrive+Dgetdrv();
Dgetpath(path,0);
sprintf(Selector->Directory,"%c:\%s",currentDrive,path);
sprintf(Selector->Directory,"%c:\%s",currentDrive,path);
#else
getcwd(Selector->Directory,MAX_PATH_CHARACTERS);
#endif
// On lit le nouveau répertoire
// read the new directory
Read_list_of_files(&Filelist, Selector->Format_filter);
Sort_list_of_files(&Filelist);
// On place la barre de sélection sur le répertoire d'où l'on vient
// Set the fileselector bar on the directory we're coming from
Highlight_file(Find_file_in_fileselector(&Filelist, previous_directory));
// display the 1st visible files
Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
Display_cursor();
New_preview_is_needed=1;
// New directory, so we need to reset the quicksearch
Reset_quicksearch();
}
else
{
Display_cursor();
Error(0);
Hide_cursor();
}
// Affichage des premiers fichiers visibles:
Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
Display_cursor();
New_preview_is_needed=1;
// On est dans un nouveau répertoire, donc on remet le quicksearch à 0
Reset_quicksearch();
}
else // Sinon on essaye de charger ou sauver le fichier
{

View File

@ -137,6 +137,7 @@ void Warning_function(const char *message, const char *filename, int line_number
void Error_function(int error_code, const char *filename, int line_number, const char *function_name)
{
T_Palette temp_palette;
T_Palette backup_palette;
int index;
printf("Error number %d occured in file %s, line %d, function %s.\n", error_code, filename,line_number,function_name);
@ -144,12 +145,13 @@ void Error_function(int error_code, const char *filename, int line_number, const
{
// L'erreur 0 n'est pas une vraie erreur, elle fait seulement un flash rouge de l'écran pour dire qu'il y a un problème.
// Toutes les autres erreurs déclenchent toujours une sortie en catastrophe du programme !
memcpy(temp_palette,Main_palette,sizeof(T_Palette));
memcpy(backup_palette, Get_current_palette(), sizeof(T_Palette));
memcpy(temp_palette, backup_palette, sizeof(T_Palette));
for (index=0;index<=255;index++)
temp_palette[index].R=255;
Set_palette(temp_palette);
Delay_with_active_mouse(50); // Half a second of red flash
Set_palette(Main_palette);
Set_palette(backup_palette);
}
else
{

View File

@ -151,11 +151,19 @@ word Count_used_colors_area(dword* usage, word start_x, word start_y,
return nb_colors;
}
static T_Palette Current_palette = {0};
const T_Components * Get_current_palette(void)
{
return Current_palette;
}
void Set_palette(T_Palette palette)
{
register int i;
SDL_Color PaletteSDL[256];
memcpy(Current_palette, palette, sizeof(T_Palette));
for(i=0;i<256;i++)
{
PaletteSDL[i].r=(palette[i].R=Round_palette_component(palette[i].R));
@ -168,9 +176,10 @@ void Set_palette(T_Palette palette)
void Set_color(byte color, byte red, byte green, byte blue)
{
SDL_Color comp;
comp.r=red;
comp.g=green;
comp.b=blue;
Current_palette[color].R = comp.r = red;
Current_palette[color].G = comp.g = green;
Current_palette[color].B = comp.b = blue;
SDL_SetPalette(Screen_SDL, SDL_PHYSPAL | SDL_LOGPAL, &comp, color, 1);
}

View File

@ -37,6 +37,7 @@ void Remap_general_lowlevel(byte * conversion_table,byte * in_buffer, byte *out_
void Scroll_picture(byte * main_src, byte * main_dest, short x_offset,short y_offset);
void Wait_end_of_click(void);
void Set_color(byte color, byte red, byte green, byte blue);
const T_Components * Get_current_palette(void);
void Set_palette(T_Palette palette);
void Palette_256_to_64(T_Palette palette);
void Palette_64_to_256(T_Palette palette);