Changeset - r3082:12642bff9b64
[Not reviewed]
master
0 1 0
bjarni - 19 years ago 2006-02-24 22:12:11
bjarni@openttd.org
(svn r3671) -Code cleanup: fixed style and removed commented out code in video/cocoa_v.m
1 file changed with 1 insertions and 11 deletions:
0 comments (0 inline, 0 general)
video/cocoa_v.m
Show inline comments
 
@@ -861,117 +861,111 @@ static void QZ_SetPortAlphaOpaque(void)
 

	
 
	/* Allocate new buffer */
 
	free(_cocoa_video_data.pixels);
 
	_cocoa_video_data.pixels = (uint8*)malloc(newViewFrame.size.width * newViewFrame.size.height);
 
	assert(_cocoa_video_data.pixels != NULL);
 

	
 

	
 
	/* Tell the game that the resolution changed */
 
	_cocoa_video_data.width = newViewFrame.size.width;
 
	_cocoa_video_data.height = newViewFrame.size.height;
 

	
 
	_screen.width = _cocoa_video_data.width;
 
	_screen.height = _cocoa_video_data.height;
 
	_screen.pitch = _cocoa_video_data.width;
 

	
 
	GameSizeChanged();
 

	
 
	/* Redraw screen */
 
	_cocoa_video_data.num_dirty_rects = MAX_DIRTY_RECTS;
 
}
 

	
 
- (void)appDidHide:(NSNotification*)note
 
{
 
	_cocoa_video_data.active = false;
 
//	DEBUG(driver, 1)("cocoa_v: appDidHide");
 
}
 

	
 

	
 
- (void)appWillUnhide:(NSNotification*)note
 
{
 
	QZ_SetPortAlphaOpaque ();
 

	
 
	/* save current visible surface */
 
	[ self cacheImageInRect:[ _cocoa_video_data.qdview frame ] ];
 
}
 

	
 
- (void)appDidUnhide:(NSNotification*)note
 
{
 
	/* restore cached image, since it may not be current, post expose event too */
 
	[ self restoreCachedImage ];
 

	
 
	_cocoa_video_data.active = true;
 
//	DEBUG(driver, 1)("cocoa_v: appDidUnhide");
 
}
 

	
 

	
 
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
 
{
 
	/* Make our window subclass receive these application notifications */
 
	[ [ NSNotificationCenter defaultCenter ] addObserver:self
 
	selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ];
 

	
 
	[ [ NSNotificationCenter defaultCenter ] addObserver:self
 
	selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ];
 

	
 
	[ [ NSNotificationCenter defaultCenter ] addObserver:self
 
	selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ];
 

	
 
	return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
 
}
 

	
 
@end
 

	
 
@implementation OTTD_QuartzWindowDelegate
 
- (BOOL)windowShouldClose:(id)sender
 
{
 
	QZ_AskQuit();
 

	
 
	return NO;
 
}
 

	
 
- (void)windowDidBecomeKey:(NSNotification*)aNotification
 
{
 
	_cocoa_video_data.active = true;
 
//	DEBUG(driver, 1)("cocoa_v: windowDidBecomeKey");
 
}
 

	
 
- (void)windowDidResignKey:(NSNotification*)aNotification
 
{
 
	_cocoa_video_data.active = false;
 
//	DEBUG(driver, 1)("cocoa_v: windowDidResignKey");
 
}
 

	
 
- (void)windowDidBecomeMain:(NSNotification*)aNotification
 
{
 
	_cocoa_video_data.active = true;
 
//	DEBUG(driver, 1)("cocoa_v: windowDidBecomeMain");
 
}
 

	
 
- (void)windowDidResignMain:(NSNotification*)aNotification
 
{
 
	_cocoa_video_data.active = false;
 
//	DEBUG(driver, 1)("cocoa_v: windowDidResignMain");
 
}
 

	
 
@end
 

	
 

	
 
static void QZ_UpdateWindowPalette(uint start, uint count)
 
{
 
	uint i;
 

	
 
	switch (_cocoa_video_data.device_bpp) {
 
		case 32:
 
			for (i = start; i < start + count; i++) {
 
				uint32 clr32 = 0xff000000;
 
				clr32 |= (uint32)_cur_palette[i].r << 16;
 
				clr32 |= (uint32)_cur_palette[i].g << 8;
 
				clr32 |= (uint32)_cur_palette[i].b;
 
				_cocoa_video_data.palette32[i] = clr32;
 
			}
 
			break;
 
		case 16:
 
			for (i = start; i < start + count; i++) {
 
				uint16 clr16 = 0x0000;
 
				clr16 |= (uint16)((_cur_palette[i].r >> 3) & 0x1f) << 10;
 
				clr16 |= (uint16)((_cur_palette[i].g >> 3) & 0x1f) << 5;
 
@@ -1462,51 +1456,49 @@ static void QZ_WaitForVerticalBlank(void
 
	CSleep((uint32)(adjustment * 1000));
 
}
 

	
 
static void QZ_DrawScreen(void)
 
{
 
	const uint8* src;
 
	uint8* dst;
 
	uint height;
 
	uint width;
 
	uint pitch;
 
	uint y;
 
	uint num_dirty_rects;
 
	uint length_drawn;
 
	uint left;
 
	uint i;
 

	
 
	src = _cocoa_video_data.pixels;
 
	dst = (uint8*)_cocoa_video_data.realpixels;
 
	height = _cocoa_video_data.height;
 
	width  = _cocoa_video_data.width;
 
	pitch  = _cocoa_video_data.pitch;
 
	num_dirty_rects = _cocoa_video_data.num_dirty_rects;
 

	
 
	/* Check if we need to do anything */
 
	if (_cocoa_video_data.num_dirty_rects == 0 ) {
 
		return;
 
	}
 
	if (_cocoa_video_data.num_dirty_rects == 0 ) return;
 

	
 
	if (num_dirty_rects >= MAX_DIRTY_RECTS) {
 
		num_dirty_rects = 1;
 
		_cocoa_video_data.dirty_rects[0].left = 0;
 
		_cocoa_video_data.dirty_rects[0].top = 0;
 
		_cocoa_video_data.dirty_rects[0].right = _cocoa_video_data.width;
 
		_cocoa_video_data.dirty_rects[0].bottom = _cocoa_video_data.height;
 
	}
 

	
 
	QZ_WaitForVerticalBlank();
 
	/* Build the region of dirty rectangles */
 
	for (i = 0; i < num_dirty_rects; i++) {
 

	
 
		y = _cocoa_video_data.dirty_rects[i].top;
 
		left = _cocoa_video_data.dirty_rects[i].left;
 
		length_drawn = _cocoa_video_data.dirty_rects[i].right - left + 1;
 
		height = _cocoa_video_data.dirty_rects[i].bottom;
 
		for (; y <= height; y++) memcpy(dst + y * pitch + left, src + y * width +left, length_drawn);
 
	}
 

	
 
	_cocoa_video_data.num_dirty_rects = 0;
 
}
 

	
 
static int QZ_ListFullscreenModes(OTTDPoint* mode_list, int max_modes)
 
@@ -1786,90 +1778,88 @@ static CGPoint QZ_PrivateLocalToCG(NSPoi
 

	
 
	cgp.x = p->x;
 
	cgp.y = p->y;
 

	
 
	return cgp;
 
}
 

	
 
static void QZ_WarpCursor(int x, int y)
 
{
 
	NSPoint p;
 
	CGPoint cgp;
 

	
 
	/* Only allow warping when in foreground */
 
	if (![ NSApp isActive ]) return;
 

	
 
	p = NSMakePoint(x, y);
 
	cgp = QZ_PrivateLocalToCG(&p);
 

	
 
	/* this is the magic call that fixes cursor "freezing" after warp */
 
	CGSetLocalEventsSuppressionInterval(0.0);
 
	/* Do the actual warp */
 
	CGWarpMouseCursorPosition(cgp);
 

	
 
	/* Generate the mouse moved event */
 
//	SDL_PrivateMouseMotion(0, 0, x, y);
 
}
 

	
 
static void QZ_ShowMouse(void)
 
{
 
	if (!_cocoa_video_data.cursor_visible) {
 
		[ NSCursor unhide ];
 
		_cocoa_video_data.cursor_visible = true;
 
	}
 
}
 

	
 
static void QZ_HideMouse(void)
 
{
 
	if (_cocoa_video_data.cursor_visible) {
 
#ifndef _DEBUG
 
		[ NSCursor hide ];
 
#endif
 
		_cocoa_video_data.cursor_visible = false;
 
	}
 
}
 

	
 

	
 
/******************************************************************************
 
 *                             OS X application creation                      *
 
 ******************************************************************************/
 

	
 
/* The main class of the application, the application's delegate */
 
@implementation OTTDMain
 
/* Called when the internal event loop has just started running */
 
- (void) applicationDidFinishLaunching: (NSNotification*) note
 
{
 
	/* Hand off to main application code */
 
	QZ_GameLoop();
 

	
 
	/* We're done, thank you for playing */
 
	[ NSApp stop:_ottd_main ];
 
}
 

	
 
/* Display the in game quit confirmation dialog */
 
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender
 
{
 
//	DEBUG(driver, 1)("cocoa_v: applicationShouldTerminate");
 

	
 
	QZ_AskQuit();
 

	
 
	return NSTerminateCancel;		// NSTerminateLater ?
 
}
 
@end
 

	
 
static void setApplicationMenu(void)
 
{
 
	/* warning: this code is very odd */
 
	NSMenu *appleMenu;
 
	NSMenuItem *menuItem;
 
	NSString *title;
 
	NSString *appName;
 

	
 
	appName = @"OTTD";
 
	appleMenu = [[NSMenu alloc] initWithTitle:appName];
 

	
 
	/* Add menu items */
 
	title = [@"About " stringByAppendingString:appName];
 
	[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
 

	
 
	[appleMenu addItem:[NSMenuItem separatorItem]];
 

	
0 comments (0 inline, 0 general)