52#ifndef TUX4KIDS_COMMON_H
53#define TUX4KIDS_COMMON_H
78#define DEBUGVAR(mask, Expr) \
79 if((mask) & (debug_status)) \
81 fprintf(stderr, #Expr ": %s\n", (Expr)); fflush(stderr); \
85#define DEBUGVARX(mask, Expr) \
86 if((mask) & (debug_status)) \
88 fprintf(stderr, #Expr ": %x\n", (Expr)); fflush(stderr); \
92#define DEBUGVARF(mask, Expr) \
93 if((mask) & (debug_status)) \
95 fprintf(stderr, #Expr ": %f\n", (Expr)); fflush(stderr); \
99#define DEBUGCODE(mask) if((mask) & debug_status)
102#define DEBUGMSG(mask, ...) \
103 if((mask) & debug_status) \
105 fprintf(stderr, __VA_ARGS__); fflush(stderr); \
109#if SDL_BYTEORDER == SDL_BIG_ENDIAN
110 #define rmask 0xff000000
111 #define gmask 0x00ff0000
112 #define bmask 0x0000ff00
113 #define amask 0x000000ff
115 #define rmask 0x000000ff
116 #define gmask 0x0000ff00
117 #define bmask 0x00ff0000
118 #define amask 0xff000000
136#define DEBUGCODE(mask) if((mask) & debug_status)
137#define DEBUGMSG(mask, ...) \
138 if((mask) & debug_status) \
140 fprintf(stderr, __VA_ARGS__); fflush(stderr); \
144static const int debug_loaders = 1 << 0;
145static const int debug_menu = 1 << 1;
146static const int debug_menu_parser = 1 << 2;
147static const int debug_sdl = 1 << 3;
148static const int debug_linewrap = 1 << 4;
149static const int debug_i18n = 1 << 5;
150static const int debug_all = ~0;
164#define START_CUSTOM_DEBUG 4
168extern SDL_Surface*
screen;
173#define MAX_SPRITE_FRAMES 15
231#define IMG_REGULAR 0x01
232#define IMG_COLORKEY 0x02
233#define IMG_ALPHA 0x04
234#define IMG_MODES 0x07
236#define IMG_NOT_REQUIRED 0x10
237#define IMG_NO_PNG_FALLBACK 0x20
240#define MAX_LINEWIDTH 256
432 void (*draw_background)(),
433 int (*handle_event)(SDL_Event*),
434 void (*handle_animations)(),
435 int (*handle_activity)(
int,
int)
486 const char* file_name
621 SDL_Rect* target_rect,
1104 SDL_Surface* curr_bkgd,
1131 SDL_Surface* curr_bkgd,
1464 SDL_Surface** fs_bkgd,
1465 SDL_Surface** win_bkgd
1638const static int T4K_AUDIO_PLAY_ONCE = 0;
1639const static int T4K_AUDIO_LOOP_FOREVER = -1;
1957 const char* UTF8_word,
An animated sprite using a collection of SDL_Surfaces.
Definition t4k_common.h:183
SDL_Surface * default_img
Definition t4k_common.h:185
int num_frames
Definition t4k_common.h:186
int cur
Definition t4k_common.h:187
int T4K_ConvertFromUTF8(wchar_t *wide_word, const char *UTF8_word, int max_length)
void T4K_ResetBlitQueue(void)
Just set the number of pending updates to zero.
@ STOP
user pressed the stop button
Definition t4k_common.h:216
@ QUIT
user decided to quit application
Definition t4k_common.h:215
@ RUN_MAIN_MENU
can be used in .xml menu structures but should not be declared in activities' lists.
Definition t4k_common.h:214
#define MAX_LINES
Maximum lines to wrap.
Definition t4k_common.h:239
SDL_Rect next_rect
Definition t4k_common.h:169
SDL_Surface * T4K_SimpleText(const char *t, int size, SDL_Color *col)
Returns a non-outlined surface using either SDL_Pango or SDL_ttf.
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.
SDL_Surface * T4K_Flip(SDL_Surface *in, int x, int y)
Flip a surface vertically or horizontally.
void T4K_FreeSprite(sprite *gfx)
Free memory allocated for a loaded sprite.
int T4K_inRect(SDL_Rect r, int x, int y)
Tells whether the point (x, y) is inside the SDL_Rect r.
int T4K_LoadBothBkgds(const char *file_name, SDL_Surface **fs_bkgd, SDL_Surface **win_bkgd)
Load backgrounds for both fullscreen and windowed resolution.
SDL_EventType T4K_WaitForEvent(SDL_EventMask events)
Block application until SDL receives an appropriate event. Use sparingly.
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 ass...
sprite * T4K_FlipSprite(sprite *in, int X, int Y)
Flip (reflect) a sprite over one or both axes.
SDL_Surface * next_arrow
Definition t4k_common.h:170
void T4K_SetActivitiesList(int num, char **acts)
Specify the set of activities the menu system should handle.
int T4K_HandleStdEvents(const SDL_Event *event)
Handle events that should have consistent effects everywhere in the program.
int T4K_CharsForWidth(int fontsize, int pixel_width)
Calculate how long a string for a given fontsize will fit within a given pixel width....
char wrapped_lines[MAX_LINES][MAX_LINEWIDTH]
Global buffer for wrapped lines.
Definition t4k_common.h:242
SDL_Surface * T4K_zoom(SDL_Surface *src, int new_w, int new_h)
This function will scale an existing surface.
WipeStyle
Different transition effects used by TransWipe().
Definition t4k_common.h:200
@ NUM_WIPES
Definition t4k_common.h:205
@ RANDOM_WIPE
Definition t4k_common.h:204
@ WIPE_BLINDS_VERT
Definition t4k_common.h:201
@ WIPE_BLINDS_BOX
Definition t4k_common.h:203
@ WIPE_BLINDS_HORIZ
Definition t4k_common.h:202
void T4K_PlaySound(Mix_Chunk *sound)
Play sound once and then exit.
void T4K_SetMenuSpritePrefix(char *pref)
Set the prefix that is used whe loading menu sprites.
char * T4K_RemoveSlash(char *path)
Remove a trailing slash from a file path.
void(* ResSwitchCallback)(int resx, int resy)
Definition t4k_common.h:878
SDL_Surface * stop_button
int T4K_EraseObject(SDL_Surface *surf, SDL_Surface *curr_bkgd, int x, int y)
Erase an object from the screen.
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 alph...
SDL_Surface * T4K_LoadBkgd(const char *file_name, int width, int height)
A wrapper for LoadImage() that optimizes the format of background image.
void T4K_OnResolutionSwitch(ResSwitchCallback callback)
Register a callback to reposition and redraw screen elements when the resolution is changed.
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.
#define MAX_SPRITE_FRAMES
Definition t4k_common.h:173
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 S...
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 value...
void T4K_ChangeWindowSize(int new_res_x, int new_res_y)
This function will change window size (unstable, works only in windowed mode).
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.
bool T4K_IsPlayingMusic(void)
This function will check if a music is currently playing.
void T4K_PrerenderMenu(int index)
Prerender a single menu based on the screen resolution.
void T4K_AudioMusicLoad(char *music_path, int loops)
Attempts to load and play the music file.
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 o...
void T4K_SetRect(SDL_Rect *rect, const float *pos)
This function will write an SDL_Rect with dimensions based on screen dimensions.
void T4K_SetMenuSounds(char *mus_path, Mix_Chunk *click, Mix_Chunk *hover)
Set optional sound effects and music for menus.
int T4K_CheckFile(const char *file)
Check whether a file exists.
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.
Mix_Music * T4K_LoadMusic(char *datafile)
Load music from a datafile.
void T4K_Throttle(int loop_msec, Uint32 *last_t)
void T4K_RoundCorners(SDL_Surface *s, Uint16 radius)
Round the corners of a surface by erasing edge pixels.
SDL_Surface * T4K_GetScreen(void)
Return a pointer to the screen we're using, as an alternative to making screen a global variable.
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 applie...
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.
void T4K_AudioMusicUnload(void)
Attempts to unload any music data that was loaded using the audioMusicLoad function.
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.
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_Rect stop_rect
Definition t4k_common.h:169
int T4K_DrawObject(SDL_Surface *surf, int x, int y)
Draw an object at the specified location. No respect to clipping.
SDL_Rect prev_rect
Definition t4k_common.h:169
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 rectan...
void T4K_PrerenderAll(void)
Prerender all menus, arrows and stop button. This function should be invoked after every resolution c...
MFStrategy
Definition t4k_common.h:223
@ MF_UNIFORM
All menus are searched and the largest size that will fit on all menus is used.
Definition t4k_common.h:224
@ MF_BESTFIT
Menus are searched separately for the largest fonts they can accommodate.
Definition t4k_common.h:225
@ MF_EXACTLY
The font size given is used directly; text may run off the screen.
Definition t4k_common.h:226
SDL_Surface * prev_arrow
Definition t4k_common.h:170
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_AddDataPrefix(const char *path)
Add a directory that should be searched when loading assets.
void T4K_AudioHaltChannel(int channel)
Will stop the channel specified in channel. If -1 is passed as the parameter to channel,...
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 linebr...
SDL_Surface * T4K_BlackOutline(const char *t, int size, SDL_Color *c)
T4K_BlackOutline() creates a surface containing text of the designated foreground color,...
void T4K_InitBlitQueue(void)
Initialize the blit queue system. This must be called before T4K_ResetBlitQueue, T4K_AddRect,...
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.
SDL_Surface * prev_gray
Definition t4k_common.h:170
void T4K_SwitchScreenMode(void)
Switch between fullscreen and windowed mode. Resolution switching callbacks are invoked.
const char * T4K_AskFontName(void)
Get the "global" font name.
int T4K_AddRect(SDL_Rect *src, SDL_Rect *dst)
Don't actually blit a surface, but add a rect to be updated next update.
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 rectang...
void T4K_AudioToggle(void)
Toggle sound enablement.
void T4K_UpdateScreen(int *frame)
Update the screen and increment the frame counter.
void T4K_SetMenuFontSize(MFStrategy strategy, int size)
Set the font size for managed menus.
#define MAX_LINEWIDTH
Maximum characters of each line.
Definition t4k_common.h:240
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 a...
void T4K_UnloadMenus(void)
free all loaded menu trees
SDL_Surface * next_gray
Definition t4k_common.h:170
Mix_Chunk * T4K_LoadSound(char *datafile)
Load a sound/music patch from a file.
void T4K_AudioEnable(bool enabled)
Enable/disable sound.
void InitT4KCommon(int debug_flags)
Initialize Tux4Kids-Common.
void T4K_AudioMusicPlay(Mix_Music *musicData, int loops)
attempts to play the passed music data, stopping current music if necessary
int T4K_DrawSprite(sprite *gfx, int x, int y)
This function will draw the sprite in the screen.
int T4K_ConvertToUTF8(const wchar_t *wide_word, char *UTF8_word, int max_length)
void T4K_UpdateRect(SDL_Surface *surf, SDL_Rect *rect)
Wrap a call to SDL_UpdateRect.
void T4K_SetFontName(const char *name)
Set the "global" font name.
void T4K_NextFrame(sprite *s)
Advance a sprite's frame.
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_DarkenScreen(Uint8 bits)
Darkens the screen by a factor of 2^bits.
bool
Definition t4k_common.h:128
void T4K_PlaySoundLoop(Mix_Chunk *sound, int loops)
Play sound "loops" times, -1 for infinite.
SDL_Surface * T4K_LoadImage(const char *file_name, int mode)
Load an image without resizing it.
void T4K_FreeSurfaceArray(SDL_Surface **surfs, int length)
Free every surface in the array together with the array itself.