rubysdl 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/NEWS.en +8 -0
  2. data/NEWS.ja +8 -0
  3. data/README.en +22 -15
  4. data/README.ja +31 -20
  5. data/depend +2 -0
  6. data/doc-en/event.rsd +3 -0
  7. data/doc-en/time.rsd +1 -1
  8. data/doc-en/video.rsd +8 -8
  9. data/doc.txt +32 -0
  10. data/doc/event.rsd +5 -0
  11. data/doc/opengl.rsd +160 -0
  12. data/doc/rsd.rb +4 -3
  13. data/doc/time.rsd +1 -1
  14. data/doc/video.rsd +8 -8
  15. data/extconf.rb +30 -15
  16. data/lib/sdl.rb +2 -1
  17. data/lib/sdl1_compatible.rb +20 -0
  18. data/mkpkg.sh +28 -0
  19. data/rubysdl.gemspec +21 -0
  20. data/rubysdl.h +1 -0
  21. data/rubysdl_cdrom.c +0 -10
  22. data/rubysdl_event.c +30 -11
  23. data/rubysdl_event_key.c +0 -5
  24. data/rubysdl_image.c +2 -2
  25. data/rubysdl_joystick.c +0 -18
  26. data/rubysdl_kanji.c +0 -5
  27. data/rubysdl_main.c +0 -2
  28. data/rubysdl_mixer.c +2 -18
  29. data/rubysdl_mouse.c +0 -4
  30. data/rubysdl_rwops.c +4 -0
  31. data/rubysdl_sdlskk.c +0 -3
  32. data/rubysdl_sge_video.c +0 -14
  33. data/rubysdl_smpeg.c +0 -1
  34. data/rubysdl_time.c +0 -10
  35. data/rubysdl_ttf.c +0 -3
  36. data/rubysdl_video.c +2 -30
  37. data/rubysdl_wm.c +0 -5
  38. data/sample/caption.rb +21 -0
  39. data/sge/INSTALL +72 -0
  40. data/sge/LICENSE +504 -0
  41. data/sge/Makefile +83 -0
  42. data/sge/Makefile.conf +63 -0
  43. data/sge/README +219 -0
  44. data/sge/Todo +7 -0
  45. data/sge/WhatsNew +224 -0
  46. data/sge/sge.h +31 -0
  47. data/sge/sge_blib.cpp +1939 -0
  48. data/sge/sge_blib.h +68 -0
  49. data/sge/sge_bm_text.cpp +451 -0
  50. data/sge/sge_bm_text.h +71 -0
  51. data/sge/sge_collision.cpp +388 -0
  52. data/sge/sge_collision.h +54 -0
  53. data/sge/sge_config.h +6 -0
  54. data/sge/sge_internal.h +152 -0
  55. data/sge/sge_misc.cpp +92 -0
  56. data/sge/sge_misc.h +37 -0
  57. data/sge/sge_primitives.cpp +2516 -0
  58. data/sge/sge_primitives.h +111 -0
  59. data/sge/sge_rotation.cpp +683 -0
  60. data/sge/sge_rotation.h +46 -0
  61. data/sge/sge_shape.cpp +762 -0
  62. data/sge/sge_shape.h +365 -0
  63. data/sge/sge_surface.cpp +1090 -0
  64. data/sge/sge_surface.h +100 -0
  65. data/sge/sge_textpp.cpp +785 -0
  66. data/sge/sge_textpp.h +270 -0
  67. data/sge/sge_tt_text.cpp +1456 -0
  68. data/sge/sge_tt_text.h +114 -0
  69. data/utils/buildtest.sh +29 -0
  70. data/win32/README.en.win32 +72 -0
  71. data/win32/README.ja.win32 +80 -0
  72. data/win32/install_rubysdl.rb +30 -0
  73. data/win32/mkpkg.sh +72 -0
  74. metadata +136 -113
  75. data/rubysdl_ref.en.html +0 -5879
  76. data/rubysdl_ref.en.rd +0 -6601
  77. data/rubysdl_ref.html +0 -6194
  78. data/rubysdl_ref.rd +0 -6950
@@ -0,0 +1,68 @@
1
+ /*
2
+ * SDL Graphics Extension
3
+ * Johan E. Thelin's BLib (header)
4
+ *
5
+ * Started 000428
6
+ *
7
+ * License: LGPL v2+ (see the file LICENSE)
8
+ * (c)2000-2003 Anders Lindstr�m & Johan E. Thelin
9
+ */
10
+
11
+ /*********************************************************************
12
+ * This library is free software; you can redistribute it and/or *
13
+ * modify it under the terms of the GNU Library General Public *
14
+ * License as published by the Free Software Foundation; either *
15
+ * version 2 of the License, or (at your option) any later version. *
16
+ *********************************************************************/
17
+
18
+ #ifndef sge_blib_H
19
+ #define sge_blib_H
20
+
21
+ #include "SDL.h"
22
+ #include "sge_internal.h"
23
+
24
+
25
+ #ifdef _SGE_C
26
+ extern "C" {
27
+ #endif
28
+ DECLSPEC void sge_FadedLine(SDL_Surface *dest,Sint16 x1,Sint16 x2,Sint16 y,Uint8 r1,Uint8 g1,Uint8 b1,Uint8 r2,Uint8 g2,Uint8 b2);
29
+ DECLSPEC void sge_TexturedLine(SDL_Surface *dest,Sint16 x1,Sint16 x2,Sint16 y,SDL_Surface *source,Sint16 sx1,Sint16 sy1,Sint16 sx2,Sint16 sy2);
30
+
31
+ DECLSPEC void sge_Trigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 color);
32
+ DECLSPEC void sge_TrigonAlpha(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 color, Uint8 alpha);
33
+ DECLSPEC void sge_AATrigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 color);
34
+ DECLSPEC void sge_AATrigonAlpha(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 color, Uint8 alpha);
35
+
36
+ DECLSPEC void sge_FilledTrigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 color);
37
+ DECLSPEC void sge_FilledTrigonAlpha(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 color, Uint8 alpha);
38
+
39
+ DECLSPEC void sge_FadedTrigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint32 c1,Uint32 c2,Uint32 c3);
40
+ DECLSPEC void sge_TexturedTrigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,SDL_Surface *source,Sint16 sx1,Sint16 sy1,Sint16 sx2,Sint16 sy2,Sint16 sx3,Sint16 sy3);
41
+
42
+ DECLSPEC void sge_TexturedRect(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Sint16 x4,Sint16 y4,SDL_Surface *source,Sint16 sx1,Sint16 sy1,Sint16 sx2,Sint16 sy2,Sint16 sx3,Sint16 sy3,Sint16 sx4,Sint16 sy4);
43
+
44
+ DECLSPEC int sge_FilledPolygon(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint32 color);
45
+ DECLSPEC int sge_FilledPolygonAlpha(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint32 color, Uint8 alpha);
46
+ DECLSPEC int sge_AAFilledPolygon(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint32 color);
47
+
48
+ DECLSPEC int sge_FadedPolygon(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint8 *R, Uint8 *G, Uint8 *B);
49
+ DECLSPEC int sge_FadedPolygonAlpha(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint8 *R, Uint8 *G, Uint8 *B, Uint8 alpha);
50
+ DECLSPEC int sge_AAFadedPolygon(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint8 *R, Uint8 *G, Uint8 *B);
51
+ #ifdef _SGE_C
52
+ }
53
+ #endif
54
+
55
+ #ifndef sge_C_ONLY
56
+ DECLSPEC void sge_Trigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint8 R, Uint8 G, Uint8 B);
57
+ DECLSPEC void sge_TrigonAlpha(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint8 R, Uint8 G, Uint8 B, Uint8 alpha);
58
+ DECLSPEC void sge_AATrigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint8 R, Uint8 G, Uint8 B);
59
+ DECLSPEC void sge_AATrigonAlpha(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint8 R, Uint8 G, Uint8 B, Uint8 alpha);
60
+ DECLSPEC void sge_FilledTrigon(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint8 R, Uint8 G, Uint8 B);
61
+ DECLSPEC void sge_FilledTrigonAlpha(SDL_Surface *dest,Sint16 x1,Sint16 y1,Sint16 x2,Sint16 y2,Sint16 x3,Sint16 y3,Uint8 R, Uint8 G, Uint8 B, Uint8 alpha);
62
+ DECLSPEC int sge_FilledPolygon(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint8 r, Uint8 g, Uint8 b);
63
+ DECLSPEC int sge_FilledPolygonAlpha(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint8 r, Uint8 g, Uint8 b, Uint8 alpha);
64
+ DECLSPEC int sge_AAFilledPolygon(SDL_Surface *dest, Uint16 n, Sint16 *x, Sint16 *y, Uint8 r, Uint8 g, Uint8 b);
65
+ #endif /* sge_C_ONLY */
66
+
67
+
68
+ #endif /* sge_blib_H */
@@ -0,0 +1,451 @@
1
+ /*
2
+ * SDL Graphics Extension
3
+ * Text/Bitmap font functions
4
+ *
5
+ * Started 990815
6
+ *
7
+ * License: LGPL v2+ (see the file LICENSE)
8
+ * (c)1999-2003 Anders Lindstr�m
9
+ */
10
+
11
+ /*********************************************************************
12
+ * This library is free software; you can redistribute it and/or *
13
+ * modify it under the terms of the GNU Library General Public *
14
+ * License as published by the Free Software Foundation; either *
15
+ * version 2 of the License, or (at your option) any later version. *
16
+ *********************************************************************/
17
+
18
+ /*
19
+ * Some of this is taken from SDL_DrawText by Garrett Banuk (mongoose@wpi.edu)
20
+ * http://www.wpi.edu/~mongoose/SDL_Console
21
+ * Thanks to Karl Bartel for the SFont format!
22
+ */
23
+
24
+ #include "SDL.h"
25
+ #include <stdarg.h>
26
+ #include <string.h>
27
+ #include <math.h>
28
+ #include <new>
29
+ #include "sge_surface.h"
30
+ #include "sge_bm_text.h"
31
+ #include "sge_tt_text.h"
32
+ #include "sge_textpp.h"
33
+
34
+ #ifdef _SGE_HAVE_IMG
35
+ #include <SDL_image.h>
36
+ #endif
37
+
38
+ using namespace std;
39
+
40
+ /* Globals used for sge_Update/sge_Lock (defined in sge_surface) */
41
+ extern Uint8 _sge_update;
42
+ extern Uint8 _sge_lock;
43
+
44
+ //==================================================================================
45
+ // Creates a new font from a surface
46
+ //==================================================================================
47
+ sge_bmpFont* sge_BF_CreateFont(SDL_Surface *surface, Uint8 flags)
48
+ {
49
+ sge_bmpFont *font;
50
+
51
+ font = new(nothrow) sge_bmpFont; if(font==NULL){SDL_SetError("SGE - Out of memory");return NULL;}
52
+
53
+ if(!(flags&SGE_BFNOCONVERT) && !(flags&SGE_BFSFONT)){ /* Get a converted copy */
54
+ font->FontSurface = SDL_DisplayFormat(surface);
55
+ if(font->FontSurface==NULL){SDL_SetError("SGE - Out of memory");return NULL;}
56
+
57
+ if(flags&SGE_BFPALETTE){ //We want an 8bit surface
58
+ SDL_Surface *tmp;
59
+ tmp = SDL_AllocSurface(SDL_SWSURFACE, surface->w, surface->h, 8, 0, 0, 0, 0);
60
+ if(tmp==NULL){SDL_SetError("SGE - Out of memory");SDL_FreeSurface(font->FontSurface);return NULL;}
61
+
62
+ //Set the palette
63
+ SDL_Color c[2];
64
+ c[0].r=0; c[1].r=255;
65
+ c[0].g=0; c[1].g=255;
66
+ c[0].b=0; c[1].b=255;
67
+ SDL_SetColors(tmp, c, 0, 2);
68
+
69
+ if (SDL_MUSTLOCK(font->FontSurface) && _sge_lock)
70
+ if (SDL_LockSurface(font->FontSurface) < 0){
71
+ SDL_SetError("SGE - Locking error");
72
+ SDL_FreeSurface(font->FontSurface);
73
+ return NULL;
74
+ }
75
+
76
+ //Copy the font to the 8bit surface
77
+ Sint16 x,y;
78
+ Uint32 bc=sge_GetPixel(font->FontSurface,0,surface->h-1);
79
+ for(y=0; y<font->FontSurface->h; y++){
80
+ for(x=0; x<font->FontSurface->w; x++){
81
+ if(sge_GetPixel(font->FontSurface,x,y)==bc)
82
+ *((Uint8 *)tmp->pixels + y * tmp->pitch + x)=0;
83
+ else
84
+ *((Uint8 *)tmp->pixels + y * tmp->pitch + x)=1;
85
+ }
86
+ }
87
+
88
+ if (SDL_MUSTLOCK(font->FontSurface) && _sge_lock) {
89
+ SDL_UnlockSurface(font->FontSurface);
90
+ }
91
+
92
+ //sge_Blit(surface, tmp, 0,0,0,0,surface->w, surface->h);
93
+ SDL_FreeSurface(font->FontSurface);
94
+ font->FontSurface=tmp;
95
+ }
96
+
97
+
98
+ if((flags&SGE_FLAG8))
99
+ SDL_FreeSurface(surface);
100
+ }
101
+ else if(flags&SGE_FLAG8) /* Use the source */
102
+ font->FontSurface = surface;
103
+ else /* Get a copy */
104
+ font->FontSurface = sge_copy_surface(surface);
105
+
106
+ if(font->FontSurface==NULL){SDL_SetError("SGE - Out of memory");return NULL;}
107
+
108
+ SDL_Surface *fnt = font->FontSurface; //Shorthand
109
+ font->Chars=0;
110
+
111
+ if(!(flags&SGE_BFSFONT)){ /* Fixed width font */
112
+ font->CharWidth = font->FontSurface->w/256;
113
+ font->CharHeight = font->FontSurface->h;
114
+ font->CharPos = NULL;
115
+ font->yoffs = 0;
116
+ font->Chars=256;
117
+ }
118
+ else{ /* Karl Bartel's sfont */
119
+ Sint16 x=0;
120
+ int i=0;
121
+
122
+ font->CharPos = new(nothrow) Sint16[256];
123
+ if(!font->CharPos){SDL_SetError("SGE - Out of memory");sge_BF_CloseFont(font);return NULL;}
124
+
125
+ Uint32 color = sge_GetPixel(fnt,0,0); //get data color
126
+
127
+ while ( x < fnt->w && font->Chars < 256 ){
128
+ if (sge_GetPixel(fnt,x,0)==color) {
129
+ font->CharPos[i++]=x;
130
+
131
+ while ( x < fnt->w-1 && sge_GetPixel(fnt,x,0) == color )
132
+ x++;
133
+
134
+ font->CharPos[i++]=x;
135
+ font->Chars++;
136
+ }
137
+ x++;
138
+ }
139
+
140
+ font->CharHeight = font->FontSurface->h-1;
141
+ font->CharWidth = 0;
142
+ font->yoffs = 1;
143
+ }
144
+
145
+ /* Set font as transparent if the flag is set */
146
+ if (SDL_MUSTLOCK(font->FontSurface) && _sge_lock)
147
+ if (SDL_LockSurface(font->FontSurface) < 0){
148
+ return font;
149
+ }
150
+ font->bcolor=sge_GetPixel(font->FontSurface,0,font->FontSurface->h-1);
151
+ if (SDL_MUSTLOCK(font->FontSurface) && _sge_lock) {
152
+ SDL_UnlockSurface(font->FontSurface);
153
+ }
154
+ if(flags&SGE_BFTRANSP || flags&SGE_BFSFONT)
155
+ #if SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) >= \
156
+ SDL_VERSIONNUM(1, 1, 4)
157
+ SDL_SetColorKey(font->FontSurface,SDL_SRCCOLORKEY, font->bcolor); //Some versions of SDL have a bug with SDL_RLEACCEL
158
+ #else
159
+ SDL_SetColorKey(font->FontSurface,SDL_SRCCOLORKEY|SDL_RLEACCEL, font->bcolor);
160
+ #endif
161
+
162
+ return font;
163
+ }
164
+
165
+
166
+ //==================================================================================
167
+ // Loads the font into a new struct
168
+ //==================================================================================
169
+ sge_bmpFont* sge_BF_OpenFont(char *file, Uint8 flags)
170
+ {
171
+ sge_bmpFont *font;
172
+ SDL_Surface *Temp;
173
+
174
+ /* load the font bitmap */
175
+ #ifdef _SGE_HAVE_IMG
176
+ if(NULL == (Temp = IMG_Load(file))) //We have SDL_Img lib!
177
+ #else
178
+ if(NULL == (Temp = SDL_LoadBMP(file))) //We can only load bmp files...
179
+ #endif
180
+ {
181
+ sge_SetError("SGE - Couldn't load font file: %s",file);
182
+ return NULL;
183
+ }
184
+
185
+ font = sge_BF_CreateFont(Temp,flags|SGE_FLAG8); //SGE_FLAG8 - no need to make a copy of the surface
186
+
187
+ return font;
188
+ }
189
+
190
+
191
+ //==================================================================================
192
+ // Draws string to surface with the selected font
193
+ // Returns pos. and size of the drawn text
194
+ //==================================================================================
195
+ SDL_Rect sge_BF_textout(SDL_Surface *surface, sge_bmpFont *font, char *string, Sint16 x, Sint16 y)
196
+ {
197
+ SDL_Rect ret; ret.x=0;ret.y=0;ret.w=0;ret.h=0;
198
+
199
+ if(font==NULL){return ret;}
200
+
201
+ int characters;
202
+ Sint16 xsrc,xdest,ofs,adv=font->CharWidth;
203
+ float diff=0;
204
+
205
+ /* Valid coords ? */
206
+ if(surface)
207
+ if(x>surface->w || y>surface->h)
208
+ return ret;
209
+
210
+ characters = strlen(string);
211
+
212
+ xdest=x;
213
+
214
+ /* Now draw it */
215
+ for(int i=0; i<characters; i++)
216
+ {
217
+ if(!font->CharPos) /* Fixed width */
218
+ xsrc = string[i] * font->CharWidth;
219
+ else{ /* Variable width */
220
+ if(string[i]==' ' || (string[i]-33)>font->Chars || string[i]<33){
221
+ xdest += font->CharPos[2]-font->CharPos[1];
222
+ continue;
223
+ }
224
+ ofs = (string[i]-33)*2+1;
225
+ xsrc = (font->CharPos[ofs]+font->CharPos[ofs-1])/2;
226
+ //font->CharWidth = (font->CharPos[ofs+2]+font->CharPos[ofs+1])/2-(font->CharPos[ofs]+font->CharPos[ofs-1])/2-1;
227
+ font->CharWidth = (font->CharPos[ofs+2]+font->CharPos[ofs+1])/2-(font->CharPos[ofs]+font->CharPos[ofs-1])/2;
228
+ adv = font->CharPos[ofs+1]-font->CharPos[ofs];
229
+ diff =float( (font->CharPos[ofs]-font->CharPos[ofs-1])/2.0 );
230
+ }
231
+
232
+ if(surface)
233
+ sge_Blit(font->FontSurface, surface, xsrc,font->yoffs, int(xdest-diff),y, font->CharWidth,font->CharHeight);
234
+
235
+ xdest += adv;
236
+ }
237
+
238
+ ret.x=x; ret.y=y; ret.w=xdest-x+font->CharWidth; ret.h=font->CharHeight;
239
+
240
+ if(surface)
241
+ sge_UpdateRect(surface, x, y, ret.w, ret.h);
242
+
243
+ return ret;
244
+ }
245
+
246
+
247
+ //==================================================================================
248
+ // Returns the size (w and h) of the string (if rendered with font)
249
+ //==================================================================================
250
+ SDL_Rect sge_BF_TextSize(sge_bmpFont *font, char *string)
251
+ {
252
+ return sge_BF_textout(NULL, font, string, 0,0);
253
+ }
254
+
255
+
256
+ //==================================================================================
257
+ // Draws formated text to surface with the selected font
258
+ // Returns pos. and size of the drawn text
259
+ // * just like printf(char *format, ...) *
260
+ //==================================================================================
261
+ SDL_Rect sge_BF_textoutf(SDL_Surface *surface, sge_bmpFont *font, Sint16 x, Sint16 y , char *format, ...)
262
+ {
263
+ char buf[256];
264
+
265
+ va_list ap;
266
+
267
+ #ifdef __WIN32__
268
+ va_start((va_list*)ap, format); //Stupid w32 crosscompiler
269
+ #else
270
+ va_start(ap, format);
271
+ #endif
272
+
273
+ vsprintf(buf, format, ap);
274
+ va_end(ap);
275
+
276
+ return sge_BF_textout(surface, font, buf, x, y);
277
+ }
278
+
279
+
280
+ //==================================================================================
281
+ // Returns the height of the font
282
+ // Returns 0 if the struct was invalid
283
+ //==================================================================================
284
+ Sint16 sge_BF_GetHeight(sge_bmpFont *font)
285
+ {
286
+ if(font)
287
+ return font->CharHeight;
288
+ else
289
+ return 0;
290
+ }
291
+
292
+
293
+ //==================================================================================
294
+ // Returns the width of the font (only fixed width fonts)
295
+ // Returns 0 if the struct was invalid
296
+ //==================================================================================
297
+ Sint16 sge_BF_GetWidth(sge_bmpFont *font)
298
+ {
299
+ if(font)
300
+ return font->CharWidth;
301
+ else
302
+ return 0;
303
+ }
304
+
305
+
306
+ //==================================================================================
307
+ // Removes font from memory
308
+ //==================================================================================
309
+ void sge_BF_CloseFont(sge_bmpFont *font)
310
+ {
311
+ if(font){
312
+ SDL_FreeSurface(font->FontSurface);
313
+
314
+ if(font->CharPos)
315
+ delete[] font->CharPos;
316
+
317
+ delete font;
318
+ font=NULL;
319
+ }
320
+ }
321
+
322
+
323
+ //==================================================================================
324
+ // Change the font color
325
+ // Will not work on 'color' fonts!
326
+ // Doesn't like 24bpp
327
+ //==================================================================================
328
+ void sge_BF_SetColor(sge_bmpFont *font, Uint8 R, Uint8 G, Uint8 B)
329
+ {
330
+ if(font==NULL){return;}
331
+
332
+ if(!font->FontSurface->format->palette){ //Slow truecolor version
333
+ Sint16 x,y;
334
+ Sint16 ypnt;
335
+ SDL_Surface *surface=font->FontSurface;
336
+ Uint32 c_keep=font->bcolor;
337
+
338
+ Uint32 color=SDL_MapRGB(font->FontSurface->format, R, G, B);
339
+
340
+ switch(surface->format->BytesPerPixel){
341
+ case 1: { /* Assuming 8-bpp */
342
+ Uint8 *pnt;
343
+ for(y=0; y<surface->h; y++){
344
+ ypnt=y*surface->pitch;
345
+ for(x=0; x<surface->w; x++){
346
+ pnt=((Uint8 *)surface->pixels + x + ypnt);
347
+ if(*pnt!=c_keep){*pnt=(Uint8)color;}
348
+ }
349
+ }
350
+ }
351
+ break;
352
+
353
+ case 2: { /* Probably 15-bpp or 16-bpp */
354
+ Uint16 *pnt;
355
+ for(y=0; y<surface->h; y++){
356
+ ypnt=y*surface->pitch/2;
357
+ for(x=0; x<surface->w; x++){
358
+ pnt=((Uint16 *)surface->pixels + x + ypnt);
359
+ if(*pnt!=c_keep){*pnt=(Uint16)color;}
360
+ }
361
+ }
362
+ }
363
+ break;
364
+
365
+ case 3: { /* Slow 24-bpp mode, usually not used */
366
+ }
367
+ break;
368
+
369
+ case 4: { /* Probably 32-bpp */
370
+ Uint32 *pnt;
371
+ for(y=0; y<surface->h; y++){
372
+ ypnt=y*surface->pitch/4;
373
+ for(x=0; x<surface->w; x++){
374
+ pnt=((Uint32 *)surface->pixels + x + ypnt);
375
+ if(*pnt!=c_keep){*pnt=(Uint32)color;}
376
+ }
377
+ }
378
+ }
379
+ break;
380
+ }
381
+ }else{ //Fast palette version
382
+ SDL_Color c[2];
383
+ c[0].r=0; c[1].r=R;
384
+ c[0].g=0; c[1].g=G;
385
+ c[0].b=0; c[1].b=B;
386
+ SDL_SetColors(font->FontSurface, c, 0, 2);
387
+ }
388
+ }
389
+
390
+
391
+ //==================================================================================
392
+ // Sets an alpha value for the font (don't work with sfonts with an alpha channel)
393
+ //==================================================================================
394
+ void sge_BF_SetAlpha(sge_bmpFont *font, Uint8 alpha)
395
+ {
396
+ SDL_SetAlpha(font->FontSurface,SDL_SRCALPHA|SDL_RLEACCEL, alpha);
397
+ }
398
+
399
+
400
+ //==================================================================================
401
+ // BitmapText input
402
+ //==================================================================================
403
+ int sge_BF_inputAlpha(SDL_Surface *screen, sge_bmpFont *font, char *string, Uint8 flags, int pos,int len, Sint16 x, Sint16 y, int Alpha)
404
+ {
405
+ if( pos==0 && len>0 )
406
+ string[0] = '\0';
407
+
408
+ sge_TextSurface text(screen, string, x, y);
409
+ text.set_bmFont(font);
410
+ text.show_cursor(true);
411
+ text.set_alpha(Alpha);
412
+ text.max_chars(len-1);
413
+
414
+ int ret = sge_text_input(&text, flags);
415
+
416
+ strncpy( string, text.get_string(false).c_str(), sizeof(char)*len );
417
+ return ret;
418
+ }
419
+
420
+ int sge_BF_inputAlpha_UNI(SDL_Surface *screen, sge_bmpFont *font, Uint16 *string, Uint8 flags, int pos,int len, Sint16 x,Sint16 y, int Alpha)
421
+ {
422
+ sge_TextSurface text(screen, "", x, y);
423
+
424
+ if( pos!=0 )
425
+ text.change_uctext(string);
426
+
427
+ text.set_bmFont(font);
428
+ text.show_cursor(true);
429
+ text.set_alpha(Alpha);
430
+ text.max_chars(len-1);
431
+
432
+ int ret = sge_text_input(&text, flags);
433
+
434
+ Uint16 *tmp = text.get_ucstring(false);
435
+
436
+ strncpy( (char*)string, (char*)tmp, sizeof(Uint16)*len );
437
+
438
+ delete[] tmp;
439
+
440
+ return ret;
441
+ }
442
+
443
+ int sge_BF_input(SDL_Surface *screen,sge_bmpFont *font,char *string, Uint8 flags, int pos,int len,Sint16 x,Sint16 y)
444
+ {
445
+ return sge_BF_inputAlpha(screen, font, string, flags, pos, len, x,y, SDL_ALPHA_OPAQUE);
446
+ }
447
+
448
+ int sge_BF_input_UNI(SDL_Surface *screen, sge_bmpFont *font, Uint16 *string, Uint8 flags, int pos,int len, Sint16 x,Sint16 y)
449
+ {
450
+ return sge_BF_inputAlpha_UNI(screen, font, string, flags, pos, len, x,y, SDL_ALPHA_OPAQUE);
451
+ }