1
0
Fork 0

(svn r17713) -Cleanup: [OSX] Move variable definitions to first use and apply more coding style.

release/1.0
michi_cc 2009-10-04 21:36:17 +00:00
parent ec90a8778f
commit 9b54d5bbd7
2 changed files with 50 additions and 77 deletions

View File

@ -89,17 +89,11 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
static void setApplicationMenu() static void setApplicationMenu()
{ {
/* warning: this code is very odd */ NSString *appName = @"OTTD";
NSMenu *appleMenu; NSMenu *appleMenu = [ [ NSMenu alloc ] initWithTitle:appName ];
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
appName = @"OTTD";
appleMenu = [[NSMenu alloc] initWithTitle:appName];
/* Add menu items */ /* Add menu items */
title = [@"About " stringByAppendingString:appName]; NSString *title = [ @"About " stringByAppendingString:appName ];
[ appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@"" ]; [ appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@"" ];
[ appleMenu addItem:[ NSMenuItem separatorItem ] ]; [ appleMenu addItem:[ NSMenuItem separatorItem ] ];
@ -107,7 +101,7 @@ static void setApplicationMenu()
title = [ @"Hide " stringByAppendingString:appName ]; title = [ @"Hide " stringByAppendingString:appName ];
[ appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h" ]; [ appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h" ];
menuItem = (NSMenuItem*)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; NSMenuItem *menuItem = [ appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h" ];
[ menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask) ]; [ menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask) ];
[ appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@"" ]; [ appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@"" ];
@ -117,7 +111,6 @@ static void setApplicationMenu()
title = [ @"Quit " stringByAppendingString:appName ]; title = [ @"Quit " stringByAppendingString:appName ];
[ appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q" ]; [ appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q" ];
/* Put menu into the menubar */ /* Put menu into the menubar */
menuItem = [ [ NSMenuItem alloc ] initWithTitle:@"" action:nil keyEquivalent:@"" ]; menuItem = [ [ NSMenuItem alloc ] initWithTitle:@"" action:nil keyEquivalent:@"" ];
[ menuItem setSubmenu:appleMenu ]; [ menuItem setSubmenu:appleMenu ];
@ -134,28 +127,22 @@ static void setApplicationMenu()
/* Create a window menu */ /* Create a window menu */
static void setupWindowMenu() static void setupWindowMenu()
{ {
NSMenu *windowMenu; NSMenu *windowMenu = [ [ NSMenu alloc ] initWithTitle:@"Window" ];
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */ /* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [ windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m" ];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */ /* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; NSMenuItem *menuItem = [ [ NSMenuItem alloc ] initWithTitle:@"Window" action:nil keyEquivalent:@"" ];
[windowMenuItem setSubmenu:windowMenu]; [ menuItem setSubmenu:windowMenu ];
[[NSApp mainMenu] addItem:windowMenuItem]; [ [ NSApp mainMenu ] addItem:menuItem ];
/* Tell the application object that this is now the window menu */ /* Tell the application object that this is now the window menu */
[ NSApp setWindowsMenu:windowMenu ]; [ NSApp setWindowsMenu:windowMenu ];
/* Finally give up our references to the objects */ /* Finally give up our references to the objects */
[ windowMenu release ]; [ windowMenu release ];
[windowMenuItem release]; [ menuItem release ];
} }
static void setupApplication() static void setupApplication()
@ -190,14 +177,12 @@ static void setupApplication()
static void QZ_UpdateVideoModes() static void QZ_UpdateVideoModes()
{ {
uint i, count;
OTTD_Point modes[32];
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
count = _cocoa_subdriver->ListModes(modes, lengthof(modes)); OTTD_Point modes[32];
uint count = _cocoa_subdriver->ListModes(modes, lengthof(modes));
for (i = 0; i < count; i++) { for (uint i = 0; i < count; i++) {
_resolutions[i].width = modes[i].x; _resolutions[i].width = modes[i].x;
_resolutions[i].height = modes[i].y; _resolutions[i].height = modes[i].y;
} }
@ -242,7 +227,7 @@ static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
#ifdef ENABLE_COCOA_QUARTZ #ifdef ENABLE_COCOA_QUARTZ
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
/* /*
* If we get here we are running 10.4 or earlier and either openttd was compiled without the quickdraw driver * If we get here we are running 10.4 or earlier and either openttd was compiled without the QuickDraw driver
* or it failed to load for some reason. Fall back to Quartz if possible even though that driver is slower. * or it failed to load for some reason. Fall back to Quartz if possible even though that driver is slower.
*/ */
if (MacOSVersionIsAtLeast(10, 4, 0)) { if (MacOSVersionIsAtLeast(10, 4, 0)) {
@ -258,9 +243,7 @@ static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback) static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback)
{ {
CocoaSubdriver *ret; CocoaSubdriver *ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp);
ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp);
if (ret != NULL) return ret; if (ret != NULL) return ret;
if (!fallback) return NULL; if (!fallback) return NULL;
@ -297,8 +280,6 @@ void VideoDriver_Cocoa::Stop()
const char *VideoDriver_Cocoa::Start(const char * const *parm) const char *VideoDriver_Cocoa::Start(const char * const *parm)
{ {
int width, height, bpp;
if (!MacOSVersionIsAtLeast(10, 3, 0)) return "The Cocoa video driver requires Mac OS X 10.3 or later."; if (!MacOSVersionIsAtLeast(10, 3, 0)) return "The Cocoa video driver requires Mac OS X 10.3 or later.";
if (_cocoa_video_started) return "Already started"; if (_cocoa_video_started) return "Already started";
@ -309,9 +290,9 @@ const char *VideoDriver_Cocoa::Start(const char * const *parm)
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */ /* Don't create a window or enter fullscreen if we're just going to show a dialog. */
if (_cocoa_video_dialog) return NULL; if (_cocoa_video_dialog) return NULL;
width = _cur_resolution.width; int width = _cur_resolution.width;
height = _cur_resolution.height; int height = _cur_resolution.height;
bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true); _cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true);
if (_cocoa_subdriver == NULL) { if (_cocoa_subdriver == NULL) {
@ -320,7 +301,6 @@ const char *VideoDriver_Cocoa::Start(const char * const *parm)
} }
QZ_GameSizeChanged(); QZ_GameSizeChanged();
QZ_UpdateVideoModes(); QZ_UpdateVideoModes();
return NULL; return NULL;
@ -341,14 +321,11 @@ void VideoDriver_Cocoa::MainLoop()
bool VideoDriver_Cocoa::ChangeResolution(int w, int h) bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
{ {
bool ret;
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
ret = _cocoa_subdriver->ChangeResolution(w, h); bool ret = _cocoa_subdriver->ChangeResolution(w, h);
QZ_GameSizeChanged(); QZ_GameSizeChanged();
QZ_UpdateVideoModes(); QZ_UpdateVideoModes();
return ret; return ret;
@ -356,11 +333,9 @@ bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen) bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
{ {
bool oldfs;
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
oldfs = _cocoa_subdriver->IsFullscreen(); bool oldfs = _cocoa_subdriver->IsFullscreen();
if (full_screen != oldfs) { if (full_screen != oldfs) {
int width = _cocoa_subdriver->GetWidth(); int width = _cocoa_subdriver->GetWidth();
int height = _cocoa_subdriver->GetHeight(); int height = _cocoa_subdriver->GetHeight();
@ -377,8 +352,8 @@ bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
} }
QZ_GameSizeChanged(); QZ_GameSizeChanged();
QZ_UpdateVideoModes(); QZ_UpdateVideoModes();
return _cocoa_subdriver->IsFullscreen() == full_screen; return _cocoa_subdriver->IsFullscreen() == full_screen;
} }
@ -386,11 +361,9 @@ bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
/* This is needed since sometimes assert is called before the videodriver is initialized */ /* This is needed since sometimes assert is called before the videodriver is initialized */
void CocoaDialog(const char *title, const char *message, const char *buttonLabel) void CocoaDialog(const char *title, const char *message, const char *buttonLabel)
{ {
bool wasstarted;
_cocoa_video_dialog = true; _cocoa_video_dialog = true;
wasstarted = _cocoa_video_started; bool wasstarted = _cocoa_video_started;
if (_video_driver == NULL) { if (_video_driver == NULL) {
setupApplication(); // Setup application before showing dialog setupApplication(); // Setup application before showing dialog
} else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) { } else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) {