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