author  Sam Lantinga <slouken@libsdl.org> 
Wed, 07 Jun 2006 16:10:28 +0000  
branch  SDL1.3 
changeset 1670  eef792d31de8 
parent 1669  9857d21967bb 
child 1675  d33dcfc3fde7 
permissions  rwrr 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

1 
/* 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

2 
SDL  Simple DirectMedia Layer 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

3 
Copyright (C) 19972006 Sam Lantinga 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

4 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

5 
This library is free software; you can redistribute it and/or 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

6 
modify it under the terms of the GNU Lesser General Public 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

7 
License as published by the Free Software Foundation; either 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

8 
version 2.1 of the License, or (at your option) any later version. 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

9 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

10 
This library is distributed in the hope that it will be useful, 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

11 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

12 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

13 
Lesser General Public License for more details. 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

14 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

15 
You should have received a copy of the GNU Lesser General Public 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

16 
License along with this library; if not, write to the Free Software 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

17 
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 021101301 USA 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

18 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

19 
Sam Lantinga 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

20 
slouken@libsdl.org 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

21 
*/ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

22 
#include "SDL_config.h" 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

23 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

24 
/* This file contains functions for backwards compatibility with SDL 1.2 */ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

25 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

26 
#include "SDL.h" 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

27 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

28 
#include "video/SDL_sysvideo.h" 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

29 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

30 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

31 
static SDL_WindowID window; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

32 
static char *wm_title; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

33 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

34 
char * 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

35 
SDL_AudioDriverName(char *namebuf, int maxlen) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

36 
{ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

37 
const char *name = SDL_GetCurrentAudioDriver(); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

38 
if (name) { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

39 
SDL_strlcpy(namebuf, name, maxlen); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

40 
return namebuf; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

41 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

42 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

43 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

44 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

45 
char * 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

46 
SDL_VideoDriverName(char *namebuf, int maxlen) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

47 
{ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

48 
const char *name = SDL_GetCurrentVideoDriver(); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

49 
if (name) { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

50 
SDL_strlcpy(namebuf, name, maxlen); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

51 
return namebuf; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

52 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

53 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

54 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

55 

1670  56 
const SDL_VideoInfo * 
57 
SDL_GetVideoInfo(void) 

58 
{ 

59 
static SDL_VideoInfo info; 

60 

61 
/* Memory leak, compatibility code, who cares? */ 

62 
if (!info.vfmt && SDL_GetDesktopDisplayMode()) { 

63 
int bpp; 

64 
Uint32 Rmask, Gmask, Bmask, Amask; 

65 

66 
SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()>format, &bpp, 

67 
&Rmask, &Gmask, &Bmask, &Amask); 

68 
info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); 

69 
} 

70 
return &info; 

71 
} 

72 

1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

73 
int 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

74 
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

75 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

76 
int i, actual_bpp = 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

77 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

78 
if (!SDL_GetVideoDevice()) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

79 
return 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

80 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

81 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

82 
if (!(flags & SDL_FULLSCREEN)) { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

83 
return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()>format); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

84 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

85 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

86 
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { 
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

87 
const SDL_DisplayMode *mode = SDL_GetDisplayMode(i); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

88 
if (!mode>w  !mode>h  (width == mode>w && height == mode>h)) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

89 
if (!mode>format) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

90 
return bpp; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

91 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

92 
if (SDL_BITSPERPIXEL(mode>format) >= bpp) { 
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

93 
actual_bpp = SDL_BITSPERPIXEL(mode>format); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

94 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

95 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

96 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

97 
return actual_bpp; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

98 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

99 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

100 
SDL_Rect ** 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

101 
SDL_ListModes(SDL_PixelFormat * format, Uint32 flags) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

102 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

103 
int i, nmodes; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

104 
SDL_Rect **modes; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

105 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

106 
if (!SDL_GetVideoDevice()) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

107 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

108 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

109 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

110 
if (!(flags & SDL_FULLSCREEN)) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

111 
return (SDL_Rect **) (1); 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

112 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

113 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

114 
/* Memory leak, but this is a compatibility function, who cares? */ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

115 
nmodes = 0; 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

116 
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { 
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

117 
const SDL_DisplayMode *mode = SDL_GetDisplayMode(i); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

118 
if (!mode>w  !mode>h) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

119 
return (SDL_Rect **) (1); 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

120 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

121 
if (SDL_BITSPERPIXEL(mode>format) != format>BitsPerPixel) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

122 
continue; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

123 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

124 
if (nmodes > 0 && modes[nmodes  1]>w == mode>w 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

125 
&& modes[nmodes  1]>h == mode>h) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

126 
continue; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

127 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

128 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

129 
modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes)); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

130 
if (!modes) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

131 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

132 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

133 
modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect)); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

134 
if (!modes[nmodes]) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

135 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

136 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

137 
modes[nmodes]>x = 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

138 
modes[nmodes]>y = 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

139 
modes[nmodes]>w = mode>w; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

140 
modes[nmodes]>h = mode>h; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

141 
++nmodes; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

142 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

143 
if (modes) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

144 
modes[nmodes] = NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

145 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

146 
return modes; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

147 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

148 

1669
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

149 
static int (*orig_eventfilter) (const SDL_Event * event); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

150 

9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

151 
static int 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

152 
SDL_CompatEventFilter(const SDL_Event * event) 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

153 
{ 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

154 
SDL_Event fake; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

155 

9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

156 
switch (event>type) { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

157 
case SDL_WINDOWEVENT: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

158 
switch (event>window.event) { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

159 
case SDL_WINDOWEVENT_RESIZED: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

160 
fake.type = SDL_VIDEORESIZE; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

161 
fake.resize.w = event>window.data1; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

162 
fake.resize.h = event>window.data2; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

163 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

164 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

165 
case SDL_WINDOWEVENT_MINIMIZED: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

166 
fake.type = SDL_ACTIVEEVENT; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

167 
fake.active.gain = 0; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

168 
fake.active.state = SDL_APPACTIVE; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

169 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

170 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

171 
case SDL_WINDOWEVENT_RESTORED: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

172 
fake.type = SDL_ACTIVEEVENT; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

173 
fake.active.gain = 1; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

174 
fake.active.state = SDL_APPACTIVE; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

175 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

176 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

177 
case SDL_WINDOWEVENT_ENTER: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

178 
fake.type = SDL_ACTIVEEVENT; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

179 
fake.active.gain = 1; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

180 
fake.active.state = SDL_APPMOUSEFOCUS; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

181 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

182 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

183 
case SDL_WINDOWEVENT_LEAVE: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

184 
fake.type = SDL_ACTIVEEVENT; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

185 
fake.active.gain = 0; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

186 
fake.active.state = SDL_APPMOUSEFOCUS; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

187 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

188 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

189 
case SDL_WINDOWEVENT_FOCUS_GAINED: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

190 
fake.type = SDL_ACTIVEEVENT; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

191 
fake.active.gain = 1; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

192 
fake.active.state = SDL_APPINPUTFOCUS; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

193 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

194 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

195 
case SDL_WINDOWEVENT_FOCUS_LOST: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

196 
fake.type = SDL_ACTIVEEVENT; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

197 
fake.active.gain = 1; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

198 
fake.active.state = SDL_APPINPUTFOCUS; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

199 
SDL_PushEvent(&fake); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

200 
break; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

201 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

202 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

203 
return orig_eventfilter(event); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

204 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

205 

1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

206 
SDL_Surface * 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

207 
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

208 
{ 
1669
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

209 
int (*filter) (const SDL_Event * event); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

210 
const SDL_DisplayMode *desktop_mode; 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

211 
SDL_DisplayMode mode; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

212 
int i; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

213 
Uint32 window_flags; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

214 
Uint32 desktop_format; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

215 
Uint32 desired_format; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

216 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

217 
if (!SDL_GetVideoDevice()) { 
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

218 
if (SDL_Init(SDL_INIT_VIDEO  SDL_INIT_NOPARACHUTE) < 0) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

219 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

220 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

221 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

222 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

223 
/* Destroy existing window */ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

224 
SDL_DestroyWindow(window); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

225 

1669
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

226 
/* Set up the event filter */ 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

227 
filter = SDL_GetEventFilter(); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

228 
if (filter != SDL_CompatEventFilter) { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

229 
orig_eventfilter = filter; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

230 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

231 
SDL_SetEventFilter(SDL_CompatEventFilter); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

232 

1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

233 
/* Create a new window */ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

234 
window_flags = SDL_WINDOW_SHOWN; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

235 
if (flags & SDL_FULLSCREEN) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

236 
window_flags = SDL_WINDOW_FULLSCREEN; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

237 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

238 
if (flags & SDL_OPENGL) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

239 
window_flags = SDL_WINDOW_OPENGL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

240 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

241 
if (flags & SDL_RESIZABLE) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

242 
window_flags = SDL_WINDOW_RESIZABLE; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

243 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

244 
if (flags & SDL_NOFRAME) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

245 
window_flags = SDL_WINDOW_BORDERLESS; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

246 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

247 
window = SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

248 
if (!window) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

249 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

250 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

251 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

252 
/* Set up the desired display mode */ 
1669
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

253 
desktop_mode = SDL_GetDesktopDisplayMode(); 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

254 
desktop_format = desktop_mode>format; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

255 
if (desktop_format && ((flags & SDL_ANYFORMAT) 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

256 
 (bpp == SDL_BITSPERPIXEL(desktop_format)))) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

257 
desired_format = desktop_format; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

258 
} else { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

259 
switch (bpp) { 
1669
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

260 
case 0: 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

261 
if (desktop_format) { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

262 
desired_format = desktop_format; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

263 
} else { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

264 
desired_format = SDL_PixelFormat_RGB888; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

265 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

266 
break; 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

267 
case 8: 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

268 
desired_format = SDL_PixelFormat_Index8; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

269 
break; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

270 
case 15: 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

271 
desired_format = SDL_PixelFormat_RGB555; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

272 
break; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

273 
case 16: 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

274 
desired_format = SDL_PixelFormat_RGB565; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

275 
break; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

276 
case 24: 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

277 
desired_format = SDL_PixelFormat_RGB24; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

278 
break; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

279 
case 32: 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

280 
desired_format = SDL_PixelFormat_RGB888; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

281 
break; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

282 
default: 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

283 
SDL_SetError("Unsupported bpp in SDL_SetVideoMode()"); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

284 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

285 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

286 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

287 
mode.format = desired_format; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

288 
mode.w = width; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

289 
mode.h = height; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

290 
mode.refresh_rate = 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

291 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

292 
/* Set the desired display mode */ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

293 
if (flags & SDL_FULLSCREEN) { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

294 
if (!SDL_GetClosestDisplayMode(&mode, &mode)) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

295 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

296 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

297 
} else { 
1669
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

298 
if (desktop_format) { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

299 
mode.format = desktop_format; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

300 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

301 
if (desktop_mode>w && desktop_mode>h) { 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

302 
mode.w = desktop_mode>w; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

303 
mode.h = desktop_mode>h; 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

304 
} 
9857d21967bb
The test programs compile again.
Sam Lantinga <slouken@libsdl.org>
parents:
1668
diff
changeset

305 
mode.refresh_rate = desktop_mode>refresh_rate; 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

306 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

307 
if (SDL_SetDisplayMode(&mode) < 0) { 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

308 
return NULL; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

309 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

310 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

311 
/* Create the display surface */ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

312 
return SDL_CreateWindowSurface(window, desired_format, flags); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

313 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

314 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

315 
SDL_Surface * 
1670  316 
SDL_CreateWindowSurface(SDL_WindowID windowID, Uint32 format, Uint32 flags) 
317 
{ 

318 
SDL_Window *window = SDL_GetWindowFromID(windowID); 

319 
Uint32 black; 

320 
SDL_Surface *surface; 

321 

322 
if (!window) { 

323 
return NULL; 

324 
} 

325 

326 
if (!_this>CreateWindowSurface) { 

327 
return NULL; 

328 
} 

329 

330 
if (!window>surface) { 

331 
_this>CreateWindowSurface(_this, window, flags); 

332 
if (!window>surface) { 

333 
return NULL; 

334 
} 

335 
window>surface>flags = SDL_SCREEN_SURFACE; 

336 

337 
/* If we have a palettized surface, create a default palette */ 

338 
if (window>surface>format>palette) { 

339 
SDL_Color colors[256]; 

340 
SDL_PixelFormat *vf = window>surface>format; 

341 
SDL_DitherColors(colors, vf>BitsPerPixel); 

342 
SDL_SetColors(window>surface, colors, 0, vf>palette>ncolors); 

343 
} 

344 
} 

345 
surface = window>surface; 

346 

347 
if (window>shadow) { 

348 
SDL_FreeSurface(window>shadow); 

349 
window>shadow = NULL; 

350 
} 

351 

352 
/* Create a shadow surface if necessary */ 

353 
if ((!(flags & SDL_ANYFORMAT) 

354 
&& (format != SDL_GetCurrentDisplayMode()>format)) 

355 
 ((flags & SDL_HWPALETTE) 

356 
&& !(window>surface>flags & SDL_HWPALETTE))) { 

357 
int bpp; 

358 
Uint32 Rmask, Gmask, Bmask, Amask; 

359 

360 
SDL_PixelFormatEnumToMasks(format, &bpp, &Amask, &Gmask, &Bmask, 

361 
&Amask); 

362 
window>shadow = 

363 
SDL_CreateRGBSurface(SDL_SWSURFACE, surface>w, surface>h, bpp, 

364 
Rmask, Gmask, Bmask, Amask); 

365 
if (window>shadow == NULL) { 

366 
return NULL; 

367 
} 

368 
window>shadow>flags = SDL_SHADOW_SURFACE; 

369 

370 
surface = window>shadow; 

371 

372 
/* 8bit shadow surfaces report that they have exclusive palette */ 

373 
if (surface>format>palette) { 

374 
surface>flags = SDL_HWPALETTE; 

375 
if (format == SDL_GetCurrentDisplayMode()>format) { 

376 
SDL_memcpy(surface>format>palette>colors, 

377 
window>surface>format>palette>colors, 

378 
window>surface>format>palette>ncolors * 

379 
sizeof(SDL_Color)); 

380 
} else { 

381 
SDL_DitherColors(surface>format>palette>colors, bpp); 

382 
} 

383 
} 

384 
} 

385 

386 
/* Clear the surface for display */ 

387 
{ 

388 
Uint32 black = SDL_MapRGB(surface>format, 0, 0, 0); 

389 
SDL_FillRect(surface, NULL, black); 

390 
if (surface>flags & SDL_DOUBLEBUF) { 

391 
SDL_Flip(surface); 

392 
SDL_FillRect(surface, NULL, black); 

393 
} 

394 
SDL_Flip(surface); 

395 
} 

396 

397 
return surface; 

398 
} 

399 

400 
SDL_Surface * 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

401 
SDL_GetVideoSurface(void) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

402 
{ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

403 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

404 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

405 
return SDL_VideoSurface; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

406 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

407 

1670  408 
SDL_Surface * 
409 
SDL_DisplayFormat(SDL_Surface * surface) 

410 
{ 

411 
Uint32 flags; 

412 

413 
if (!SDL_PublicSurface) { 

414 
SDL_SetError("No video mode has been set"); 

415 
return (NULL); 

416 
} 

417 
/* Set the flags appropriate for copying to display surface */ 

418 
if (((SDL_PublicSurface>flags & SDL_HWSURFACE) == SDL_HWSURFACE) 

419 
&& _this>info.blit_hw) 

420 
flags = SDL_HWSURFACE; 

421 
else 

422 
flags = SDL_SWSURFACE; 

423 
#ifdef AUTORLE_DISPLAYFORMAT 

424 
flags = (surface>flags & (SDL_SRCCOLORKEY  SDL_SRCALPHA)); 

425 
flags = SDL_RLEACCELOK; 

426 
#else 

427 
flags = 

428 
surface>flags & (SDL_SRCCOLORKEY  SDL_SRCALPHA  SDL_RLEACCELOK); 

429 
#endif 

430 
return (SDL_ConvertSurface(surface, SDL_PublicSurface>format, flags)); 

431 
} 

432 

433 
SDL_Surface * 

434 
SDL_DisplayFormatAlpha(SDL_Surface * surface) 

435 
{ 

436 
SDL_PixelFormat *vf; 

437 
SDL_PixelFormat *format; 

438 
SDL_Surface *converted; 

439 
Uint32 flags; 

440 
/* default to ARGB8888 */ 

441 
Uint32 amask = 0xff000000; 

442 
Uint32 rmask = 0x00ff0000; 

443 
Uint32 gmask = 0x0000ff00; 

444 
Uint32 bmask = 0x000000ff; 

445 

446 
if (!SDL_PublicSurface) { 

447 
SDL_SetError("No video mode has been set"); 

448 
return (NULL); 

449 
} 

450 
vf = SDL_PublicSurface>format; 

451 

452 
switch (vf>BytesPerPixel) { 

453 
case 2: 

454 
/* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. 

455 
For anything else (like ARGB4444) it doesn't matter 

456 
since we have no special code for it anyway */ 

457 
if ((vf>Rmask == 0x1f) && 

458 
(vf>Bmask == 0xf800  vf>Bmask == 0x7c00)) { 

459 
rmask = 0xff; 

460 
bmask = 0xff0000; 

461 
} 

462 
break; 

463 

464 
case 3: 

465 
case 4: 

466 
/* Keep the video format, as long as the high 8 bits are 

467 
unused or alpha */ 

468 
if ((vf>Rmask == 0xff) && (vf>Bmask == 0xff0000)) { 

469 
rmask = 0xff; 

470 
bmask = 0xff0000; 

471 
} 

472 
break; 

473 

474 
default: 

475 
/* We have no other optimised formats right now. When/if a new 

476 
optimised alpha format is written, add the converter here */ 

477 
break; 

478 
} 

479 
format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); 

480 
flags = SDL_PublicSurface>flags & SDL_HWSURFACE; 

481 
flags = surface>flags & (SDL_SRCALPHA  SDL_RLEACCELOK); 

482 
converted = SDL_ConvertSurface(surface, format, flags); 

483 
SDL_FreeFormat(format); 

484 
return (converted); 

485 
} 

486 

487 
void 

488 
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) 

489 
{ 

490 
if (screen) { 

491 
SDL_Rect rect; 

492 

493 
/* Perform some checking */ 

494 
if (w == 0) 

495 
w = screen>w; 

496 
if (h == 0) 

497 
h = screen>h; 

498 
if ((int) (x + w) > screen>w) 

499 
return; 

500 
if ((int) (y + h) > screen>h) 

501 
return; 

502 

503 
/* Fill the rectangle */ 

504 
rect.x = (Sint16) x; 

505 
rect.y = (Sint16) y; 

506 
rect.w = (Uint16) w; 

507 
rect.h = (Uint16) h; 

508 
SDL_UpdateRects(screen, 1, &rect); 

509 
} 

510 
} 

511 
void 

512 
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects) 

513 
{ 

514 
int i; 

515 
SDL_Window *window; 

516 

517 
/* Find the window corresponding to this surface */ 

518 
window = SDL_GetWindowFromSurface(screen); 

519 
if (!window) { 

520 
SDL_SetError("Couldn't find window associated with surface"); 

521 
return; 

522 
} 

523 

524 
if (screen>flags & SDL_SHADOW_SURFACE) { 

525 
if (SHOULD_DRAWCURSOR(SDL_cursorstate)) { 

526 
SDL_LockCursor(); 

527 
SDL_DrawCursor(screen); 

528 
for (i = 0; i < numrects; ++i) { 

529 
SDL_LowerBlit(screen, &rects[i], window>surface, &rects[i]); 

530 
} 

531 
SDL_EraseCursor(screen); 

532 
SDL_UnlockCursor(); 

533 
} else { 

534 
for (i = 0; i < numrects; ++i) { 

535 
SDL_LowerBlit(screen, &rects[i], window>surface, &rects[i]); 

536 
} 

537 
} 

538 

539 
/* Fall through to video surface update */ 

540 
screen = window>surface; 

541 
} 

542 
if ((screen>flags & SDL_SCREEN_SURFACE) && _this>UpdateWindowSurface) { 

543 
/* Update the video surface */ 

544 
if (screen>offset) { 

545 
int offset_y = screen>offset / screen>pitch; 

546 
int offset_x = screen>offset % screen>pitch; 

547 
for (i = 0; i < numrects; ++i) { 

548 
rects[i].x += offset_x; 

549 
rects[i].y += offset_y; 

550 
} 

551 
_this>UpdateWindowSurface(_this, window, numrects, rects); 

552 
for (i = 0; i < numrects; ++i) { 

553 
rects[i].x = offset_x; 

554 
rects[i].y = offset_y; 

555 
} 

556 
} else { 

557 
_this>UpdateWindowSurface(_this, window, numrects, rects); 

558 
} 

559 
} 

560 
} 

561 

562 
int 

563 
SDL_Flip(SDL_Surface * screen) 

564 
{ 

565 
SDL_Window *window; 

566 

567 
/* Find the window corresponding to this surface */ 

568 
window = SDL_GetWindowFromSurface(screen); 

569 
if (!window) { 

570 
SDL_SetError("Couldn't find window associated with surface"); 

571 
return; 

572 
} 

573 

574 
/* Copy the shadow surface to the video surface */ 

575 
if (screen>flags & SDL_SHADOW_SURFACE) { 

576 
SDL_Rect rect; 

577 

578 
rect.x = 0; 

579 
rect.y = 0; 

580 
rect.w = screen>w; 

581 
rect.h = screen>h; 

582 
if (SHOULD_DRAWCURSOR(SDL_cursorstate)) { 

583 
SDL_LockCursor(); 

584 
SDL_DrawCursor(screen); 

585 
SDL_LowerBlit(screen, &rect, window>surface, &rect); 

586 
SDL_EraseCursor(screen); 

587 
SDL_UnlockCursor(); 

588 
} else { 

589 
SDL_LowerBlit(screen, &rect, window>surface, &rect); 

590 
} 

591 

592 
/* Fall through to video surface update */ 

593 
screen = window>surface; 

594 
} 

595 
if (screen>flags & SDL_DOUBLEBUF) { 

596 
_this>FlipWindowSurface(_this, window); 

597 
} else { 

598 
SDL_UpdateRect(screen, 0, 0, 0, 0); 

599 
} 

600 
return (0); 

601 
} 

602 

1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

603 
void 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

604 
SDL_WM_SetCaption(const char *title, const char *icon) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

605 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

606 
if (wm_title) { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

607 
SDL_free(wm_title); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

608 
} else { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

609 
wm_title = SDL_strdup(title); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

610 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

611 
SDL_SetWindowTitle(window, wm_title); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

612 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

613 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

614 
void 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

615 
SDL_WM_GetCaption(char **title, char **icon) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

616 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

617 
if (title) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

618 
*title = wm_title; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

619 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

620 
if (icon) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

621 
*icon = ""; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

622 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

623 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

624 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

625 
void 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

626 
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

627 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

628 
/* FIXME */ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

629 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

630 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

631 
int 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

632 
SDL_WM_IconifyWindow(void) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

633 
{ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

634 
SDL_MinimizeWindow(window); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

635 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

636 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

637 
int 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

638 
SDL_WM_ToggleFullScreen(SDL_Surface * surface) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

639 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

640 
return 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

641 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

642 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

643 
SDL_GrabMode 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

644 
SDL_WM_GrabInput(SDL_GrabMode mode) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

645 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

646 
if (mode != SDL_GRAB_QUERY) { 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

647 
SDL_SetWindowGrab(window, mode); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

648 
} 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

649 
return (SDL_GrabMode) SDL_GetWindowGrab(window); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

650 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

651 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

652 
Uint8 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

653 
SDL_GetAppState(void) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

654 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

655 
Uint8 state = 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

656 
Uint32 flags = 0; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

657 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

658 
flags = SDL_GetWindowFlags(window); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

659 
if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

660 
state = SDL_APPACTIVE; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

661 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

662 
if (flags & SDL_WINDOW_KEYBOARD_FOCUS) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

663 
state = SDL_APPINPUTFOCUS; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

664 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

665 
if (flags & SDL_WINDOW_MOUSE_FOCUS) { 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

666 
state = SDL_APPMOUSEFOCUS; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

667 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

668 
return state; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

669 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

670 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

671 
const SDL_version * 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

672 
SDL_Linked_Version(void) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

673 
{ 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

674 
static SDL_version version; 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

675 
SDL_VERSION(&version); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

676 
return &version; 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

677 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

678 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

679 
int 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

680 
SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors, 
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

681 
int firstcolor, int ncolors) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

682 
{ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

683 
SDL_SetColors(surface, colors, firstcolor, ncolors); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

684 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

685 

1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

686 
int 
1670  687 
SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor, 
688 
int ncolors) 

689 
{ 

690 
SDL_Window *window = NULL; 

691 
SDL_Palette *pal; 

692 
int gotall; 

693 
int palsize; 

694 

695 
/* Verify the parameters */ 

696 
pal = screen>format>palette; 

697 
if (!pal) { 

698 
return 0; /* not a palettized surface */ 

699 
} 

700 
gotall = 1; 

701 
palsize = 1 << screen>format>BitsPerPixel; 

702 
if (ncolors > (palsize  firstcolor)) { 

703 
ncolors = (palsize  firstcolor); 

704 
gotall = 0; 

705 
} 

706 

707 
if (screen>flags & (SDL_SHADOW_SURFACE  SDL_SCREEN_SURFACE)) { 

708 
window = SDL_GetWindowFromSurface(screen); 

709 
if (!window) { 

710 
return 0; 

711 
} 

712 
} 

713 

714 
if (screen>flags & SDL_SHADOW_SURFACE) { 

715 
SDL_Palette *vidpal; 

716 

717 
vidpal = window>surface>format>palette; 

718 
if (vidpal && vidpal>ncolors == pal>ncolors) { 

719 
/* This is a shadow surface, and the physical 

720 
* framebuffer is also indexed. Propagate the 

721 
* changes to its logical palette so that 

722 
* updates are always identity blits 

723 
*/ 

724 
SDL_memcpy(vidpal>colors + firstcolor, colors, 

725 
ncolors * sizeof(*colors)); 

726 
} 

727 
if (window>surface>flags & SDL_HWPALETTE) { 

728 
/* Set the physical palette */ 

729 
screen = window>surface; 

730 
} else { 

731 
SDL_UpdateRect(screen, 0, 0, 0, 0); 

732 
} 

733 
} 

734 

735 
if (screen>flags & SDL_SCREEN_SURFACE) { 

736 
if (_this>SetWindowColors) { 

737 
gotall = 

738 
_this>SetWindowColors(_this, window, firstcolor, ncolors, 

739 
colors); 

740 
if (!gotall) { 

741 
/* The video flags shouldn't have SDL_HWPALETTE, and 

742 
the video driver is responsible for copying back the 

743 
correct colors into the video surface palette. 

744 
*/ 

745 
; 

746 
} 

747 
} 

748 
SDL_CursorPaletteChanged(); 

749 
} 

750 

751 
return gotall; 

752 
} 

753 

754 
int 

1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

755 
SDL_GetWMInfo(SDL_SysWMinfo * info) 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

756 
{ 
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1667
diff
changeset

757 
return SDL_GetWindowWMInfo(window, info); 
1667
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

758 
} 
1fddae038bc8
Implemented many compatibility functions
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset

759 

1670  760 
void 
761 
SDL_MoveCursor(int x, int y) 

762 
{ 

763 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 

764 

765 
/* Erase and update the current mouse position */ 

766 
if (SHOULD_DRAWCURSOR(SDL_cursorstate)) { 

767 
/* Erase and redraw mouse cursor in new position */ 

768 
SDL_LockCursor(); 

769 
SDL_EraseCursor(SDL_VideoSurface); 

770 
SDL_cursor>area.x = (x  SDL_cursor>hot_x); 

771 
SDL_cursor>area.y = (y  SDL_cursor>hot_y); 

772 
SDL_DrawCursor(SDL_VideoSurface); 

773 
SDL_UnlockCursor(); 

774 
} else if (_this>MoveWMCursor) { 

775 
_this>MoveWMCursor(_this, x, y); 

776 
} 

777 
} 

778 

779 
/* Keep track of the current cursor colors */ 

780 
static int palette_changed = 1; 

781 
static Uint8 pixels8[2]; 

782 

783 
void 

784 
SDL_CursorPaletteChanged(void) 

785 
{ 

786 
palette_changed = 1; 

787 
} 

788 

789 
void 

790 
SDL_MouseRect(SDL_Rect * area) 

791 
{ 

792 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 

793 
int clip_diff; 

794 

795 
*area = SDL_cursor>area; 

796 
if (area>x < 0) { 

797 
area>w += area>x; 

798 
area>x = 0; 

799 
} 

800 
if (area>y < 0) { 

801 
area>h += area>y; 

802 
area>y = 0; 

803 
} 

804 
clip_diff = (area>x + area>w)  SDL_VideoSurface>w; 

805 
if (clip_diff > 0) { 

806 
area>w = area>w < clip_diff ? 0 : area>w  clip_diff; 

807 
} 

808 
clip_diff = (area>y + area>h)  SDL_VideoSurface>h; 

809 
if (clip_diff > 0) { 

810 
area>h = area>h < clip_diff ? 0 : area>h  clip_diff; 

811 
} 

812 
} 

813 

814 
static void 

815 
SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area) 

816 
{ 

817 
const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 }; 

818 
int i, w, h; 

819 
Uint8 *data, datab; 

820 
Uint8 *mask, maskb; 

821 

822 
data = SDL_cursor>data + area>y * SDL_cursor>area.w / 8; 

823 
mask = SDL_cursor>mask + area>y * SDL_cursor>area.w / 8; 

824 
switch (screen>format>BytesPerPixel) { 

825 

826 
case 1: 

827 
{ 

828 
Uint8 *dst; 

829 
int dstskip; 

830 

831 
if (palette_changed) { 

832 
pixels8[0] = 

833 
(Uint8) SDL_MapRGB(screen>format, 255, 255, 255); 

834 
pixels8[1] = (Uint8) SDL_MapRGB(screen>format, 0, 0, 0); 

835 
palette_changed = 0; 

836 
} 

837 
dst = (Uint8 *) screen>pixels + 

838 
(SDL_cursor>area.y + area>y) * screen>pitch + 

839 
SDL_cursor>area.x; 

840 
dstskip = screen>pitch  area>w; 

841 

842 
for (h = area>h; h; h) { 

843 
for (w = area>w / 8; w; w) { 

844 
maskb = *mask++; 

845 
datab = *data++; 

846 
for (i = 0; i < 8; ++i) { 

847 
if (maskb & 0x80) { 

848 
*dst = pixels8[datab >> 7]; 

849 
} 

850 
maskb <<= 1; 

851 
datab <<= 1; 

852 
dst++; 

853 
} 

854 
} 

855 
dst += dstskip; 

856 
} 

857 
} 

858 
break; 

859 

860 
case 2: 

861 
{ 

862 
Uint16 *dst; 

863 
int dstskip; 

864 

865 
dst = (Uint16 *) screen>pixels + 

866 
(SDL_cursor>area.y + area>y) * screen>pitch / 2 + 

867 
SDL_cursor>area.x; 

868 
dstskip = (screen>pitch / 2)  area>w; 

869 

870 
for (h = area>h; h; h) { 

871 
for (w = area>w / 8; w; w) { 

872 
maskb = *mask++; 

873 
datab = *data++; 

874 
for (i = 0; i < 8; ++i) { 

875 
if (maskb & 0x80) { 

876 
*dst = (Uint16) pixels[datab >> 7]; 

877 
} 

878 
maskb <<= 1; 

879 
datab <<= 1; 

880 
dst++; 

881 
} 

882 
} 

883 
dst += dstskip; 

884 
} 

885 
} 

886 
break; 

887 

888 
case 3: 

889 
{ 

890 
Uint8 *dst; 

891 
int dstskip; 

892 

893 
dst = (Uint8 *) screen>pixels + 

894 
(SDL_cursor>area.y + area>y) * screen>pitch + 

895 
SDL_cursor>area.x * 3; 

896 
dstskip = screen>pitch  area>w * 3; 

897 

898 
for (h = area>h; h; h) { 

899 
for (w = area>w / 8; w; w) { 

900 
maskb = *mask++; 

901 
datab = *data++; 

902 
for (i = 0; i < 8; ++i) { 

903 
if (maskb & 0x80) { 

904 
SDL_memset(dst, pixels[datab >> 7], 3); 

905 
} 

906 
maskb <<= 1; 

907 
datab <<= 1; 

908 
dst += 3; 

909 
} 

910 
} 

911 
dst += dstskip; 

912 
} 

913 
} 

914 
break; 

915 

916 
case 4: 

917 
{ 

918 
Uint32 *dst; 

919 
int dstskip; 

920 

921 
dst = (Uint32 *) screen>pixels + 

922 
(SDL_cursor>area.y + area>y) * screen>pitch / 4 + 

923 
SDL_cursor>area.x; 

924 
dstskip = (screen>pitch / 4)  area>w; 

925 

926 
for (h = area>h; h; h) { 

927 
for (w = area>w / 8; w; w) { 

928 
maskb = *mask++; 

929 
datab = *data++; 

930 
for (i = 0; i < 8; ++i) { 

931 
if (maskb & 0x80) { 

932 
*dst = pixels[datab >> 7]; 

933 
} 

934 
maskb <<= 1; 

935 
datab <<= 1; 

936 
dst++; 

937 
} 

938 
} 

939 
dst += dstskip; 

940 
} 

941 
} 

942 
break; 

943 
} 

944 
} 

945 

946 
static void 

947 
SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area) 

948 
{ 

949 
const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 }; 

950 
int h; 

951 
int x, minx, maxx; 

952 
Uint8 *data, datab = 0; 

953 
Uint8 *mask, maskb = 0; 

954 
Uint8 *dst; 

955 
int dstbpp, dstskip; 

956 

957 
data = SDL_cursor>data + area>y * SDL_cursor>area.w / 8; 

958 
mask = SDL_cursor>mask + area>y * SDL_cursor>area.w / 8; 

959 
dstbpp = screen>format>BytesPerPixel; 

960 
dst = (Uint8 *) screen>pixels + 

961 
(SDL_cursor>area.y + area>y) * screen>pitch + 

962 
SDL_cursor>area.x * dstbpp; 

963 
dstskip = screen>pitch  SDL_cursor>area.w * dstbpp; 

964 

965 
minx = area>x; 

966 
maxx = area>x + area>w; 

967 
if (screen>format>BytesPerPixel == 1) { 

968 
if (palette_changed) { 

969 
pixels8[0] = (Uint8) SDL_MapRGB(screen>format, 255, 255, 255); 

970 
pixels8[1] = (Uint8) SDL_MapRGB(screen>format, 0, 0, 0); 

971 
palette_changed = 0; 

972 
} 

973 
for (h = area>h; h; h) { 

974 
for (x = 0; x < SDL_cursor>area.w; ++x) { 

975 
if ((x % 8) == 0) { 

976 
maskb = *mask++; 

977 
datab = *data++; 

978 
} 

979 
if ((x >= minx) && (x < maxx)) { 

980 
if (maskb & 0x80) { 

981 
SDL_memset(dst, pixels8[datab >> 7], dstbpp); 

982 
} 

983 
} 

984 
maskb <<= 1; 

985 
datab <<= 1; 

986 
dst += dstbpp; 

987 
} 

988 
dst += dstskip; 

989 
} 

990 
} else { 

991 
for (h = area>h; h; h) { 

992 
for (x = 0; x < SDL_cursor>area.w; ++x) { 

993 
if ((x % 8) == 0) { 

994 
maskb = *mask++; 

995 
datab = *data++; 

996 
} 

997 
if ((x >= minx) && (x < maxx)) { 

998 
if (maskb & 0x80) { 

999 
SDL_memset(dst, pixels[datab >> 7], dstbpp); 

1000 
} 

1001 
} 

1002 
maskb <<= 1; 

1003 
datab <<= 1; 

1004 
dst += dstbpp; 

1005 
} 

1006 
dst += dstskip; 

1007 
} 

1008 
} 

1009 
} 

1010 

1011 
/* This handles the ugly work of converting the saved cursor background from 

1012 
the pixel format of the shadow surface to that of the video surface. 

1013 
This is only necessary when blitting from a shadow surface of a different 

1014 
pixel format than the video surface, and using a software rendered cursor. 

1015 
*/ 

1016 
static void 

1017 
SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h) 

1018 
{ 

1019 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 

1020 
SDL_BlitInfo info; 

1021 
SDL_loblit RunBlit; 

1022 

1023 
/* Make sure we can steal the blit mapping */ 

1024 
if (screen>map>dst != SDL_VideoSurface) { 

1025 
return; 

1026 
} 

1027 

1028 
/* Set up the blit information */ 

1029 
info.s_pixels = SDL_cursor>save[1]; 

1030 
info.s_width = w; 

1031 
info.s_height = h; 

1032 
info.s_skip = 0; 

1033 
info.d_pixels = SDL_cursor>save[0]; 

1034 
info.d_width = w; 

1035 
info.d_height = h; 

1036 
info.d_skip = 0; 

1037 
info.aux_data = screen>map>sw_data>aux_data; 

1038 
info.src = screen>format; 

1039 
info.table = screen>map>table; 

1040 
info.dst = SDL_VideoSurface>format; 

1041 
RunBlit = screen>map>sw_data>blit; 

1042 

1043 
/* Run the actual software blit */ 

1044 
RunBlit(&info); 

1045 
} 

1046 

1047 
void 

1048 
SDL_DrawCursorNoLock(SDL_Surface * screen) 

1049 
{ 

1050 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 

1051 
SDL_Rect area; 

1052 

1053 
/* Get the mouse rectangle, clipped to the screen */ 

1054 
SDL_MouseRect(&area); 

1055 
if ((area.w == 0)  (area.h == 0)) { 

1056 
return; 

1057 
} 

1058 

1059 
/* Copy mouse background */ 

1060 
{ 

1061 
int w, h, screenbpp; 

1062 
Uint8 *src, *dst; 

1063 

1064 
/* Set up the copy pointers */ 

1065 
screenbpp = screen>format>BytesPerPixel; 

1066 
if ((screen == SDL_VideoSurface)  

1067 
FORMAT_EQUAL(screen>format, SDL_VideoSurface>format)) { 

1068 
dst = SDL_cursor>save[0]; 

1069 
} else { 

1070 
dst = SDL_cursor>save[1]; 

1071 
} 

1072 
src = (Uint8 *) screen>pixels + area.y * screen>pitch + 

1073 
area.x * screenbpp; 

1074 

1075 
/* Perform the copy */ 

1076 
w = area.w * screenbpp; 

1077 
h = area.h; 

1078 
while (h) { 

1079 
SDL_memcpy(dst, src, w); 

1080 
dst += w; 

1081 
src += screen>pitch; 

1082 
} 

1083 
} 

1084 

1085 
/* Draw the mouse cursor */ 

1086 
area.x = SDL_cursor>area.x; 

1087 
area.y = SDL_cursor>area.y; 

1088 
if ((area.x == 0) && (area.w == SDL_cursor>area.w)) { 

1089 
SDL_DrawCursorFast(screen, &area); 

1090 
} else { 

1091 
SDL_DrawCursorSlow(screen, &area); 

1092 
} 

1093 
} 

1094 

1095 
void 

1096 
SDL_DrawCursor(SDL_Surface * screen) 

1097 
{ 

1098 
/* Lock the screen if necessary */ 

1099 
if (screen == NULL) { 

1100 
return; 

1101 
} 

1102 
if (SDL_MUSTLOCK(screen)) { 

1103 
if (SDL_LockSurface(screen) < 0) { 

1104 
return; 

1105 
} 

1106 
} 

1107 

1108 
SDL_DrawCursorNoLock(screen); 

1109 

1110 
/* Unlock the screen and update if necessary */ 

1111 
if (SDL_MUSTLOCK(screen)) { 

1112 
SDL_UnlockSurface(screen); 

1113 
} 

1114 
if ((screen>flags & SDL_SCREEN_SURFACE) && 

1115 
!(screen>flags & SDL_HWSURFACE)) { 

1116 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 

1117 
SDL_Window *window; 

1118 
SDL_Rect area; 

1119 

1120 
window = SDL_GetWindowFromSurface(screen); 

1121 
if (!window) { 

1122 
return; 

1123 
} 

1124 

1125 
SDL_MouseRect(&area); 

1126 

1127 
if (_this>UpdateWindowSurface) { 

1128 
_this>UpdateWindowSurface(_this, window, 1, &area); 

1129 
} 

1130 
} 

1131 
} 

1132 

1133 
void 

1134 
SDL_EraseCursorNoLock(SDL_Surface * screen) 

1135 
{ 

1136 
SDL_VideoDevice *_this = SDL_GetVideoDevice(); 

1137 
SDL_Window *window; 

1138 
SDL_Rect area; 

1139 

1140 
/* Get the window associated with the surface */ 

1141 
window = SDL_GetWindowFromSurface(screen); 

1142 
if (!window  !window>surface) { 

1143 
return; 

1144 
} 

eef792d31de8
Work in progress. :)
Sam Lantinga & 