Changeset - r8171:ff11fcdf6589
[Not reviewed]
master
0 15 0
belugas - 17 years ago 2008-01-01 14:20:48
belugas@openttd.org
(svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
-Fix[FS#1519]: When you can not use this resolution at full screen, now you'll know that it failed.
As for the reason it did not work, each computer/OS has its reason.
15 files changed with 30 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -1272,18 +1272,19 @@ void SetAnimatedMouseCursor(const AnimCu
 

	
 
bool ChangeResInGame(int width, int height)
 
{
 
	return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height);
 
}
 

	
 
void ToggleFullScreen(bool fs)
 
bool ToggleFullScreen(bool fs)
 
{
 
	_video_driver->ToggleFullscreen(fs);
 
	bool result = _video_driver->ToggleFullscreen(fs);
 
	if (_fullscreen != fs && _num_resolutions == 0) {
 
		DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
 
	}
 
	return result;
 
}
 

	
 
static int CDECL compare_res(const void *pa, const void *pb)
 
{
 
	int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0];
 
	if (x != 0) return x;
src/gfx_func.h
Show inline comments
 
@@ -148,13 +148,13 @@ void SetAnimatedMouseCursor(const AnimCu
 
void CursorTick();
 
void DrawMouseCursor();
 
void ScreenSizeChanged();
 
void UndrawMouseCursor();
 
bool ChangeResInGame(int w, int h);
 
void SortResolutions(int count);
 
void ToggleFullScreen(bool fs);
 
bool ToggleFullScreen(bool fs);
 

	
 
/* gfx.cpp */
 
#define ASCII_LETTERSTART 32
 
extern FontSize _cur_fontsize;
 

	
 
byte GetCharacterWidth(FontSize size, uint32 key);
src/lang/english.txt
Show inline comments
 
@@ -938,12 +938,13 @@ STR_CURR_CUSTOM                         
 
STR_OPTIONS_LANG                                                :{BLACK}Language
 
STR_OPTIONS_LANG_CBO                                            :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_OPTIONS_LANG_TIP                                            :{BLACK}Select the interface language to use
 

	
 
STR_OPTIONS_FULLSCREEN                                          :{BLACK}Fullscreen
 
STR_OPTIONS_FULLSCREEN_TIP                                      :{BLACK}Check this box to play OpenTTD fullscreen mode
 
STR_FULLSCREEN_FAILED                                           :{WHITE}Fullscreen mode failed
 

	
 
STR_OPTIONS_RES                                                 :{BLACK}Screen resolution
 
STR_OPTIONS_RES_CBO                                             :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_OPTIONS_RES_TIP                                             :{BLACK}Select the screen resolution to use
 

	
 
STR_OPTIONS_SCREENSHOT_FORMAT                                   :{BLACK}Screenshot format
src/settings_gui.cpp
Show inline comments
 
@@ -198,14 +198,17 @@ static void GameOptionsWndProc(Window *w
 
			ShowDropDownMenu(w, _dynlang.dropdown, _dynlang.curr, 24, 0, 0);
 
			return;
 
		case 26: case 27: /* Setup resolution dropdown */
 
			ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), 27, 0, 0);
 
			return;
 
		case 28: /* Click fullscreen on/off */
 
			w->SetWidgetLoweredState(28, !_fullscreen);
 
			ToggleFullScreen(!_fullscreen); // toggle full-screen on/off
 
			/* try to toggle full-screen on/off */
 
			if (!ToggleFullScreen(!_fullscreen)) {
 
				ShowErrorMessage(INVALID_STRING_ID, STR_FULLSCREEN_FAILED, 0, 0);
 
			}
 
			w->SetWidgetLoweredState(28, _fullscreen);
 
			SetWindowDirty(w);
 
			return;
 
		case 30: case 31: /* Setup screenshot format dropdown */
 
			ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, 31, 0, 0);
 
			return;
 
		}
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -16,13 +16,13 @@ public:
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ void ToggleFullscreen(bool fullscreen);
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
};
 

	
 
class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "cocoa"; }
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -358,13 +358,13 @@ bool VideoDriver_Cocoa::ChangeResolution
 

	
 
	QZ_UpdateVideoModes();
 

	
 
	return ret;
 
}
 

	
 
void VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
 
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
 
{
 
	bool oldfs;
 

	
 
	assert(_cocoa_subdriver != NULL);
 

	
 
	oldfs = _cocoa_subdriver->IsFullscreen();
 
@@ -383,12 +383,13 @@ void VideoDriver_Cocoa::ToggleFullscreen
 
		}
 
	}
 

	
 
	QZ_GameSizeChanged();
 

	
 
	QZ_UpdateVideoModes();
 
	return _cocoa_subdriver->IsFullscreen() == full_screen;
 
}
 

	
 

	
 
/* This is needed since sometimes assert is called before the videodriver is initialized */
 
void CocoaDialog(const char* title, const char* message, const char* buttonLabel)
 
{
src/video/dedicated_v.cpp
Show inline comments
 
@@ -165,13 +165,13 @@ void VideoDriver_Dedicated::Stop()
 
#endif
 
	free(_dedicated_video_mem);
 
}
 

	
 
void VideoDriver_Dedicated::MakeDirty(int left, int top, int width, int height) {}
 
bool VideoDriver_Dedicated::ChangeResolution(int w, int h) { return false; }
 
void VideoDriver_Dedicated::ToggleFullscreen(bool fs) {}
 
bool VideoDriver_Dedicated::ToggleFullscreen(bool fs) { return false; }
 

	
 
#if defined(UNIX) || defined(__OS2__) || defined(PSP)
 
static bool InputWaiting()
 
{
 
	struct timeval tv;
 
	fd_set readfds;
src/video/dedicated_v.h
Show inline comments
 
@@ -14,13 +14,13 @@ public:
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ void ToggleFullscreen(bool fullscreen);
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
};
 

	
 
class FVideoDriver_Dedicated: public VideoDriverFactory<FVideoDriver_Dedicated> {
 
public:
 
	static const int priority = 0;
 
	/* virtual */ const char *GetName() { return "dedicated"; }
src/video/null_v.cpp
Show inline comments
 
@@ -35,7 +35,7 @@ void VideoDriver_Null::MainLoop()
 
		UpdateWindows();
 
	}
 
}
 

	
 
bool VideoDriver_Null::ChangeResolution(int w, int h) { return false; }
 

	
 
void VideoDriver_Null::ToggleFullscreen(bool fs) {}
 
bool VideoDriver_Null::ToggleFullscreen(bool fs) { return false; }
src/video/null_v.h
Show inline comments
 
@@ -17,13 +17,13 @@ public:
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ void ToggleFullscreen(bool fullscreen);
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
};
 

	
 
class FVideoDriver_Null: public VideoDriverFactory<FVideoDriver_Null> {
 
public:
 
	static const int priority = 1;
 
	/* virtual */ const char *GetName() { return "null"; }
src/video/sdl_v.cpp
Show inline comments
 
@@ -518,17 +518,19 @@ void VideoDriver_SDL::MainLoop()
 

	
 
bool VideoDriver_SDL::ChangeResolution(int w, int h)
 
{
 
	return CreateMainSurface(w, h);
 
}
 

	
 
void VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
 
bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
 
{
 
	_fullscreen = fullscreen;
 
	GetVideoModes(); // get the list of available video modes
 
	if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution[0], _cur_resolution[1])) {
 
		// switching resolution failed, put back full_screen to original status
 
		_fullscreen ^= true;
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
#endif /* WITH_SDL */
src/video/sdl_v.h
Show inline comments
 
@@ -14,13 +14,13 @@ public:
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ void ToggleFullscreen(bool fullscreen);
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
};
 

	
 
class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> {
 
public:
 
	static const int priority = 5;
 
	/* virtual */ const char *GetName() { return "sdl"; }
src/video/video_driver.hpp
Show inline comments
 
@@ -10,13 +10,13 @@ public:
 
	virtual void MakeDirty(int left, int top, int width, int height) = 0;
 

	
 
	virtual void MainLoop() = 0;
 

	
 
	virtual bool ChangeResolution(int w, int h) = 0;
 

	
 
	virtual void ToggleFullscreen(bool fullscreen) = 0;
 
	virtual bool ToggleFullscreen(bool fullscreen) = 0;
 
};
 

	
 
class VideoDriverFactoryBase: public DriverFactoryBase {
 
};
 

	
 
template <class T>
src/video/win32_v.cpp
Show inline comments
 
@@ -207,13 +207,13 @@ static void CALLBACK TrackMouseTimerProc
 
	if (!PtInRect(&rc, pt) || (WindowFromPoint(pt) != hwnd)) {
 
		KillTimer(hwnd, event);
 
		PostMessage(hwnd, WM_MOUSELEAVE, 0, 0L);
 
	}
 
}
 

	
 
static void MakeWindow(bool full_screen)
 
static bool MakeWindow(bool full_screen)
 
{
 
	_fullscreen = full_screen;
 

	
 
	// recreate window?
 
	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
 
		DestroyWindow(_wnd.main_wnd);
 
@@ -239,14 +239,14 @@ static void MakeWindow(bool full_screen)
 
		settings.dmBitsPerPel = _fullscreen_bpp;
 
		settings.dmPelsWidth  = _wnd.width_org;
 
		settings.dmPelsHeight = _wnd.height_org;
 
		settings.dmDisplayFrequency = _display_hz;
 

	
 
		if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
 
			MakeWindow(false);
 
			return;
 
			MakeWindow(false);  // don't care about the result
 
			return false;  // the request failed
 
		}
 
	} else if (_wnd.fullscreen) {
 
		// restore display?
 
		ChangeDisplaySettings(NULL, 0);
 
	}
 
#endif
 
@@ -288,12 +288,13 @@ static void MakeWindow(bool full_screen)
 
			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
 
			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
 
			ShowWindow(_wnd.main_wnd, showstyle);
 
		}
 
	}
 
	GameSizeChanged(); // invalidate all windows, force redraw
 
	return true; // the request succedded
 
}
 

	
 
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
{
 
	static uint32 keycode = 0;
 
	static bool console = false;
 
@@ -892,15 +893,13 @@ void VideoDriver_Win32::MainLoop()
 

	
 
bool VideoDriver_Win32::ChangeResolution(int w, int h)
 
{
 
	_wnd.width = _wnd.width_org = w;
 
	_wnd.height = _wnd.height_org = h;
 

	
 
	MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
 

	
 
	return true;
 
	return MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
 
}
 

	
 
void VideoDriver_Win32::ToggleFullscreen(bool full_screen)
 
bool VideoDriver_Win32::ToggleFullscreen(bool full_screen)
 
{
 
	MakeWindow(full_screen);
 
	return MakeWindow(full_screen);
 
}
src/video/win32_v.h
Show inline comments
 
@@ -14,13 +14,13 @@ public:
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ void ToggleFullscreen(bool fullscreen);
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
};
 

	
 
class FVideoDriver_Win32: public VideoDriverFactory<FVideoDriver_Win32> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "win32"; }
0 comments (0 inline, 0 general)