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, 2011.
6 // Authors: Brendan Luchen, David Bruce.
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 #include <sys/types.h>
56 #include <sys/stat.h>
57 #include <fcntl.h>
58 #include <unistd.h>
59 #include <dirent.h>
60 #include <wchar.h>
61 #include "SDL.h"
62 #include "SDL_image.h"
63 #include "SDL_mixer.h"
64 
65 //TTS Macros
66 #define DEFAULT_VALUE 30
67 #define INTERRUPT 0
68 #define APPEND 1
69 
70 //==============================================================================
71 // Debugging macros
72 //
73 // All macros take a debug mask as their first argument, which should roughly
74 // indicate what part of the program the debugging info is related to, and
75 // which can be one of the flags defined below, a program-specific flag, or
76 // an OR'd combination.
77 //
78 // DEBUGVAR prints out the name and value of a string variable
79 #ifndef DEBUGMSG
80 
82 #define DEBUGVAR(mask, Expr) \
83  if((mask) & (debug_status)) \
84 { \
85  fprintf(stderr, #Expr ": %s\n", (Expr)); fflush(stderr); \
86 }
87 
89 #define DEBUGVARX(mask, Expr) \
90  if((mask) & (debug_status)) \
91 { \
92  fprintf(stderr, #Expr ": %x\n", (Expr)); fflush(stderr); \
93 }
94 
96 #define DEBUGVARF(mask, Expr) \
97  if((mask) & (debug_status)) \
98 { \
99  fprintf(stderr, #Expr ": %f\n", (Expr)); fflush(stderr); \
100 }
101 
103 #define DEBUGCODE(mask) if((mask) & debug_status)
104 
106 #define DEBUGMSG(mask, ...) \
107  if((mask) & debug_status) \
108 { \
109  fprintf(stderr, __VA_ARGS__); fflush(stderr); \
110 }
111 #endif
112 
113 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
114 #define rmask 0xff000000
115 #define gmask 0x00ff0000
116 #define bmask 0x0000ff00
117 #define amask 0x000000ff
118 #else
119 #define rmask 0x000000ff
120 #define gmask 0x0000ff00
121 #define bmask 0x00ff0000
122 #define amask 0xff000000
123 #endif
124 
125 #ifndef bool
126 typedef enum
127 {
128  false,
129  true
130 }
131 bool;
132 #endif
133 
134 // These values have to match those used in games.
135 static const int debug_loaders = 1 << 0;
136 static const int debug_menu = 1 << 1;
137 static const int debug_menu_parser = 1 << 2;
138 static const int debug_sdl = 1 << 3;
139 static const int debug_linewrap = 1 << 4;
140 static const int debug_i18n = 1 << 5;
141 static const int debug_all = ~0;
142 
143 extern int debug_status;
144 
145 //Define our color constants:
146 static const SDL_Color black = {0x00, 0x00, 0x00, 0xff};
147 static const SDL_Color gray = {0x80, 0x80, 0x80, 0xff};
148 static const SDL_Color dark_blue = {0x00, 0x00, 0x60, 0xff};
149 static const SDL_Color red = {0xff, 0x00, 0x00, 0xff};
150 static const SDL_Color white = {0xff, 0xff, 0xff, 0xff};
151 static const SDL_Color yellow = {0xff, 0xff, 0x00, 0xff};
152 static const SDL_Color bright_green = {0x60, 0xff, 0x00, 0xff};
153 
164 #define START_CUSTOM_DEBUG 6
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 //==============================================================================
176 typedef struct
184 {
185  SDL_Surface *frame[MAX_SPRITE_FRAMES];
186  SDL_Surface *default_img;
188  int cur;
189 }
190 sprite;
191 
192 //==============================================================================
200 typedef enum
201 {
207 }
208 WipeStyle;
209 
210 //==============================================================================
214 enum
215 {
217  QUIT = -2,
218  STOP = -1
219 };
220 
221 //==============================================================================
228 typedef enum
229 {
233 }
234 MFStrategy;
235 
236 // from tk4_loaders.c
237 #define IMG_REGULAR 0x01
238 #define IMG_COLORKEY 0x02
239 #define IMG_ALPHA 0x04
240 #define IMG_MODES 0x07
241 
242 #define IMG_NOT_REQUIRED 0x10
243 #define IMG_NO_PNG_FALLBACK 0x20
244 
245 #define MAX_LINES 128
246 #define MAX_LINEWIDTH 256
247 
248 static char wrapped_lines[MAX_LINES][MAX_LINEWIDTH];
249 
250 //TODO separate headers for different areas a la SDL?
251 
252 
253 //==============================================================================
254 // Structure used to pass arguments for T4K_Tts_say()
255 typedef struct
256 {
257  int mode;
258  wchar_t text[10000];
259 }tts_argument;
260 
261 
262 //==============================================================================
263 // Public Definitions in t4k_tts.c
264 //==============================================================================
265 int T4K_Tts_init();
266 int T4K_Tts_set_voice(char voice_name[]);
267 void T4K_Tts_set_volume(int volume);
268 void T4K_Tts_set_rate(int rate);
269 void T4K_Tts_set_pitch(int pitch);
270 void T4K_Tts_say(int rate,int pitch, int mode, const char* text, ...);
271 
272 
273 
274 
275 //==============================================================================
276 // Public Definitions in t4k_main.c
277 //==============================================================================
278 
279 //==============================================================================
280 //
281 // InitT4KCommon
282 //
300 int InitT4KCommon( int debug_flags );
301 
302 //==============================================================================
303 //
304 // CleanupT4KCommon
305 //
315 void CleanupT4KCommon( void );
316 
317 //==============================================================================
318 //
319 // T4K_HandleStdEvents
320 //
333 int T4K_HandleStdEvents( const SDL_Event* event );
334 
335 
336 //==============================================================================
337 // Public Definitions in t4k_menu.c
338 //==============================================================================
339 
340 //==============================================================================
341 //
342 // T4K_SetActivitiesList
343 //
355 void T4K_SetActivitiesList( int num,
356  char** acts
357  );
358 
359 //==============================================================================
360 //
361 // T4K_SetMenuSounds
362 //
376 void T4K_SetMenuSounds( char* mus_path,
377  Mix_Chunk* click,
378  Mix_Chunk* hover
379  );
380 
381 //==============================================================================
382 //
383 // T4K_SetMenuSpritePrefix
384 //
394 void T4K_SetMenuSpritePrefix( char* pref );
395 
396 //==============================================================================
397 //
398 // T4K_SetMenuFontSize
399 //
412 void T4K_SetMenuFontSize( MFStrategy strategy,
413  int size
414  );
415 
416 //==============================================================================
417 //
418 // T4K_CreateOneLevelMenu
419 //
439 void T4K_CreateOneLevelMenu( int index,
440  int items,
441  char** item_names,
442  char** sprite_names,
443  char* title,
444  char* trailer
445  );
446 
447 //==============================================================================
448 //
449 // T4K_RunMenu
450 //
474 int T4K_RunMenu( int index,
475  bool return_choice,
476  void (*draw_background)(),
477  int (*handle_event)(SDL_Event*),
478  void (*handle_animations)(),
479  int (*handle_activity)(int, int)
480  );
481 
482 //==============================================================================
483 //
484 // T4K_PrerenderMenu
485 //
495 void T4K_PrerenderMenu( int index );
496 
497 //==============================================================================
498 //
499 // T4K_PrerenderAll
500 //
511 void T4K_PrerenderAll( void );
512 
513 //==============================================================================
514 //
515 // T4K_LoadMenu
516 //
529 void T4K_LoadMenu( int index,
530  const char* file_name
531  );
532 
533 //==============================================================================
534 //
535 // T4K_UnloadMenus
536 //
546 void T4K_UnloadMenus( void );
547 
548 
549 //==============================================================================
550 // Public Definitions in tk4_sdl.c
551 //==============================================================================
552 
553 //==============================================================================
554 //
555 // T4K_GetScreen
556 //
567 SDL_Surface* T4K_GetScreen( void );
568 
569 
570 //==============================================================================
571 //
572 // T4K_GetResolutions
573 //
592 int T4K_GetResolutions( int* win_x,
593  int* win_y,
594  int* full_x,
595  int* full_y
596  );
597 
598 //==============================================================================
599 //
600 // T4K_DrawButton
601 //
624 void T4K_DrawButton( SDL_Rect* target_rect,
625  int radius,
626  Uint8 r,
627  Uint8 g,
628  Uint8 b,
629  Uint8 a
630  );
631 
632 //==============================================================================
633 //
634 // T4K_DrawButtonOn
635 //
664 void T4K_DrawButtonOn( SDL_Surface* target,
665  SDL_Rect* target_rect,
666  int radius,
667  Uint8 r,
668  Uint8 g,
669  Uint8 b,
670  Uint8 a
671  );
672 
673 //==============================================================================
674 //
675 // T4K_CreateButton
676 //
700 SDL_Surface* T4K_CreateButton( int w,
701  int h,
702  int radius,
703  Uint8 r,
704  Uint8 g,
705  Uint8 b,
706  Uint8 a
707  );
708 
709 //==============================================================================
710 //
711 // T4K_RoundCorners
712 //
725 void T4K_RoundCorners( SDL_Surface* s,
726  Uint16 radius
727  );
728 
729 //==============================================================================
730 //
731 // T4K_Flip
732 //
746 SDL_Surface* T4K_Flip( SDL_Surface* in,
747  int x,
748  int y
749  );
750 
751 //==============================================================================
752 //
753 // T4K_Blend
754 //
776 SDL_Surface* T4K_Blend( SDL_Surface* S1,
777  SDL_Surface* S2,
778  float gamma
779  );
780 
781 //==============================================================================
782 //
783 // T4K_FreeSurfaceArray
784 //
796 void T4K_FreeSurfaceArray( SDL_Surface** surfs,
797  int length
798  );
799 
800 //==============================================================================
801 //
802 // T4K_inRect
803 //
819 int T4K_inRect( SDL_Rect r,
820  int x,
821  int y
822  );
823 
824 //==============================================================================
825 //
826 // T4K_SetRect
827 //
842 void T4K_SetRect( SDL_Rect* rect,
843  const float* pos
844  );
845 
846 //==============================================================================
847 //
848 // T4K_UpdateRect
849 //
861 void T4K_UpdateRect( SDL_Surface* surf,
862  SDL_Rect* rect
863  );
864 
865 //==============================================================================
866 //
867 // T4K_DarkenScreen
868 //
879 void T4K_DarkenScreen( Uint8 bits );
880 
881 //==============================================================================
882 //
883 // T4K_ChangeWindowSize
884 //
897 void T4K_ChangeWindowSize( int new_res_x,
898  int new_res_y
899  );
900 
901 //==============================================================================
902 //
903 // T4K_SwitchScreenMode
904 //
915 void T4K_SwitchScreenMode( void );
916 
917 //==============================================================================
918 //
922 typedef void (*ResSwitchCallback)(int resx, int resy);
923 
924 //==============================================================================
925 //
926 // T4K_OnResolutionSwitch
927 //
939 
940 //==============================================================================
941 //
942 // T4K_WaitForEvent
943 //
954 SDL_EventType T4K_WaitForEvent( SDL_EventMask events );
955 
956 //==============================================================================
957 //
958 // T4K_zoom
959 //
973 SDL_Surface* T4K_zoom( SDL_Surface* src,
974  int new_w,
975  int new_h
976  );
977 
978 //==============================================================================
979 //
980 // T4K_TransWipe
981 //
998 int T4K_TransWipe( const SDL_Surface* newbkg,
999  WipeStyle type,
1000  int segments,
1001  int duration
1002  );
1003 
1004 //==============================================================================
1005 //
1006 // T4K_InitBlitQueue
1007 //
1024 void T4K_InitBlitQueue( void );
1025 
1026 //==============================================================================
1027 //
1028 // T4K_ResetBlitQueue
1029 //
1039 void T4K_ResetBlitQueue( void );
1040 
1041 //==============================================================================
1042 //
1043 // T4K_AddRect
1044 //
1059 int T4K_AddRect( SDL_Rect* src,
1060  SDL_Rect* dst
1061  );
1062 
1063 //==============================================================================
1064 //
1065 // T4K_DrawSprite
1066 //
1081 int T4K_DrawSprite( sprite* gfx,
1082  int x,
1083  int y
1084  );
1085 
1086 //==============================================================================
1087 //
1088 // T4K_DrawObject
1089 //
1105 int T4K_DrawObject( SDL_Surface* surf,
1106  int x,
1107  int y
1108  );
1109 
1110 //==============================================================================
1111 //
1112 // T4K_UpdateScreen
1113 //
1123 void T4K_UpdateScreen( int* frame );
1124 
1125 //==============================================================================
1126 //
1127 // T4K_EraseSprite
1128 //
1147 int T4K_EraseSprite( sprite* img,
1148  SDL_Surface* curr_bkgd,
1149  int x,
1150  int y
1151  );
1152 
1153 //==============================================================================
1154 //
1155 // T4K_EraseObject
1156 //
1174 int T4K_EraseObject( SDL_Surface* surf,
1175  SDL_Surface* curr_bkgd,
1176  int x,
1177  int y
1178  );
1179 
1180 //==============================================================================
1181 //
1182 // T4K_SetFontName
1183 //
1193 void T4K_SetFontName( const char* name );
1194 
1195 //==============================================================================
1196 //
1197 // T4K_AskFontName
1198 //
1208 const char* T4K_AskFontName( void );
1209 
1210 //==============================================================================
1211 //
1212 // T4K_Setup_SDL_Text
1213 //
1225 int T4K_Setup_SDL_Text( void );
1226 
1227 //==============================================================================
1228 //
1229 // T4K_Cleanup_SDL_Text
1230 //
1240 void T4K_Cleanup_SDL_Text( void );
1241 
1242 //==============================================================================
1243 //
1244 // T4K_BlackOutline
1245 //
1263 SDL_Surface* T4K_BlackOutline( const char* t,
1264  int size,
1265  const SDL_Color* c
1266  );
1267 
1268 //==============================================================================
1269 //
1270 // T4K_SimpleText
1271 //
1285 SDL_Surface* T4K_SimpleText( const char* t,
1286  int size,
1287  const SDL_Color* col
1288  );
1289 
1290 //==============================================================================
1291 //
1292 // T4K_SimpleTextWithOffset
1293 //
1309 SDL_Surface* T4K_SimpleTextWithOffset( const char* t,
1310  int size,
1311  const SDL_Color* col,
1312  int* glyph_offset
1313  );
1314 
1315 //==============================================================================
1316 // T4K_CharsForWidth
1317 //
1329 int T4K_CharsForWidth( int fontsize,
1330  int pixel_width
1331  );
1332 
1333 //==============================================================================
1334 // Public Definitions in t4k_loaders.c
1335 //==============================================================================
1336 
1337 //==============================================================================
1338 //
1339 // T4K_AddDataPrefix
1340 //
1350 void T4K_AddDataPrefix( const char* path );
1351 
1352 //==============================================================================
1353 //
1354 // T4K_CheckFile
1355 //
1367 int T4K_CheckFile( const char* file );
1368 
1369 //==============================================================================
1370 //
1371 // T4K_RemoveSlash
1372 //
1382 char* T4K_RemoveSlash( char *path );
1383 
1384 //==============================================================================
1385 //
1386 // T4K_LoadImage
1387 //
1400 SDL_Surface* T4K_LoadImage( const char* file_name,
1401  int mode
1402  );
1403 
1404 //==============================================================================
1405 //
1406 // T4K_LoadScaledImage
1407 //
1429 SDL_Surface* T4K_LoadScaledImage( const char* file_name,
1430  int mode,
1431  int width,
1432  int height
1433  );
1434 
1435 //==============================================================================
1436 //
1437 // T4K_LoadImageOfBoundingBox
1438 //
1458 SDL_Surface* T4K_LoadImageOfBoundingBox( const char* file_name,
1459  int mode,
1460  int max_width,
1461  int max_height
1462  );
1463 
1464 //=============================================================================
1465 //
1466 // T4K_LoadBkgd
1467 //
1483 SDL_Surface* T4K_LoadBkgd( const char* file_name,
1484  int width,
1485  int height
1486  );
1487 
1488 //=============================================================================
1489 //
1490 // T4K_LoadBothBkgds
1491 //
1507 int T4K_LoadBothBkgds( const char* file_name,
1508  SDL_Surface** fs_bkgd,
1509  SDL_Surface** win_bkgd
1510  );
1511 
1512 //==============================================================================
1513 //
1514 // T4K_LoadSprite
1515 //
1530 sprite* T4K_LoadSprite( const char* name,
1531  int mode
1532  );
1533 
1534 //==============================================================================
1535 //
1536 // T4K_LoadScaledSprite
1537 //
1557 sprite* T4K_LoadScaledSprite( const char* name,
1558  int mode,
1559  int width,
1560  int height
1561  );
1562 
1563 //==============================================================================
1564 //
1565 // T4K_LoadSpriteOfBoundingBox
1566 //
1586 sprite* T4K_LoadSpriteOfBoundingBox( const char* name,
1587  int mode,
1588  int max_width,
1589  int max_height
1590  );
1591 
1592 //==============================================================================
1593 //
1594 // T4K_FlipSprite
1595 //
1613  int X,
1614  int Y
1615  );
1616 
1617 //==============================================================================
1618 //
1619 // T4K_FreeSprite
1620 //
1630 void T4K_FreeSprite( sprite* gfx );
1631 
1632 //==============================================================================
1633 //
1634 // T4K_NextFrame
1635 //
1645 void T4K_NextFrame( sprite* s );
1646 
1647 //==============================================================================
1648 //
1649 // T4K_LoadSound
1650 //
1660 Mix_Chunk* T4K_LoadSound( char* datafile );
1661 
1662 //==============================================================================
1663 //
1664 // T4K_LoadMusic
1665 //
1675 Mix_Music* T4K_LoadMusic( char *datafile );
1676 
1677 
1678 //==============================================================================
1679 // Public Definitions from t4k_audio.c
1680 //==============================================================================
1681 
1682 const static int T4K_AUDIO_PLAY_ONCE = 0;
1683 const static int T4K_AUDIO_LOOP_FOREVER = -1;
1684 
1685 //==============================================================================
1686 //
1687 // T4K_PlaySound
1688 //
1698 void T4K_PlaySound( Mix_Chunk* sound );
1699 
1700 //==============================================================================
1701 //
1702 // T4K_PlaySoundLoop
1703 //
1715 void T4K_PlaySoundLoop( Mix_Chunk* sound,
1716  int loops
1717  );
1718 
1719 //==============================================================================
1720 //
1721 // T4K_AudioHaltChannel
1722 //
1733 void T4K_AudioHaltChannel( int channel );
1734 
1735 //==============================================================================
1736 //
1737 // T4K_AudioMusicLoad
1738 //
1750 void T4K_AudioMusicLoad( char* music_path,
1751  int loops
1752  );
1753 
1754 //==============================================================================
1755 //
1756 // T4K_AudioMusicUnload
1757 //
1768 void T4K_AudioMusicUnload( void );
1769 
1770 //==============================================================================
1771 //
1772 // T4K_IsPlayingMusic
1773 //
1785 bool T4K_IsPlayingMusic( void );
1786 
1787 //==============================================================================
1788 //
1789 // T4K_AudioMusicPlay
1790 //
1803 void T4K_AudioMusicPlay( Mix_Music* musicData,
1804  int loops
1805  );
1806 
1807 //==============================================================================
1808 //
1809 // T4K_AudioEnable
1810 //
1821 void T4K_AudioEnable( bool enabled );
1822 
1823 //==============================================================================
1824 //
1825 // T4K_AudioToggle
1826 //
1836 void T4K_AudioToggle( void );
1837 
1838 
1839 //=============================================================================
1840 // Public Definitions for t4k_linewrap.c
1841 //=============================================================================
1842 
1843 //=============================================================================
1844 //
1845 // T4K_LineWrap
1846 //
1870 int T4K_LineWrap( const char* input,
1871  char str_list[MAX_LINES][MAX_LINEWIDTH],
1872  int width,
1873  int max_lines,
1874  int max_width
1875  );
1876 
1877 //=============================================================================
1878 //
1879 // T4K_LineWrapInsBreaks
1880 //
1903 int T4K_LineWrapInsBreaks( const char* input,
1904  char* output,
1905  int width,
1906  int max_lines,
1907  int max_width
1908  );
1909 
1910 //=============================================================================
1911 //
1912 // T4K_LineWrapList
1913 //
1937 void T4K_LineWrapList( const char input[MAX_LINES][MAX_LINEWIDTH],
1938  char str_list[MAX_LINES][MAX_LINEWIDTH],
1939  int width,
1940  int max_lines,
1941  int max_width
1942  );
1943 
1944 
1945 //=============================================================================
1946 // Public Definitions for t4k_throttle.c
1947 //=============================================================================
1948 
1949 
1950 //=============================================================================
1951 //
1952 // T4K_Throttle
1953 //
1969 void T4K_Throttle( int loop_msec,
1970  Uint32* last_t
1971  );
1972 
1973 
1974 //=============================================================================
1975 // Public Definitions for t4k_convert_utf.c
1976 //=============================================================================
1977 
1978 
1979 //=============================================================================
1980 //
1981 // T4K_ConvertFromUTF8
1982 //
2000 int T4K_ConvertFromUTF8( wchar_t* wide_word,
2001  const char* UTF8_word,
2002  int max_length
2003  );
2004 
2005 //=============================================================================
2006 //
2007 // T4K_ConvertToUTF8
2008 //
2026 int T4K_ConvertToUTF8( const wchar_t* wide_word,
2027  char* UTF8_word,
2028  int max_length
2029  );
2030 
2031 
2032 //=============================================================================
2033 // Public Definitions for t4k_replacements.c
2034 //=============================================================================
2035 
2036 //==============================================================================
2037 //
2038 // T4K_alphasort
2039 //
2056 int T4K_alphasort( const struct dirent** d1,
2057  const struct dirent** d2
2058  );
2059 
2060 //==============================================================================
2061 //
2062 // T4K_scandir
2063 //
2096 int T4K_scandir( const char* dirname,
2097  struct dirent*** namelist,
2098  int (*sdfilter)(struct dirent *),
2099  int (*dcomp)(const void *, const void *)
2100  );
2101 
2102 #endif /* TUX4KIDS_COMMON_H */
2103 
#define MAX_LINEWIDTH
Maximum characters of each line.
Definition: t4k_common.h:246
void T4K_AddDataPrefix(const char *path)
Add a directory that should be searched when loading assets.
SDL_Surface * T4K_SimpleTextWithOffset(const char *t, int size, const SDL_Color *col, int *glyph_offset)
Same as T4K_SimpleText, but the text offset is also stored.
void T4K_Tts_set_pitch(int pitch)
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_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:230
int num_frames
Definition: t4k_common.h:187
SDL_Surface * prev_arrow
Definition: t4k_common.h:255
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:200
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.
int T4K_Tts_init()
user pressed the stop button
Definition: t4k_common.h:218
void T4K_Tts_set_rate(int rate)
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:126
SDL_Surface * T4K_SimpleText(const char *t, int size, const SDL_Color *col)
Returns a non-outlined surface using either SDL_Pango or SDL_ttf.
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.
int mode
Definition: t4k_common.h:257
void T4K_SetRect(SDL_Rect *rect, const float *pos)
This function will write an SDL_Rect with dimensions based on screen dimensions.
int T4K_alphasort(const struct dirent **d1, const struct dirent **d2)
Wrapper for alphasort function, using either platform's alphasort or our replacement in t4k_replaceme...
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.
int InitT4KCommon(int debug_flags)
Initialize Tux4Kids-Common.
int T4K_scandir(const char *dirname, struct dirent ***namelist, int(*sdfilter)(struct dirent *), int(*dcomp)(const void *, const void *))
Wrapper for scandir function, using either platform's scandir or our replacement in t4k_replacements ...
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,...
void CleanupT4KCommon(void)
Cleanup Tux4Kids-Common.
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:216
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.
SDL_Surface * T4K_BlackOutline(const char *t, int size, const SDL_Color *c)
T4K_BlackOutline() creates a surface containing text of the designated foreground color,...
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:206
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.
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:231
#define MAX_LINES
Maximum lines to wrap.
Definition: t4k_common.h:245
int T4K_EraseObject(SDL_Surface *surf, SDL_Surface *curr_bkgd, int x, int y)
Erase an object from the screen.
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_Tts_set_volume(int volume)
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:204
Definition: t4k_common.h:203
SDL_Rect prev_rect
void T4K_AudioEnable(bool enabled)
Enable/disable sound.
Definition: t4k_common.h:183
void T4K_Tts_say(int rate, int pitch, int mode, const char *text,...)
void T4K_SwitchScreenMode(void)
Switch between fullscreen and windowed mode. Resolution switching callbacks are invoked.
Definition: t4k_common.h:205
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:186
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
user decided to quit application
Definition: t4k_common.h:217
void(* ResSwitchCallback)(int resx, int resy)
Definition: t4k_common.h:922
int cur
Definition: t4k_common.h:188
void T4K_AudioMusicUnload(void)
Attempts to unload any music data that was loaded using the audioMusicLoad function.
Definition: t4k_common.h:202
int T4K_CharsForWidth(int fontsize, int pixel_width)
Calculate how long a string for a given fontsize will fit within a given pixel width....
int T4K_Tts_set_voice(char voice_name[])
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:232
SDL_Rect stop_rect
void T4K_PrerenderMenu(int index)
Prerender a single menu based on the screen resolution.
MFStrategy
Definition: t4k_common.h:228
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.