Mercurial > sdl-ios-xcode
annotate src/video/cybergfx/SDL_cgxmodes.c @ 150:df1d68818edb
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 18 Aug 2001 10:33:55 +0000 |
parents | 75a95f82bc1f |
children | e8157fcb3114 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Utilities for getting and setting the X display mode */ | |
29 | |
30 /* | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 */ | |
34 | |
35 #include "SDL_timer.h" | |
36 #include "SDL_error.h" | |
37 #include "SDL_events.h" | |
38 #include "SDL_events_c.h" | |
39 #include "SDL_cgxvideo.h" | |
40 #include "SDL_cgxwm_c.h" | |
41 #include "SDL_cgxmodes_c.h" | |
42 | |
43 #define CGX_DEBUG | |
44 | |
45 static void set_best_resolution(_THIS, int width, int height) | |
46 { | |
47 Uint32 idok; | |
48 int depth=8; | |
49 | |
50 if(SDL_Display) | |
51 depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH); | |
52 | |
53 idok=BestCModeIDTags(CYBRBIDTG_NominalWidth,width, | |
54 CYBRBIDTG_NominalHeight,height, | |
55 CYBRBIDTG_Depth,depth, | |
56 TAG_DONE); | |
57 | |
58 if(idok!=INVALID_ID) | |
59 { | |
60 if(SDL_Display) | |
61 { | |
62 if(currently_fullscreen) | |
63 CloseScreen(SDL_Display); | |
64 else | |
65 UnlockPubScreen(NULL,SDL_Display); | |
66 } | |
67 SDL_Display=GFX_Display=OpenScreenTags(NULL,SA_Width,width,SA_Height,height, | |
68 SA_Depth,depth,SA_DisplayID,idok, | |
69 TAG_DONE); | |
70 } | |
71 } | |
72 | |
73 static void get_real_resolution(_THIS, int* w, int* h) | |
74 { | |
75 *w = SDL_Display->Width; | |
76 *h = SDL_Display->Height; | |
77 } | |
78 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 static void move_cursor_to(_THIS, int x, int y) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
80 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 /* XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
82 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
83 /* DA FARE! */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
84 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
85 |
0 | 86 static void add_visual(_THIS, int depth, int class) |
87 { | |
88 Uint32 tID; | |
89 | |
90 tID=BestCModeIDTags(CYBRBIDTG_Depth,depth, | |
91 CYBRBIDTG_NominalWidth,640, | |
92 CYBRBIDTG_NominalHeight,480, | |
93 TAG_DONE); | |
94 | |
95 if(tID!=INVALID_ID) | |
96 { | |
97 int n = this->hidden->nvisuals; | |
98 | |
99 this->hidden->visuals[n].depth = depth; | |
100 this->hidden->visuals[n].visual = tID; | |
101 this->hidden->visuals[n].bpp = GetCyberIDAttr(CYBRIDATTR_BPPIX,tID); | |
102 this->hidden->nvisuals++; | |
103 } | |
104 } | |
105 | |
106 #define TrueColor 1 | |
107 #define PseudoColor 2 | |
108 | |
109 int CGX_GetVideoModes(_THIS) | |
110 { | |
111 int i; | |
112 ULONG nextid; | |
113 int nmodes=0; | |
114 | |
115 SDL_modelist=NULL; | |
116 | |
117 nextid=NextDisplayInfo(INVALID_ID); | |
118 | |
119 while(nextid!=INVALID_ID) | |
120 { | |
121 if(IsCyberModeID(nextid)) | |
122 { | |
123 DisplayInfoHandle h; | |
124 | |
125 if(h=FindDisplayInfo(nextid)) | |
126 { | |
127 struct DimensionInfo info; | |
128 | |
129 if(GetDisplayInfoData(h,(char *)&info,sizeof(struct DimensionInfo),DTAG_DIMS,NULL)) | |
130 { | |
131 int ok=0; | |
132 | |
133 for(i=0;i<nmodes;i++) | |
134 { | |
135 if( SDL_modelist[i]->w == (info.Nominal.MaxX+1) && | |
136 SDL_modelist[i]->h == (info.Nominal.MaxY+1) ) | |
137 ok=1; | |
138 } | |
139 | |
140 if(!ok) | |
141 { | |
142 nmodes++; | |
143 | |
144 SDL_modelist = (SDL_Rect **)realloc(SDL_modelist,(nmodes+1)*sizeof(SDL_Rect *)); | |
145 SDL_modelist[nmodes]=NULL; | |
146 | |
147 if ( SDL_modelist ) | |
148 { | |
149 SDL_modelist[nmodes-1] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
150 | |
151 if ( SDL_modelist[nmodes-1] == NULL ) | |
152 break; | |
153 | |
154 SDL_modelist[nmodes-1]->x = 0; | |
155 SDL_modelist[nmodes-1]->y = 0; | |
156 SDL_modelist[nmodes-1]->w = info.Nominal.MaxX+1; | |
157 SDL_modelist[nmodes-1]->h = info.Nominal.MaxY+1; | |
158 } | |
159 } | |
160 } | |
161 } | |
162 } | |
163 nextid=NextDisplayInfo(nextid); | |
164 } | |
165 | |
166 | |
167 this->hidden->nvisuals = 0; | |
168 /* Search for the visuals in deepest-first order, so that the first | |
169 will be the richest one */ | |
170 add_visual(this, 32, TrueColor); | |
171 add_visual(this, 24, TrueColor); | |
172 add_visual(this, 16, TrueColor); | |
173 add_visual(this, 15, TrueColor); | |
174 add_visual(this, 8, PseudoColor); | |
175 | |
176 if(this->hidden->nvisuals == 0) { | |
177 SDL_SetError("Found no sufficiently capable CGX visuals"); | |
178 return -1; | |
179 } | |
180 | |
181 if ( SDL_modelist == NULL ) { | |
182 SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *)); | |
183 i = 0; | |
184 if ( SDL_modelist ) { | |
185 SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
186 if ( SDL_modelist[i] ) { | |
187 SDL_modelist[i]->x = 0; | |
188 SDL_modelist[i]->y = 0; | |
189 SDL_modelist[i]->w = SDL_Display->Width; | |
190 SDL_modelist[i]->h = SDL_Display->Height; | |
191 ++i; | |
192 } | |
193 SDL_modelist[i] = NULL; | |
194 } | |
195 } | |
196 | |
197 D( if ( SDL_modelist ) { | |
198 bug("CGX video mode list: (%ld)\n",nmodes); | |
199 for ( i=0; SDL_modelist[i]; ++i ) { | |
200 bug( "\t%ld x %ld\n", | |
201 SDL_modelist[i]->w, SDL_modelist[i]->h); | |
202 } | |
203 } | |
204 ); | |
205 | |
206 D( { bug("CGX visuals list: (%ld)\n",this->hidden->nvisuals); | |
207 | |
208 for(i=0;i<this->hidden->nvisuals;i++) | |
209 bug("\t%lx - depth: %ld bpp: %ld\n",this->hidden->visuals[i].visual,this->hidden->visuals[i].depth,this->hidden->visuals[i].bpp); | |
210 } | |
211 ); | |
212 return 0; | |
213 } | |
214 | |
215 int CGX_SupportedVisual(_THIS, SDL_PixelFormat *format) | |
216 { | |
217 int i; | |
218 for(i = 0; i < this->hidden->nvisuals; i++) | |
219 { | |
220 if(this->hidden->visuals[i].depth == format->BitsPerPixel) // Era bpp | |
221 return 1; | |
222 } | |
223 return 0; | |
224 } | |
225 | |
226 SDL_Rect **CGX_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
227 { | |
228 if ( CGX_SupportedVisual(this, format) ) { | |
229 if ( flags & SDL_FULLSCREEN ) { | |
230 return(SDL_modelist); | |
231 } else { | |
232 return((SDL_Rect **)-1); | |
233 } | |
234 } else { | |
235 return((SDL_Rect **)0); | |
236 } | |
237 } | |
238 | |
239 void CGX_FreeVideoModes(_THIS) | |
240 { | |
241 int i; | |
242 | |
243 if ( SDL_modelist ) { | |
244 for ( i=0; SDL_modelist[i]; ++i ) { | |
245 free(SDL_modelist[i]); | |
246 } | |
247 free(SDL_modelist); | |
248 SDL_modelist = NULL; | |
249 } | |
250 } | |
251 | |
252 int CGX_ResizeFullScreen(_THIS) | |
253 { | |
254 int x, y; | |
255 int real_w, real_h; | |
256 | |
257 if ( currently_fullscreen ) { | |
258 /* Per ora non faccio nulla qui */ | |
259 } | |
260 return(1); | |
261 } | |
262 | |
263 void _QueueEnterFullScreen(_THIS) | |
264 { | |
265 } | |
266 | |
267 int CGX_EnterFullScreen(_THIS) | |
268 { | |
269 int okay; | |
270 | |
271 okay = 1; | |
272 if ( ! currently_fullscreen ) | |
273 { | |
274 int real_w, real_h; | |
275 | |
276 /* Map the fullscreen window to blank the screen */ | |
277 get_real_resolution(this, &real_w, &real_h); | |
278 | |
279 CGX_DestroyWindow(this,this->screen); | |
280 set_best_resolution(this, real_w,real_h); | |
281 | |
282 /* Grab the mouse on the fullscreen window | |
283 The event handling will know when we become active, and then | |
284 enter fullscreen mode if we can't grab the mouse this time. | |
285 */ | |
286 #if 0 | |
287 if ( (XGrabPointer(SDL_Display, FSwindow, True, 0, | |
288 GrabModeAsync, GrabModeAsync, | |
289 FSwindow, None, CurrentTime) != GrabSuccess) || | |
290 (XGrabKeyboard(SDL_Display, WMwindow, True, | |
291 GrabModeAsync, GrabModeAsync, CurrentTime) != 0) ) { | |
292 XUnmapWindow(SDL_Display, FSwindow); | |
293 X11_WaitUnmapped(this, FSwindow); | |
294 X11_QueueEnterFullScreen(this); | |
295 return(0); | |
296 } | |
297 #endif | |
298 | |
299 currently_fullscreen = 1; | |
300 | |
301 CGX_CreateWindow(this,this->screen,real_w,real_h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); | |
302 | |
303 /* Set the new resolution */ | |
304 okay = CGX_ResizeFullScreen(this); | |
305 if ( ! okay ) { | |
306 CGX_LeaveFullScreen(this); | |
307 } | |
308 /* Set the colormap */ | |
309 /* | |
310 if ( SDL_XColorMap ) { | |
311 XInstallColormap(SDL_Display, SDL_XColorMap); | |
312 } | |
313 */ | |
314 } | |
315 // CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); | |
316 return(okay); | |
317 } | |
318 | |
319 int CGX_LeaveFullScreen(_THIS) | |
320 { | |
321 if ( currently_fullscreen ) { | |
322 int width,height; | |
323 if ( SDL_Window ) { | |
324 CloseWindow(SDL_Window); | |
325 SDL_Window=NULL; | |
326 } | |
327 CloseScreen(SDL_Display); | |
328 | |
329 GFX_Display=SDL_Display=LockPubScreen(NULL); | |
330 | |
331 currently_fullscreen = 0; | |
332 | |
333 CGX_CreateWindow(this,this->screen,this->screen->w,this->screen->h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); | |
334 CGX_ResizeImage(this,this->screen,0L); | |
335 } | |
336 | |
337 return(0); | |
338 } |