Skip to content

Latest commit

 

History

History
315 lines (257 loc) · 7.53 KB

SDL_cgxmodes.c

File metadata and controls

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