1 /*
2 * IceBreaker
3 * Copyright (c) 2002 Matthew Miller <mattdm@mattdm.org> and
4 * Enrico Tassi <gareuselesinge@infinito.it>
5 *
6 * <http://www.mattdm.org/icebreaker/>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24
25 #include <SDL.h>
26 #include <stdlib.h>
27 #include "icebreaker.h"
28 #include "globals.h"
29 #include "laundry.h"
30 #include "options.h"
31 #include "text.h"
32 #include "titlebar.h"
33
makefullscreen()34 int makefullscreen()
35 {
36 SDL_Surface* fullscreensave = NULL;
37
38
39 //for window manager caption -- the title bar
40 char *curcaptiontitle=NULL,*curcaptionicon=NULL;
41 char newcaptiontitle[35];
42
43
44
45 if (screen!=NULL)
46 {
47 clean(); // very important!
48
49 fullscreensave=SDL_CreateRGBSurface(SDL_SWSURFACE,WIDTH,HEIGHT,screen->format->BitsPerPixel,0,0,0,0);
50 SDL_BlitSurface(screen, NULL, fullscreensave, NULL);
51
52 // the resolution switch is ugly if we don't do this, since
53 // sometimes the window gets resized a second before the mode
54 // switch. ugh.
55 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format, 0, 0, 0));
56 SDL_UpdateRect(screen,0,0,0,0);
57 }
58
59 fullscreen = SDL_SetVideoMode(FULLWIDTH, FULLHEIGHT, VIDEODEPTH, SDL_SWSURFACE | SDL_FULLSCREEN );
60 if (fullscreen == NULL)
61 {
62 // FIX -- if this happens, don't die: just stay in windowed
63 // mode and return failure (and change calling code to
64 // deal with the return value).
65 fprintf(stderr, "Couldn't switch to full screen mode.\n"
66 "SDL error: "
67 "%s\n\n", SDL_GetError());
68 exit(1);
69 }
70
71 screen = NULL;
72
73 // very clever idea from Enrico
74 screen = SDL_CreateRGBSurfaceFrom(fullscreen->pixels +
75 fullscreen->format->BytesPerPixel * FULLLEFTMARGIN +
76 FULLTOPMARGIN*fullscreen->format->BytesPerPixel * FULLWIDTH,
77 WIDTH, HEIGHT, VIDEODEPTH,
78 FULLWIDTH * fullscreen->format->BytesPerPixel,0,0,0,0);
79
80 if (screen == NULL)
81 {
82 // fix -- same as above -- try to recover gracefully if this
83 // happens
84 fprintf(stderr, "Couldn't access full screen surface. That's not good.\n"
85 "SDL error: "
86 "%s\n\n", SDL_GetError());
87 exit(1);
88 }
89 gameflags.isfullscreen=true;
90
91 // if we wanted to something interesting in the border in full-screen
92 // mode, here would be the place.
93 SDL_FillRect(fullscreen,NULL,SDL_MapRGB(screen->format, 0, 0, 0));
94
95 if (fullscreensave!=NULL)
96 SDL_BlitSurface(fullscreensave, NULL, screen, NULL);
97
98 // Set Window Caption For some odd reason, you can't feed the result
99 // of GetCaption directly back into SetCaption. So we have to do this.
100 SDL_WM_GetCaption(&curcaptiontitle, &curcaptionicon);
101 if (curcaptiontitle != NULL && curcaptionicon != NULL)
102 {
103 snprintf(newcaptiontitle,35,"%s",curcaptiontitle);
104 drawtitlebar(newcaptiontitle);
105 }
106
107 SDL_UpdateRect(fullscreen,0,0,0,0);
108
109 SDL_FreeSurface(fullscreensave);
110
111
112 // hmmm -- we might need to recalculate the colors if the video
113 // depth happens to change when switching to fullscreen. could
114 // happen....
115
116 return 0;
117 }
118
makewindowed()119 int makewindowed()
120 {
121 SDL_Surface * fullscreensave=SDL_CreateRGBSurface(SDL_SWSURFACE,WIDTH,HEIGHT,screen->format->BitsPerPixel,0,0,0,0);
122
123 clean(); // very important!
124
125 SDL_BlitSurface(screen, NULL, fullscreensave, NULL);
126
127 screen = SDL_SetVideoMode(WIDTH, HEIGHT, VIDEODEPTH, SDL_SWSURFACE);
128 if (screen == NULL)
129 {
130 fprintf(stderr, "Couldn't switch to windowed screen mode.\n"
131 "SDL error: "
132 "%s\n\n", SDL_GetError());
133 exit(1);
134 }
135 gameflags.isfullscreen=false;
136
137 SDL_BlitSurface(fullscreensave, NULL, screen, NULL);
138
139 SDL_UpdateRect(screen,0,0,0,0);
140
141 SDL_FreeSurface(fullscreensave);
142
143 return 0;
144 }
145