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 * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
|
||||||
{
|
{
|
||||||
T_Gui_skin * gfx;
|
T_Gui_skin * gfx;
|
||||||
char * filename;
|
char * directory;
|
||||||
size_t len;
|
size_t len;
|
||||||
T_GFX2_Surface * gui;
|
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
|
// Read the "skin" file
|
||||||
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + strlen(PATH_SEPARATOR) + strlen(skin_file) + 1;
|
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + 1;
|
||||||
filename = GFX2_malloc(len);
|
directory = GFX2_malloc(len);
|
||||||
if (filename == NULL)
|
if (directory == NULL)
|
||||||
{
|
{
|
||||||
free(gfx);
|
free(gfx);
|
||||||
return NULL;
|
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)
|
if (!gui)
|
||||||
{
|
{
|
||||||
sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?) : %s\n", 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(filename);
|
free(directory);
|
||||||
free(gfx);
|
free(gfx);
|
||||||
gfx = NULL;
|
gfx = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
free(filename);
|
free(directory);
|
||||||
if (Parse_skin(gui, gfx) != 0)
|
if (Parse_skin(gui, gfx) != 0)
|
||||||
{
|
{
|
||||||
free(gfx);
|
free(gfx);
|
||||||
@ -758,7 +758,7 @@ byte * Load_font(const char * font_name, int is_main)
|
|||||||
{
|
{
|
||||||
byte * font = NULL;
|
byte * font = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
char * filename;
|
char * directory;
|
||||||
T_GFX2_Surface * image;
|
T_GFX2_Surface * image;
|
||||||
|
|
||||||
if (font_name == NULL || font_name[0] == '\0')
|
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
|
// Read the file containing the image
|
||||||
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + strlen(PATH_SEPARATOR) + strlen(font_name) + 1;
|
len = strlen(Data_directory) + strlen(SKINS_SUBDIRECTORY) + 1;
|
||||||
filename = GFX2_malloc(len);
|
directory = GFX2_malloc(len);
|
||||||
if (filename == NULL)
|
if (directory == NULL)
|
||||||
return 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)
|
if (!image)
|
||||||
{
|
{
|
||||||
sprintf(Gui_loading_error_message, "Unable to load the font image (missing? not an image file?)\n%s\n", 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(filename);
|
free(directory);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
free(filename);
|
free(directory);
|
||||||
font = Parse_font(image, is_main);
|
font = Parse_font(image, is_main);
|
||||||
Free_GFX2_Surface(image);
|
Free_GFX2_Surface(image);
|
||||||
return font;
|
return font;
|
||||||
|
|||||||
@ -605,9 +605,9 @@ void Load_image(T_IO_Context *context)
|
|||||||
}
|
}
|
||||||
if (context->Format != FORMAT_CLIPBOARD)
|
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);
|
Error(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1192,12 +1192,12 @@ void Load_SDL_Image(T_IO_Context *context)
|
|||||||
#endif
|
#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_GFX2_Surface * bmp=NULL;
|
||||||
T_IO_Context context;
|
T_IO_Context context;
|
||||||
|
|
||||||
Init_context_surface(&context, full_name, "");
|
Init_context_surface(&context, filename, directory);
|
||||||
Load_image(&context);
|
Load_image(&context);
|
||||||
|
|
||||||
if (context.Surface)
|
if (context.Surface)
|
||||||
|
|||||||
@ -55,9 +55,9 @@ typedef struct
|
|||||||
|
|
||||||
// File properties
|
// File properties
|
||||||
|
|
||||||
char * File_name;
|
char * File_name; ///< File name in UTF-8 (or short ASCII file nmae under win32)
|
||||||
word * File_name_unicode;
|
word * File_name_unicode; ///< Wide character version of the filename
|
||||||
char * File_directory;
|
char * File_directory; ///< Directory. If NULL File_name should be the full path name
|
||||||
byte Format;
|
byte Format;
|
||||||
|
|
||||||
// Image properties
|
// Image properties
|
||||||
@ -190,9 +190,10 @@ void Image_emergency_backup(void);
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// Load an arbitrary Surface.
|
/// 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
|
/// @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;
|
byte * new_brush = NULL;
|
||||||
|
|
||||||
// Chargement de la fonte
|
// 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)
|
if (!font_surface)
|
||||||
{
|
{
|
||||||
Verbose_message("Warning", "Error loading font");
|
Verbose_message("Warning", "Error loading font");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user