Changeset - r18160:133e96e28508
[Not reviewed]
master
0 12 0
michi_cc - 13 years ago 2011-10-04 21:35:40
michi_cc@openttd.org
(svn r22999) -Codechange: Allow changing the blitter during the running game.
12 files changed with 97 insertions and 46 deletions:
0 comments (0 inline, 0 general)
src/video/allegro_v.cpp
Show inline comments
 
@@ -546,13 +546,18 @@ bool VideoDriver_Allegro::ToggleFullscre
 
#else
 
	_fullscreen = fullscreen;
 
	GetVideoModes(); // get the list of available video modes
 
	if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) {
 
		/* switching resolution failed, put back full_screen to original status */
 
		_fullscreen ^= true;
 
		return false;
 
	}
 
	return true;
 
#endif
 
}
 

	
 
bool VideoDriver_Allegro::AfterBlitterChange()
 
{
 
	return CreateMainSurface(_screen.width, _screen.height);
 
}
 

	
 
#endif /* WITH_ALLEGRO */
src/video/allegro_v.h
Show inline comments
 
@@ -19,24 +19,27 @@ class VideoDriver_Allegro: public VideoD
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

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

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

	
 
	/* virtual */ bool AfterBlitterChange();
 

	
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** Factory for the allegro video driver. */
 
class FVideoDriver_Allegro: public VideoDriverFactory<FVideoDriver_Allegro> {
 
public:
 
	static const int priority = 4;
 
	/* virtual */ const char *GetName() { return "allegro"; }
 
	/* virtual */ const char *GetDescription() { return "Allegro Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Allegro(); }
 
};
 

	
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -38,24 +38,29 @@ public:
 
	 * @param w New window width
 
	 * @param h New window height
 
	 * @return Whether change was successful
 
	 */
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/** Set a new window mode
 
	 * @param fullscreen Whether to set fullscreen mode or not
 
	 * @return Whether changing the screen mode was successful
 
	 */
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 

	
 
	/** Callback invoked after the blitter was changed.
 
	 * @return True if no error.
 
	 */
 
	/* virtual */ bool AfterBlitterChange();
 

	
 
	/** Return driver name
 
	 * @return driver name
 
	 */
 
	/* virtual */ const char *GetName() const { return "cocoa"; }
 
};
 

	
 
class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "cocoa"; }
 
	/* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
 
@@ -114,25 +119,25 @@ public:
 
	virtual void MakeDirty(int left, int top, int width, int height) = 0;
 

	
 
	/** Update the palette */
 
	virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
 

	
 
	virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
 

	
 
	/** Change window resolution
 
	 * @param w New window width
 
	 * @param h New window height
 
	 * @return Whether change was successful
 
	 */
 
	virtual bool ChangeResolution(int w, int h) = 0;
 
	virtual bool ChangeResolution(int w, int h, int bpp) = 0;
 

	
 
	/** Are we in fullscreen mode
 
	 * @return whether fullscreen mode is currently used
 
	 */
 
	virtual bool IsFullscreen() = 0;
 

	
 
	/** Toggle between fullscreen and windowed mode
 
	 * @return whether switch was successfull
 
	 */
 
	virtual bool ToggleFullscreen() { return false; };
 

	
 
	/** Return the width of the current view
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -391,25 +391,25 @@ void VideoDriver_Cocoa::MainLoop()
 

	
 
/**
 
 * Change the resolution when using a cocoa video driver.
 
 *
 
 * @param w New window width.
 
 * @param h New window height.
 
 * @return Whether the video driver was successfully updated.
 
 */
 
bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
 
{
 
	assert(_cocoa_subdriver != NULL);
 

	
 
	bool ret = _cocoa_subdriver->ChangeResolution(w, h);
 
	bool ret = _cocoa_subdriver->ChangeResolution(w, h, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth());
 

	
 
	QZ_GameSizeChanged();
 
	QZ_UpdateVideoModes();
 

	
 
	return ret;
 
}
 

	
 
/**
 
 * Toggle between windowed and full screen mode for cocoa display driver.
 
 *
 
 * @param full_screen Whether to switch to full screen or not.
 
 * @return Whether the mode switch was successful.
 
@@ -435,24 +435,34 @@ bool VideoDriver_Cocoa::ToggleFullscreen
 
			_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, oldfs, true);
 
			if (_cocoa_subdriver == NULL) error("Cocoa: Failed to create subdriver");
 
		}
 
	}
 

	
 
	QZ_GameSizeChanged();
 
	QZ_UpdateVideoModes();
 

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

	
 
/**
 
 * Callback invoked after the blitter was changed.
 
 *
 
 * @return True if no error.
 
 */
 
bool VideoDriver_Cocoa::AfterBlitterChange()
 
{
 
	return this->ChangeResolution(_screen.width, _screen.height);
 
}
 

	
 
/**
 
 * Catch asserts prior to initialization of the videodriver.
 
 *
 
 * @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;
 

	
src/video/cocoa/fullscreen.mm
Show inline comments
 
@@ -241,48 +241,48 @@ class FullscreenSubdriver: public CocoaS
 
		double target = this->device_height;
 

	
 
		/* Figure out the first delay so we start off about right */
 
		double position = CGDisplayBeamPosition(this->display_id);
 
		if (position > target) position = 0;
 

	
 
		double adjustment = (target - position) / linesPerSecond;
 

	
 
		CSleep((uint32)(adjustment * 1000));
 
	}
 

	
 

	
 
	bool SetVideoMode(int w, int h)
 
	bool SetVideoMode(int w, int h, int bpp)
 
	{
 
		/* Define this variables at the top (against coding style) because
 
		 * otherwise GCC 4.2 barfs at the goto's jumping over variable initialization. */
 
		NSRect screen_rect;
 
		int gamma_error;
 
		NSPoint mouseLocation;
 

	
 
		/* Destroy any previous mode */
 
		if (this->pixel_buffer != NULL) {
 
			free(this->pixel_buffer);
 
			this->pixel_buffer = NULL;
 
		}
 

	
 
		/* See if requested mode exists */
 
		boolean_t exact_match;
 
		this->cur_mode = CGDisplayBestModeForParameters(this->display_id, this->device_depth, w, h, &exact_match);
 
		this->cur_mode = CGDisplayBestModeForParameters(this->display_id, bpp, w, h, &exact_match);
 

	
 
		/* If the mode wasn't an exact match, check if it has the right bpp, and update width and height */
 
		if (!exact_match) {
 
			int bpp;
 
			int act_bpp;
 
			CFNumberRef number = (const __CFNumber*) CFDictionaryGetValue(this->cur_mode, kCGDisplayBitsPerPixel);
 
			CFNumberGetValue(number, kCFNumberSInt32Type, &bpp);
 
			if (bpp != this->device_depth) {
 
			CFNumberGetValue(number, kCFNumberSInt32Type, &act_bpp);
 
			if (act_bpp != bpp) {
 
				DEBUG(driver, 0, "Failed to find display resolution");
 
				goto ERR_NO_MATCH;
 
			}
 

	
 
			number = (const __CFNumber*)CFDictionaryGetValue(this->cur_mode, kCGDisplayWidth);
 
			CFNumberGetValue(number, kCFNumberSInt32Type, &w);
 

	
 
			number = (const __CFNumber*)CFDictionaryGetValue(this->cur_mode, kCGDisplayHeight);
 
			CFNumberGetValue(number, kCFNumberSInt32Type, &h);
 
		}
 

	
 
		/* Capture the main screen */
 
@@ -314,24 +314,25 @@ class FullscreenSubdriver: public CocoaS
 
		if (MacOSVersionIsAtLeast(10, 7, 0)) {
 
			this->window_buffer = NULL;
 
			this->window_pitch  = NULL;
 
		} else {
 
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
 
			this->window_buffer = CGDisplayBaseAddress(this->display_id);
 
			this->window_pitch  = CGDisplayBytesPerRow(this->display_id);
 
#endif
 
		}
 

	
 
		this->device_width  = CGDisplayPixelsWide(this->display_id);
 
		this->device_height = CGDisplayPixelsHigh(this->display_id);
 
		this->device_depth  = bpp;
 

	
 
		/* Setup double-buffer emulation */
 
		this->pixel_buffer = malloc(this->device_width * this->device_height * this->device_depth / 8);
 
		if (this->pixel_buffer == NULL) {
 
			DEBUG(driver, 0, "Failed to allocate memory for double buffering");
 
			goto ERR_DOUBLEBUF;
 
		}
 

	
 
		if (this->device_depth == 8 && !CGDisplayCanSetPalette(this->display_id)) {
 
			DEBUG(driver, 0, "Not an indexed display mode.");
 
			goto ERR_NOT_INDEXED;
 
		}
 
@@ -409,40 +410,36 @@ ERR_NO_MATCH:
 
		if (this->pixel_buffer != NULL) {
 
			free(this->pixel_buffer);
 
			this->pixel_buffer = NULL;
 
		}
 

	
 
		if (!gamma_error) this->FadeGammaIn(&gamma_table);
 

	
 
		this->device_width  = CGDisplayPixelsWide(this->display_id);
 
		this->device_height = CGDisplayPixelsHigh(this->display_id);
 
	}
 

	
 
public:
 
	FullscreenSubdriver(int bpp)
 
	FullscreenSubdriver()
 
	{
 
		if (bpp != 8 && bpp != 32) {
 
			error("Cocoa: This video driver only supports 8 and 32 bpp blitters.");
 
		}
 

	
 
		/* Initialize the video settings; this data persists between mode switches */
 
		this->display_id = kCGDirectMainDisplay;
 
		this->save_mode  = CGDisplayCurrentMode(this->display_id);
 

	
 
		if (bpp == 8) this->palette = CGPaletteCreateDefaultColorPalette();
 
		this->palette = CGPaletteCreateDefaultColorPalette();
 

	
 
		this->device_width  = CGDisplayPixelsWide(this->display_id);
 
		this->device_height = CGDisplayPixelsHigh(this->display_id);
 
		this->device_depth  = bpp;
 
		this->pixel_buffer   = NULL;
 
		this->device_depth  = 0;
 
		this->pixel_buffer  = NULL;
 

	
 
		this->num_dirty_rects = MAX_DIRTY_RECTS;
 
	}
 

	
 
	virtual ~FullscreenSubdriver()
 
	{
 
		this->RestoreVideoMode();
 
	}
 

	
 
	virtual void Draw(bool force_update)
 
	{
 
		const uint8 *src   = (uint8 *)this->pixel_buffer;
 
@@ -503,32 +500,34 @@ public:
 

	
 
			CGPaletteSetColorAtIndex(this->palette, color, index);
 
		}
 

	
 
		CGDisplaySetPalette(this->display_id, this->palette);
 
	}
 

	
 
	virtual uint ListModes(OTTD_Point *modes, uint max_modes)
 
	{
 
		return QZ_ListModes(modes, max_modes, this->display_id, this->device_depth);
 
	}
 

	
 
	virtual bool ChangeResolution(int w, int h)
 
	virtual bool ChangeResolution(int w, int h, int bpp)
 
	{
 
		int old_width  = this->device_width;
 
		int old_height = this->device_height;
 
		int old_bpp    = this->device_depth;
 

	
 
		if (SetVideoMode(w, h)) return true;
 
		if (bpp != 8 && bpp != 32) error("Cocoa: This video driver only supports 8 and 32 bpp blitters.");
 

	
 
		if (old_width != 0 && old_height != 0) SetVideoMode(old_width, old_height);
 
		if (SetVideoMode(w, h, bpp)) return true;
 
		if (old_width != 0 && old_height != 0) SetVideoMode(old_width, old_height, old_bpp);
 

	
 
		return false;
 
	}
 

	
 
	virtual bool IsFullscreen()
 
	{
 
		return true;
 
	}
 

	
 
	virtual int GetWidth()
 
	{
 
		return this->device_width;
 
@@ -574,23 +573,23 @@ public:
 

	
 
CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp)
 
{
 
	/* OSX 10.7 doesn't support this way of the fullscreen driver. If we end up here
 
	 * OpenTTD was compiled without SDK 10.7 available and - and thus we don't support
 
	 * fullscreen mode in OSX 10.7 or higher, as necessary elements for this way have
 
	 * been removed from the API.
 
	 */
 
	if (MacOSVersionIsAtLeast(10, 7, 0)) {
 
		return NULL;
 
	}
 

	
 
	FullscreenSubdriver *ret = new FullscreenSubdriver(bpp);
 
	FullscreenSubdriver *ret = new FullscreenSubdriver();
 

	
 
	if (!ret->ChangeResolution(width, height)) {
 
	if (!ret->ChangeResolution(width, height, bpp)) {
 
		delete ret;
 
		return NULL;
 
	}
 

	
 
	return ret;
 
}
 

	
 
#endif /* WITH_COCOA */
src/video/cocoa/wnd_quartz.mm
Show inline comments
 
@@ -54,37 +54,37 @@ class WindowQuartzSubdriver: public Coco
 
private:
 
	/**
 
	 * This function copies 8bpp pixels from the screen buffer in 32bpp windowed mode.
 
	 *
 
	 * @param left The x coord for the left edge of the box to blit.
 
	 * @param top The y coord for the top edge of the box to blit.
 
	 * @param right The x coord for the right edge of the box to blit.
 
	 * @param bottom The y coord for the bottom edge of the box to blit.
 
	 */
 
	void BlitIndexedToView32(int left, int top, int right, int bottom);
 

	
 
	virtual void GetDeviceInfo();
 
	virtual bool SetVideoMode(int width, int height);
 
	virtual bool SetVideoMode(int width, int height, int bpp);
 

	
 
public:
 
	WindowQuartzSubdriver(int bpp);
 
	WindowQuartzSubdriver();
 
	virtual ~WindowQuartzSubdriver();
 

	
 
	virtual void Draw(bool force_update);
 
	virtual void MakeDirty(int left, int top, int width, int height);
 
	virtual void UpdatePalette(uint first_color, uint num_colors);
 

	
 
	virtual uint ListModes(OTTD_Point *modes, uint max_modes);
 

	
 
	virtual bool ChangeResolution(int w, int h);
 
	virtual bool ChangeResolution(int w, int h, int bpp);
 

	
 
	virtual bool IsFullscreen() { return false; }
 
	virtual bool ToggleFullscreen(); /* Full screen mode on OSX 10.7 */
 

	
 
	virtual int GetWidth() { return window_width; }
 
	virtual int GetHeight() { return window_height; }
 
	virtual void *GetPixelBuffer() { return buffer_depth == 8 ? pixel_buffer : window_buffer; }
 

	
 
	/* Convert local coordinate to window server (CoreGraphics) coordinate */
 
	virtual CGPoint PrivateLocalToCG(NSPoint *p);
 

	
 
	virtual NSPoint GetMouseLocation(NSEvent *event);
 
@@ -239,25 +239,25 @@ void WindowQuartzSubdriver::GetDeviceInf
 
 * @return Whether we switched to full screen
 
 */
 
bool WindowQuartzSubdriver::ToggleFullscreen()
 
{
 
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
 
	[this->window toggleFullScreen:this->window];
 
	return true;
 
#else
 
	return false;
 
#endif
 
}
 

	
 
bool WindowQuartzSubdriver::SetVideoMode(int width, int height)
 
bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp)
 
{
 
	this->setup = true;
 
	this->GetDeviceInfo();
 

	
 
	if (width > this->device_width) width = this->device_width;
 
	if (height > this->device_height) height = this->device_height;
 

	
 
	NSRect contentRect = NSMakeRect(0, 0, width, height);
 

	
 
	/* Check if we should recreate the window */
 
	if (this->window == nil) {
 
		OTTD_CocoaWindowDelegate *delegate;
 
@@ -328,24 +328,25 @@ bool WindowQuartzSubdriver::SetVideoMode
 

	
 
		/* Ensure frame height - title bar height >= view height */
 
		contentRect.size.height = Clamp(height, 0, [ this->window frame ].size.height - 22 /* 22 is the height of title bar of window*/);
 

	
 
		if (this->cocoaview != nil) {
 
			height = contentRect.size.height;
 
			[ this->cocoaview setFrameSize:contentRect.size ];
 
		}
 
	}
 

	
 
	this->window_width = width;
 
	this->window_height = height;
 
	this->buffer_depth = bpp;
 

	
 
	[ this->window center ];
 

	
 
	/* Only recreate the view if it doesn't already exist */
 
	if (this->cocoaview == nil) {
 
		this->cocoaview = [ [ OTTD_QuartzView alloc ] initWithFrame:contentRect ];
 
		if (this->cocoaview == nil) {
 
			DEBUG(driver, 0, "Could not create the Quartz view.");
 
			this->setup = false;
 
			return false;
 
		}
 

	
 
@@ -372,29 +373,29 @@ void WindowQuartzSubdriver::BlitIndexedT
 
	uint32       *dst   = (uint32*)this->window_buffer;
 
	uint          width = this->window_width;
 
	uint          pitch = this->window_width;
 

	
 
	for (int y = top; y < bottom; y++) {
 
		for (int x = left; x < right; x++) {
 
			dst[y * pitch + x] = pal[src[y * width + x]];
 
		}
 
	}
 
}
 

	
 

	
 
WindowQuartzSubdriver::WindowQuartzSubdriver(int bpp)
 
WindowQuartzSubdriver::WindowQuartzSubdriver()
 
{
 
	this->window_width  = 0;
 
	this->window_height = 0;
 
	this->buffer_depth  = bpp;
 
	this->buffer_depth  = 0;
 
	this->window_buffer  = NULL;
 
	this->pixel_buffer  = NULL;
 
	this->active        = false;
 
	this->setup         = false;
 

	
 
	this->window = nil;
 
	this->cocoaview = nil;
 

	
 
	this->cgcontext = NULL;
 

	
 
	this->num_dirty_rects = MAX_DIRTY_RECTS;
 
}
 
@@ -472,31 +473,32 @@ void WindowQuartzSubdriver::UpdatePalett
 
		clr |= (uint32)_cur_palette[i].b;
 
		this->palette[i] = clr;
 
	}
 

	
 
	this->num_dirty_rects = MAX_DIRTY_RECTS;
 
}
 

	
 
uint WindowQuartzSubdriver::ListModes(OTTD_Point *modes, uint max_modes)
 
{
 
	return QZ_ListModes(modes, max_modes, kCGDirectMainDisplay, this->buffer_depth);
 
}
 

	
 
bool WindowQuartzSubdriver::ChangeResolution(int w, int h)
 
bool WindowQuartzSubdriver::ChangeResolution(int w, int h, int bpp)
 
{
 
	int old_width  = this->window_width;
 
	int old_height = this->window_height;
 
	int old_bpp    = this->buffer_depth;
 

	
 
	if (this->SetVideoMode(w, h)) return true;
 
	if (old_width != 0 && old_height != 0) this->SetVideoMode(old_width, old_height);
 
	if (this->SetVideoMode(w, h, bpp)) return true;
 
	if (old_width != 0 && old_height != 0) this->SetVideoMode(old_width, old_height, old_bpp);
 

	
 
	return false;
 
}
 

	
 
/* Convert local coordinate to window server (CoreGraphics) coordinate */
 
CGPoint WindowQuartzSubdriver::PrivateLocalToCG(NSPoint *p)
 
{
 

	
 
	p->y = this->window_height - p->y;
 
	*p = [ this->cocoaview convertPoint:*p toView:nil ];
 

	
 
	*p = [ this->window convertBaseToScreen:*p ];
 
@@ -590,26 +592,26 @@ bool WindowQuartzSubdriver::WindowResize
 
CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp)
 
{
 
	if (!MacOSVersionIsAtLeast(10, 4, 0)) {
 
		DEBUG(driver, 0, "The cocoa quartz subdriver requires Mac OS X 10.4 or later.");
 
		return NULL;
 
	}
 

	
 
	if (bpp != 8 && bpp != 32) {
 
		DEBUG(driver, 0, "The cocoa quartz subdriver only supports 8 and 32 bpp.");
 
		return NULL;
 
	}
 

	
 
	WindowQuartzSubdriver *ret = new WindowQuartzSubdriver(bpp);
 
	WindowQuartzSubdriver *ret = new WindowQuartzSubdriver();
 

	
 
	if (!ret->ChangeResolution(width, height)) {
 
	if (!ret->ChangeResolution(width, height, bpp)) {
 
		delete ret;
 
		return NULL;
 
	}
 

	
 
	return ret;
 
}
 

	
 

	
 
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 */
 
#endif /* ENABLE_COCOA_QUARTZ */
 
#endif /* WITH_COCOA */
src/video/cocoa/wnd_quickdraw.mm
Show inline comments
 
@@ -72,37 +72,37 @@ private:
 
	 *
 
	 * @param left The x coord for the left edge of the box to blit.
 
	 * @param top The y coord for the top edge of the box to blit.
 
	 * @param right The x coord for the right edge of the box to blit.
 
	 * @param bottom The y coord for the bottom edge of the box to blit.
 
	 */
 
	void BlitIndexedToView16(int left, int top, int right, int bottom);
 

	
 
	inline void BlitToView(int left, int top, int right, int bottom);
 
	void DrawResizeIcon();
 

	
 
	virtual void GetDeviceInfo();
 
	virtual bool SetVideoMode(int width, int height);
 
	virtual bool SetVideoMode(int width, int height, int bpp);
 

	
 
public:
 
	WindowQuickdrawSubdriver(int bpp);
 
	WindowQuickdrawSubdriver();
 
	virtual ~WindowQuickdrawSubdriver();
 

	
 
	virtual void Draw(bool force_update);
 
	virtual void MakeDirty(int left, int top, int width, int height);
 
	virtual void UpdatePalette(uint first_color, uint num_colors);
 

	
 
	virtual uint ListModes(OTTD_Point *modes, uint max_modes);
 

	
 
	virtual bool ChangeResolution(int w, int h);
 
	virtual bool ChangeResolution(int w, int h, int bpp);
 

	
 
	virtual bool IsFullscreen() { return false; }
 

	
 
	virtual int GetWidth() { return window_width; }
 
	virtual int GetHeight() { return window_height; }
 
	virtual void *GetPixelBuffer() { return pixel_buffer; }
 

	
 
	/* Convert local coordinate to window server (CoreGraphics) coordinate */
 
	virtual CGPoint PrivateLocalToCG(NSPoint *p);
 

	
 
	virtual NSPoint GetMouseLocation(NSEvent *event);
 
	virtual bool MouseIsInsideView(NSPoint *pt);
 
@@ -143,30 +143,30 @@ void WindowQuickdrawSubdriver::GetDevice
 

	
 
	/* Gather some information that is useful to know about the display */
 
	CFNumberGetValue((const __CFNumber*)CFDictionaryGetValue(cur_mode, kCGDisplayBitsPerPixel),
 
		kCFNumberSInt32Type, &this->device_depth);
 

	
 
	CFNumberGetValue((const __CFNumber*)CFDictionaryGetValue(cur_mode, kCGDisplayWidth),
 
		kCFNumberSInt32Type, &this->device_width);
 

	
 
	CFNumberGetValue((const __CFNumber*)CFDictionaryGetValue(cur_mode, kCGDisplayHeight),
 
		kCFNumberSInt32Type, &this->device_height);
 
}
 

	
 
bool WindowQuickdrawSubdriver::SetVideoMode(int width, int height)
 
bool WindowQuickdrawSubdriver::SetVideoMode(int width, int height, int bpp)
 
{
 
	this->setup = true;
 
	this->GetDeviceInfo();
 

	
 
	if (this->buffer_depth > this->device_depth) {
 
	if (bpp > this->device_depth) {
 
		DEBUG(driver, 0, "Cannot use a blitter with a higer screen depth than the display when running in windowed mode.");
 
		this->setup = false;
 
		return false;
 
	}
 

	
 
	if (width > this->device_width) width = this->device_width;
 
	if (height > this->device_height) height = this->device_height;
 

	
 
	NSRect contentRect = NSMakeRect(0, 0, width, height);
 

	
 
	/* Check if we should recreate the window */
 
	if (this->window == nil) {
 
@@ -208,24 +208,25 @@ bool WindowQuickdrawSubdriver::SetVideoM
 
		/* We already have a window, just change its size */
 
		[ this->window setContentSize:contentRect.size ];
 
		/* Ensure frame height - title bar height >= view height
 
		 * The height of title bar of the window is 22 pixels */
 
		contentRect.size.height = Clamp(height, 0, [ this->window frame ].size.height - 22);
 
		height = contentRect.size.height;
 
		[ this->cocoaview setFrameSize:contentRect.size ];
 
	}
 

	
 
	/* Update again */
 
	this->window_width = width;
 
	this->window_height = height;
 
	this->buffer_depth = bpp;
 

	
 
	[ this->window center ];
 

	
 
	/* Only recreate the view if it doesn't already exist */
 
	if (this->cocoaview == nil) {
 
		this->cocoaview = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ];
 
		if (this->cocoaview == nil) {
 
			DEBUG(driver, 0, "Could not create the Quickdraw view.");
 
			this->setup = false;
 
			return false;
 
		}
 

	
 
@@ -326,29 +327,29 @@ void WindowQuickdrawSubdriver::DrawResiz
 
			for (int y = 0; y < _resize_icon_height; y++) {
 
				uint16 *trg = (uint16*)this->window_buffer + (yoff + y) * this->window_pitch / 2 + xoff;
 

	
 
				for (int x = 0; x < _resize_icon_width; x++, trg++) {
 
					if (_resize_icon[y * _resize_icon_width + x]) *trg = 0x0000;
 
				}
 
			}
 
			break;
 
	}
 
}
 

	
 

	
 
WindowQuickdrawSubdriver::WindowQuickdrawSubdriver(int bpp)
 
WindowQuickdrawSubdriver::WindowQuickdrawSubdriver()
 
{
 
	this->window_width  = 0;
 
	this->window_height = 0;
 
	this->buffer_depth  = bpp;
 
	this->buffer_depth  = 0;
 
	this->pixel_buffer  = NULL;
 
	this->active        = false;
 
	this->setup         = false;
 

	
 
	this->window = nil;
 
	this->cocoaview = nil;
 

	
 
	this->num_dirty_rects = MAX_DIRTY_RECTS;
 
}
 

	
 
WindowQuickdrawSubdriver::~WindowQuickdrawSubdriver()
 
{
 
@@ -431,32 +432,33 @@ void WindowQuickdrawSubdriver::UpdatePal
 
			}
 
			break;
 
	}
 

	
 
	this->num_dirty_rects = MAX_DIRTY_RECTS;
 
}
 

	
 
uint WindowQuickdrawSubdriver::ListModes(OTTD_Point *modes, uint max_modes)
 
{
 
	return QZ_ListModes(modes, max_modes, kCGDirectMainDisplay, this->buffer_depth);
 
}
 

	
 
bool WindowQuickdrawSubdriver::ChangeResolution(int w, int h)
 
bool WindowQuickdrawSubdriver::ChangeResolution(int w, int h, int bpp)
 
{
 
	int old_width  = this->window_width;
 
	int old_height = this->window_height;
 
	int old_bpp    = this->buffer_depth;
 

	
 
	if (this->SetVideoMode(w, h)) return true;
 
	if (this->SetVideoMode(w, h, bpp)) return true;
 

	
 
	if (old_width != 0 && old_height != 0) this->SetVideoMode(old_width, old_height);
 
	if (old_width != 0 && old_height != 0) this->SetVideoMode(old_width, old_height, old_bpp);
 

	
 
	return false;
 
}
 

	
 
/* Convert local coordinate to window server (CoreGraphics) coordinate */
 
CGPoint WindowQuickdrawSubdriver::PrivateLocalToCG(NSPoint *p)
 
{
 
	*p = [ this->cocoaview convertPoint:*p toView: nil ];
 
	*p = [ this->window convertBaseToScreen:*p ];
 
	p->y = this->device_height - p->y;
 

	
 
	return CGPointMake(p->x, p->y);
 
@@ -535,24 +537,24 @@ CocoaSubdriver *QZ_CreateWindowQuickdraw
 
{
 
	WindowQuickdrawSubdriver *ret;
 

	
 
	if (MacOSVersionIsAtLeast(10, 5, 0)) {
 
		DEBUG(driver, 0, "The cocoa quickdraw subdriver is not recommended for Mac OS X 10.5 or later.");
 
	}
 

	
 
	if (bpp != 8 && bpp != 32) {
 
		DEBUG(driver, 0, "The cocoa quickdraw subdriver only supports 8 and 32 bpp.");
 
		return NULL;
 
	}
 

	
 
	ret = new WindowQuickdrawSubdriver(bpp);
 
	ret = new WindowQuickdrawSubdriver();
 

	
 
	if (!ret->ChangeResolution(width, height)) {
 
	if (!ret->ChangeResolution(width, height, bpp)) {
 
		delete ret;
 
		return NULL;
 
	}
 

	
 
	return ret;
 
}
 

	
 
#endif /* ENABLE_COCOA_QUICKDRAW */
 
#endif /* WITH_COCOA */
src/video/sdl_v.cpp
Show inline comments
 
@@ -626,13 +626,18 @@ bool VideoDriver_SDL::ChangeResolution(i
 
bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
 
{
 
	_fullscreen = fullscreen;
 
	GetVideoModes(); // get the list of available video modes
 
	if (_num_resolutions == 0 || !CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) {
 
		/* switching resolution failed, put back full_screen to original status */
 
		_fullscreen ^= true;
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
bool VideoDriver_SDL::AfterBlitterChange()
 
{
 
	return this->ChangeResolution(_screen.width, _screen.height)
 
}
 

	
 
#endif /* WITH_SDL */
src/video/sdl_v.h
Show inline comments
 
@@ -19,24 +19,27 @@ class VideoDriver_SDL: public VideoDrive
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

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

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

	
 
	/* virtual */ bool AfterBlitterChange();
 

	
 
	/* virtual */ const char *GetName() const { return "sdl"; }
 
};
 

	
 
/** Factory for the SDL video driver. */
 
class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> {
 
public:
 
	static const int priority = 5;
 
	/* virtual */ const char *GetName() { return "sdl"; }
 
	/* virtual */ const char *GetDescription() { return "SDL Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_SDL(); }
 
};
 

	
src/video/video_driver.hpp
Show inline comments
 
@@ -39,24 +39,33 @@ public:
 
	 * @return True if the change succeeded.
 
	 */
 
	virtual bool ChangeResolution(int w, int h) = 0;
 

	
 
	/**
 
	 * Change the full screen setting.
 
	 * @param fullscreen The new setting.
 
	 * @return True if the change succeeded.
 
	 */
 
	virtual bool ToggleFullscreen(bool fullscreen) = 0;
 

	
 
	/**
 
	 * Callback invoked after the blitter was changed.
 
	 * @return True if no error.
 
	 */
 
	virtual bool AfterBlitterChange()
 
	{
 
		return true;
 
	}
 

	
 
	/**
 
	 * Whether the driver has a graphical user interface with the end user.
 
	 * Or in other words, whether we should spawn a thread for world generation
 
	 * and NewGRF scanning so the graphical updates can keep coming. Otherwise
 
	 * progress has to be shown on the console, which uses by definition another
 
	 * thread/process for display purposes.
 
	 * @return True for all drivers except null and dedicated.
 
	 */
 
	virtual bool HasGUI() const
 
	{
 
		return true;
 
	}
 
};
src/video/win32_v.cpp
Show inline comments
 
@@ -140,25 +140,25 @@ static uint MapWindowsKey(uint sym)
 
		if ((uint)(sym - map->vk_from) <= map->vk_count) {
 
			key = sym - map->vk_from + map->map_to;
 
			break;
 
		}
 
	}
 

	
 
	if (GetAsyncKeyState(VK_SHIFT)   < 0) key |= WKC_SHIFT;
 
	if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL;
 
	if (GetAsyncKeyState(VK_MENU)    < 0) key |= WKC_ALT;
 
	return key;
 
}
 

	
 
static bool AllocateDibSection(int w, int h);
 
static bool AllocateDibSection(int w, int h, bool force = false);
 

	
 
static void ClientSizeChanged(int w, int h)
 
{
 
	/* allocate new dib section of the new size */
 
	if (AllocateDibSection(w, h)) {
 
		/* mark all palette colors dirty */
 
		_pal_first_dirty = 0;
 
		_pal_count_dirty = 256;
 

	
 
		BlitterFactoryBase::GetCurrentBlitter()->PostResize();
 

	
 
		GameSizeChanged();
 
@@ -681,36 +681,36 @@ static void RegisterWndClass()
 
			LoadIcon(hinst, MAKEINTRESOURCE(100)),
 
			LoadCursor(NULL, IDC_ARROW),
 
			0,
 
			0,
 
			_T("OTTD")
 
		};
 

	
 
		registered = true;
 
		if (!RegisterClass(&wnd)) usererror("RegisterClass failed");
 
	}
 
}
 

	
 
static bool AllocateDibSection(int w, int h)
 
static bool AllocateDibSection(int w, int h, bool force)
 
{
 
	BITMAPINFO *bi;
 
	HDC dc;
 
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
 

	
 
	w = max(w, 64);
 
	h = max(h, 64);
 

	
 
	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
 

	
 
	if (w == _screen.width && h == _screen.height) return false;
 
	if (!force && w == _screen.width && h == _screen.height) return false;
 

	
 
	_screen.width = w;
 
	_screen.pitch = (bpp == 8) ? Align(w, 4) : w;
 
	_screen.height = h;
 
	bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
 
	memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
 
	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 

	
 
	bi->bmiHeader.biWidth = _wnd.width = w;
 
	bi->bmiHeader.biHeight = -(_wnd.height = h);
 

	
 
	bi->bmiHeader.biPlanes = 1;
 
@@ -918,12 +918,17 @@ void VideoDriver_Win32::MainLoop()
 
bool VideoDriver_Win32::ChangeResolution(int w, int h)
 
{
 
	_wnd.width = _wnd.width_org = w;
 
	_wnd.height = _wnd.height_org = h;
 

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

	
 
bool VideoDriver_Win32::ToggleFullscreen(bool full_screen)
 
{
 
	return this->MakeWindow(full_screen);
 
}
 

	
 
bool VideoDriver_Win32::AfterBlitterChange()
 
{
 
	return AllocateDibSection(_screen.width, _screen.height, true) && this->MakeWindow(_fullscreen);
 
}
src/video/win32_v.h
Show inline comments
 
@@ -19,24 +19,27 @@ class VideoDriver_Win32: public VideoDri
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

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

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

	
 
	/* virtual */ bool AfterBlitterChange();
 

	
 
	/* virtual */ const char *GetName() const { return "win32"; }
 

	
 
	bool MakeWindow(bool full_screen);
 
};
 

	
 
/** The factory for Windows' video driver. */
 
class FVideoDriver_Win32: public VideoDriverFactory<FVideoDriver_Win32> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "win32"; }
 
	/* virtual */ const char *GetDescription() { return "Win32 GDI Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Win32(); }
0 comments (0 inline, 0 general)