Tux4Kids-Common
t4k_common.h
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // t4k_common.h: Contains public headers for the t4k_common library
4 //
5 // Copyright 2009, 2010.
6 // Author: Brendan Luchen
7 // Project email: <tuxmath-devel@lists.sourceforge.net>
8 // Project website: http://tux4kids.alioth.debian.org
9 //
10 // t4k_common.h is part of the t4k_common library.
11 //
12 // t4k_common is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // t4k_common is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 //
25 //==============================================================================
26 
27 //==============================================================================
28 //
51 
52 #ifndef TUX4KIDS_COMMON_H
53 #define TUX4KIDS_COMMON_H
54 
55 
56 #include <sys/types.h>
57 #include <sys/stat.h>
58 #include <fcntl.h>
59 #include <unistd.h>
60 #include <dirent.h>
61 #include <wchar.h>
62 #include "SDL.h"
63 #include "SDL_image.h"
64 #include "SDL_mixer.h"
65 
66 //==============================================================================
67 // Debugging macros
68 //
69 // All macros take a debug mask as their first argument, which should roughly
70 // indicate what part of the program the debugging info is related to, and
71 // which can be one of the flags defined below, a program-specific flag, or
72 // an OR'd combination.
73 //
74 // DEBUGVAR prints out the name and value of a string variable
75 #ifndef DEBUGMSG
76 
78 #define DEBUGVAR(mask, Expr) \
79  if((mask) & (debug_status)) \
80  { \
81  fprintf(stderr, #Expr ": %s\n", (Expr)); fflush(stderr); \
82  }
83 
85 #define DEBUGVARX(mask, Expr) \
86  if((mask) & (debug_status)) \
87  { \
88  fprintf(stderr, #Expr ": %x\n", (Expr)); fflush(stderr); \
89  }
90 
92 #define DEBUGVARF(mask, Expr) \
93  if((mask) & (debug_status)) \
94  { \
95  fprintf(stderr, #Expr ": %f\n", (Expr)); fflush(stderr); \
96  }
97 
99 #define DEBUGCODE(mask) if((mask) & debug_status)
100 
102 #define DEBUGMSG(mask, ...) \
103  if((mask) & debug_status) \
104  { \
105  fprintf(stderr, __VA_ARGS__); fflush(stderr); \
106  }
107 #endif
108 
109 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
110  #define rmask 0xff000000
111  #define gmask 0x00ff0000
112  #define bmask 0x0000ff00
113  #define amask 0x000000ff
114 #else
115  #define rmask 0x000000ff
116  #define gmask 0x0000ff00
117  #define bmask 0x00ff0000
118  #define amask 0xff000000
119 #endif
120 
121 // Hold off on gettext until we decide if we are really going to
122 // use it from within t4kcommon - DSB
123 //#define _(String) String
124 // #define _(String) gettext (String)
125 
126 #ifndef bool
127 typedef enum
128 {
129  false,
130  true
131 }
132 bool;
133 #endif
134 
135 // Debug macros
136 #define DEBUGCODE(mask) if((mask) & debug_status)
137 #define DEBUGMSG(mask, ...) \
138  if((mask) & debug_status) \
139  { \
140  fprintf(stderr, __VA_ARGS__); fflush(stderr); \
141  }
142 
143 // These values have to match those used in games.
144 static const int debug_loaders = 1 << 0;
145 static const int debug_menu = 1 << 1;
146 static const int debug_menu_parser = 1 << 2;
147 static const int debug_sdl = 1 << 3;
148 static const int debug_linewrap = 1 << 4;
149 static const int debug_i18n = 1 << 5;
150 static const int debug_all = ~0;
151 
152 extern int debug_status;
153 
164 #define START_CUSTOM_DEBUG 4
165 
166 // FIXME: global vars such as screen should be hidden when all games
167 // are using only getters (such as GetScreen() )
168 extern SDL_Surface* screen;
169 extern SDL_Rect menu_rect, stop_rect, prev_rect, next_rect;
170 extern SDL_Surface *stop_button, *prev_arrow, *next_arrow, *prev_gray, *next_gray;
171 
172 
173 #define MAX_SPRITE_FRAMES 15
175 typedef struct
183 {
184  SDL_Surface *frame[MAX_SPRITE_FRAMES];
185  SDL_Surface *default_img;
187  int cur;
188 }
189 sprite;
190 
191 //==============================================================================
199 typedef enum
200 {
206 }
207 WipeStyle;
208 
212 enum
213 {
215  QUIT = -2,
216  STOP = -1
217 };
218 
222 typedef enum
223 {
227 }
228 MFStrategy;
229 
230 // from tk4_loaders.c
231 #define IMG_REGULAR 0x01
232 #define IMG_COLORKEY 0x02
233 #define IMG_ALPHA 0x04
234 #define IMG_MODES 0x07
235 
236 #define IMG_NOT_REQUIRED 0x10
237 #define IMG_NO_PNG_FALLBACK 0x20
238 
239 #define MAX_LINES 128
240 #define MAX_LINEWIDTH 256
241 
243 
244 //TODO separate headers for different areas a la SDL?
245 
246 //==============================================================================
247 // Public Definitions in t4k_main.c
248 //==============================================================================
249 
250 //==============================================================================
251 //
252 // InitT4KCommon
253 //
271 void InitT4KCommon( int debug_flags );
272 
273 //==============================================================================
274 //
275 // T4K_HandleStdEvents
276 //
289 int T4K_HandleStdEvents( const SDL_Event* event );
290 
291 
292 //==============================================================================
293 // Public Definitions in t4k_menu.c
294 //==============================================================================
295 
296 //==============================================================================
297 //
298 // T4K_SetActivitiesList
299 //
311 void T4K_SetActivitiesList( int num,
312  char** acts
313  );
314 
315 //==============================================================================
316 //
317 // T4K_SetMenuSounds
318 //
332 void T4K_SetMenuSounds( char* mus_path,
333  Mix_Chunk* click,
334  Mix_Chunk* hover
335  );
336 
337 //==============================================================================
338 //
339 // T4K_SetMenuSpritePrefix
340 //
350 void T4K_SetMenuSpritePrefix( char* pref );
351 
352 //==============================================================================
353 //
354 // T4K_SetMenuFontSize
355 //
368 void T4K_SetMenuFontSize( MFStrategy strategy,
369  int size
370  );
371 
372 //==============================================================================
373 //
374 // T4K_CreateOneLevelMenu
375 //
395 void T4K_CreateOneLevelMenu( int index,
396  int items,
397  char** item_names,
398  char** sprite_names,
399  char* title,
400  char* trailer
401  );
402 
403 //==============================================================================
404 //
405 // T4K_RunMenu
406 //
430 int T4K_RunMenu( int index,
431  bool return_choice,
432  void (*draw_background)(),
433  int (*handle_event)(SDL_Event*),
434  void (*handle_animations)(),
435  int (*handle_activity)(int, int)
436  );
437 
438 //==============================================================================
439 //
440 // T4K_PrerenderMenu
441 //
451 void T4K_PrerenderMenu( int index );
452 
453 //==============================================================================
454 //
455 // T4K_PrerenderAll
456 //
467 void T4K_PrerenderAll( void );
468 
469 //==============================================================================
470 //
471 // T4K_LoadMenu
472 //
485 void T4K_LoadMenu( int index,
486  const char* file_name
487  );
488 
489 //==============================================================================
490 //
491 // T4K_UnloadMenus
492 //
502 void T4K_UnloadMenus( void );
503 
504 
505 //==============================================================================
506 // Public Definitions in tk4_sdl.c
507 //==============================================================================
508 
509 //==============================================================================
510 //
511 // T4K_GetScreen
512 //
523 SDL_Surface* T4K_GetScreen( void );
524 
525 
526 //==============================================================================
527 //
528 // T4K_GetResolutions
529 //
548 int T4K_GetResolutions( int* win_x,
549  int* win_y,
550  int* full_x,
551  int* full_y
552  );
553 
554 //==============================================================================
555 //
556 // T4K_DrawButton
557 //
580 void T4K_DrawButton( SDL_Rect* target_rect,
581  int radius,
582  Uint8 r,
583  Uint8 g,
584  Uint8 b,
585  Uint8 a
586  );
587 
588 //==============================================================================
589 //
590 // T4K_DrawButtonOn
591 //
620 void T4K_DrawButtonOn( SDL_Surface* target,
621  SDL_Rect* target_rect,
622  int radius,
623  Uint8 r,
624  Uint8 g,
625  Uint8 b,
626  Uint8 a
627  );
628 
629 //==============================================================================
630 //
631 // T4K_CreateButton
632 //
656 SDL_Surface* T4K_CreateButton( int w,
657  int h,
658  int radius,
659  Uint8 r,
660  Uint8 g,
661  Uint8 b,
662  Uint8 a
663  );
664 
665 //==============================================================================
666 //
667 // T4K_RoundCorners
668 //
681 void T4K_RoundCorners( SDL_Surface* s,
682  Uint16 radius
683  );
684 
685 //==============================================================================
686 //
687 // T4K_Flip
688 //
702 SDL_Surface* T4K_Flip( SDL_Surface* in,
703  int x,
704  int y
705  );
706 
707 //==============================================================================
708 //
709 // T4K_Blend
710 //
732 SDL_Surface* T4K_Blend( SDL_Surface* S1,
733  SDL_Surface* S2,
734  float gamma
735  );
736 
737 //==============================================================================
738 //
739 // T4K_FreeSurfaceArray
740 //
752 void T4K_FreeSurfaceArray( SDL_Surface** surfs,
753  int length
754  );
755 
756 //==============================================================================
757 //
758 // T4K_inRect
759 //
775 int T4K_inRect( SDL_Rect r,
776  int x,
777  int y
778  );
779 
780 //==============================================================================
781 //
782 // T4K_SetRect
783 //
798 void T4K_SetRect( SDL_Rect* rect,
799  const float* pos
800  );
801 
802 //==============================================================================
803 //
804 // T4K_UpdateRect
805 //
817 void T4K_UpdateRect( SDL_Surface* surf,
818  SDL_Rect* rect
819  );
820 
821 //==============================================================================
822 //
823 // T4K_DarkenScreen
824 //
835 void T4K_DarkenScreen( Uint8 bits );
836 
837 //==============================================================================
838 //
839 // T4K_ChangeWindowSize
840 //
853 void T4K_ChangeWindowSize( int new_res_x,
854  int new_res_y
855  );
856 
857 //==============================================================================
858 //
859 // T4K_SwitchScreenMode
860 //
871 void T4K_SwitchScreenMode( void );
872 
873 //==============================================================================
874 //
878 typedef void (*ResSwitchCallback)(int resx, int resy);
879 
880 //==============================================================================
881 //
882 // T4K_OnResolutionSwitch
883 //
895 
896 //==============================================================================
897 //
898 // T4K_WaitForEvent
899 //
910 SDL_EventType T4K_WaitForEvent( SDL_EventMask events );
911 
912 //==============================================================================
913 //
914 // T4K_zoom
915 //
929 SDL_Surface* T4K_zoom( SDL_Surface* src,
930  int new_w,
931  int new_h
932  );
933 
934 //==============================================================================
935 //
936 // T4K_TransWipe
937 //
954 int T4K_TransWipe( const SDL_Surface* newbkg,
955  WipeStyle type,
956  int segments,
957  int duration
958  );
959 
960 //==============================================================================
961 //
962 // T4K_InitBlitQueue
963 //
980 void T4K_InitBlitQueue( void );
981 
982 //==============================================================================
983 //
984 // T4K_ResetBlitQueue
985 //
995 void T4K_ResetBlitQueue( void );
996 
997 //==============================================================================
998 //
999 // T4K_AddRect
1000 //
1015 int T4K_AddRect( SDL_Rect* src,
1016  SDL_Rect* dst
1017  );
1018 
1019 //==============================================================================
1020 //
1021 // T4K_DrawSprite
1022 //
1037 int T4K_DrawSprite( sprite* gfx,
1038  int x,
1039  int y
1040  );
1041 
1042 //==============================================================================
1043 //
1044 // T4K_DrawObject
1045 //
1061 int T4K_DrawObject( SDL_Surface* surf,
1062  int x,
1063  int y
1064  );
1065 
1066 //==============================================================================
1067 //
1068 // T4K_UpdateScreen
1069 //
1079 void T4K_UpdateScreen( int* frame );
1080 
1081 //==============================================================================
1082 //
1083 // T4K_EraseSprite
1084 //
1103 int T4K_EraseSprite( sprite* img,
1104  SDL_Surface* curr_bkgd,
1105  int x,
1106  int y
1107  );
1108 
1109 //==============================================================================
1110 //
1111 // T4K_EraseObject
1112 //
1130 int T4K_EraseObject( SDL_Surface* surf,
1131  SDL_Surface* curr_bkgd,
1132  int x,
1133  int y
1134  );
1135 
1136 //==============================================================================
1137 //
1138 // T4K_SetFontName
1139 //
1149 void T4K_SetFontName( const char* name );
1150 
1151 //==============================================================================
1152 //
1153 // T4K_AskFontName
1154 //
1164 const char* T4K_AskFontName( void );
1165 
1166 //==============================================================================
1167 //
1168 // T4K_Setup_SDL_Text
1169 //
1181 int T4K_Setup_SDL_Text( void );
1182 
1183 //==============================================================================
1184 //
1185 // T4K_Cleanup_SDL_Text
1186 //
1196 void T4K_Cleanup_SDL_Text( void );
1197 
1198 //==============================================================================
1199 //
1200 // T4K_BlackOutline
1201 //
1219 SDL_Surface* T4K_BlackOutline( const char* t,
1220  int size,
1221  SDL_Color* c
1222  );
1223 
1224 //==============================================================================
1225 //
1226 // T4K_SimpleText
1227 //
1241 SDL_Surface* T4K_SimpleText( const char* t,
1242  int size,
1243  SDL_Color* col
1244  );
1245 
1246 //==============================================================================
1247 //
1248 // T4K_SimpleTextWithOffset
1249 //
1265 SDL_Surface* T4K_SimpleTextWithOffset( const char* t,
1266  int size,
1267  SDL_Color* col,
1268  int* glyph_offset
1269  );
1270 
1271 //==============================================================================
1272 // T4K_CharsForWidth
1273 //
1285 int T4K_CharsForWidth( int fontsize,
1286  int pixel_width
1287  );
1288 
1289 //==============================================================================
1290 // Public Definitions in t4k_loaders.c
1291 //==============================================================================
1292 
1293 //==============================================================================
1294 //
1295 // T4K_AddDataPrefix
1296 //
1306 void T4K_AddDataPrefix( const char* path );
1307 
1308 //==============================================================================
1309 //
1310 // T4K_CheckFile
1311 //
1323 int T4K_CheckFile( const char* file );
1324 
1325 //==============================================================================
1326 //
1327 // T4K_RemoveSlash
1328 //
1338 char* T4K_RemoveSlash( char *path );
1339 
1340 //==============================================================================
1341 //
1342 // T4K_LoadImage
1343 //
1356 SDL_Surface* T4K_LoadImage( const char* file_name,
1357  int mode
1358  );
1359 
1360 //==============================================================================
1361 //
1362 // T4K_LoadScaledImage
1363 //
1385 SDL_Surface* T4K_LoadScaledImage( const char* file_name,
1386  int mode,
1387  int width,
1388  int height
1389  );
1390 
1391 //==============================================================================
1392 //
1393 // T4K_LoadImageOfBoundingBox
1394 //
1414 SDL_Surface* T4K_LoadImageOfBoundingBox( const char* file_name,
1415  int mode,
1416  int max_width,
1417  int max_height
1418  );
1419 
1420 //=============================================================================
1421 //
1422 // T4K_LoadBkgd
1423 //
1439 SDL_Surface* T4K_LoadBkgd( const char* file_name,
1440  int width,
1441  int height
1442  );
1443 
1444 //=============================================================================
1445 //
1446 // T4K_LoadBothBkgds
1447 //
1463 int T4K_LoadBothBkgds( const char* file_name,
1464  SDL_Surface** fs_bkgd,
1465  SDL_Surface** win_bkgd
1466  );
1467 
1468 //==============================================================================
1469 //
1470 // T4K_LoadSprite
1471 //
1486 sprite* T4K_LoadSprite( const char* name,
1487  int mode
1488  );
1489 
1490 //==============================================================================
1491 //
1492 // T4K_LoadScaledSprite
1493 //
1513 sprite* T4K_LoadScaledSprite( const char* name,
1514  int mode,
1515  int width,
1516  int height
1517  );
1518 
1519 //==============================================================================
1520 //
1521 // T4K_LoadSpriteOfBoundingBox
1522 //
1542 sprite* T4K_LoadSpriteOfBoundingBox( const char* name,
1543  int mode,
1544  int max_width,
1545  int max_height
1546  );
1547 
1548 //==============================================================================
1549 //
1550 // T4K_FlipSprite
1551 //
1569  int X,
1570  int Y
1571  );
1572 
1573 //==============================================================================
1574 //
1575 // T4K_FreeSprite
1576 //
1586 void T4K_FreeSprite( sprite* gfx );
1587 
1588 //==============================================================================
1589 //
1590 // T4K_NextFrame
1591 //
1601 void T4K_NextFrame( sprite* s );
1602 
1603 //==============================================================================
1604 //
1605 // T4K_LoadSound
1606 //
1616 Mix_Chunk* T4K_LoadSound( char* datafile );
1617 
1618 //==============================================================================
1619 //
1620 // T4K_LoadMusic
1621 //
1631 Mix_Music* T4K_LoadMusic( char *datafile );
1632 
1633 
1634 //==============================================================================
1635 // Public Definitions from t4k_audio.c
1636 //==============================================================================
1637 
1638 const static int T4K_AUDIO_PLAY_ONCE = 0;
1639 const static int T4K_AUDIO_LOOP_FOREVER = -1;
1640 
1641 //==============================================================================
1642 //
1643 // T4K_PlaySound
1644 //
1654 void T4K_PlaySound( Mix_Chunk* sound );
1655 
1656 //==============================================================================
1657 //
1658 // T4K_PlaySoundLoop
1659 //
1671 void T4K_PlaySoundLoop( Mix_Chunk* sound,
1672  int loops
1673  );
1674 
1675 //==============================================================================
1676 //
1677 // T4K_AudioHaltChannel
1678 //
1689 void T4K_AudioHaltChannel( int channel );
1690 
1691 //==============================================================================
1692 //
1693 // T4K_AudioMusicLoad
1694 //
1706 void T4K_AudioMusicLoad( char* music_path,
1707  int loops
1708  );
1709 
1710 //==============================================================================
1711 //
1712 // T4K_AudioMusicUnload
1713 //
1724 void T4K_AudioMusicUnload( void );
1725 
1726 //==============================================================================
1727 //
1728 // T4K_IsPlayingMusic
1729 //
1741 bool T4K_IsPlayingMusic( void );
1742 
1743 //==============================================================================
1744 //
1745 // T4K_AudioMusicPlay
1746 //
1758 void T4K_AudioMusicPlay( Mix_Music* musicData,
1759  int loops
1760  );
1761 
1762 //==============================================================================
1763 //
1764 // T4K_AudioEnable
1765 //
1776 void T4K_AudioEnable( bool enabled );
1777 
1778 //==============================================================================
1779 //
1780 // T4K_AudioToggle
1781 //
1791 void T4K_AudioToggle( void );
1792 
1793 
1794 //=============================================================================
1795 // Public Definitions for t4k_linewrap.c
1796 //=============================================================================
1797 
1798 //=============================================================================
1799 //
1800 // T4K_LineWrap
1801 //
1825 int T4K_LineWrap( const char* input,
1826  char str_list[MAX_LINES][MAX_LINEWIDTH],
1827  int width,
1828  int max_lines,
1829  int max_width
1830  );
1831 
1832 //=============================================================================
1833 //
1834 // T4K_LineWrapInsBreaks
1835 //
1858 int T4K_LineWrapInsBreaks( const char* input,
1859  char* output,
1860  int width,
1861  int max_lines,
1862  int max_width
1863  );
1864 //=============================================================================
1865 //
1866 // T4K_LineWrapList
1867 //
1891 void T4K_LineWrapList( const char input[MAX_LINES][MAX_LINEWIDTH],
1892  char str_list[MAX_LINES][MAX_LINEWIDTH],
1893  int width,
1894  int max_lines,
1895  int max_width
1896  );
1897 
1898 
1899 //=============================================================================
1900 // Public Definitions for t4k_throttle.c
1901 //=============================================================================
1902 
1903 
1904 //=============================================================================
1905 //
1906 // T4K_Throttle
1907 //
1923 void T4K_Throttle( int loop_msec,
1924  Uint32* last_t
1925  );
1926 
1927 
1928 #endif
1929 
1930 
1931 //=============================================================================
1932 // Public Definitions for t4k_convert_utf.c
1933 //=============================================================================
1934 
1935 
1936 //=============================================================================
1937 //
1938 // T4K_ConvertFromUTF8
1939 //
1956 int T4K_ConvertFromUTF8(wchar_t* wide_word,
1957  const char* UTF8_word,
1958  int max_length
1959  );
1960 
1961 //=============================================================================
1962 //
1963 // T4K_ConvertToUTF8
1964 //
1981 int T4K_ConvertToUTF8(const wchar_t* wide_word,
1982  char* UTF8_word,
1983  int max_length
1984  );
#define MAX_LINEWIDTH
Maximum characters of each line.
Definition: t4k_common.h:240
void T4K_AddDataPrefix(const char *path)
Add a directory that should be searched when loading assets.
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 InitT4KCommon(int debug_flags)
Initialize Tux4Kids-Common.
void T4K_Cleanup_SDL_Text(void)
Shut down the backend used for text-drawing functions.
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...
void T4K_UpdateRect(SDL_Surface *surf, SDL_Rect *rect)
Wrap a call to SDL_UpdateRect.
#define MAX_SPRITE_FRAMES
Definition: t4k_common.h:173
void T4K_AudioMusicPlay(Mix_Music *musicData, int loops)
attempts to play the passed music data, stopping current music if necessary
void T4K_SetFontName(const char *name)
Set the "global" font name.
All menus are searched and the largest size that will fit on all menus is used.
Definition: t4k_common.h:224
int num_frames
Definition: t4k_common.h:186
SDL_Surface * prev_arrow
SDL_Surface * T4K_Flip(SDL_Surface *in, int x, int y)
Flip a surface vertically or horizontally.
void T4K_SetMenuSounds(char *mus_path, Mix_Chunk *click, Mix_Chunk *hover)
Set optional sound effects and music for menus.
void T4K_ResetBlitQueue(void)
Just set the number of pending updates to zero.
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_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...
WipeStyle
Definition: t4k_common.h:199
char * T4K_RemoveSlash(char *path)
Remove a trailing slash from a file path.
void T4K_DarkenScreen(Uint8 bits)
Darkens the screen by a factor of 2^bits.
SDL_Surface * T4K_BlackOutline(const char *t, int size, SDL_Color *c)
T4K_BlackOutline() creates a surface containing text of the designated foreground color,...
user pressed the stop button
Definition: t4k_common.h:216
int T4K_AddRect(SDL_Rect *src, SDL_Rect *dst)
Don't actually blit a surface, but add a rect to be updated next update.
bool
Definition: t4k_common.h:127
void T4K_InitBlitQueue(void)
Initialize the blit queue system. This must be called before T4K_ResetBlitQueue, T4K_AddRect,...
Mix_Chunk * T4K_LoadSound(char *datafile)
Load a sound/music patch from a file.
void T4K_PlaySoundLoop(Mix_Chunk *sound, int loops)
Play sound "loops" times, -1 for infinite.
void T4K_SetRect(SDL_Rect *rect, const float *pos)
This function will write an SDL_Rect with dimensions based on screen dimensions.
void T4K_AudioToggle(void)
Toggle sound enablement.
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.
void T4K_ChangeWindowSize(int new_res_x, int new_res_y)
This function will change window size (unstable, works only in windowed mode).
SDL_EventType T4K_WaitForEvent(SDL_EventMask events)
Block application until SDL receives an appropriate event. Use sparingly.
int T4K_ConvertToUTF8(const wchar_t *wide_word, char *UTF8_word, int max_length)
bool T4K_IsPlayingMusic(void)
This function will check if a music is currently playing.
void T4K_FreeSurfaceArray(SDL_Surface **surfs, int length)
Free every surface in the array together with the array itself.
int T4K_DrawObject(SDL_Surface *surf, int x, int y)
Draw an object at the specified location. No respect to clipping.
int T4K_CheckFile(const char *file)
Check whether a file exists.
void T4K_PlaySound(Mix_Chunk *sound)
Play sound once and then exit.
int T4K_LoadBothBkgds(const char *file_name, SDL_Surface **fs_bkgd, SDL_Surface **win_bkgd)
Load backgrounds for both fullscreen and windowed resolution.
SDL_Surface * T4K_LoadImage(const char *file_name, int mode)
Load an image without resizing it.
int T4K_DrawSprite(sprite *gfx, int x, int y)
This function will draw the sprite in the screen.
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_AudioMusicLoad(char *music_path, int loops)
Attempts to load and play the music file.
void T4K_AudioHaltChannel(int channel)
Will stop the channel specified in channel. If -1 is passed as the parameter to channel,...
SDL_Surface * T4K_LoadBkgd(const char *file_name, int width, int height)
A wrapper for LoadImage() that optimizes the format of background image.
can be used in .xml menu structures but should not be declared in activities' lists.
Definition: t4k_common.h:214
int T4K_ConvertFromUTF8(wchar_t *wide_word, const char *UTF8_word, int max_length)
int T4K_inRect(SDL_Rect r, int x, int y)
Tells whether the point (x, y) is inside the SDL_Rect r.
void T4K_RoundCorners(SDL_Surface *s, Uint16 radius)
Round the corners of a surface by erasing edge pixels.
sprite * T4K_FlipSprite(sprite *in, int X, int Y)
Flip (reflect) a sprite over one or both axes.
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 * 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_SetMenuFontSize(MFStrategy strategy, int size)
Set the font size for managed menus.
SDL_Surface * screen
Definition: t4k_common.h:205
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_SetMenuSpritePrefix(char *pref)
Set the prefix that is used whe loading menu sprites.
SDL_Surface * T4K_SimpleText(const char *t, int size, SDL_Color *col)
Returns a non-outlined surface using either SDL_Pango or SDL_ttf.
Mix_Music * T4K_LoadMusic(char *datafile)
Load music from a datafile.
void T4K_SetActivitiesList(int num, char **acts)
Specify the set of activities the menu system should handle.
Menus are searched separately for the largest fonts they can accommodate.
Definition: t4k_common.h:225
#define MAX_LINES
Maximum lines to wrap.
Definition: t4k_common.h:239
int T4K_EraseObject(SDL_Surface *surf, SDL_Surface *curr_bkgd, int x, int y)
Erase an object from the screen.
char wrapped_lines[MAX_LINES][MAX_LINEWIDTH]
Global buffer for wrapped lines.
Definition: t4k_common.h:242
int debug_status
SDL_Rect menu_rect
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...
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...
const char * T4K_AskFontName(void)
Get the "global" font name.
SDL_Rect next_rect
int T4K_HandleStdEvents(const SDL_Event *event)
Handle events that should have consistent effects everywhere in the program.
SDL_Surface * stop_button
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...
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)
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 * prev_gray
void T4K_Throttle(int loop_msec, Uint32 *last_t)
Definition: t4k_common.h:203
Definition: t4k_common.h:202
SDL_Rect prev_rect
void T4K_AudioEnable(bool enabled)
Enable/disable sound.
Definition: t4k_common.h:182
void T4K_SwitchScreenMode(void)
Switch between fullscreen and windowed mode. Resolution switching callbacks are invoked.
Definition: t4k_common.h:204
SDL_Surface * next_gray
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...
void T4K_UnloadMenus(void)
free all loaded menu trees
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...
SDL_Surface * default_img
Definition: t4k_common.h:185
void T4K_OnResolutionSwitch(ResSwitchCallback callback)
Register a callback to reposition and redraw screen elements when the resolution is changed.
void T4K_UpdateScreen(int *frame)
Update the screen and increment the frame counter.
int T4K_Setup_SDL_Text(void)
Initialize the backend (Pango or TTF) used for text-drawing functions.
SDL_Surface * next_arrow
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.
user decided to quit application
Definition: t4k_common.h:215
void(* ResSwitchCallback)(int resx, int resy)
Definition: t4k_common.h:878
int cur
Definition: t4k_common.h:187
void T4K_AudioMusicUnload(void)
Attempts to unload any music data that was loaded using the audioMusicLoad function.
Definition: t4k_common.h:201
int T4K_CharsForWidth(int fontsize, int pixel_width)
Calculate how long a string for a given fontsize will fit within a given pixel width....
void T4K_NextFrame(sprite *s)
Advance a sprite's frame.
The font size given is used directly; text may run off the screen.
Definition: t4k_common.h:226
SDL_Rect stop_rect
void T4K_PrerenderMenu(int index)
Prerender a single menu based on the screen resolution.
MFStrategy
Definition: t4k_common.h:222
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_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_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...
void T4K_FreeSprite(sprite *gfx)
Free memory allocated for a loaded sprite.