Commit | Line | Data |
b41abbd6 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
4 | |
5 | #ifndef aTHX_ |
6 | #define aTHX_ |
7 | #endif |
8 | |
9 | #include <SDL.h> |
10 | #include <SDL_ttf.h> |
11 | |
12 | MODULE = SDL PACKAGE = SDL |
13 | PROTOTYPES : DISABLE |
14 | |
15 | |
16 | =for comment |
17 | |
18 | These are here right now to keep them around with using the code. |
19 | |
20 | int |
21 | TTFGetFontStyle ( font ) |
22 | TTF_Font *font |
23 | CODE: |
24 | RETVAL = TTF_GetFontStyle(font); |
25 | OUTPUT: |
26 | RETVAL |
27 | |
28 | void |
29 | TTFSetFontStyle ( font, style ) |
30 | TTF_Font *font |
31 | int style |
32 | CODE: |
33 | TTF_SetFontStyle(font,style); |
34 | |
35 | int |
36 | TTFFontHeight ( font ) |
37 | TTF_Font *font |
38 | CODE: |
39 | RETVAL = TTF_FontHeight(font); |
40 | OUTPUT: |
41 | RETVAL |
42 | |
43 | int |
44 | TTFFontAscent ( font ) |
45 | TTF_Font *font |
46 | CODE: |
47 | RETVAL = TTF_FontAscent(font); |
48 | OUTPUT: |
49 | RETVAL |
50 | |
51 | int |
52 | TTFFontDescent ( font ) |
53 | TTF_Font *font |
54 | CODE: |
55 | RETVAL = TTF_FontDescent(font); |
56 | OUTPUT: |
57 | RETVAL |
58 | |
59 | int |
60 | TTFFontLineSkip ( font ) |
61 | TTF_Font *font |
62 | CODE: |
63 | RETVAL = TTF_FontLineSkip(font); |
64 | OUTPUT: |
65 | RETVAL |
66 | |
67 | AV* |
68 | TTFGlyphMetrics ( font, ch ) |
69 | TTF_Font *font |
70 | Uint16 ch |
71 | CODE: |
72 | int minx, miny, maxx, maxy, advance; |
73 | RETVAL = newAV(); |
74 | TTF_GlyphMetrics(font, ch, &minx, &miny, &maxx, &maxy, &advance); |
75 | av_push(RETVAL,newSViv(minx)); |
76 | av_push(RETVAL,newSViv(miny)); |
77 | av_push(RETVAL,newSViv(maxx)); |
78 | av_push(RETVAL,newSViv(maxy)); |
79 | av_push(RETVAL,newSViv(advance)); |
80 | OUTPUT: |
81 | RETVAL |
82 | |
83 | |
84 | AV* |
85 | TTFSizeUTF8 ( font, text ) |
86 | TTF_Font *font |
87 | char *text |
88 | CODE: |
89 | int w,h; |
90 | RETVAL = newAV(); |
91 | if(TTF_SizeUTF8(font,text,&w,&h)) |
92 | { |
93 | av_push(RETVAL,newSViv(w)); |
94 | av_push(RETVAL,newSViv(h)); |
95 | sv_2mortal((SV*)RETVAL); |
96 | |
97 | } |
98 | else |
99 | { |
100 | printf("TTF error at TTFSizeUTF8 with : %s \n", TTF_GetError()); |
101 | Perl_croak (aTHX_ "TTF error \n"); |
102 | } |
103 | |
104 | OUTPUT: |
105 | RETVAL |
106 | |
107 | AV* |
108 | TTFSizeUNICODE ( font, text ) |
109 | TTF_Font *font |
110 | const Uint16 *text |
111 | CODE: |
112 | int w,h; |
113 | RETVAL = newAV(); |
114 | if(TTF_SizeUNICODE(font,text,&w,&h)) |
115 | { |
116 | av_push(RETVAL,newSViv(w)); |
117 | av_push(RETVAL,newSViv(h)); |
118 | sv_2mortal((SV*)RETVAL); |
119 | |
120 | } |
121 | else |
122 | { |
123 | printf("TTF error at TTFSizeUNICODE : %s \n", TTF_GetError()); |
124 | Perl_croak (aTHX_ "TTF error \n"); |
125 | } |
126 | |
127 | OUTPUT: |
128 | RETVAL |
129 | |
130 | SDL_Surface* |
131 | TTFRenderTextSolid ( font, text, fg ) |
132 | TTF_Font *font |
133 | char *text |
134 | SDL_Color *fg |
135 | CODE: |
136 | RETVAL = TTF_RenderText_Solid(font,text,*fg); |
137 | OUTPUT: |
138 | RETVAL |
139 | |
140 | SDL_Surface* |
141 | TTFRenderUTF8Solid ( font, text, fg ) |
142 | TTF_Font *font |
143 | char *text |
144 | SDL_Color *fg |
145 | CODE: |
146 | RETVAL = TTF_RenderUTF8_Solid(font,text,*fg); |
147 | OUTPUT: |
148 | RETVAL |
149 | |
150 | SDL_Surface* |
151 | TTFRenderUNICODESolid ( font, text, fg ) |
152 | TTF_Font *font |
153 | const Uint16 *text |
154 | SDL_Color *fg |
155 | CODE: |
156 | RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg); |
157 | OUTPUT: |
158 | RETVAL |
159 | |
160 | SDL_Surface* |
161 | TTFRenderGlyphSolid ( font, ch, fg ) |
162 | TTF_Font *font |
163 | Uint16 ch |
164 | SDL_Color *fg |
165 | CODE: |
166 | RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg); |
167 | OUTPUT: |
168 | RETVAL |
169 | |
170 | SDL_Surface* |
171 | TTFRenderTextShaded ( font, text, fg, bg ) |
172 | TTF_Font *font |
173 | char *text |
174 | SDL_Color *fg |
175 | SDL_Color *bg |
176 | CODE: |
177 | RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg); |
178 | OUTPUT: |
179 | RETVAL |
180 | |
181 | SDL_Surface* |
182 | TTFRenderUTF8Shaded( font, text, fg, bg ) |
183 | TTF_Font *font |
184 | char *text |
185 | SDL_Color *fg |
186 | SDL_Color *bg |
187 | CODE: |
188 | RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg); |
189 | OUTPUT: |
190 | RETVAL |
191 | |
192 | SDL_Surface* |
193 | TTFRenderUNICODEShaded( font, text, fg, bg ) |
194 | TTF_Font *font |
195 | const Uint16 *text |
196 | SDL_Color *fg |
197 | SDL_Color *bg |
198 | CODE: |
199 | RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg); |
200 | OUTPUT: |
201 | RETVAL |
202 | |
203 | SDL_Surface* |
204 | TTFRenderGlyphShaded ( font, ch, fg, bg ) |
205 | TTF_Font *font |
206 | Uint16 ch |
207 | SDL_Color *fg |
208 | SDL_Color *bg |
209 | CODE: |
210 | RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg); |
211 | OUTPUT: |
212 | RETVAL |
213 | |
214 | SDL_Surface* |
215 | TTFRenderTextBlended( font, text, fg ) |
216 | TTF_Font *font |
217 | char *text |
218 | SDL_Color *fg |
219 | CODE: |
220 | RETVAL = TTF_RenderText_Blended(font,text,*fg); |
221 | OUTPUT: |
222 | RETVAL |
223 | |
224 | SDL_Surface* |
225 | TTFRenderUTF8Blended( font, text, fg ) |
226 | TTF_Font *font |
227 | char *text |
228 | SDL_Color *fg |
229 | CODE: |
230 | RETVAL = TTF_RenderUTF8_Blended(font,text,*fg); |
231 | OUTPUT: |
232 | RETVAL |
233 | |
234 | SDL_Surface* |
235 | TTFRenderUNICODEBlended( font, text, fg ) |
236 | TTF_Font *font |
237 | const Uint16 *text |
238 | SDL_Color *fg |
239 | CODE: |
240 | RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg); |
241 | OUTPUT: |
242 | RETVAL |
243 | |
244 | SDL_Surface* |
245 | TTFRenderGlyphBlended( font, ch, fg ) |
246 | TTF_Font *font |
247 | Uint16 ch |
248 | SDL_Color *fg |
249 | CODE: |
250 | RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg); |
251 | OUTPUT: |
252 | RETVAL |
253 | |
254 | void |
255 | TTFCloseFont ( font ) |
256 | TTF_Font *font |
257 | CODE: |
258 | TTF_CloseFont(font); |
259 | font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont |
260 | |
261 | SDL_Surface* |
262 | TTFPutString ( font, mode, surface, x, y, fg, bg, text ) |
263 | TTF_Font *font |
264 | int mode |
265 | SDL_Surface *surface |
266 | int x |
267 | int y |
268 | SDL_Color *fg |
269 | SDL_Color *bg |
270 | char *text |
271 | CODE: |
272 | SDL_Surface *img; |
273 | SDL_Rect dest; |
274 | int w,h; |
275 | dest.x = x; |
276 | dest.y = y; |
277 | RETVAL = NULL; |
278 | switch (mode) { |
279 | case TEXT_SOLID: |
280 | img = TTF_RenderText_Solid(font,text,*fg); |
281 | TTF_SizeText(font,text,&w,&h); |
282 | dest.w = w; |
283 | dest.h = h; |
284 | break; |
285 | case TEXT_SHADED: |
286 | img = TTF_RenderText_Shaded(font,text,*fg,*bg); |
287 | TTF_SizeText(font,text,&w,&h); |
288 | dest.w = w; |
289 | dest.h = h; |
290 | break; |
291 | case TEXT_BLENDED: |
292 | img = TTF_RenderText_Blended(font,text,*fg); |
293 | TTF_SizeText(font,text,&w,&h); |
294 | dest.w = w; |
295 | dest.h = h; |
296 | break; |
297 | case UTF8_SOLID: |
298 | img = TTF_RenderUTF8_Solid(font,text,*fg); |
299 | TTF_SizeUTF8(font,text,&w,&h); |
300 | dest.w = w; |
301 | dest.h = h; |
302 | break; |
303 | case UTF8_SHADED: |
304 | img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg); |
305 | TTF_SizeUTF8(font,text,&w,&h); |
306 | dest.w = w; |
307 | dest.h = h; |
308 | break; |
309 | case UTF8_BLENDED: |
310 | img = TTF_RenderUTF8_Blended(font,text,*fg); |
311 | TTF_SizeUTF8(font,text,&w,&h); |
312 | dest.w = w; |
313 | dest.h = h; |
314 | break; |
315 | case UNICODE_SOLID: |
316 | img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg); |
317 | TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); |
318 | dest.w = w; |
319 | dest.h = h; |
320 | break; |
321 | case UNICODE_SHADED: |
322 | img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg); |
323 | TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); |
324 | dest.w = w; |
325 | dest.h = h; |
326 | break; |
327 | case UNICODE_BLENDED: |
328 | img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg); |
329 | TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); |
330 | dest.w = w; |
331 | dest.h = h; |
332 | break; |
333 | default: |
334 | img = TTF_RenderText_Shaded(font,text,*fg,*bg); |
335 | TTF_SizeText(font,text,&w,&h); |
336 | dest.w = w; |
337 | dest.h = h; |
338 | } |
339 | if ( img && img->format && img->format->palette ) { |
340 | SDL_Color *c = &img->format->palette->colors[0]; |
341 | Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b ); |
342 | SDL_SetColorKey(img,SDL_SRCCOLORKEY,key ); |
343 | if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) { |
344 | SDL_FreeSurface(img); |
345 | RETVAL = NULL; |
346 | } else { |
347 | RETVAL = img; |
348 | } |
349 | } |
350 | OUTPUT: |
351 | RETVAL |
352 | |
353 | =cut |