Changeset - r21436:38079fc3bcd8
[Not reviewed]
src/blitter/32bpp_anim.cpp
Show inline comments
 
@@ -473,25 +473,25 @@ void Blitter_32bppAnim::PaletteAnimate(c
 
			uint colour = GB(*anim, 0, 8);
 
			if (colour >= PALETTE_ANIM_START) {
 
				/* Update this pixel */
 
				*dst = this->AdjustBrightness(LookupColourInPalette(colour), GB(*anim, 8, 8));
 
			}
 
			dst++;
 
			anim++;
 
		}
 
		dst += _screen.pitch - this->anim_buf_width;
 
	}
 

	
 
	/* Make sure the backend redraws the whole screen */
 
	_video_driver->MakeDirty(0, 0, _screen.width, _screen.height);
 
	VideoDriver::GetInstance()->MakeDirty(0, 0, _screen.width, _screen.height);
 
}
 

	
 
Blitter::PaletteAnimation Blitter_32bppAnim::UsePaletteAnimation()
 
{
 
	return Blitter::PALETTE_ANIMATION_BLITTER;
 
}
 

	
 
void Blitter_32bppAnim::PostResize()
 
{
 
	if (_screen.width != this->anim_buf_width || _screen.height != this->anim_buf_height) {
 
		/* The size of the screen changed; we can assume we can wipe all data from our buffer */
 
		free(this->anim_buf);
src/bootstrap_gui.cpp
Show inline comments
 
@@ -237,25 +237,25 @@ bool HandleBootstrap()
 
	static const int offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 };
 
	for (uint i = 0; i != 16; i++) {
 
		for (int j = 0; j < 8; j++) {
 
			_colour_gradient[i][j] = offsets[i] + j;
 
		}
 
	}
 

	
 
	/* Finally ask the question. */
 
	new BootstrapBackground();
 
	new BootstrapAskForDownloadWindow();
 

	
 
	/* Process the user events. */
 
	_video_driver->MainLoop();
 
	VideoDriver::GetInstance()->MainLoop();
 

	
 
	/* _exit_game is used to get out of the video driver's main loop.
 
	 * In case GM_BOOTSTRAP is still set we did not exit it via the
 
	 * "download complete" event, so it was a manual exit. Obey it. */
 
	_exit_game = _game_mode == GM_BOOTSTRAP;
 
	if (_exit_game) return false;
 

	
 
	/* Try to probe the graphics. Should work this time. */
 
	if (!BaseGraphics::SetSet(NULL)) goto failure;
 

	
 
	/* Finally we can continue heading for the menu. */
 
	_game_mode = GM_MENU;
src/console_gui.cpp
Show inline comments
 
@@ -178,25 +178,25 @@ struct IConsoleWindow : Window
 
	{
 
		_iconsole_mode = ICONSOLE_OPENED;
 
		this->line_height = FONT_HEIGHT_NORMAL + ICON_LINE_SPACING;
 
		this->line_offset = GetStringBoundingBox("] ").width + 5;
 

	
 
		this->InitNested(0);
 
		ResizeWindow(this, _screen.width, _screen.height / 3);
 
	}
 

	
 
	~IConsoleWindow()
 
	{
 
		_iconsole_mode = ICONSOLE_CLOSED;
 
		_video_driver->EditBoxLostFocus();
 
		VideoDriver::GetInstance()->EditBoxLostFocus();
 
	}
 

	
 
	/**
 
	 * Scroll the content of the console.
 
	 * @param amount Number of lines to scroll back.
 
	 */
 
	void Scroll(int amount)
 
	{
 
		int max_scroll = max<int>(0, IConsoleLine::size + 1 - this->height / this->line_height);
 
		IConsoleWindow::scroll = Clamp<int>(IConsoleWindow::scroll + amount, 0, max_scroll);
 
		this->SetDirty();
 
	}
 
@@ -367,25 +367,25 @@ struct IConsoleWindow : Window
 
		if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return NULL;
 

	
 
		return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
 
	}
 

	
 
	virtual void OnMouseWheel(int wheel)
 
	{
 
		this->Scroll(-wheel);
 
	}
 

	
 
	virtual void OnFocusLost()
 
	{
 
		_video_driver->EditBoxLostFocus();
 
		VideoDriver::GetInstance()->EditBoxLostFocus();
 
	}
 
};
 

	
 
int IConsoleWindow::scroll = 0;
 

	
 
void IConsoleGUIInit()
 
{
 
	IConsoleResetHistoryPos();
 
	_iconsole_mode = ICONSOLE_CLOSED;
 

	
 
	IConsoleLine::Reset();
 
	memset(_iconsole_history, 0, sizeof(_iconsole_history));
src/crashlog.cpp
Show inline comments
 
@@ -131,32 +131,32 @@ char *CrashLog::LogConfiguration(char *b
 
			" Graphics set: %s (%u)\n"
 
			" Language:     %s\n"
 
			" Music driver: %s\n"
 
			" Music set:    %s (%u)\n"
 
			" Network:      %s\n"
 
			" Sound driver: %s\n"
 
			" Sound set:    %s (%u)\n"
 
			" Video driver: %s\n\n",
 
			BlitterFactory::GetCurrentBlitter() == NULL ? "none" : BlitterFactory::GetCurrentBlitter()->GetName(),
 
			BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
 
			BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
 
			_current_language == NULL ? "none" : _current_language->file,
 
			_music_driver == NULL ? "none" : _music_driver->GetName(),
 
			MusicDriver::GetInstance() == NULL ? "none" : MusicDriver::GetInstance()->GetName(),
 
			BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
 
			BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
 
			_networking ? (_network_server ? "server" : "client") : "no",
 
			_sound_driver == NULL ? "none" : _sound_driver->GetName(),
 
			SoundDriver::GetInstance() == NULL ? "none" : SoundDriver::GetInstance()->GetName(),
 
			BaseSounds::GetUsedSet() == NULL ? "none" : BaseSounds::GetUsedSet()->name,
 
			BaseSounds::GetUsedSet() == NULL ? UINT32_MAX : BaseSounds::GetUsedSet()->version,
 
			_video_driver == NULL ? "none" : _video_driver->GetName()
 
			VideoDriver::GetInstance() == NULL ? "none" : VideoDriver::GetInstance()->GetName()
 
	);
 

	
 
	buffer += seprintf(buffer, last,
 
			"Fonts:\n"
 
			" Small:  %s\n"
 
			" Medium: %s\n"
 
			" Large:  %s\n"
 
			" Mono:   %s\n\n",
 
			FontCache::Get(FS_SMALL)->GetFontName(),
 
			FontCache::Get(FS_NORMAL)->GetFontName(),
 
			FontCache::Get(FS_LARGE)->GetFontName(),
 
			FontCache::Get(FS_MONO)->GetFontName()
 
@@ -475,16 +475,16 @@ bool CrashLog::MakeCrashLog() const
 
 */
 
/* static */ void CrashLog::SetErrorMessage(const char *message)
 
{
 
	CrashLog::message = message;
 
}
 

	
 
/**
 
 * Try to close the sound/video stuff so it doesn't keep lingering around
 
 * incorrect video states or so, e.g. keeping dpmi disabled.
 
 */
 
/* static */ void CrashLog::AfterCrashLogCleanup()
 
{
 
	if (_music_driver != NULL) _music_driver->Stop();
 
	if (_sound_driver != NULL) _sound_driver->Stop();
 
	if (_video_driver != NULL) _video_driver->Stop();
 
	if (MusicDriver::GetInstance() != NULL) MusicDriver::GetInstance()->Stop();
 
	if (SoundDriver::GetInstance() != NULL) SoundDriver::GetInstance()->Stop();
 
	if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
 
}
src/driver.cpp
Show inline comments
 
@@ -9,35 +9,32 @@
 

	
 
/** @file driver.cpp Base for all driver handling. */
 

	
 
#include "stdafx.h"
 
#include "debug.h"
 
#include "sound/sound_driver.hpp"
 
#include "music/music_driver.hpp"
 
#include "video/video_driver.hpp"
 
#include "string_func.h"
 

	
 
#include "safeguards.h"
 

	
 
VideoDriver *_video_driver; ///< The currently active video driver.
 
char *_ini_videodriver;     ///< The video driver a stored in the configuration file.
 
int _num_resolutions;       ///< The number of resolutions.
 
Dimension _resolutions[32]; ///< List of resolutions.
 
Dimension _cur_resolution;  ///< The current resolution.
 
bool _rightclick_emulate;   ///< Whether right clicking is emulated.
 

	
 
SoundDriver *_sound_driver; ///< The currently active sound driver.
 
char *_ini_sounddriver;     ///< The sound driver a stored in the configuration file.
 

	
 
MusicDriver *_music_driver; ///< The currently active music driver.
 
char *_ini_musicdriver;     ///< The music driver a stored in the configuration file.
 

	
 
char *_ini_blitter;         ///< The blitter as stored in the configuration file.
 
bool _blitter_autodetected; ///< Was the blitter autodetected or specified by the user?
 

	
 
/**
 
 * Get a string parameter the list of parameters.
 
 * @param parm The parameters.
 
 * @param name The parameter name we're looking for.
 
 * @return The parameter value.
 
 */
 
const char *GetDriverParam(const char * const *parm, const char *name)
 
@@ -79,46 +76,62 @@ bool GetDriverParamBool(const char * con
 
int GetDriverParamInt(const char * const *parm, const char *name, int def)
 
{
 
	const char *p = GetDriverParam(parm, name);
 
	return p != NULL ? atoi(p) : def;
 
}
 

	
 
/**
 
 * Find the requested driver and return its class.
 
 * @param name the driver to select.
 
 * @param type the type of driver to select
 
 * @post Sets the driver so GetCurrentDriver() returns it too.
 
 */
 
Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
 
void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
 
{
 
	if (GetDrivers().size() == 0) return NULL;
 
	if (!DriverFactoryBase::SelectDriverImpl(name, type)) {
 
		StrEmpty(name) ?
 
			usererror("Failed to autoprobe %s driver", GetDriverTypeName(type)) :
 
			usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name);
 
	}
 
}
 

	
 
/**
 
 * Find the requested driver and return its class.
 
 * @param name the driver to select.
 
 * @param type the type of driver to select
 
 * @post Sets the driver so GetCurrentDriver() returns it too.
 
 * @return True upon success, otherwise false.
 
 */
 
bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
 
{
 
	if (GetDrivers().size() == 0) return false;
 

	
 
	if (StrEmpty(name)) {
 
		/* Probe for this driver, but do not fall back to dedicated/null! */
 
		for (int priority = 10; priority > 0; priority--) {
 
			Drivers::iterator it = GetDrivers().begin();
 
			for (; it != GetDrivers().end(); ++it) {
 
				DriverFactoryBase *d = (*it).second;
 

	
 
				/* Check driver type */
 
				if (d->type != type) continue;
 
				if (d->priority != priority) continue;
 

	
 
				Driver *newd = d->CreateInstance();
 
				const char *err = newd->Start(NULL);
 
				if (err == NULL) {
 
					DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
 
					delete *GetActiveDriver(type);
 
					*GetActiveDriver(type) = newd;
 
					return newd;
 
					return true;
 
				}
 

	
 
				DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
 
				delete newd;
 
			}
 
		}
 
		usererror("Couldn't find any suitable %s driver", GetDriverTypeName(type));
 
	} else {
 
		char *parm;
 
		char buffer[256];
 
		const char *parms[32];
 

	
 
@@ -151,25 +164,25 @@ Driver *DriverFactoryBase::SelectDriver(
 
			/* Found our driver, let's try it */
 
			Driver *newd = d->CreateInstance();
 

	
 
			const char *err = newd->Start(parms);
 
			if (err != NULL) {
 
				delete newd;
 
				usererror("Unable to load driver '%s'. The error was: %s", d->name, err);
 
			}
 

	
 
			DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
 
			delete *GetActiveDriver(type);
 
			*GetActiveDriver(type) = newd;
 
			return newd;
 
			return true;
 
		}
 
		usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
 
	}
 
}
 

	
 
/**
 
 * Build a human readable list of available drivers, grouped by type.
 
 * @param p The buffer to write to.
 
 * @param last The last element in the buffer.
 
 * @return The end of the written buffer.
 
 */
 
char *DriverFactoryBase::GetDriversInfo(char *p, const char *last)
src/driver.h
Show inline comments
 
@@ -50,24 +50,28 @@ public:
 
	 * Get the name of this driver.
 
	 * @return The name of the driver.
 
	 */
 
	virtual const char *GetName() const = 0;
 
};
 

	
 
DECLARE_POSTFIX_INCREMENT(Driver::Type)
 

	
 

	
 
/** Base for all driver factories. */
 
class DriverFactoryBase {
 
private:
 
	friend class MusicDriver;
 
	friend class SoundDriver;
 
	friend class VideoDriver;
 

	
 
	Driver::Type type;       ///< The type of driver.
 
	int priority;            ///< The priority of this factory.
 
	const char *name;        ///< The name of the drivers of this factory.
 
	const char *description; ///< The description of this driver.
 

	
 
	typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers; ///< Type for a map of drivers.
 

	
 
	/**
 
	 * Get the map with drivers.
 
	 */
 
	static Drivers &GetDrivers()
 
	{
 
@@ -88,42 +92,44 @@ private:
 

	
 
	/**
 
	 * Get the driver type name.
 
	 * @param type The type of driver to get the name of.
 
	 * @return The name of the type.
 
	 */
 
	static const char *GetDriverTypeName(Driver::Type type)
 
	{
 
		static const char * const driver_type_name[] = { "music", "sound", "video" };
 
		return driver_type_name[type];
 
	}
 

	
 
	static bool SelectDriverImpl(const char *name, Driver::Type type);
 

	
 
protected:
 
	DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
 

	
 
	virtual ~DriverFactoryBase();
 

	
 
public:
 
	/**
 
	 * Shuts down all active drivers
 
	 */
 
	static void ShutdownDrivers()
 
	{
 
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
 
			Driver *driver = *GetActiveDriver(dt);
 
			if (driver != NULL) driver->Stop();
 
		}
 
	}
 

	
 
	static Driver *SelectDriver(const char *name, Driver::Type type);
 
	static void SelectDriver(const char *name, Driver::Type type);
 
	static char *GetDriversInfo(char *p, const char *last);
 

	
 
	/**
 
	 * Get a nice description of the driver-class.
 
	 * @return The description.
 
	 */
 
	const char *GetDescription() const
 
	{
 
		return this->description;
 
	}
 

	
 
	/**
src/genworld.cpp
Show inline comments
 
@@ -322,25 +322,25 @@ void GenerateWorld(GenWorldMode mode, ui
 
	ResetWindowSystem();
 

	
 
	/* Create toolbars */
 
	SetupColoursAndInitialWindow();
 
	SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
 

	
 
	if (_gw.thread != NULL) {
 
		_gw.thread->Join();
 
		delete _gw.thread;
 
		_gw.thread = NULL;
 
	}
 

	
 
	if (!_video_driver->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
 
	if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
 
		DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
 
		_gw.threaded = false;
 
		_modal_progress_work_mutex->EndCritical();
 
		_GenerateWorld(NULL);
 
		_modal_progress_work_mutex->BeginCritical();
 
		return;
 
	}
 

	
 
	UnshowCriticalError();
 
	/* Remove any open window */
 
	DeleteAllNonVitalWindows();
 
	/* Hide vital windows, because we don't allow to use them */
src/gfx.cpp
Show inline comments
 
@@ -79,25 +79,25 @@ void GfxScroll(int left, int top, int wi
 
	Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 

	
 
	if (xo == 0 && yo == 0) return;
 

	
 
	if (_cursor.visible) UndrawMouseCursor();
 

	
 
#ifdef ENABLE_NETWORK
 
	if (_networking) NetworkUndrawChatMessage();
 
#endif /* ENABLE_NETWORK */
 

	
 
	blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
 
	/* This part of the screen is now dirty. */
 
	_video_driver->MakeDirty(left, top, width, height);
 
	VideoDriver::GetInstance()->MakeDirty(left, top, width, height);
 
}
 

	
 

	
 
/**
 
 * Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
 
 *
 
 * @pre dpi->zoom == ZOOM_LVL_NORMAL, right >= left, bottom >= top
 
 * @param left Minimum X (inclusive)
 
 * @param top Minimum Y (inclusive)
 
 * @param right Maximum X (inclusive)
 
 * @param bottom Maximum Y (inclusive)
 
 * @param colour A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolour spritenumber (FILLRECT_RECOLOUR)
 
@@ -1177,25 +1177,25 @@ void ScreenSizeChanged()
 
	_cursor.visible = false;
 
}
 

	
 
void UndrawMouseCursor()
 
{
 
	/* Don't undraw the mouse cursor if the screen is not ready */
 
	if (_screen.dst_ptr == NULL) return;
 

	
 
	if (_cursor.visible) {
 
		Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 
		_cursor.visible = false;
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y);
 
		_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 
		VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 
	}
 
}
 

	
 
void DrawMouseCursor()
 
{
 
#if defined(WINCE)
 
	/* Don't ever draw the mouse for WinCE, as we work with a stylus */
 
	return;
 
#endif
 

	
 
	/* Don't draw the mouse cursor if the screen is not ready */
 
	if (_screen.dst_ptr == NULL) return;
 
@@ -1237,49 +1237,49 @@ void DrawMouseCursor()
 
	_cursor.draw_pos.y = y;
 
	_cursor.draw_size.y = h;
 

	
 
	uint8 *buffer = _cursor_backup.Allocate(blitter->BufferSize(w, h));
 

	
 
	/* Make backup of stuff below cursor */
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), buffer, _cursor.draw_size.x, _cursor.draw_size.y);
 

	
 
	/* Draw cursor on screen */
 
	_cur_dpi = &_screen;
 
	DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x + _cursor.short_vehicle_offset, _cursor.pos.y);
 

	
 
	_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 
	VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 

	
 
	_cursor.visible = true;
 
	_cursor.dirty = false;
 
}
 

	
 
void RedrawScreenRect(int left, int top, int right, int bottom)
 
{
 
	assert(right <= _screen.width && bottom <= _screen.height);
 
	if (_cursor.visible) {
 
		if (right > _cursor.draw_pos.x &&
 
				left < _cursor.draw_pos.x + _cursor.draw_size.x &&
 
				bottom > _cursor.draw_pos.y &&
 
				top < _cursor.draw_pos.y + _cursor.draw_size.y) {
 
			UndrawMouseCursor();
 
		}
 
	}
 

	
 
#ifdef ENABLE_NETWORK
 
	if (_networking) NetworkUndrawChatMessage();
 
#endif /* ENABLE_NETWORK */
 

	
 
	DrawOverlappedWindowForAll(left, top, right, bottom);
 

	
 
	_video_driver->MakeDirty(left, top, right - left, bottom - top);
 
	VideoDriver::GetInstance()->MakeDirty(left, top, right - left, bottom - top);
 
}
 

	
 
/**
 
 * Repaints the rectangle blocks which are marked as 'dirty'.
 
 *
 
 * @see SetDirtyBlocks
 
 */
 
void DrawDirtyBlocks()
 
{
 
	byte *b = _dirty_blocks;
 
	const int w = Align(_screen.width,  DIRTY_BLOCK_WIDTH);
 
	const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT);
 
@@ -1570,30 +1570,30 @@ void SetMouseCursor(CursorID sprite, Pal
 
 * @see SetMouseCursor
 
 */
 
void SetAnimatedMouseCursor(const AnimCursor *table)
 
{
 
	_cursor.animate_list = table;
 
	_cursor.animate_cur = NULL;
 
	_cursor.pal = PAL_NONE;
 
	SwitchAnimatedCursor();
 
}
 

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

	
 
bool ToggleFullScreen(bool fs)
 
{
 
	bool result = _video_driver->ToggleFullscreen(fs);
 
	bool result = VideoDriver::GetInstance()->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 Dimension *pa, const Dimension *pb)
 
{
 
	int x = pa->width - pb->width;
 
	if (x != 0) return x;
 
	return pa->height - pb->height;
 
}
src/gfxinit.cpp
Show inline comments
 
@@ -280,27 +280,27 @@ static bool SwitchNewGRFBlitter()
 
		const char *repl_blitter = replacement_blitters[i].name;
 

	
 
		if (strcmp(repl_blitter, cur_blitter) == 0) return false;
 
		if (BlitterFactory::GetBlitterFactory(repl_blitter) == NULL) continue;
 

	
 
		DEBUG(misc, 1, "Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter);
 
		Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
 
		if (new_blitter == NULL) NOT_REACHED();
 
		DEBUG(misc, 1, "Successfully switched to %s.", repl_blitter);
 
		break;
 
	}
 

	
 
	if (!_video_driver->AfterBlitterChange()) {
 
	if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
 
		/* Failed to switch blitter, let's hope we can return to the old one. */
 
		if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !_video_driver->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
 
		if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !VideoDriver::GetInstance()->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Check whether we still use the right blitter, or use another (better) one. */
 
void CheckBlitter()
 
{
 
	if (!SwitchNewGRFBlitter()) return;
 

	
 
	ClearFontCache();
 
	GfxClearSpriteCache();
src/music/extmidi.cpp
Show inline comments
 
@@ -28,26 +28,26 @@
 
#include "../safeguards.h"
 

	
 
#ifndef EXTERNAL_PLAYER
 
/** The default external midi player. */
 
#define EXTERNAL_PLAYER "timidity"
 
#endif
 

	
 
/** Factory for the midi player that uses external players. */
 
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
 

	
 
const char *MusicDriver_ExtMidi::Start(const char * const * parm)
 
{
 
	if (strcmp(_video_driver->GetName(), "allegro") == 0 ||
 
			strcmp(_sound_driver->GetName(), "allegro") == 0) {
 
	if (strcmp(VideoDriver::GetInstance()->GetName(), "allegro") == 0 ||
 
			strcmp(SoundDriver::GetInstance()->GetName(), "allegro") == 0) {
 
		return "the extmidi driver does not work when Allegro is loaded.";
 
	}
 

	
 
	const char *command = GetDriverParam(parm, "cmd");
 
	if (StrEmpty(command)) command = EXTERNAL_PLAYER;
 

	
 
	this->command = stredup(command);
 
	this->song[0] = '\0';
 
	this->pid = -1;
 
	return NULL;
 
}
 

	
src/music/music_driver.hpp
Show inline comments
 
@@ -30,18 +30,24 @@ public:
 

	
 
	/**
 
	 * Are we currently playing a song?
 
	 * @return True if a song is being played.
 
	 */
 
	virtual bool IsSongPlaying() = 0;
 

	
 
	/**
 
	 * Set the volume, if possible.
 
	 * @param vol The new volume.
 
	 */
 
	virtual void SetVolume(byte vol) = 0;
 

	
 
	/**
 
	 * Get the currently active instance of the music driver.
 
	 */
 
	static MusicDriver *GetInstance() {
 
		return static_cast<MusicDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_MUSIC));
 
	}
 
};
 

	
 
extern MusicDriver *_music_driver;
 
extern char *_ini_musicdriver;
 

	
 
#endif /* MUSIC_MUSIC_DRIVER_HPP */
src/music_gui.cpp
Show inline comments
 
@@ -167,40 +167,40 @@ static void SkipToNextSong()
 
		while (b[1] != 0) {
 
			b[0] = b[1];
 
			b++;
 
		}
 
		b[0] = t;
 
	}
 

	
 
	_song_is_active = false;
 
}
 

	
 
static void MusicVolumeChanged(byte new_vol)
 
{
 
	_music_driver->SetVolume(new_vol);
 
	MusicDriver::GetInstance()->SetVolume(new_vol);
 
}
 

	
 
static void DoPlaySong()
 
{
 
	char filename[MAX_PATH];
 
	if (FioFindFullPath(filename, lastof(filename), BASESET_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename) == NULL) {
 
		FioFindFullPath(filename, lastof(filename), OLD_GM_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename);
 
	}
 
	_music_driver->PlaySong(filename);
 
	MusicDriver::GetInstance()->PlaySong(filename);
 
	SetWindowDirty(WC_MUSIC_WINDOW, 0);
 
}
 

	
 
static void DoStopMusic()
 
{
 
	_music_driver->StopSong();
 
	MusicDriver::GetInstance()->StopSong();
 
	SetWindowDirty(WC_MUSIC_WINDOW, 0);
 
}
 

	
 
static void SelectSongToPlay()
 
{
 
	uint i = 0;
 
	uint j = 0;
 

	
 
	memset(_cur_playlist, 0, sizeof(_cur_playlist));
 
	do {
 
		const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_settings_client.music.playlist][i] - 1].filename;
 
		/* We are now checking for the existence of that file prior
 
@@ -264,25 +264,25 @@ void ResetMusic()
 
}
 

	
 
void MusicLoop()
 
{
 
	if (!_settings_client.music.playing && _song_is_active) {
 
		StopMusic();
 
	} else if (_settings_client.music.playing && !_song_is_active) {
 
		PlayPlaylistSong();
 
	}
 

	
 
	if (!_song_is_active) return;
 

	
 
	if (!_music_driver->IsSongPlaying()) {
 
	if (!MusicDriver::GetInstance()->IsSongPlaying()) {
 
		if (_game_mode != GM_MENU) {
 
			StopMusic();
 
			SkipToNextSong();
 
			PlayPlaylistSong();
 
		} else {
 
			ResetMusic();
 
		}
 
	}
 
}
 

	
 
static void SelectPlaylist(byte list)
 
{
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -160,25 +160,25 @@ void NetworkUndrawChatMessage()
 
			height = max(height + y, min(_chatmsg_box.height, _screen.height));
 
			y = 0;
 
		}
 
		if (x + width >= _screen.width) {
 
			width = _screen.width - x;
 
		}
 
		if (width <= 0 || height <= 0) return;
 

	
 
		_chatmessage_visible = false;
 
		/* Put our 'shot' back to the screen */
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
 
		/* And make sure it is updated next time */
 
		_video_driver->MakeDirty(x, y, width, height);
 
		VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
 

	
 
		_chatmessage_dirty = true;
 
	}
 
}
 

	
 
/** Check if a message is expired. */
 
void NetworkChatMessageLoop()
 
{
 
	for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) {
 
		ChatMessage *cmsg = &_chatmsg_list[i];
 
		if (cmsg->message[0] == '\0') continue;
 

	
 
@@ -247,25 +247,25 @@ void NetworkDrawChatMessage()
 
			PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR // black, but with some alpha for background
 
		);
 

	
 
	/* Paint the chat messages starting with the lowest at the bottom */
 
	int ypos = bottom - 2;
 

	
 
	for (int i = count - 1; i >= 0; i--) {
 
		ypos = DrawStringMultiLine(_chatmsg_box.x + 3, _chatmsg_box.x + _chatmsg_box.width - 1, top, ypos, _chatmsg_list[i].message, _chatmsg_list[i].colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - NETWORK_CHAT_LINE_SPACING;
 
		if (ypos < top) break;
 
	}
 

	
 
	/* Make sure the data is updated next flush */
 
	_video_driver->MakeDirty(x, y, width, height);
 
	VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
 

	
 
	_chatmessage_visible = true;
 
	_chatmessage_dirty = false;
 
}
 

	
 
/**
 
 * Send an actual chat message.
 
 * @param buf The message to send.
 
 * @param type The type of destination.
 
 * @param dest The actual destination index.
 
 */
 
static void SendChat(const char *buf, DestType type, int dest)
src/newgrf_config.cpp
Show inline comments
 
@@ -766,25 +766,25 @@ void DoScanNewGRFFiles(void *callback)
 

	
 
/**
 
 * Scan for all NewGRFs.
 
 * @param callback The callback to call after the scanning is complete.
 
 */
 
void ScanNewGRFFiles(NewGRFScanCallback *callback)
 
{
 
	/* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */
 
	SetModalProgress(true);
 
	/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
 
	MarkWholeScreenDirty();
 

	
 
	if (!_video_driver->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
 
	if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
 
		_modal_progress_work_mutex->EndCritical();
 
		_modal_progress_paint_mutex->EndCritical();
 
		DoScanNewGRFFiles(callback);
 
		_modal_progress_paint_mutex->BeginCritical();
 
		_modal_progress_work_mutex->BeginCritical();
 
	} else {
 
		UpdateNewGRFScanStatus(0, NULL);
 
	}
 
}
 

	
 
/**
 
 * Find a NewGRF in the scanned list.
src/openttd.cpp
Show inline comments
 
@@ -88,25 +88,25 @@ extern char *_config_file;
 
 * @note Does NEVER return.
 
 */
 
void CDECL usererror(const char *s, ...)
 
{
 
	va_list va;
 
	char buf[512];
 

	
 
	va_start(va, s);
 
	vseprintf(buf, lastof(buf), s, va);
 
	va_end(va);
 

	
 
	ShowOSErrorBox(buf, false);
 
	if (_video_driver != NULL) _video_driver->Stop();
 
	if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
 

	
 
	exit(1);
 
}
 

	
 
/**
 
 * Error handling for fatal non-user errors.
 
 * @param s the string to print.
 
 * @note Does NEVER return.
 
 */
 
void CDECL error(const char *s, ...)
 
{
 
	va_list va;
 
@@ -334,25 +334,25 @@ static void LoadIntroGame(bool load_newg
 
		SetLocalCompany(COMPANY_SPECTATOR);
 
	} else {
 
		SetLocalCompany(COMPANY_FIRST);
 
	}
 

	
 
	_pause_mode = PM_UNPAUSED;
 
	_cursor.fix_at = false;
 

	
 
	if (load_newgrfs) CheckForMissingSprites();
 
	CheckForMissingGlyphs();
 

	
 
	/* Play main theme */
 
	if (_music_driver->IsSongPlaying()) ResetMusic();
 
	if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic();
 
}
 

	
 
void MakeNewgameSettingsLive()
 
{
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		if (_settings_game.ai_config[c] != NULL) {
 
			delete _settings_game.ai_config[c];
 
		}
 
	}
 
	if (_settings_game.game_config != NULL) {
 
		delete _settings_game.game_config;
 
	}
 
@@ -427,25 +427,25 @@ struct AfterNewGRFScan : NewGRFScanCallb
 

	
 
		Game::Uninitialize(true);
 
		AI::Uninitialize(true);
 
		CheckConfig();
 
		LoadFromHighScore();
 
		LoadHotkeysFromConfig();
 
		WindowDesc::LoadFromConfig();
 

	
 
		/* We have loaded the config, so we may possibly save it. */
 
		*save_config_ptr = save_config;
 

	
 
		/* restore saved music volume */
 
		_music_driver->SetVolume(_settings_client.music.music_vol);
 
		MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
 

	
 
		if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
 
		if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
 

	
 
#if defined(ENABLE_NETWORK)
 
		if (dedicated_host != NULL) {
 
			_network_bind_list.Clear();
 
			*_network_bind_list.Append() = stredup(dedicated_host);
 
		}
 
		if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
 
#endif /* ENABLE_NETWORK */
 

	
 
@@ -766,30 +766,25 @@ int openttd_main(int argc, char *argv[])
 
	if (!_blitter_autodetected ||
 
			(_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
 
			BlitterFactory::SelectBlitter("32bpp-anim") == NULL) {
 
		if (BlitterFactory::SelectBlitter(blitter) == NULL) {
 
			StrEmpty(blitter) ?
 
				usererror("Failed to autoprobe blitter") :
 
				usererror("Failed to select requested blitter '%s'; does it exist?", blitter);
 
		}
 
	}
 
	free(blitter);
 

	
 
	if (videodriver == NULL && _ini_videodriver != NULL) videodriver = stredup(_ini_videodriver);
 
	_video_driver = (VideoDriver*)DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
 
	if (_video_driver == NULL) {
 
		StrEmpty(videodriver) ?
 
			usererror("Failed to autoprobe video driver") :
 
			usererror("Failed to select requested video driver '%s'", videodriver);
 
	}
 
	DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
 
	free(videodriver);
 

	
 
	InitializeSpriteSorter();
 

	
 
	/* Initialize the zoom level of the screen to normal */
 
	_screen.zoom = ZOOM_LVL_NORMAL;
 

	
 
	NetworkStartUp(); // initialize network-core
 

	
 
#if defined(ENABLE_NETWORK)
 
	if (debuglog_conn != NULL && _network_available) {
 
		const char *not_used = NULL;
 
@@ -802,25 +797,25 @@ int openttd_main(int argc, char *argv[])
 
		if (port != NULL) rport = atoi(port);
 

	
 
		NetworkStartDebugLog(NetworkAddress(debuglog_conn, rport));
 
	}
 
#endif /* ENABLE_NETWORK */
 

	
 
	if (!HandleBootstrap()) {
 
		ShutdownGame();
 

	
 
		goto exit_bootstrap;
 
	}
 

	
 
	_video_driver->ClaimMousePointer();
 
	VideoDriver::GetInstance()->ClaimMousePointer();
 

	
 
	/* initialize screenshot formats */
 
	InitializeScreenshotFormats();
 

	
 
	BaseSounds::FindSets();
 
	if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = stredup(BaseSounds::ini_set);
 
	if (!BaseSounds::SetSet(sounds_set)) {
 
		if (StrEmpty(sounds_set) || !BaseSounds::SetSet(NULL)) {
 
			usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of readme.txt.");
 
		} else {
 
			ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
 
			msg.SetDParamStr(0, sounds_set);
 
@@ -834,57 +829,47 @@ int openttd_main(int argc, char *argv[])
 
	if (!BaseMusic::SetSet(music_set)) {
 
		if (StrEmpty(music_set) || !BaseMusic::SetSet(NULL)) {
 
			usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of readme.txt.");
 
		} else {
 
			ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
 
			msg.SetDParamStr(0, music_set);
 
			ScheduleErrorMessage(msg);
 
		}
 
	}
 
	free(music_set);
 

	
 
	if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = stredup(_ini_sounddriver);
 
	_sound_driver = (SoundDriver*)DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
 
	if (_sound_driver == NULL) {
 
		StrEmpty(sounddriver) ?
 
			usererror("Failed to autoprobe sound driver") :
 
			usererror("Failed to select requested sound driver '%s'", sounddriver);
 
	}
 
	DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
 
	free(sounddriver);
 

	
 
	if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = stredup(_ini_musicdriver);
 
	_music_driver = (MusicDriver*)DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
 
	if (_music_driver == NULL) {
 
		StrEmpty(musicdriver) ?
 
			usererror("Failed to autoprobe music driver") :
 
			usererror("Failed to select requested music driver '%s'", musicdriver);
 
	}
 
	DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
 
	free(musicdriver);
 

	
 
	/* Take our initial lock on whatever we might want to do! */
 
	_modal_progress_paint_mutex->BeginCritical();
 
	_modal_progress_work_mutex->BeginCritical();
 

	
 
	GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
 
	WaitTillGeneratedWorld();
 

	
 
	LoadIntroGame(false);
 

	
 
	CheckForMissingGlyphs();
 

	
 
	/* ScanNewGRFFiles now has control over the scanner. */
 
	ScanNewGRFFiles(scanner);
 
	scanner = NULL;
 

	
 
	_video_driver->MainLoop();
 
	VideoDriver::GetInstance()->MainLoop();
 

	
 
	WaitTillSaved();
 

	
 
	/* only save config if we have to */
 
	if (save_config) {
 
		SaveToConfig();
 
		SaveHotkeysToConfig();
 
		WindowDesc::SaveToConfig();
 
		SaveToHighScore();
 
	}
 

	
 
	/* Reset windowing system, stop drivers, free used memory, ... */
 
@@ -934,25 +919,25 @@ void HandleExitGameRequest()
 
		DoExitSave();
 
		_exit_game = true;
 
	} else {
 
		AskExitGame();
 
	}
 
}
 

	
 
static void MakeNewGameDone()
 
{
 
	SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
 

	
 
	/* In a dedicated server, the server does not play */
 
	if (!_video_driver->HasGUI()) {
 
	if (!VideoDriver::GetInstance()->HasGUI()) {
 
		SetLocalCompany(COMPANY_SPECTATOR);
 
		if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
 
		IConsoleCmdExec("exec scripts/game_start.scr 0");
 
		return;
 
	}
 

	
 
	/* Create a single company */
 
	DoStartupNewCompany(false);
 

	
 
	Company *c = Company::Get(COMPANY_FIRST);
 
	c->settings = _settings_client.company;
 

	
 
@@ -1500,15 +1485,15 @@ void GameLoop()
 
		NetworkChatMessageLoop();
 
	}
 
#else
 
	StateGameLoop();
 
#endif /* ENABLE_NETWORK */
 

	
 
	if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
 

	
 
	if (!_pause_mode || _game_mode == GM_EDITOR || _settings_game.construction.command_pause_level > CMDPL_NO_CONSTRUCTION) MoveAllTextEffects();
 

	
 
	InputLoop();
 

	
 
	_sound_driver->MainLoop();
 
	SoundDriver::GetInstance()->MainLoop();
 
	MusicLoop();
 
}
src/os/windows/crashlog_win.cpp
Show inline comments
 
@@ -514,25 +514,25 @@ static LONG WINAPI ExceptionHandler(EXCE
 

	
 
	CrashLogWindows *log = new CrashLogWindows(ep);
 
	CrashLogWindows::current = log;
 
	char *buf = log->FillCrashLog(log->crashlog, lastof(log->crashlog));
 
	log->WriteCrashDump(log->crashdump_filename, lastof(log->crashdump_filename));
 
	log->AppendDecodedStacktrace(buf, lastof(log->crashlog));
 
	log->WriteCrashLog(log->crashlog, log->crashlog_filename, lastof(log->crashlog_filename));
 
	log->WriteScreenshot(log->screenshot_filename, lastof(log->screenshot_filename));
 

	
 
	/* Close any possible log files */
 
	CloseConsoleLogIfActive();
 

	
 
	if ((_video_driver == NULL || _video_driver->HasGUI()) && _safe_esp != NULL) {
 
	if ((VideoDriver::GetInstance() == NULL || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != NULL) {
 
#ifdef _M_AMD64
 
		ep->ContextRecord->Rip = (DWORD64)ShowCrashlogWindow;
 
		ep->ContextRecord->Rsp = (DWORD64)_safe_esp;
 
#else
 
		ep->ContextRecord->Eip = (DWORD)ShowCrashlogWindow;
 
		ep->ContextRecord->Esp = (DWORD)_safe_esp;
 
#endif
 
		return EXCEPTION_CONTINUE_EXECUTION;
 
	}
 

	
 
	CrashLog::AfterCrashLogCleanup();
 
	return EXCEPTION_EXECUTE_HANDLER;
src/osk_gui.cpp
Show inline comments
 
@@ -199,25 +199,25 @@ struct OskWindow : public Window {
 
		this->parent->SetWidgetDirty(this->text_btn);
 
	}
 

	
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (!gui_scope) return;
 
		this->SetWidgetDirty(WID_OSK_TEXT);
 
		this->parent->SetWidgetDirty(this->text_btn);
 
	}
 

	
 
	virtual void OnFocusLost()
 
	{
 
		_video_driver->EditBoxLostFocus();
 
		VideoDriver::GetInstance()->EditBoxLostFocus();
 
		delete this;
 
	}
 
};
 

	
 
static const int HALF_KEY_WIDTH = 7;  // Width of 1/2 key in pixels.
 
static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys.
 

	
 
/**
 
 * Add a key widget to a row of the keyboard.
 
 * @param hor     Row container to add key widget to.
 
 * @param height  Height of the key (all keys in a row should have equal height).
 
 * @param num_half Number of 1/2 key widths that this key has.
src/sound/sound_driver.hpp
Show inline comments
 
@@ -10,18 +10,24 @@
 
/** @file sound_driver.hpp Base for all sound drivers. */
 

	
 
#ifndef SOUND_SOUND_DRIVER_HPP
 
#define SOUND_SOUND_DRIVER_HPP
 

	
 
#include "../driver.h"
 

	
 
/** Base for all sound drivers. */
 
class SoundDriver : public Driver {
 
public:
 
	/** Called once every tick */
 
	virtual void MainLoop() {}
 

	
 
	/**
 
	 * Get the currently active instance of the sound driver.
 
	 */
 
	static SoundDriver *GetInstance() {
 
		return static_cast<SoundDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_SOUND));
 
	}
 
};
 

	
 
extern SoundDriver *_sound_driver;
 
extern char *_ini_sounddriver;
 

	
 
#endif /* SOUND_SOUND_DRIVER_HPP */
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -588,34 +588,34 @@ void VideoDriver_Cocoa::EditBoxLostFocus
 
 *
 
 * @param title Window title.
 
 * @param message Message text.
 
 * @param buttonLabel Button text.
 
 *
 
 * @note This is needed since sometimes assert is called before the videodriver is initialized .
 
 */
 
void CocoaDialog(const char *title, const char *message, const char *buttonLabel)
 
{
 
	_cocoa_video_dialog = true;
 

	
 
	bool wasstarted = _cocoa_video_started;
 
	if (_video_driver == NULL) {
 
	if (VideoDriver::GetInstance() == NULL) {
 
		setupApplication(); // Setup application before showing dialog
 
	} else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) {
 
	} else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(NULL) != NULL) {
 
		fprintf(stderr, "%s: %s\n", title, message);
 
		return;
 
	}
 

	
 
	NSRunAlertPanel([ NSString stringWithUTF8String:title ], [ NSString stringWithUTF8String:message ], [ NSString stringWithUTF8String:buttonLabel ], nil, nil);
 

	
 
	if (!wasstarted && _video_driver != NULL) _video_driver->Stop();
 
	if (!wasstarted && VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
 

	
 
	_cocoa_video_dialog = false;
 
}
 

	
 
/** Set the application's bundle directory.
 
 *
 
 * This is needed since OS X application bundles do not have a
 
 * current directory and the data files are 'somewhere' in the bundle.
 
 */
 
void cocoaSetApplicationBundleDir()
 
{
 
	char tmp[MAXPATHLEN];
src/video/cocoa/event.mm
Show inline comments
 
@@ -278,25 +278,25 @@ static bool QZ_KeyEvent(unsigned short k
 

	
 
	switch (keycode) {
 
		case QZ_UP:    SB(_dirkeys, 1, 1, down); break;
 
		case QZ_DOWN:  SB(_dirkeys, 3, 1, down); break;
 
		case QZ_LEFT:  SB(_dirkeys, 0, 1, down); break;
 
		case QZ_RIGHT: SB(_dirkeys, 2, 1, down); break;
 

	
 
		case QZ_TAB: _tab_is_down = down; break;
 

	
 
		case QZ_RETURN:
 
		case QZ_f:
 
			if (down && (_current_mods & NSCommandKeyMask)) {
 
				_video_driver->ToggleFullscreen(!_fullscreen);
 
				VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
 
			}
 
			break;
 
	}
 

	
 
	if (down) {
 
		uint32 pressed_key = QZ_MapKey(keycode);
 

	
 
		static bool console = false;
 

	
 
		if (pressed_key == WKC_BACKQUOTE && unicode == 0) {
 
			if (!console) {
 
				/* Backquote is a dead key, require a double press for hotkey behaviour (i.e. console). */
src/video/sdl_v.cpp
Show inline comments
 
@@ -402,25 +402,25 @@ bool VideoDriver_SDL::CreateMainSurface(
 

	
 
	Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 
	blitter->PostResize();
 

	
 
	InitPalette();
 
	switch (blitter->UsePaletteAnimation()) {
 
		case Blitter::PALETTE_ANIMATION_NONE:
 
		case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
 
			UpdatePalette();
 
			break;
 

	
 
		case Blitter::PALETTE_ANIMATION_BLITTER:
 
			if (_video_driver != NULL) blitter->PaletteAnimate(_local_palette);
 
			if (VideoDriver::GetInstance() != NULL) blitter->PaletteAnimate(_local_palette);
 
			break;
 

	
 
		default:
 
			NOT_REACHED();
 
	}
 

	
 
	seprintf(caption, lastof(caption), "OpenTTD %s", _openttd_revision);
 
	SDL_CALL SDL_WM_SetCaption(caption, caption);
 

	
 
	GameSizeChanged();
 

	
 
	return true;
src/video/video_driver.hpp
Show inline comments
 
@@ -69,22 +69,28 @@ public:
 
	 * thread/process for display purposes.
 
	 * @return True for all drivers except null and dedicated.
 
	 */
 
	virtual bool HasGUI() const
 
	{
 
		return true;
 
	}
 

	
 
	/**
 
	 * An edit box lost the input focus. Abort character compositing if necessary.
 
	 */
 
	virtual void EditBoxLostFocus() {}
 

	
 
	/**
 
	 * Get the currently active instance of the video driver.
 
	 */
 
	static VideoDriver *GetInstance() {
 
		return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO));
 
	}
 
};
 

	
 
extern VideoDriver *_video_driver;
 
extern char *_ini_videodriver;
 
extern int _num_resolutions;
 
extern Dimension _resolutions[32];
 
extern Dimension _cur_resolution;
 
extern bool _rightclick_emulate;
 

	
 
#endif /* VIDEO_VIDEO_DRIVER_HPP */
src/video/win32_v.cpp
Show inline comments
 
@@ -993,25 +993,25 @@ static LRESULT CALLBACK WndProcGdi(HWND 
 

	
 
#if !defined(WINCE)
 
		case WM_ACTIVATE: {
 
			/* Don't do anything if we are closing openttd */
 
			if (_exit_game) break;
 

	
 
			bool active = (LOWORD(wParam) != WA_INACTIVE);
 
			bool minimized = (HIWORD(wParam) != 0);
 
			if (_wnd.fullscreen) {
 
				if (active && minimized) {
 
					/* Restore the game window */
 
					ShowWindow(hwnd, SW_RESTORE);
 
					static_cast<VideoDriver_Win32 *>(_video_driver)->MakeWindow(true);
 
					static_cast<VideoDriver_Win32 *>(VideoDriver::GetInstance())->MakeWindow(true);
 
				} else if (!active && !minimized) {
 
					/* Minimise the window and restore desktop */
 
					ShowWindow(hwnd, SW_MINIMIZE);
 
					ChangeDisplaySettings(NULL, 0);
 
				}
 
			}
 
			break;
 
		}
 
#endif
 
	}
 

	
 
	return DefWindowProc(hwnd, msg, wParam, lParam);
src/window.cpp
Show inline comments
 
@@ -439,60 +439,60 @@ bool EditBoxInGlobalFocus()
 
	/* The console does not have an edit box so a special case is needed. */
 
	if (_focused_window->window_class == WC_CONSOLE) return true;
 

	
 
	return _focused_window->nested_focus != NULL && _focused_window->nested_focus->type == WWT_EDITBOX;
 
}
 

	
 
/**
 
 * Makes no widget on this window have focus. The function however doesn't change which window has focus.
 
 */
 
void Window::UnfocusFocusedWidget()
 
{
 
	if (this->nested_focus != NULL) {
 
		if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
 
		if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
 

	
 
		/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
 
		this->nested_focus->SetDirty(this);
 
		this->nested_focus = NULL;
 
	}
 
}
 

	
 
/**
 
 * Set focus within this window to the given widget. The function however doesn't change which window has focus.
 
 * @param widget_index Index of the widget in the window to set the focus to.
 
 * @return Focus has changed.
 
 */
 
bool Window::SetFocusedWidget(int widget_index)
 
{
 
	/* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */
 
	if ((uint)widget_index >= this->nested_array_size) return false;
 

	
 
	assert(this->nested_array[widget_index] != NULL); // Setting focus to a non-existing widget is a bad idea.
 
	if (this->nested_focus != NULL) {
 
		if (this->GetWidget<NWidgetCore>(widget_index) == this->nested_focus) return false;
 

	
 
		/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
 
		this->nested_focus->SetDirty(this);
 
		if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
 
		if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
 
	}
 
	this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
 
	return true;
 
}
 

	
 
/**
 
 * Called when window looses focus
 
 */
 
void Window::OnFocusLost()
 
{
 
	if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
 
	if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
 
}
 

	
 
/**
 
 * Sets the enabled/disabled status of a list of widgets.
 
 * By default, widgets are enabled.
 
 * On certain conditions, they have to be disabled.
 
 * @param disab_stat status to use ie: disabled = true, enabled = false
 
 * @param widgets list of widgets ended by WIDGET_LIST_END
 
 */
 
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
 
{
 
	va_list wdg_list;
0 comments (0 inline, 0 general)