File: datafun.h

package info (click to toggle)
rockdodger 0.9.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,220 kB
  • ctags: 756
  • sloc: ansic: 5,374; makefile: 159; sh: 21
file content (97 lines) | stat: -rw-r--r-- 3,257 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef __DATAFUN_H__
#define __DATAFUN_H__
#include <SDL/SDL.h>

/*! \brief structure to hold multiple surfaces
 *
 * Mostly used for load_images_ck... All fields are set by the load
 * functions and should be left alone. surfaces_end and num_surfaces
 * are redundant!
 */
typedef struct sdl_surfaces {
  SDL_Surface **surfaces; //!< pointer to an array of surfaces
  SDL_Surface **surfaces_end; //!< pointer to SDL_Surface *after* the last surface
  unsigned short num_surfaces; //!< number of surfaces
} sdl_surfaces_t;

/*! \brief global variable for the path to the data directory
 * This variable must be set before any other function is called
 */
extern char *data_dir;

char *get_data_dir(void);

/*! \brief get load file name
 *
 * Get the load file name of a file. Actually does only prepend the
 * file path. The returned value is a static array!
 *
 * \return pointer to static array
 */
char *load_file(const char *s);

/*! \brief get load file name in a directory
 *
 * Get the load file name of a file. Actually does only prepend the
 * data directory path and the dir path. The returned value is a
 * static array!
 *
 * \return pointer to a static array
 */
const char *load_file_dir(const char *dir, const char *name);

/*! \brief load an image with optional colour key
 *
 * This function loads an image in the standard image directory and
 * transforms it to the display format. Optionally a colour key for
 * transparency can be given. If any of the kr, kg, kb is < 0 then no
 * colour key transparency is done.
 *
 * \warning The image is transformed into the screen format, this
 * breaks transparency!
 *
 * \param fname file name
 * \param kr red component for colour key
 * \param kg green component for colour key
 * \param kb blue component for colour key
 * \return surface or NULL on any error
 */
SDL_Surface *load_image(const char *fname, short kr, short kg, short kb);

/*! \brief load images with optional colour key
 *
 * This function loads images in the standard image directory and
 * transforms it to the display format. Optionally a colour key for
 * transparency can be given. If any of the kr, kg, kb is < 0 then no
 * colour key transparency is done.
 *
 * \warning The image is transformed into the screen format, this
 * breaks transparency!
 *
 * \param fname file name pattern with format qualifier for a unsigned short, e.g. "image.%hx.lbm" (I know this could lead to a security hole...)
 * \param kr red component for colour key
 * \param kg green component for colour key
 * \param kb blue component for colour key
 * \return surfaces or NULL on any error
 */
sdl_surfaces_t *load_images_ck(const char *fname, short kr, short kg, short kb);

/*! \brief Check is directory is missing
 *
 * \param dirname directory name
 * \return 0 = no directory
 */
int missing(const char *dirname);

/*! \brief Destroy multiple surfaces in sdl_surfaces_t
 *
 * This function deletes all the surfaces which can be found in the
 * structure. It will also clear the whole surfaces so that there will
 * be no more dangling pointers. This sets the number of surfaces also
 * to zero.
 *
 * \param surfaces pointer to a sdl_surfaces_t which will be destroyed
 */
void destroy_sdl_surfaces(sdl_surfaces_t *surfaces);

#endif