comparison src/video/cybergfx/SDL_cgxmodes.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents d910939febfa
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
30 #include "SDL_cgxwm_c.h" 30 #include "SDL_cgxwm_c.h"
31 #include "SDL_cgxmodes_c.h" 31 #include "SDL_cgxmodes_c.h"
32 32
33 #define CGX_DEBUG 33 #define CGX_DEBUG
34 34
35 static void set_best_resolution(_THIS, int width, int height) 35 static void
36 { 36 set_best_resolution (_THIS, int width, int height)
37 Uint32 idok; 37 {
38 int depth=8; 38 Uint32 idok;
39 39 int depth = 8;
40 if(SDL_Display) 40
41 depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH); 41 if (SDL_Display)
42 42 depth =
43 idok=BestCModeIDTags(CYBRBIDTG_NominalWidth,width, 43 GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
44 CYBRBIDTG_NominalHeight,height, 44
45 CYBRBIDTG_Depth,depth, 45 idok = BestCModeIDTags (CYBRBIDTG_NominalWidth, width,
46 TAG_DONE); 46 CYBRBIDTG_NominalHeight, height,
47 47 CYBRBIDTG_Depth, depth, TAG_DONE);
48 if(idok!=INVALID_ID) 48
49 { 49 if (idok != INVALID_ID) {
50 if(SDL_Display) 50 if (SDL_Display) {
51 { 51 if (currently_fullscreen)
52 if(currently_fullscreen) 52 CloseScreen (SDL_Display);
53 CloseScreen(SDL_Display); 53 else
54 else 54 UnlockPubScreen (NULL, SDL_Display);
55 UnlockPubScreen(NULL,SDL_Display); 55 }
56 } 56 SDL_Display = GFX_Display =
57 SDL_Display=GFX_Display=OpenScreenTags(NULL,SA_Width,width,SA_Height,height, 57 OpenScreenTags (NULL, SA_Width, width, SA_Height, height,
58 SA_Depth,depth,SA_DisplayID,idok, 58 SA_Depth, depth, SA_DisplayID, idok,
59 SA_ShowTitle,FALSE, 59 SA_ShowTitle, FALSE, TAG_DONE);
60 TAG_DONE); 60 }
61 } 61 }
62 } 62
63 63 static void
64 static void get_real_resolution(_THIS, int* w, int* h) 64 get_real_resolution (_THIS, int *w, int *h)
65 { 65 {
66 *w = /*SDL_Display->Width*/ SDL_Window->Width-SDL_Window->BorderLeft-SDL_Window->BorderRight; 66 *w = /*SDL_Display->Width */ SDL_Window->Width - SDL_Window->BorderLeft -
67 *h = /*SDL_Display->Height*/ SDL_Window->Height-SDL_Window->BorderBottom-SDL_Window->BorderTop; 67 SDL_Window->BorderRight;
68 } 68 *h = /*SDL_Display->Height */ SDL_Window->Height -
69 69 SDL_Window->BorderBottom - SDL_Window->BorderTop;
70 static void move_cursor_to(_THIS, int x, int y) 70 }
71
72 static void
73 move_cursor_to (_THIS, int x, int y)
71 { 74 {
72 /* XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); */ 75 /* XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); */
73 76
74 /* DA FARE! */ 77 /* DA FARE! */
75 } 78 }
76 79
77 static void add_visual(_THIS, int depth, int class) 80 static void
78 { 81 add_visual (_THIS, int depth, int class)
79 Uint32 tID; 82 {
80 83 Uint32 tID;
81 tID=BestCModeIDTags(CYBRBIDTG_Depth,depth, 84
82 CYBRBIDTG_NominalWidth,640, 85 tID = BestCModeIDTags (CYBRBIDTG_Depth, depth,
83 CYBRBIDTG_NominalHeight,480, 86 CYBRBIDTG_NominalWidth, 640,
84 TAG_DONE); 87 CYBRBIDTG_NominalHeight, 480, TAG_DONE);
85 88
86 if(tID!=INVALID_ID) 89 if (tID != INVALID_ID) {
87 { 90 int n = this->hidden->nvisuals;
88 int n = this->hidden->nvisuals; 91
89 92 this->hidden->visuals[n].depth = depth;
90 this->hidden->visuals[n].depth = depth; 93 this->hidden->visuals[n].visual = tID;
91 this->hidden->visuals[n].visual = tID; 94 this->hidden->visuals[n].bpp = GetCyberIDAttr (CYBRIDATTR_BPPIX, tID);
92 this->hidden->visuals[n].bpp = GetCyberIDAttr(CYBRIDATTR_BPPIX,tID); 95 this->hidden->nvisuals++;
93 this->hidden->nvisuals++; 96 }
94 }
95 } 97 }
96 98
97 #define TrueColor 1 99 #define TrueColor 1
98 #define PseudoColor 2 100 #define PseudoColor 2
99 101
100 int CGX_GetVideoModes(_THIS) 102 int
103 CGX_GetVideoModes (_THIS)
101 { 104 {
102 int i; 105 int i;
103 ULONG nextid; 106 ULONG nextid;
104 int nmodes=0; 107 int nmodes = 0;
105 108
106 SDL_modelist=NULL; 109 SDL_modelist = NULL;
107 110
108 nextid=NextDisplayInfo(INVALID_ID); 111 nextid = NextDisplayInfo (INVALID_ID);
109 112
110 while(nextid!=INVALID_ID) 113 while (nextid != INVALID_ID) {
111 { 114 if (IsCyberModeID (nextid)) {
112 if(IsCyberModeID(nextid)) 115 DisplayInfoHandle h;
113 { 116
114 DisplayInfoHandle h; 117 if (h = FindDisplayInfo (nextid)) {
115 118 struct DimensionInfo info;
116 if(h=FindDisplayInfo(nextid)) 119
117 { 120 if (GetDisplayInfoData
118 struct DimensionInfo info; 121 (h, (char *) &info, sizeof (struct DimensionInfo),
119 122 DTAG_DIMS, NULL)) {
120 if(GetDisplayInfoData(h,(char *)&info,sizeof(struct DimensionInfo),DTAG_DIMS,NULL)) 123 int ok = 0;
121 { 124
122 int ok=0; 125 for (i = 0; i < nmodes; i++) {
123 126 if (SDL_modelist[i]->w == (info.Nominal.MaxX + 1)
124 for(i=0;i<nmodes;i++) 127 && SDL_modelist[i]->h == (info.Nominal.MaxY + 1))
125 { 128 ok = 1;
126 if( SDL_modelist[i]->w == (info.Nominal.MaxX+1) && 129 }
127 SDL_modelist[i]->h == (info.Nominal.MaxY+1) ) 130
128 ok=1; 131 if (!ok) {
129 } 132 nmodes++;
130 133
131 if(!ok) 134 SDL_modelist =
132 { 135 (SDL_Rect **) SDL_realloc (SDL_modelist,
133 nmodes++; 136 (nmodes +
134 137 1) *
135 SDL_modelist = (SDL_Rect **)SDL_realloc(SDL_modelist,(nmodes+1)*sizeof(SDL_Rect *)); 138 sizeof (SDL_Rect *));
136 SDL_modelist[nmodes]=NULL; 139 SDL_modelist[nmodes] = NULL;
137 140
138 if ( SDL_modelist ) 141 if (SDL_modelist) {
139 { 142 SDL_modelist[nmodes - 1] = (SDL_Rect *)
140 SDL_modelist[nmodes-1] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); 143 SDL_malloc (sizeof (SDL_Rect));
141 144
142 if ( SDL_modelist[nmodes-1] == NULL ) 145 if (SDL_modelist[nmodes - 1] == NULL)
143 break; 146 break;
144 147
145 SDL_modelist[nmodes-1]->x = 0; 148 SDL_modelist[nmodes - 1]->x = 0;
146 SDL_modelist[nmodes-1]->y = 0; 149 SDL_modelist[nmodes - 1]->y = 0;
147 SDL_modelist[nmodes-1]->w = info.Nominal.MaxX+1; 150 SDL_modelist[nmodes - 1]->w =
148 SDL_modelist[nmodes-1]->h = info.Nominal.MaxY+1; 151 info.Nominal.MaxX + 1;
149 } 152 SDL_modelist[nmodes - 1]->h =
150 } 153 info.Nominal.MaxY + 1;
151 } 154 }
152 } 155 }
153 } 156 }
154 nextid=NextDisplayInfo(nextid); 157 }
155 } 158 }
156 159 nextid = NextDisplayInfo (nextid);
157 160 }
158 this->hidden->nvisuals = 0; 161
159 /* Search for the visuals in deepest-first order, so that the first 162
160 will be the richest one */ 163 this->hidden->nvisuals = 0;
161 add_visual(this, 32, TrueColor); 164 /* Search for the visuals in deepest-first order, so that the first
162 add_visual(this, 24, TrueColor); 165 will be the richest one */
163 add_visual(this, 16, TrueColor); 166 add_visual (this, 32, TrueColor);
164 add_visual(this, 15, TrueColor); 167 add_visual (this, 24, TrueColor);
165 add_visual(this, 8, PseudoColor); 168 add_visual (this, 16, TrueColor);
166 169 add_visual (this, 15, TrueColor);
167 if(this->hidden->nvisuals == 0) { 170 add_visual (this, 8, PseudoColor);
168 SDL_SetError("Found no sufficiently capable CGX visuals"); 171
169 return -1; 172 if (this->hidden->nvisuals == 0) {
170 } 173 SDL_SetError ("Found no sufficiently capable CGX visuals");
171 174 return -1;
172 if ( SDL_modelist == NULL ) { 175 }
173 SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *)); 176
177 if (SDL_modelist == NULL) {
178 SDL_modelist =
179 (SDL_Rect **) SDL_malloc ((1 + 1) * sizeof (SDL_Rect *));
174 i = 0; 180 i = 0;
175 if ( SDL_modelist ) { 181 if (SDL_modelist) {
176 SDL_modelist[i] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); 182 SDL_modelist[i] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
177 if ( SDL_modelist[i] ) { 183 if (SDL_modelist[i]) {
178 SDL_modelist[i]->x = 0; 184 SDL_modelist[i]->x = 0;
179 SDL_modelist[i]->y = 0; 185 SDL_modelist[i]->y = 0;
180 SDL_modelist[i]->w = SDL_Display->Width; 186 SDL_modelist[i]->w = SDL_Display->Width;
181 SDL_modelist[i]->h = SDL_Display->Height; 187 SDL_modelist[i]->h = SDL_Display->Height;
182 ++i; 188 ++i;
183 } 189 }
184 SDL_modelist[i] = NULL; 190 SDL_modelist[i] = NULL;
185 } 191 }
186 } 192 }
187 193
188 D( if ( SDL_modelist ) { 194 D (if (SDL_modelist) {
189 bug("CGX video mode list: (%ld)\n",nmodes); 195 bug ("CGX video mode list: (%ld)\n", nmodes);
190 for ( i=0; SDL_modelist[i]; ++i ) { 196 for (i = 0; SDL_modelist[i]; ++i) {
191 bug( "\t%ld x %ld\n", 197 bug ("\t%ld x %ld\n", SDL_modelist[i]->w, SDL_modelist[i]->h);}
192 SDL_modelist[i]->w, SDL_modelist[i]->h); 198 }
193 }
194 }
195 ); 199 );
196 200
197 D( { bug("CGX visuals list: (%ld)\n",this->hidden->nvisuals); 201 D ( {
198 202 bug ("CGX visuals list: (%ld)\n", this->hidden->nvisuals);
199 for(i=0;i<this->hidden->nvisuals;i++) 203 for (i = 0; i < this->hidden->nvisuals; i++)
200 bug("\t%lx - depth: %ld bpp: %ld\n",this->hidden->visuals[i].visual,this->hidden->visuals[i].depth,this->hidden->visuals[i].bpp); 204 bug ("\t%lx - depth: %ld bpp: %ld\n",
201 } 205 this->hidden->visuals[i].visual,
206 this->hidden->visuals[i].depth, this->hidden->visuals[i].bpp);}
202 ); 207 );
203 return 0; 208 return 0;
204 } 209 }
205 210
206 int CGX_SupportedVisual(_THIS, SDL_PixelFormat *format) 211 int
212 CGX_SupportedVisual (_THIS, SDL_PixelFormat * format)
207 { 213 {
208 int i; 214 int i;
209 for(i = 0; i < this->hidden->nvisuals; i++) 215 for (i = 0; i < this->hidden->nvisuals; i++) {
210 { 216 if (this->hidden->visuals[i].depth == format->BitsPerPixel) // Era bpp
211 if(this->hidden->visuals[i].depth == format->BitsPerPixel) // Era bpp 217 return 1;
212 return 1; 218 }
213 }
214 return 0; 219 return 0;
215 } 220 }
216 221
217 SDL_Rect **CGX_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 222 SDL_Rect **
218 { 223 CGX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
219 if ( CGX_SupportedVisual(this, format) ) { 224 {
220 if ( flags & SDL_FULLSCREEN ) { 225 if (CGX_SupportedVisual (this, format)) {
221 return(SDL_modelist); 226 if (flags & SDL_FULLSCREEN) {
227 return (SDL_modelist);
222 } else { 228 } else {
223 return((SDL_Rect **)-1); 229 return ((SDL_Rect **) - 1);
224 } 230 }
225 } else { 231 } else {
226 return((SDL_Rect **)0); 232 return ((SDL_Rect **) 0);
227 } 233 }
228 } 234 }
229 235
230 void CGX_FreeVideoModes(_THIS) 236 void
237 CGX_FreeVideoModes (_THIS)
231 { 238 {
232 int i; 239 int i;
233 240
234 if ( SDL_modelist ) { 241 if (SDL_modelist) {
235 for ( i=0; SDL_modelist[i]; ++i ) { 242 for (i = 0; SDL_modelist[i]; ++i) {
236 SDL_free(SDL_modelist[i]); 243 SDL_free (SDL_modelist[i]);
237 } 244 }
238 SDL_free(SDL_modelist); 245 SDL_free (SDL_modelist);
239 SDL_modelist = NULL; 246 SDL_modelist = NULL;
240 } 247 }
241 } 248 }
242 249
243 int CGX_ResizeFullScreen(_THIS) 250 int
251 CGX_ResizeFullScreen (_THIS)
244 { 252 {
245 int x, y; 253 int x, y;
246 int real_w, real_h; 254 int real_w, real_h;
247 255
248 if ( currently_fullscreen ) { 256 if (currently_fullscreen) {
249 /* Per ora non faccio nulla qui */ 257 /* Per ora non faccio nulla qui */
250 } 258 }
251 return(1); 259 return (1);
252 } 260 }
253 261
254 void _QueueEnterFullScreen(_THIS) 262 void
255 { 263 _QueueEnterFullScreen (_THIS)
256 } 264 {
257 265 }
258 int CGX_EnterFullScreen(_THIS) 266
267 int
268 CGX_EnterFullScreen (_THIS)
259 { 269 {
260 int okay; 270 int okay;
261 Uint32 saved_flags; 271 Uint32 saved_flags;
262 272
263 okay = 1; 273 okay = 1;
264 saved_flags = this->screen->flags; 274 saved_flags = this->screen->flags;
265 275
266 if ( ! currently_fullscreen ) 276 if (!currently_fullscreen) {
267 {
268 int real_w, real_h; 277 int real_w, real_h;
269 278
270 /* Map the fullscreen window to blank the screen */ 279 /* Map the fullscreen window to blank the screen */
271 get_real_resolution(this, &real_w, &real_h); 280 get_real_resolution (this, &real_w, &real_h);
272 281
273 CGX_DestroyWindow(this,this->screen); 282 CGX_DestroyWindow (this, this->screen);
274 set_best_resolution(this, real_w,real_h); 283 set_best_resolution (this, real_w, real_h);
275 284
276 currently_fullscreen = 1; 285 currently_fullscreen = 1;
277 this->screen->flags = saved_flags; 286 this->screen->flags = saved_flags;
278 287
279 CGX_CreateWindow(this,this->screen,real_w,real_h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); 288 CGX_CreateWindow (this, this->screen, real_w, real_h,
289 GetCyberMapAttr (SDL_Display->RastPort.BitMap,
290 CYBRMATTR_DEPTH),
291 this->screen->flags);
280 292
281 /* Set the new resolution */ 293 /* Set the new resolution */
282 okay = CGX_ResizeFullScreen(this); 294 okay = CGX_ResizeFullScreen (this);
283 if ( ! okay ) { 295 if (!okay) {
284 CGX_LeaveFullScreen(this); 296 CGX_LeaveFullScreen (this);
285 } 297 }
286 /* Set the colormap */ 298 /* Set the colormap */
287 /* 299 /*
288 if ( SDL_XColorMap ) { 300 if ( SDL_XColorMap ) {
289 XInstallColormap(SDL_Display, SDL_XColorMap); 301 XInstallColormap(SDL_Display, SDL_XColorMap);
290 } 302 }
291 */ 303 */
292 } 304 }
293 // CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); 305 // CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
294 return(okay); 306 return (okay);
295 } 307 }
296 308
297 int CGX_LeaveFullScreen(_THIS) 309 int
298 { 310 CGX_LeaveFullScreen (_THIS)
299 if ( currently_fullscreen ) { 311 {
300 int width,height; 312 if (currently_fullscreen) {
301 if ( SDL_Window ) { 313 int width, height;
302 CloseWindow(SDL_Window); 314 if (SDL_Window) {
303 SDL_Window=NULL; 315 CloseWindow (SDL_Window);
304 } 316 SDL_Window = NULL;
305 CloseScreen(SDL_Display); 317 }
306 318 CloseScreen (SDL_Display);
307 GFX_Display=SDL_Display=LockPubScreen(NULL); 319
308 320 GFX_Display = SDL_Display = LockPubScreen (NULL);
309 currently_fullscreen = 0; 321
310 322 currently_fullscreen = 0;
311 CGX_CreateWindow(this,this->screen,this->screen->w,this->screen->h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); 323
312 CGX_ResizeImage(this,this->screen,0L); 324 CGX_CreateWindow (this, this->screen, this->screen->w,
313 } 325 this->screen->h,
314 326 GetCyberMapAttr (SDL_Display->RastPort.BitMap,
315 return(0); 327 CYBRMATTR_DEPTH),
316 } 328 this->screen->flags);
329 CGX_ResizeImage (this, this->screen, 0L);
330 }
331
332 return (0);
333 }
334
335 /* vi: set ts=4 sw=4 expandtab: */