...
|
...
|
@@ -41,6 +41,141 @@ |
41
|
41
|
|
42
|
42
|
extern SDL_Window *window;
|
43
|
43
|
|
|
44
|
+#define SDL_SRCALPHA 0x00010000
|
|
45
|
+int SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
|
|
46
|
+{
|
|
47
|
+ if (flag & SDL_SRCALPHA) {
|
|
48
|
+ /* According to the docs, value is ignored for alpha surfaces */
|
|
49
|
+ if (surface->format->Amask) {
|
|
50
|
+ value = 0xFF;
|
|
51
|
+ }
|
|
52
|
+ SDL_SetSurfaceAlphaMod(surface, value);
|
|
53
|
+ SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
|
|
54
|
+ } else {
|
|
55
|
+ SDL_SetSurfaceAlphaMod(surface, 0xFF);
|
|
56
|
+ SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
|
|
57
|
+ }
|
|
58
|
+ SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));
|
|
59
|
+
|
|
60
|
+ return 0;
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+typedef struct SDL_VideoInfo
|
|
64
|
+{
|
|
65
|
+ Uint32 hw_available:1;
|
|
66
|
+ Uint32 wm_available:1;
|
|
67
|
+ Uint32 UnusedBits1:6;
|
|
68
|
+ Uint32 UnusedBits2:1;
|
|
69
|
+ Uint32 blit_hw:1;
|
|
70
|
+ Uint32 blit_hw_CC:1;
|
|
71
|
+ Uint32 blit_hw_A:1;
|
|
72
|
+ Uint32 blit_sw:1;
|
|
73
|
+ Uint32 blit_sw_CC:1;
|
|
74
|
+ Uint32 blit_sw_A:1;
|
|
75
|
+ Uint32 blit_fill:1;
|
|
76
|
+ Uint32 UnusedBits3:16;
|
|
77
|
+ Uint32 video_mem;
|
|
78
|
+
|
|
79
|
+ SDL_PixelFormat *vfmt;
|
|
80
|
+
|
|
81
|
+ int current_w;
|
|
82
|
+ int current_h;
|
|
83
|
+} SDL_VideoInfo;
|
|
84
|
+
|
|
85
|
+static int
|
|
86
|
+GetVideoDisplay()
|
|
87
|
+{
|
|
88
|
+ const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
|
|
89
|
+ if ( !variable ) {
|
|
90
|
+ variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
|
|
91
|
+ }
|
|
92
|
+ if ( variable ) {
|
|
93
|
+ return SDL_atoi(variable);
|
|
94
|
+ } else {
|
|
95
|
+ return 0;
|
|
96
|
+ }
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+const SDL_VideoInfo *SDL_GetVideoInfo(void)
|
|
100
|
+{
|
|
101
|
+ static SDL_VideoInfo info;
|
|
102
|
+ SDL_DisplayMode mode;
|
|
103
|
+
|
|
104
|
+ /* Memory leak, compatibility code, who cares? */
|
|
105
|
+ if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
|
|
106
|
+ info.vfmt = SDL_AllocFormat(mode.format);
|
|
107
|
+ info.current_w = mode.w;
|
|
108
|
+ info.current_h = mode.h;
|
|
109
|
+ }
|
|
110
|
+ return &info;
|
|
111
|
+}
|
|
112
|
+
|
|
113
|
+SDL_Rect **
|
|
114
|
+SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
|
|
115
|
+{
|
|
116
|
+ int i, nmodes;
|
|
117
|
+ SDL_Rect **modes;
|
|
118
|
+
|
|
119
|
+/* if (!SDL_GetVideoDevice()) {
|
|
120
|
+ return NULL;
|
|
121
|
+ }
|
|
122
|
+ */
|
|
123
|
+/* if (!(flags & SDL_FULLSCREEN)) {
|
|
124
|
+ return (SDL_Rect **) (-1);
|
|
125
|
+ }
|
|
126
|
+*/
|
|
127
|
+ if (!format) {
|
|
128
|
+ format = SDL_GetVideoInfo()->vfmt;
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ /* Memory leak, but this is a compatibility function, who cares? */
|
|
132
|
+ nmodes = 0;
|
|
133
|
+ modes = NULL;
|
|
134
|
+ for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
|
|
135
|
+ SDL_DisplayMode mode;
|
|
136
|
+ int bpp;
|
|
137
|
+
|
|
138
|
+ SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
|
|
139
|
+ if (!mode.w || !mode.h) {
|
|
140
|
+ return (SDL_Rect **) (-1);
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ /* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */
|
|
144
|
+ if (SDL_BYTESPERPIXEL(mode.format) <= 2) {
|
|
145
|
+ bpp = SDL_BITSPERPIXEL(mode.format);
|
|
146
|
+ } else {
|
|
147
|
+ bpp = SDL_BYTESPERPIXEL(mode.format) * 8;
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ if (bpp != format->BitsPerPixel) {
|
|
151
|
+ continue;
|
|
152
|
+ }
|
|
153
|
+ if (nmodes > 0 && modes[nmodes - 1]->w == mode.w
|
|
154
|
+ && modes[nmodes - 1]->h == mode.h) {
|
|
155
|
+ continue;
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
|
|
159
|
+ if (!modes) {
|
|
160
|
+ return NULL;
|
|
161
|
+ }
|
|
162
|
+ modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
|
|
163
|
+ if (!modes[nmodes]) {
|
|
164
|
+ return NULL;
|
|
165
|
+ }
|
|
166
|
+ modes[nmodes]->x = 0;
|
|
167
|
+ modes[nmodes]->y = 0;
|
|
168
|
+ modes[nmodes]->w = mode.w;
|
|
169
|
+ modes[nmodes]->h = mode.h;
|
|
170
|
+ ++nmodes;
|
|
171
|
+ }
|
|
172
|
+ if (modes) {
|
|
173
|
+ modes[nmodes] = NULL;
|
|
174
|
+ }
|
|
175
|
+ return modes;
|
|
176
|
+}
|
|
177
|
+
|
|
178
|
+
|
44
|
179
|
/***** Helpers *****/
|
45
|
180
|
static GLenum sdl_gl_texture_format(SDL_Surface *s) {
|
46
|
181
|
// get the number of channels in the SDL surface
|
...
|
...
|
@@ -180,12 +315,12 @@ static int lua_set_current_keyhandler(lua_State *L) |
180
|
315
|
static int lua_get_mod_state(lua_State *L)
|
181
|
316
|
{
|
182
|
317
|
const char *mod = luaL_checkstring(L, 1);
|
183
|
|
- SDLMod smod = SDL_GetModState();
|
|
318
|
+ SDL_Keymod smod = SDL_GetModState();
|
184
|
319
|
|
185
|
320
|
if (!strcmp(mod, "shift")) lua_pushboolean(L, smod & KMOD_SHIFT);
|
186
|
321
|
else if (!strcmp(mod, "ctrl")) lua_pushboolean(L, smod & KMOD_CTRL);
|
187
|
322
|
else if (!strcmp(mod, "alt")) lua_pushboolean(L, smod & KMOD_ALT);
|
188
|
|
- else if (!strcmp(mod, "meta")) lua_pushboolean(L, smod & KMOD_META);
|
|
323
|
+ else if (!strcmp(mod, "meta")) lua_pushboolean(L, smod & KMOD_GUI);
|
189
|
324
|
else if (!strcmp(mod, "caps")) lua_pushboolean(L, smod & KMOD_CAPS);
|
190
|
325
|
else lua_pushnil(L);
|
191
|
326
|
|
...
|
...
|
@@ -354,12 +489,6 @@ static const struct luaL_reg gamelib[] = |
354
|
489
|
******************************************************************/
|
355
|
490
|
static bool no_text_aa = FALSE;
|
356
|
491
|
|
357
|
|
-static int sdl_fullscreen(lua_State *L)
|
358
|
|
-{
|
359
|
|
- SDL_WM_ToggleFullScreen(screen);
|
360
|
|
- return 0;
|
361
|
|
-}
|
362
|
|
-
|
363
|
492
|
extern bool is_fullscreen;
|
364
|
493
|
static int sdl_screen_size(lua_State *L)
|
365
|
494
|
{
|
...
|
...
|
@@ -639,7 +768,7 @@ static int sdl_font_draw(lua_State *L) |
639
|
768
|
#else
|
640
|
769
|
rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000;
|
641
|
770
|
#endif
|
642
|
|
- SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, max_width, h, 32, rmask, gmask, bmask, amask);
|
|
771
|
+ SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE, max_width, h, 32, rmask, gmask, bmask, amask);
|
643
|
772
|
SDL_FillRect(s, NULL, SDL_MapRGBA(s->format, 0, 0, 0, 0));
|
644
|
773
|
|
645
|
774
|
int id_dduid = 1;
|
...
|
...
|
@@ -916,7 +1045,7 @@ static int sdl_new_tile(lua_State *L) |
916
|
1045
|
#endif
|
917
|
1046
|
|
918
|
1047
|
*s = SDL_CreateRGBSurface(
|
919
|
|
- SDL_SWSURFACE | SDL_SRCALPHA,
|
|
1048
|
+ SDL_SWSURFACE,
|
920
|
1049
|
w,
|
921
|
1050
|
h,
|
922
|
1051
|
32,
|
...
|
...
|
@@ -957,7 +1086,7 @@ static int sdl_new_surface(lua_State *L) |
957
|
1086
|
#endif
|
958
|
1087
|
|
959
|
1088
|
*s = SDL_CreateRGBSurface(
|
960
|
|
- SDL_SWSURFACE | SDL_SRCALPHA,
|
|
1089
|
+ SDL_SWSURFACE,
|
961
|
1090
|
w,
|
962
|
1091
|
h,
|
963
|
1092
|
32,
|
...
|
...
|
@@ -1011,7 +1140,7 @@ int init_blank_surface() |
1011
|
1140
|
amask = 0xff000000;
|
1012
|
1141
|
#endif
|
1013
|
1142
|
SDL_Surface *s = SDL_CreateRGBSurface(
|
1014
|
|
- SDL_SWSURFACE | SDL_SRCALPHA,
|
|
1143
|
+ SDL_SWSURFACE,
|
1015
|
1144
|
4,
|
1016
|
1145
|
4,
|
1017
|
1146
|
32,
|
...
|
...
|
@@ -1417,7 +1546,7 @@ static int sdl_surface_alpha(lua_State *L) |
1417
|
1546
|
if (lua_isnumber(L, 2))
|
1418
|
1547
|
{
|
1419
|
1548
|
int a = luaL_checknumber(L, 2);
|
1420
|
|
- SDL_SetAlpha(*s, SDL_SRCALPHA | SDL_RLEACCEL, (a < 0) ? 0 : (a > 255) ? 255 : a);
|
|
1549
|
+ SDL_SetAlpha(*s, /*SDL_SRCALPHA | */SDL_RLEACCEL, (a < 0) ? 0 : (a > 255) ? 255 : a);
|
1421
|
1550
|
}
|
1422
|
1551
|
else
|
1423
|
1552
|
{
|
...
|
...
|
@@ -2219,7 +2348,7 @@ static int get_text_aa(lua_State *L) |
2219
|
2348
|
static int sdl_get_modes_list(lua_State *L)
|
2220
|
2349
|
{
|
2221
|
2350
|
SDL_PixelFormat format;
|
2222
|
|
- SDL_Rect **modes;
|
|
2351
|
+ SDL_Rect **modes = NULL;
|
2223
|
2352
|
int loops = 0;
|
2224
|
2353
|
int bpp = 0;
|
2225
|
2354
|
int nb = 1;
|
...
|
...
|
@@ -2244,7 +2373,7 @@ static int sdl_get_modes_list(lua_State *L) |
2244
|
2373
|
}
|
2245
|
2374
|
|
2246
|
2375
|
//get available fullscreen/hardware modes
|
2247
|
|
- modes = SDL_ListModes(&format, SDL_FULLSCREEN);
|
|
2376
|
+ modes = SDL_ListModes(&format, 0);
|
2248
|
2377
|
if (modes)
|
2249
|
2378
|
{
|
2250
|
2379
|
int i;
|
...
|
...
|
@@ -2388,7 +2517,6 @@ static const struct luaL_reg displaylib[] = |
2388
|
2517
|
{"setTextBlended", set_text_aa},
|
2389
|
2518
|
{"getTextBlended", get_text_aa},
|
2390
|
2519
|
{"forceRedraw", sdl_redraw_screen},
|
2391
|
|
- {"fullscreen", sdl_fullscreen},
|
2392
|
2520
|
{"size", sdl_screen_size},
|
2393
|
2521
|
{"newFont", sdl_new_font},
|
2394
|
2522
|
{"newSurface", sdl_new_surface},
|
...
|
...
|
|