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