add directory argument to Load_Surface()
You can pass NULL if filename is an absolute path
This commit is contained in:
parent
bdbf942f18
commit
bfbeaf4ca8
36
src/init.c
36
src/init.c
@ -655,7 +655,7 @@ static byte Parse_skin(T_GFX2_Surface * gui, T_Gui_skin *gfx)
|
||||
T_Gui_skin * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
|
||||
{
|
||||
T_Gui_skin * gfx;
|
||||
char * filename;
|
||||
char * directory;
|
||||
size_t len;
|
||||
T_GFX2_Surface * gui;
|
||||
|
||||
@ -673,25 +673,25 @@ T_Gui_skin * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
|
||||
}
|
||||
|
||||
// Read the "skin" file
|
||||
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + strlen(PATH_SEPARATOR) + strlen(skin_file) + 1;
|
||||
filename = GFX2_malloc(len);
|
||||
if (filename == NULL)
|
||||
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + 1;
|
||||
directory = GFX2_malloc(len);
|
||||
if (directory == NULL)
|
||||
{
|
||||
free(gfx);
|
||||
return NULL;
|
||||
}
|
||||
snprintf(filename, len, "%s%s%s%s", Data_directory, SKINS_SUBDIRECTORY, PATH_SEPARATOR, skin_file);
|
||||
snprintf(directory, len, "%s%s", Data_directory, SKINS_SUBDIRECTORY);
|
||||
|
||||
gui = Load_surface(filename, gradients);
|
||||
gui = Load_surface(skin_file, directory, gradients);
|
||||
if (!gui)
|
||||
{
|
||||
sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?) : %s\n", filename);
|
||||
free(filename);
|
||||
sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?) : %s in %s\n", skin_file, directory);
|
||||
free(directory);
|
||||
free(gfx);
|
||||
gfx = NULL;
|
||||
return NULL;
|
||||
}
|
||||
free(filename);
|
||||
free(directory);
|
||||
if (Parse_skin(gui, gfx) != 0)
|
||||
{
|
||||
free(gfx);
|
||||
@ -758,7 +758,7 @@ byte * Load_font(const char * font_name, int is_main)
|
||||
{
|
||||
byte * font = NULL;
|
||||
size_t len;
|
||||
char * filename;
|
||||
char * directory;
|
||||
T_GFX2_Surface * image;
|
||||
|
||||
if (font_name == NULL || font_name[0] == '\0')
|
||||
@ -768,20 +768,20 @@ byte * Load_font(const char * font_name, int is_main)
|
||||
}
|
||||
|
||||
// Read the file containing the image
|
||||
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + strlen(PATH_SEPARATOR) + strlen(font_name) + 1;
|
||||
filename = GFX2_malloc(len);
|
||||
if (filename == NULL)
|
||||
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + 1;
|
||||
directory = GFX2_malloc(len);
|
||||
if (directory == NULL)
|
||||
return NULL;
|
||||
snprintf(filename, len, "%s%s%s%s", Data_directory, SKINS_SUBDIRECTORY, PATH_SEPARATOR, font_name);
|
||||
snprintf(directory, len, "%s%s", Data_directory, SKINS_SUBDIRECTORY);
|
||||
|
||||
image = Load_surface(filename, NULL);
|
||||
image = Load_surface(font_name, directory, NULL);
|
||||
if (!image)
|
||||
{
|
||||
sprintf(Gui_loading_error_message, "Unable to load the font image (missing? not an image file?)\n%s\n", filename);
|
||||
free(filename);
|
||||
sprintf(Gui_loading_error_message, "Unable to load the font image (missing? not an image file?)\n%s in %s\n", font_name, directory);
|
||||
free(directory);
|
||||
return NULL;
|
||||
}
|
||||
free(filename);
|
||||
free(directory);
|
||||
font = Parse_font(image, is_main);
|
||||
Free_GFX2_Surface(image);
|
||||
return font;
|
||||
|
||||
@ -605,9 +605,9 @@ void Load_image(T_IO_Context *context)
|
||||
}
|
||||
if (context->Format != FORMAT_CLIPBOARD)
|
||||
{
|
||||
if (context->File_name == NULL || context->File_directory == NULL)
|
||||
if (context->File_name == NULL)
|
||||
{
|
||||
GFX2_Log(GFX2_ERROR, "Load_Image() called with NULL file name or directory\n");
|
||||
GFX2_Log(GFX2_ERROR, "Load_Image() called with NULL file name\n");
|
||||
Error(0);
|
||||
return;
|
||||
}
|
||||
@ -1192,12 +1192,12 @@ void Load_SDL_Image(T_IO_Context *context)
|
||||
#endif
|
||||
|
||||
|
||||
T_GFX2_Surface * Load_surface(const char *full_name, T_Gradient_array *gradients)
|
||||
T_GFX2_Surface * Load_surface(const char *filename, const char * directory, T_Gradient_array *gradients)
|
||||
{
|
||||
T_GFX2_Surface * bmp=NULL;
|
||||
T_IO_Context context;
|
||||
|
||||
Init_context_surface(&context, full_name, "");
|
||||
Init_context_surface(&context, filename, directory);
|
||||
Load_image(&context);
|
||||
|
||||
if (context.Surface)
|
||||
|
||||
@ -55,9 +55,9 @@ typedef struct
|
||||
|
||||
// File properties
|
||||
|
||||
char * File_name;
|
||||
word * File_name_unicode;
|
||||
char * File_directory;
|
||||
char * File_name; ///< File name in UTF-8 (or short ASCII file nmae under win32)
|
||||
word * File_name_unicode; ///< Wide character version of the filename
|
||||
char * File_directory; ///< Directory. If NULL File_name should be the full path name
|
||||
byte Format;
|
||||
|
||||
// Image properties
|
||||
@ -190,9 +190,10 @@ void Image_emergency_backup(void);
|
||||
|
||||
///
|
||||
/// Load an arbitrary Surface.
|
||||
/// @param full_name Full (absolute) path of the file to load.
|
||||
/// @param filename file to load.
|
||||
/// @param directory path of the file to load. if NULL, filename have to be a full path name
|
||||
/// @param gradients Pass the address of a target T_Gradient_array if you want the gradients, NULL otherwise
|
||||
T_GFX2_Surface * Load_surface(const char *full_name, T_Gradient_array *gradients);
|
||||
T_GFX2_Surface * Load_surface(const char *filename, const char *directory, T_Gradient_array *gradients);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@ -726,7 +726,7 @@ byte *Render_text_SFont(const char *str, int font_number, int *width, int *heigh
|
||||
byte * new_brush = NULL;
|
||||
|
||||
// Chargement de la fonte
|
||||
font_surface = Load_surface(Font_name(font_number), NULL);
|
||||
font_surface = Load_surface(Font_name(font_number), NULL, NULL);
|
||||
if (!font_surface)
|
||||
{
|
||||
Verbose_message("Warning", "Error loading font");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user