Tux4Kids-Common
|
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <wchar.h>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
Go to the source code of this file.
Data Structures | |
struct | sprite |
An animated sprite using a collection of SDL_Surfaces. More... | |
Macros | |
#define | DEBUGVAR(mask, Expr) |
DEBUGVAR prints out the name and value of a string variable. | |
#define | DEBUGVARX(mask, Expr) |
DEBUGVARX prints out the name and hex value of an integral variable. | |
#define | DEBUGVARF(mask, Expr) |
DEBUGVARF prints out the name and decimal value of a floating point variable. | |
#define | DEBUGCODE(mask) if((mask) & debug_status) |
DEBUGCODE is a conditional and should be followed by a code block. | |
#define | DEBUGMSG(mask, ...) |
DEBUGMSG prints out a specific message, which can be formatted like printf. | |
#define | rmask 0xff000000 |
SDL red mask. | |
#define | gmask 0x00ff0000 |
SDL green mask. | |
#define | bmask 0x0000ff00 |
SDL blue mask. | |
#define | amask 0x000000ff |
SDL alpha mask. | |
#define | DEBUGCODE(mask) if((mask) & debug_status) |
DEBUGCODE is a conditional and should be followed by a code block. | |
#define | DEBUGMSG(mask, ...) |
DEBUGMSG prints out a specific message, which can be formatted like printf. | |
#define | START_CUSTOM_DEBUG 4 |
#define | MAX_SPRITE_FRAMES 15 |
#define | IMG_REGULAR 0x01 |
#define | IMG_COLORKEY 0x02 |
#define | IMG_ALPHA 0x04 |
#define | IMG_MODES 0x07 |
#define | IMG_NOT_REQUIRED 0x10 |
#define | IMG_NO_PNG_FALLBACK 0x20 |
#define | MAX_LINES 128 |
Maximum lines to wrap. | |
#define | MAX_LINEWIDTH 256 |
Maximum characters of each line. | |
Typedefs | |
typedef void(* | ResSwitchCallback) (int resx, int resy) |
Enumerations | |
enum | bool { false , true } |
enum | WipeStyle { WIPE_BLINDS_VERT , WIPE_BLINDS_HORIZ , WIPE_BLINDS_BOX , RANDOM_WIPE , NUM_WIPES } |
Different transition effects used by TransWipe(). More... | |
enum | { RUN_MAIN_MENU = -3 , QUIT = -2 , STOP = -1 } |
enum | MFStrategy { MF_UNIFORM , MF_BESTFIT , MF_EXACTLY } |
Functions | |
void | InitT4KCommon (int debug_flags) |
Initialize Tux4Kids-Common. | |
int | T4K_HandleStdEvents (const SDL_Event *event) |
Handle events that should have consistent effects everywhere in the program. | |
void | T4K_SetActivitiesList (int num, char **acts) |
Specify the set of activities the menu system should handle. | |
void | T4K_SetMenuSounds (char *mus_path, Mix_Chunk *click, Mix_Chunk *hover) |
Set optional sound effects and music for menus. | |
void | T4K_SetMenuSpritePrefix (char *pref) |
Set the prefix that is used whe loading menu sprites. | |
void | T4K_SetMenuFontSize (MFStrategy strategy, int size) |
Set the font size for managed menus. | |
void | T4K_CreateOneLevelMenu (int index, int items, char **item_names, char **sprite_names, char *title, char *trailer) |
Dynamically create a simple menu. All given strings are copied. | |
int | T4K_RunMenu (int index, bool return_choice, void(*draw_background)(), int(*handle_event)(SDL_Event *), void(*handle_animations)(), int(*handle_activity)(int, int)) |
RunMenu - main function to display the menu and run the event loop this function is a modified copy of choose_menu_item() | |
void | T4K_PrerenderMenu (int index) |
Prerender a single menu based on the screen resolution. | |
void | T4K_PrerenderAll (void) |
Prerender all menus, arrows and stop button. This function should be invoked after every resolution change. | |
void | T4K_LoadMenu (int index, const char *file_name) |
Load menu from given XML file and store its tree under given index in "menus" array. | |
void | T4K_UnloadMenus (void) |
free all loaded menu trees | |
SDL_Surface * | T4K_GetScreen (void) |
Return a pointer to the screen we're using, as an alternative to making screen a global variable. | |
int | T4K_GetResolutions (int *win_x, int *win_y, int *full_x, int *full_y) |
Provide current values of x and y resolutions for windowed and fullscreen modes. | |
void | T4K_DrawButton (SDL_Rect *target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
Creates a translucent button with rounded ends and draws it on the screen. All colors and alpha values are supported. This is equivalent to T4K_DrawButtonOn(T4K_GetScreen()); | |
void | T4K_DrawButtonOn (SDL_Surface *target, SDL_Rect *target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
Creates a translucent button with rounded ends and draws it on the given surface. All colors and alpha values are supported. | |
SDL_Surface * | T4K_CreateButton (int w, int h, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
Creates a translucent button with rounded ends All colors and alpha values are supported. | |
void | T4K_RoundCorners (SDL_Surface *s, Uint16 radius) |
Round the corners of a surface by erasing edge pixels. | |
SDL_Surface * | T4K_Flip (SDL_Surface *in, int x, int y) |
Flip a surface vertically or horizontally. | |
SDL_Surface * | T4K_Blend (SDL_Surface *S1, SDL_Surface *S2, float gamma) |
Blend two surfaces together. The third argument is between 0.0 and 1.0, and represents the weight assigned to the first surface. If the pointer to the second surface is NULL, this performs fading. | |
void | T4K_FreeSurfaceArray (SDL_Surface **surfs, int length) |
Free every surface in the array together with the array itself. | |
int | T4K_inRect (SDL_Rect r, int x, int y) |
Tells whether the point (x, y) is inside the SDL_Rect r. | |
void | T4K_SetRect (SDL_Rect *rect, const float *pos) |
This function will write an SDL_Rect with dimensions based on screen dimensions. | |
void | T4K_UpdateRect (SDL_Surface *surf, SDL_Rect *rect) |
Wrap a call to SDL_UpdateRect. | |
void | T4K_DarkenScreen (Uint8 bits) |
Darkens the screen by a factor of 2^bits. | |
void | T4K_ChangeWindowSize (int new_res_x, int new_res_y) |
This function will change window size (unstable, works only in windowed mode). | |
void | T4K_SwitchScreenMode (void) |
Switch between fullscreen and windowed mode. Resolution switching callbacks are invoked. | |
void | T4K_OnResolutionSwitch (ResSwitchCallback callback) |
Register a callback to reposition and redraw screen elements when the resolution is changed. | |
SDL_EventType | T4K_WaitForEvent (SDL_EventMask events) |
Block application until SDL receives an appropriate event. Use sparingly. | |
SDL_Surface * | T4K_zoom (SDL_Surface *src, int new_w, int new_h) |
This function will scale an existing surface. | |
int | T4K_TransWipe (const SDL_Surface *newbkg, WipeStyle type, int segments, int duration) |
Perform a wipe from the current screen image to a new one. | |
void | T4K_InitBlitQueue (void) |
Initialize the blit queue system. This must be called before T4K_ResetBlitQueue, T4K_AddRect, T4K_DrawSprite, T4K_DrawObject, T4K_EraseObject, T4K_EraseSprite or T4K_UpdateScreen. | |
void | T4K_ResetBlitQueue (void) |
Just set the number of pending updates to zero. | |
int | T4K_AddRect (SDL_Rect *src, SDL_Rect *dst) |
Don't actually blit a surface, but add a rect to be updated next update. | |
int | T4K_DrawSprite (sprite *gfx, int x, int y) |
This function will draw the sprite in the screen. | |
int | T4K_DrawObject (SDL_Surface *surf, int x, int y) |
Draw an object at the specified location. No respect to clipping. | |
void | T4K_UpdateScreen (int *frame) |
Update the screen and increment the frame counter. | |
int | T4K_EraseSprite (sprite *img, SDL_Surface *curr_bkgd, int x, int y) |
Basically puts in an order to overdraw sprite with corresponding rect of bkgd img. | |
int | T4K_EraseObject (SDL_Surface *surf, SDL_Surface *curr_bkgd, int x, int y) |
Erase an object from the screen. | |
void | T4K_SetFontName (const char *name) |
Set the "global" font name. | |
const char * | T4K_AskFontName (void) |
Get the "global" font name. | |
int | T4K_Setup_SDL_Text (void) |
Initialize the backend (Pango or TTF) used for text-drawing functions. | |
void | T4K_Cleanup_SDL_Text (void) |
Shut down the backend used for text-drawing functions. | |
SDL_Surface * | T4K_BlackOutline (const char *t, int size, SDL_Color *c) |
T4K_BlackOutline() creates a surface containing text of the designated foreground color, surrounded by a black shadow, on a transparent background. The appearance can be tuned by adjusting the number of background copies and the offset where the foreground text is finally written (see below). | |
SDL_Surface * | T4K_SimpleText (const char *t, int size, SDL_Color *col) |
Returns a non-outlined surface using either SDL_Pango or SDL_ttf. | |
SDL_Surface * | T4K_SimpleTextWithOffset (const char *t, int size, SDL_Color *col, int *glyph_offset) |
Same as T4K_SimpleText, but the text offset is also stored. | |
int | T4K_CharsForWidth (int fontsize, int pixel_width) |
Calculate how long a string for a given fontsize will fit within a given pixel width. The estimate is based on strings of 'x'. | |
void | T4K_AddDataPrefix (const char *path) |
Add a directory that should be searched when loading assets. | |
int | T4K_CheckFile (const char *file) |
Check whether a file exists. | |
char * | T4K_RemoveSlash (char *path) |
Remove a trailing slash from a file path. | |
SDL_Surface * | T4K_LoadImage (const char *file_name, int mode) |
Load an image without resizing it. | |
SDL_Surface * | T4K_LoadScaledImage (const char *file_name, int mode, int width, int height) |
Load an image and resize it to given dimensions. If width or height is negative no resizing is applied. | |
SDL_Surface * | T4K_LoadImageOfBoundingBox (const char *file_name, int mode, int max_width, int max_height) |
Same as LoadScaledImage but preserve image proportions and fit it into max_width x max_height rectangle. | |
SDL_Surface * | T4K_LoadBkgd (const char *file_name, int width, int height) |
A wrapper for LoadImage() that optimizes the format of background image. | |
int | T4K_LoadBothBkgds (const char *file_name, SDL_Surface **fs_bkgd, SDL_Surface **win_bkgd) |
Load backgrounds for both fullscreen and windowed resolution. | |
sprite * | T4K_LoadSprite (const char *name, int mode) |
Load a multiple-frame sprite from disk. This function loads an SVG sprite or multiple PNGs as needed. | |
sprite * | T4K_LoadScaledSprite (const char *name, int mode, int width, int height) |
Load a multiple-frame sprite from disk and scale it to the given dimensions. This function loads an SVG sprite or multiple PNGs as needed. | |
sprite * | T4K_LoadSpriteOfBoundingBox (const char *name, int mode, int max_width, int max_height) |
Same as LoadScaledSprite but preserve image proportions and fit it into max_width x max_height rectangle. NOTE: Returned surface is not necessarily max_width x max_height ! | |
sprite * | T4K_FlipSprite (sprite *in, int X, int Y) |
Flip (reflect) a sprite over one or both axes. | |
void | T4K_FreeSprite (sprite *gfx) |
Free memory allocated for a loaded sprite. | |
void | T4K_NextFrame (sprite *s) |
Advance a sprite's frame. | |
Mix_Chunk * | T4K_LoadSound (char *datafile) |
Load a sound/music patch from a file. | |
Mix_Music * | T4K_LoadMusic (char *datafile) |
Load music from a datafile. | |
void | T4K_PlaySound (Mix_Chunk *sound) |
Play sound once and then exit. | |
void | T4K_PlaySoundLoop (Mix_Chunk *sound, int loops) |
Play sound "loops" times, -1 for infinite. | |
void | T4K_AudioHaltChannel (int channel) |
Will stop the channel specified in channel. If -1 is passed as the parameter to channel, all channels will be stopped. | |
void | T4K_AudioMusicLoad (char *music_path, int loops) |
Attempts to load and play the music file. | |
void | T4K_AudioMusicUnload (void) |
Attempts to unload any music data that was loaded using the audioMusicLoad function. | |
bool | T4K_IsPlayingMusic (void) |
This function will check if a music is currently playing. | |
void | T4K_AudioMusicPlay (Mix_Music *musicData, int loops) |
attempts to play the passed music data, stopping current music if necessary | |
void | T4K_AudioEnable (bool enabled) |
Enable/disable sound. | |
void | T4K_AudioToggle (void) |
Toggle sound enablement. | |
int | T4K_LineWrap (const char *input, char str_list[MAX_LINES][MAX_LINEWIDTH], int width, int max_lines, int max_width) |
This function takes an input string (can be in essentially arbitrary encoding) and loads it into an array of strings, each corresponding to one line of output text. | |
int | T4K_LineWrapInsBreaks (const char *input, char *output, int width, int max_lines, int max_width) |
This function takes an input string and inserts newline characters at places determined by the linebreak library, returning a single string. | |
void | T4K_LineWrapList (const char input[MAX_LINES][MAX_LINEWIDTH], char str_list[MAX_LINES][MAX_LINEWIDTH], int width, int max_lines, int max_width) |
void | T4K_Throttle (int loop_msec, Uint32 *last_t) |
int | T4K_ConvertFromUTF8 (wchar_t *wide_word, const char *UTF8_word, int max_length) |
int | T4K_ConvertToUTF8 (const wchar_t *wide_word, char *UTF8_word, int max_length) |
Variables | |
int | debug_status |
SDL_Surface * | screen |
SDL_Rect | menu_rect |
SDL_Rect | stop_rect |
SDL_Rect | prev_rect |
SDL_Rect | next_rect |
SDL_Surface * | stop_button |
SDL_Surface * | prev_arrow |
SDL_Surface * | next_arrow |
SDL_Surface * | prev_gray |
SDL_Surface * | next_gray |
char | wrapped_lines [MAX_LINES][MAX_LINEWIDTH] |
Global buffer for wrapped lines. | |
#define amask 0x000000ff |
SDL alpha mask.
#define bmask 0x0000ff00 |
SDL blue mask.
#define DEBUGCODE | ( | mask | ) | if((mask) & debug_status) |
DEBUGCODE is a conditional and should be followed by a code block.
#define DEBUGCODE | ( | mask | ) | if((mask) & debug_status) |
DEBUGCODE is a conditional and should be followed by a code block.
#define DEBUGMSG | ( | mask, | |
... ) |
DEBUGMSG prints out a specific message, which can be formatted like printf.
#define DEBUGMSG | ( | mask, | |
... ) |
DEBUGMSG prints out a specific message, which can be formatted like printf.
#define DEBUGVAR | ( | mask, | |
Expr ) |
DEBUGVAR prints out the name and value of a string variable.
#define DEBUGVARF | ( | mask, | |
Expr ) |
DEBUGVARF prints out the name and decimal value of a floating point variable.
#define DEBUGVARX | ( | mask, | |
Expr ) |
DEBUGVARX prints out the name and hex value of an integral variable.
#define gmask 0x00ff0000 |
SDL green mask.
#define IMG_ALPHA 0x04 |
#define IMG_COLORKEY 0x02 |
#define IMG_MODES 0x07 |
#define IMG_NO_PNG_FALLBACK 0x20 |
#define IMG_NOT_REQUIRED 0x10 |
#define IMG_REGULAR 0x01 |
#define MAX_LINES 128 |
Maximum lines to wrap.
#define MAX_LINEWIDTH 256 |
Maximum characters of each line.
#define MAX_SPRITE_FRAMES 15 |
The max number of images a single sprite can use
#define rmask 0xff000000 |
SDL red mask.
#define START_CUSTOM_DEBUG 4 |
Games defining custom debug flags should use this constant to ensure consistency with t4k_common values.
For example:
const int debug_something_of_mine = 1 << START_CUSTOM_DEBUG; const int debug_something_else = 2 << START_CUSTOM_DEBUG; const int debug_some_more_stuff = 4 << START_CUSTOM_DEBUG;
typedef void(* ResSwitchCallback) (int resx, int resy) |
A function to handle a resolution switch, which should take parameters for the new horizontal and vertical screen dimensions.
anonymous enum |
enum bool |
enum MFStrategy |
Strategies for determining menu font sizes.
enum WipeStyle |
void InitT4KCommon | ( | int | debug_flags | ) |
Initialize Tux4Kids-Common.
debug_flags | - The flags used for debugging output. |
Games may define their own debug flags, but several are available by default:
void T4K_AddDataPrefix | ( | const char * | path | ) |
Add a directory that should be searched when loading assets.
path | - Directory path to set as prefix of the data. |
int T4K_AddRect | ( | SDL_Rect * | src, |
SDL_Rect * | dst ) |
Don't actually blit a surface, but add a rect to be updated next update.
src | - The source dimension of the screen. |
dst | - The destination dimension of the screen. |
const char * T4K_AskFontName | ( | void | ) |
Get the "global" font name.
None |
void T4K_AudioEnable | ( | bool | enabled | ) |
Enable/disable sound.
enabled | - Set true if Audio is enabled or false to disable the audition. |
void T4K_AudioHaltChannel | ( | int | channel | ) |
Will stop the channel specified in channel. If -1 is passed as the parameter to channel, all channels will be stopped.
channel | - Parameter to stop. |
void T4K_AudioMusicLoad | ( | char * | music_path, |
int | loops ) |
Attempts to load and play the music file.
music_path | - Path of the music file. |
loops | - Number of loops. |
void T4K_AudioMusicPlay | ( | Mix_Music * | musicData, |
int | loops ) |
attempts to play the passed music data, stopping current music if necessary
musicData | - Data of music. |
loops | - The number of times to loop, or -1 forever |
void T4K_AudioMusicUnload | ( | void | ) |
Attempts to unload any music data that was loaded using the audioMusicLoad function.
None |
void T4K_AudioToggle | ( | void | ) |
Toggle sound enablement.
None |
SDL_Surface * T4K_BlackOutline | ( | const char * | t, |
int | size, | ||
SDL_Color * | c ) |
T4K_BlackOutline() creates a surface containing text of the designated foreground color, surrounded by a black shadow, on a transparent background. The appearance can be tuned by adjusting the number of background copies and the offset where the foreground text is finally written (see below).
t | - The text to draw |
size | - the font size to use |
c | - the fill color to use |
SDL_Surface * T4K_Blend | ( | SDL_Surface * | S1, |
SDL_Surface * | S2, | ||
float | gamma ) |
Blend two surfaces together. The third argument is between 0.0 and 1.0, and represents the weight assigned to the first surface. If the pointer to the second surface is NULL, this performs fading.
Currently this works only with RGBA images, but this is largely to make the (fast) pointer arithmetic work out; it could be easily generalized to other image types.
S1 | - The first surface |
S2 | - The second surface |
gamma | - A value between 0.0 and 1.0, representing the weight assigned to the first surface. |
void T4K_ChangeWindowSize | ( | int | new_res_x, |
int | new_res_y ) |
This function will change window size (unstable, works only in windowed mode).
new_res_x | - The new width of the window. |
new_res_y | - The new height of the window. |
int T4K_CharsForWidth | ( | int | fontsize, |
int | pixel_width ) |
Calculate how long a string for a given fontsize will fit within a given pixel width. The estimate is based on strings of 'x'.
fontsize | - Font size |
pixel_width | - Width in pixels of the desired text box |
int T4K_CheckFile | ( | const char * | file | ) |
Check whether a file exists.
file | - File to check. |
void T4K_Cleanup_SDL_Text | ( | void | ) |
Shut down the backend used for text-drawing functions.
None |
int T4K_ConvertFromUTF8 | ( | wchar_t * | wide_word, |
const char * | UTF8_word, | ||
int | max_length ) |
/brief A simple wrapper for using GNU iconv() to convert UTF-8 text to wchar_t ("Unicode") text. /param wide_word - ptr to wchar_t buffer to contain converted text. /param UTF8_word - ptr to UTF-8 string to be converted. /param max_length - generally the length of the output buffer to avoid overflow. It also must be no greater than the buffer length used internally in this function (i.e. UTF_BUF_LENGTH, currently 1024).
/return Returns the length of the wchar_t string generated, 0 on errors.
int T4K_ConvertToUTF8 | ( | const wchar_t * | wide_word, |
char * | UTF8_word, | ||
int | max_length ) |
/brief A simple wrapper for using GNU iconv() to convert wchar_t ("Unicode") text to UTF-8 text. /param wide_word - ptr to wchar_t string to be converted. /param UTF8_word - ptr to buffer to hold UTF-8 string after conversion. /param max_length - generally the length of the output buffer to avoid overflow. It also must be no greater than the buffer length used internally in this function (i.e. UTF_BUF_LENGTH, currently 1024).
/return Returns the length of the UTF-8 string generated, 0 on errors.
SDL_Surface * T4K_CreateButton | ( | int | w, |
int | h, | ||
int | radius, | ||
Uint8 | r, | ||
Uint8 | g, | ||
Uint8 | b, | ||
Uint8 | a ) |
Creates a translucent button with rounded ends All colors and alpha values are supported.
w | - The width of the button |
h | - The height of the button |
radius | - The radius of the arcs on each corner. A smaller radius results in sharper edges. |
r | - R component of the button's color |
g | - G component of the button's color |
b | - B component of the button's color |
a | - The opacity of the button |
void T4K_CreateOneLevelMenu | ( | int | index, |
int | items, | ||
char ** | item_names, | ||
char ** | sprite_names, | ||
char * | title, | ||
char * | trailer ) |
Dynamically create a simple menu. All given strings are copied.
index | - The unique index of the menu. |
items | - The number of items in the menu. |
item_names | - The name of the items |
sprite_names | - The name of sprite or icon. |
title | - The title of the menu. |
trailer | - An optional item appended to the end of item_names. |
void T4K_DarkenScreen | ( | Uint8 | bits | ) |
Darkens the screen by a factor of 2^bits.
bits | - An exponent between 1 and 8. Realistically, 1 and 2 are the only useful values. |
void T4K_DrawButton | ( | SDL_Rect * | target_rect, |
int | radius, | ||
Uint8 | r, | ||
Uint8 | g, | ||
Uint8 | b, | ||
Uint8 | a ) |
Creates a translucent button with rounded ends and draws it on the screen. All colors and alpha values are supported. This is equivalent to T4K_DrawButtonOn(T4K_GetScreen());
target_rect | - The bounding rectangle for the button. |
radius | - The radius of the arcs on each corner. A smaller radius results in sharper edges. |
r | - R component of the button's color. |
g | - G component of the button's color. |
b | - B component of the button's color. |
a | - The opacity of the button. |
void T4K_DrawButtonOn | ( | SDL_Surface * | target, |
SDL_Rect * | target_rect, | ||
int | radius, | ||
Uint8 | r, | ||
Uint8 | g, | ||
Uint8 | b, | ||
Uint8 | a ) |
Creates a translucent button with rounded ends and draws it on the given surface. All colors and alpha values are supported.
This function creates a temporary surface to blit onto target. If performance is an issue, consider using T4K_CreateButton to save the surface.
target | - The SDL_Surface to draw on |
target_rect | - the bounding rectangle for the button |
radius | - The radius of the arcs on each corner. A smaller radius results in sharper edges. |
r | - R component of the button's color |
g | - G component of the button's color |
b | - B component of the button's color |
a | - The opacity of the button |
int T4K_DrawObject | ( | SDL_Surface * | surf, |
int | x, | ||
int | y ) |
Draw an object at the specified location. No respect to clipping.
surf | - Holds the surface to draw. |
x | - The x position to draw the object. |
y | - The y position to draw the object. |
int T4K_DrawSprite | ( | sprite * | gfx, |
int | x, | ||
int | y ) |
This function will draw the sprite in the screen.
gfx | - Holds the sprite object. |
x | - The x position to draw the sprite. |
y | - The y position to draw the sprite. |
int T4K_EraseObject | ( | SDL_Surface * | surf, |
SDL_Surface * | curr_bkgd, | ||
int | x, | ||
int | y ) |
Erase an object from the screen.
surf | - Surface to delete |
curr_bkgd | - Current background |
x | - x coordinate |
y | - y coordinate |
int T4K_EraseSprite | ( | sprite * | img, |
SDL_Surface * | curr_bkgd, | ||
int | x, | ||
int | y ) |
Basically puts in an order to overdraw sprite with corresponding rect of bkgd img.
img | - Sprite to delete. |
curr_bkgd | - Surface of the background. |
x | - x coordinate |
y | - y coordinate |
SDL_Surface * T4K_Flip | ( | SDL_Surface * | in, |
int | x, | ||
int | y ) |
Flip a surface vertically or horizontally.
in | - The source surface |
x | - if nonzero, the image will be flipped horizontally |
y | - if nonzero, the image will be flipped vertically |
Flip (reflect) a sprite over one or both axes.
in | - The original image |
X | - If nonzero, the image is flipped horizontally. |
Y | - If nonzero, the image is flipped vertically. |
void T4K_FreeSprite | ( | sprite * | gfx | ) |
Free memory allocated for a loaded sprite.
gfx | - The sprite to free. |
void T4K_FreeSurfaceArray | ( | SDL_Surface ** | surfs, |
int | length ) |
Free every surface in the array together with the array itself.
surfs | - An array of SDL_Surface pointers to free. |
length | - The size of the array. |
int T4K_GetResolutions | ( | int * | win_x, |
int * | win_y, | ||
int * | full_x, | ||
int * | full_y ) |
Provide current values of x and y resolutions for windowed and fullscreen modes.
win_x | - Will hold the width of windowed resolution. |
win_y | - Will hold the height of windowed resolution. |
full_x | - Will hold the width of fullscreen resolution. |
full_y | - Will hold the height of fullscreen resolution. |
SDL_Surface * T4K_GetScreen | ( | void | ) |
Return a pointer to the screen we're using, as an alternative to making screen a global variable.
None |
int T4K_HandleStdEvents | ( | const SDL_Event * | event | ) |
Handle events that should have consistent effects everywhere in the program.
event | - the event to check |
void T4K_InitBlitQueue | ( | void | ) |
Initialize the blit queue system. This must be called before T4K_ResetBlitQueue, T4K_AddRect, T4K_DrawSprite, T4K_DrawObject, T4K_EraseObject, T4K_EraseSprite or T4K_UpdateScreen.
None |
int T4K_inRect | ( | SDL_Rect | r, |
int | x, | ||
int | y ) |
Tells whether the point (x, y) is inside the SDL_Rect r.
r | - The bounding rect. |
x | - The x coordinate to test. |
y | - The y coordinate to test. |
bool T4K_IsPlayingMusic | ( | void | ) |
This function will check if a music is currently playing.
None |
int T4K_LineWrap | ( | const char * | input, |
char | str_list[MAX_LINES][MAX_LINEWIDTH], | ||
int | width, | ||
int | max_lines, | ||
int | max_width ) |
This function takes an input string (can be in essentially arbitrary encoding) and loads it into an array of strings, each corresponding to one line of output text.
input | - A null-terminated input string. |
str_list | - A PRE_ALLOCATED array of characters pointers. This must be at least of size str_list[max_lines][max_width] |
width | - The desired number of characters per line. Note that words with more characters than "width" are not hypenated, so it's possible to get a line that is longer than "width". |
max_lines | - Memory-safety parameters for str_list. |
max_width | - Memory-safety parameters for str_list. |
int T4K_LineWrapInsBreaks | ( | const char * | input, |
char * | output, | ||
int | width, | ||
int | max_lines, | ||
int | max_width ) |
This function takes an input string and inserts newline characters at places determined by the linebreak library, returning a single string.
input | - A null-terminated input string. \para output - Pre-allocated location to contain string with breaks inserted. |
width | - The desired number of characters per line. Note that words with more characters than "width" are not hypenated, so it's possible to get a line that is longer than "width". |
max_lines | - Memory-safety parameters for str_list. |
max_width | - Memory-safety parameters for str_list. |
void T4K_LineWrapList | ( | const char | input[MAX_LINES][MAX_LINEWIDTH], |
char | str_list[MAX_LINES][MAX_LINEWIDTH], | ||
int | width, | ||
int | max_lines, | ||
int | max_width ) |
/brief This function takes a NULL_terminated array of strings and performs translations and linewrapping, outputting another NULL-terminated array.
/param input - A null-terminated input string. /param str_list - A PRE_ALLOCATED array of characters pointers. This must be at least of size str_list[max_lines][max_width] /param width - The desired number of characters per line. Note that words with more characters than "width" are not hypenated, so it's possible to get a line that is longer than "width". /param max_lines - Memory-safety parameters for str_list. /param max_width - Memory-safety parameters for str_list.
/return None
SDL_Surface * T4K_LoadBkgd | ( | const char * | file_name, |
int | width, | ||
int | height ) |
A wrapper for LoadImage() that optimizes the format of background image.
file_name | - File name of background image. |
width | - Width of the image. |
height | - Height of the image. |
int T4K_LoadBothBkgds | ( | const char * | file_name, |
SDL_Surface ** | fs_bkgd, | ||
SDL_Surface ** | win_bkgd ) |
Load backgrounds for both fullscreen and windowed resolution.
file_name | - File name of background image. |
fs_bkgd | - Fullscreen surface. |
win_bkgd | - Windowed surface |
SDL_Surface * T4K_LoadImage | ( | const char * | file_name, |
int | mode ) |
Load an image without resizing it.
file_name | - File name of the image. |
mode | - Image mode. |
SDL_Surface * T4K_LoadImageOfBoundingBox | ( | const char * | file_name, |
int | mode, | ||
int | max_width, | ||
int | max_height ) |
Same as LoadScaledImage but preserve image proportions and fit it into max_width x max_height rectangle.
NOTE: Returned surface is not necessarily max_width x max_height!
file_name | - File name of the image. |
mode | - Image modes. |
max_width | - Max size of width of image. |
max_height | - Max size of height of image. |
void T4K_LoadMenu | ( | int | index, |
const char * | file_name ) |
Load menu from given XML file and store its tree under given index in "menus" array.
index | - The unique index of the menu. |
file_name | - The file name of the xml menu file. |
Mix_Music * T4K_LoadMusic | ( | char * | datafile | ) |
Load music from a datafile.
datafile | - File name of the music date. |
SDL_Surface * T4K_LoadScaledImage | ( | const char * | file_name, |
int | mode, | ||
int | width, | ||
int | height ) |
Load an image and resize it to given dimensions. If width or height is negative no resizing is applied.
The loader backend is chosen depending on file extension, If an SVG file is not found, try to load its PNG equivalent (unless IMG_NO_PNG_FALLBACK is set in mode)
file_name | - File name of the image. |
mode | - Image Mode |
width | - Width size of the image. |
height | - Height size of the image. |
sprite * T4K_LoadScaledSprite | ( | const char * | name, |
int | mode, | ||
int | width, | ||
int | height ) |
Load a multiple-frame sprite from disk and scale it to the given dimensions. This function loads an SVG sprite or multiple PNGs as needed.
name | - The filename of the sprite to load, without an extension. |
mode | - Loader flags to use, semantics the same as LoadImage. |
width | - Width of sprite. |
height | - Height of sprite. |
Mix_Chunk * T4K_LoadSound | ( | char * | datafile | ) |
Load a sound/music patch from a file.
datafile | - File name of the sound data. |
sprite * T4K_LoadSprite | ( | const char * | name, |
int | mode ) |
Load a multiple-frame sprite from disk. This function loads an SVG sprite or multiple PNGs as needed.
name | - The filename of the sprite to load, without an extension. |
mode | - Loader flags to use, semantics the same as LoadImage. |
sprite * T4K_LoadSpriteOfBoundingBox | ( | const char * | name, |
int | mode, | ||
int | max_width, | ||
int | max_height ) |
Same as LoadScaledSprite but preserve image proportions and fit it into max_width x max_height rectangle. NOTE: Returned surface is not necessarily max_width x max_height !
name | - The filename of the sprite to load, without an extension. |
mode | - Loader flags to use, semantics the same as LoadImage. |
max_width | - Max width of sprite. |
max_height | - Max height of sprite. |
void T4K_NextFrame | ( | sprite * | s | ) |
Advance a sprite's frame.
s | - The sprite to advance. |
void T4K_OnResolutionSwitch | ( | ResSwitchCallback | callback | ) |
Register a callback to reposition and redraw screen elements when the resolution is changed.
callback | - A function to be called when resolution changes. |
void T4K_PlaySound | ( | Mix_Chunk * | sound | ) |
Play sound once and then exit.
sound | - Sound effect to play. |
void T4K_PlaySoundLoop | ( | Mix_Chunk * | sound, |
int | loops ) |
Play sound "loops" times, -1 for infinite.
sound | - Sound effect to play. |
loops | - Number of repeats to play the sound. |
void T4K_PrerenderAll | ( | void | ) |
Prerender all menus, arrows and stop button. This function should be invoked after every resolution change.
None |
void T4K_PrerenderMenu | ( | int | index | ) |
Prerender a single menu based on the screen resolution.
index | - The unique index of the menu. |
char * T4K_RemoveSlash | ( | char * | path | ) |
Remove a trailing slash from a file path.
path | - A path that may or may not end in a slash. |
void T4K_ResetBlitQueue | ( | void | ) |
Just set the number of pending updates to zero.
None |
void T4K_RoundCorners | ( | SDL_Surface * | s, |
Uint16 | radius ) |
Round the corners of a surface by erasing edge pixels.
s | - The surface to process. |
radius | - The radius of the arcs on each corner. A smaller radius results in sharper edges. |
int T4K_RunMenu | ( | int | index, |
bool | return_choice, | ||
void(* | draw_background )(), | ||
int(* | handle_event )(SDL_Event *), | ||
void(* | handle_animations )(), | ||
int(* | handle_activity )(int, int) ) |
RunMenu - main function to display the menu and run the event loop this function is a modified copy of choose_menu_item()
index | - The unique index of the menu. |
return_choice | - If true, then return chosen value instead of running handle_activity(). |
draw_background | - A function that draws game-specific items, called once per frame. |
handle_event | - A function to process game-specific events. |
handle_animations | - A function to animate game-specific items. |
handle_activity | - A function to start an activity when the user selects it. |
void T4K_SetActivitiesList | ( | int | num, |
char ** | acts ) |
Specify the set of activities the menu system should handle.
num | - The number of activities. acts should have num elements. |
acts | - An array of strings, each an activity provided by the game. |
void T4K_SetFontName | ( | const char * | name | ) |
Set the "global" font name.
name | - Name of the font to set. |
void T4K_SetMenuFontSize | ( | MFStrategy | strategy, |
int | size ) |
Set the font size for managed menus.
strategy | - How to determine menus' font size |
size | - A literal size to use. This will be ignored unless strategy is MF_EXACTLY. |
void T4K_SetMenuSounds | ( | char * | mus_path, |
Mix_Chunk * | click, | ||
Mix_Chunk * | hover ) |
Set optional sound effects and music for menus.
mus_path | - The path to background music. NOT used! |
click | - The sound effect to play when an item is clicked |
hover | - The sound effect to play when an item is highlighted |
void T4K_SetMenuSpritePrefix | ( | char * | pref | ) |
Set the prefix that is used whe loading menu sprites.
pref | - The prefix that is used whe loading menu sprites. |
void T4K_SetRect | ( | SDL_Rect * | rect, |
const float * | pos ) |
This function will write an SDL_Rect with dimensions based on screen dimensions.
rect | - A pointer to the rect to fill. |
pos | - Four floats between 0.0 and 1.0 which specify the desired x, y, w and h as a percentage of screen dimensions. |
int T4K_Setup_SDL_Text | ( | void | ) |
Initialize the backend (Pango or TTF) used for text-drawing functions.
None |
SDL_Surface * T4K_SimpleText | ( | const char * | t, |
int | size, | ||
SDL_Color * | col ) |
Returns a non-outlined surface using either SDL_Pango or SDL_ttf.
t | - String to draw. |
size | - Font size |
col | - Color |
SDL_Surface * T4K_SimpleTextWithOffset | ( | const char * | t, |
int | size, | ||
SDL_Color * | col, | ||
int * | glyph_offset ) |
Same as T4K_SimpleText, but the text offset is also stored.
t | - String to draw. |
size | - Font size |
col | - Color |
glyph_off | - Set the var in which to store the offset. |
void T4K_SwitchScreenMode | ( | void | ) |
Switch between fullscreen and windowed mode. Resolution switching callbacks are invoked.
None |
void T4K_Throttle | ( | int | loop_msec, |
Uint32 * | last_t ) |
/brief Use this simple function to keep a loop from eating all CPU. Here we use SDL_Delay() to wait to return until 'loop_msec' milliseconds after it returned the last time. Per SDL docs, the granularity is likely no better than 10 msec
/param loop_msec - The desired loop duration, in msec /param last_t - The valid location of a Uint32 where timing can be stored between invocations of this function.
/return None
int T4K_TransWipe | ( | const SDL_Surface * | newbkg, |
WipeStyle | type, | ||
int | segments, | ||
int | duration ) |
Perform a wipe from the current screen image to a new one.
newbkg | - The new image to wipe. |
type | - The WipeStyle to use. |
segments | - The number of division of the screen. |
duration | - The length of the animation in milliseconds. |
void T4K_UnloadMenus | ( | void | ) |
free all loaded menu trees
None |
void T4K_UpdateRect | ( | SDL_Surface * | surf, |
SDL_Rect * | rect ) |
Wrap a call to SDL_UpdateRect.
surf | - The surface to update. |
rect | - The dimension of the surface to update. |
void T4K_UpdateScreen | ( | int * | frame | ) |
Update the screen and increment the frame counter.
frame | - Increments every update of the screen. |
SDL_EventType T4K_WaitForEvent | ( | SDL_EventMask | events | ) |
Block application until SDL receives an appropriate event. Use sparingly.
events | - A single or OR'd combination of event masks. |
SDL_Surface * T4K_zoom | ( | SDL_Surface * | src, |
int | new_w, | ||
int | new_h ) |
This function will scale an existing surface.
src | - The original surface, which is left unscathed. |
new_w | - The width of the new surface. |
new_h | - The height of the new surface. |
|
extern |
|
extern |
SDL_Surface * next_arrow |
SDL_Surface * next_gray |
SDL_Rect next_rect |
SDL_Surface * prev_arrow |
SDL_Surface * prev_gray |
SDL_Rect prev_rect |
|
extern |
|
extern |
SDL_Rect stop_rect |
char wrapped_lines[MAX_LINES][MAX_LINEWIDTH] |
Global buffer for wrapped lines.