video/cocoa_v.m
changeset 2827 12c9eda7edcd
parent 2743 a6c91eb763e8
child 2845 e520ad0a77b7
equal deleted inserted replaced
2826:b1dbd94a5e23 2827:12c9eda7edcd
   173 
   173 
   174 	uint16 palette16[256];
   174 	uint16 palette16[256];
   175 	uint32 palette32[256];
   175 	uint32 palette32[256];
   176 } _cocoa_video_data;
   176 } _cocoa_video_data;
   177 
   177 
   178 
   178 static bool _cocoa_video_started = false;
       
   179 static bool _cocoa_video_dialog = false;
   179 
   180 
   180 
   181 
   181 
   182 
   182 
   183 
   183 /******************************************************************************************
   184 /******************************************************************************************
  1870 /* The main class of the application, the application's delegate */
  1871 /* The main class of the application, the application's delegate */
  1871 @implementation OTTDMain
  1872 @implementation OTTDMain
  1872 /* Called when the internal event loop has just started running */
  1873 /* Called when the internal event loop has just started running */
  1873 - (void) applicationDidFinishLaunching: (NSNotification *) note
  1874 - (void) applicationDidFinishLaunching: (NSNotification *) note
  1874 {
  1875 {
  1875     /* Hand off to main application code */
  1876 	/* Hand off to main application code */
  1876 	QZ_GameLoop();
  1877 	QZ_GameLoop();
  1877 
  1878 
  1878 	/* We're done, thank you for playing */
  1879 	/* We're done, thank you for playing */
  1879 	[ NSApp stop:_ottd_main ];
  1880 	[ NSApp stop:_ottd_main ];
  1880 }
  1881 }
  2005 
  2006 
  2006 static void CocoaVideoStop(void)
  2007 static void CocoaVideoStop(void)
  2007 {
  2008 {
  2008 	DEBUG(driver, 1)("cocoa_v: CocoaVideoStop");
  2009 	DEBUG(driver, 1)("cocoa_v: CocoaVideoStop");
  2009 
  2010 
       
  2011 	if(!_cocoa_video_started)
       
  2012 		return;
       
  2013 
  2010 	if(_cocoa_video_data.isset)
  2014 	if(_cocoa_video_data.isset)
  2011 		QZ_UnsetVideoMode();
  2015 		QZ_UnsetVideoMode();
  2012 
  2016 
  2013 	[_ottd_main release];
  2017 	[_ottd_main release];
       
  2018 
       
  2019 	_cocoa_video_started = false;
  2014 }
  2020 }
  2015 
  2021 
  2016 static const char *CocoaVideoStart(const char * const *parm)
  2022 static const char *CocoaVideoStart(const char * const *parm)
  2017 {
  2023 {
  2018 	const char *ret;
  2024 	const char *ret;
  2019 
  2025 
  2020 	DEBUG(driver, 1)("cocoa_v: CocoaVideoStart");
  2026 	DEBUG(driver, 1)("cocoa_v: CocoaVideoStart");
  2021 
  2027 
       
  2028 	if(_cocoa_video_started)
       
  2029 		return "Already started";
       
  2030 	_cocoa_video_started = true;
       
  2031 
       
  2032 	memset(&_cocoa_video_data, 0, sizeof(_cocoa_video_data));
       
  2033 
  2022 	setupApplication();
  2034 	setupApplication();
       
  2035 
       
  2036 	/* Don't create a window or enter fullscreen if we're just going to show a dialog. */
       
  2037 	if(_cocoa_video_dialog)
       
  2038 		return NULL;
  2023 
  2039 
  2024 	QZ_VideoInit();
  2040 	QZ_VideoInit();
  2025 
  2041 
  2026 	ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen);
  2042 	ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen);
  2027 	if(ret != NULL)
  2043 	if(ret != NULL)
  2084 	CocoaVideoChangeRes,
  2100 	CocoaVideoChangeRes,
  2085 	CocoaVideoFullScreen,
  2101 	CocoaVideoFullScreen,
  2086 };
  2102 };
  2087 
  2103 
  2088 
  2104 
       
  2105 
       
  2106 
       
  2107 /* This is needed since sometimes assert is called before the videodriver is initialized */
       
  2108 void CocoaDialog ( const char *title, const char *message, const char *buttonLabel )
       
  2109 {
       
  2110 	bool wasstarted;
       
  2111 
       
  2112 	_cocoa_video_dialog = true;
       
  2113 
       
  2114 	wasstarted = _cocoa_video_started;
       
  2115 	if(!_cocoa_video_started && CocoaVideoStart(NULL) != NULL) {
       
  2116 		fprintf(stderr, "%s: %s\n", title, message);
       
  2117 		return;
       
  2118 	}
       
  2119 
       
  2120 
       
  2121 	NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil);
       
  2122 
       
  2123 	if(!wasstarted)
       
  2124 		CocoaVideoStop();
       
  2125 
       
  2126 	_cocoa_video_dialog = false;
       
  2127 }
       
  2128 
       
  2129 
  2089 /* This is needed since OS X applications are started with the working dir set to / when double-clicked */
  2130 /* This is needed since OS X applications are started with the working dir set to / when double-clicked */
  2090 void cocoaSetWorkingDirectory(void)
  2131 void cocoaSetWorkingDirectory(void)
  2091 {
  2132 {
  2092 	char parentdir[MAXPATHLEN];
  2133 	char parentdir[MAXPATHLEN];
  2093 	int chdir_ret;
  2134 	int chdir_ret;