summaryrefslogtreecommitdiff
path: root/sdl.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-09-23 21:14:20 +0000
committerdarkvater <darkvater@openttd.org>2004-09-23 21:14:20 +0000
commitf3758d133a2a0330cdaee175383807bac0ad0249 (patch)
treeaa2a36ed9fc21776897ac8ece0176964b2798d57 /sdl.c
parentd72abf6c3ed68fe8e410f29458211aa04521c4ab (diff)
downloadopenttd-f3758d133a2a0330cdaee175383807bac0ad0249.tar.xz
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
-Fix: [1030393] some screensizes crashes OTTD. Fix in general bug that only allows resolutions which were multiple of 8 in width and height. Also use closest possible resolution in fullscreen if window size is not a valid resolution (Tron)
Diffstat (limited to 'sdl.c')
-rw-r--r--sdl.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/sdl.c b/sdl.c
index e8bfb8d59..d7782a7d8 100644
--- a/sdl.c
+++ b/sdl.c
@@ -248,9 +248,8 @@ static void GetVideoModes(void) {
for(i = 0; modes[i]; i++) {
int w = modes[i]->w;
int h = modes[i]->h;
- if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH+1) &&
- IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT+1) &&
- w%8 == 0 && h%8 == 0) { // disable screen resolutions which are not multiples of 8
+ if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH + 1) &&
+ IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT + 1)) {
int j;
for (j = 0; j < n; ++j)
if (_resolutions[j][0] == w && _resolutions[j][1] == h)
@@ -270,35 +269,42 @@ static void GetVideoModes(void) {
static int GetAvailableVideoMode(int *w, int *h)
{
int i;
-
+ int best;
+ uint delta;
// all modes available?
if (_all_modes)
return 1;
// is the wanted mode among the available modes?
- for(i = 0; i != _num_resolutions; i++) {
+ for (i = 0; i != _num_resolutions; i++) {
if(*w == _resolutions[i][0] && *h == _resolutions[i][1])
return 1;
}
+ // use the closest possible resolution
+ best = 0;
+ delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h));
+ for (i = 1; i != _num_resolutions; ++i) {
+ uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h));
+ if (newdelta < delta) {
+ best = i;
+ delta = newdelta;
+ }
+ }
+
// use the default mode
- *w = _resolutions[0][0];
- *h = _resolutions[0][1];
+ *w = _resolutions[best][0];
+ *h = _resolutions[best][1];
return 2;
}
static bool CreateMainSurface(int w, int h)
{
SDL_Surface *newscreen;
- bool sizechange;
GetAvailableVideoMode(&w, &h);
- sizechange = (_screen.width != w || _screen.height != h);
- _screen.pitch = _screen.width = w;
- _screen.height = h;
-
DEBUG(misc, 0) ("sdl: using mode %dx%d", w, h);
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
@@ -306,14 +312,17 @@ static bool CreateMainSurface(int w, int h)
if(newscreen == NULL)
return false;
+ _screen.width = newscreen->w;
+ _screen.height = newscreen->h;
+ _screen.pitch = newscreen->pitch;
+
_sdl_screen = newscreen;
InitPalette();
SDL_CALL SDL_WM_SetCaption("OpenTTD", "OpenTTD");
SDL_CALL SDL_ShowCursor(0);
-// if(sizechange)
- GameSizeChanged();
+ GameSizeChanged();
return true;
}
@@ -491,8 +500,8 @@ static int PollEvent() {
w = ev.resize.w;
h = ev.resize.h;
- w = clamp(w & ~0x7, 64, MAX_SCREEN_WIDTH);
- h = clamp(h & ~0x7, 64, MAX_SCREEN_HEIGHT);
+ w = clamp(w, 64, MAX_SCREEN_WIDTH);
+ h = clamp(h, 64, MAX_SCREEN_HEIGHT);
ChangeResInGame(w, h);