129 static void QZ_UnsetVideoMode(); |
131 static void QZ_UnsetVideoMode(); |
130 static void QZ_UpdatePalette(uint start, uint count); |
132 static void QZ_UpdatePalette(uint start, uint count); |
131 static void QZ_WarpCursor(int x, int y); |
133 static void QZ_WarpCursor(int x, int y); |
132 static void QZ_ShowMouse(); |
134 static void QZ_ShowMouse(); |
133 static void QZ_HideMouse(); |
135 static void QZ_HideMouse(); |
134 static void CocoaVideoFullScreen(bool full_screen); |
|
135 |
136 |
136 |
137 |
137 static NSAutoreleasePool *_ottd_autorelease_pool; |
138 static NSAutoreleasePool *_ottd_autorelease_pool; |
138 static OTTDMain *_ottd_main; |
139 static OTTDMain *_ottd_main; |
139 |
140 |
140 |
141 |
141 static struct CocoaVideoData { |
142 static struct VideoDriver_Cocoa::Data { |
142 bool isset; |
143 bool isset; |
143 bool issetting; |
144 bool issetting; |
144 |
145 |
145 CGDirectDisplayID display_id; /* 0 == main display (only support single display) */ |
146 CGDirectDisplayID display_id; /* 0 == main display (only support single display) */ |
146 CFDictionaryRef mode; /* current mode of the display */ |
147 CFDictionaryRef mode; /* current mode of the display */ |
1968 |
1969 |
1969 /****************************************************************************** |
1970 /****************************************************************************** |
1970 * Video driver interface * |
1971 * Video driver interface * |
1971 ******************************************************************************/ |
1972 ******************************************************************************/ |
1972 |
1973 |
1973 static void CocoaVideoStop() |
1974 static FVideoDriver_Cocoa iFVideoDriver_Cocoa; |
|
1975 |
|
1976 void VideoDriver_Cocoa::Stop() |
1974 { |
1977 { |
1975 if (!_cocoa_video_started) return; |
1978 if (!_cocoa_video_started) return; |
1976 |
1979 |
1977 if (_cocoa_video_data.isset) QZ_UnsetVideoMode(); |
1980 if (_cocoa_video_data.isset) QZ_UnsetVideoMode(); |
1978 |
1981 |
1979 [_ottd_main release]; |
1982 [_ottd_main release]; |
1980 |
1983 |
1981 _cocoa_video_started = false; |
1984 _cocoa_video_started = false; |
1982 } |
1985 } |
1983 |
1986 |
1984 static const char *CocoaVideoStart(const char * const *parm) |
1987 const char *VideoDriver_Cocoa::Start(const char * const *parm) |
1985 { |
1988 { |
1986 const char *ret; |
1989 const char *ret; |
1987 |
1990 |
1988 if (_cocoa_video_started) return "Already started"; |
1991 if (_cocoa_video_started) return "Already started"; |
1989 _cocoa_video_started = true; |
1992 _cocoa_video_started = true; |
1996 if (_cocoa_video_dialog) return NULL; |
1999 if (_cocoa_video_dialog) return NULL; |
1997 |
2000 |
1998 QZ_VideoInit(); |
2001 QZ_VideoInit(); |
1999 |
2002 |
2000 ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen); |
2003 ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen); |
2001 if (ret != NULL) CocoaVideoStop(); |
2004 if (ret != NULL) VideoDriver_Cocoa::Stop(); |
2002 |
2005 |
2003 return ret; |
2006 return ret; |
2004 } |
2007 } |
2005 |
2008 |
2006 static void CocoaVideoMakeDirty(int left, int top, int width, int height) |
2009 void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height) |
2007 { |
2010 { |
2008 if (_cocoa_video_data.num_dirty_rects < MAX_DIRTY_RECTS) { |
2011 if (_cocoa_video_data.num_dirty_rects < MAX_DIRTY_RECTS) { |
2009 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].left = left; |
2012 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].left = left; |
2010 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].top = top; |
2013 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].top = top; |
2011 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].right = left + width; |
2014 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].right = left + width; |
2012 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].bottom = top + height; |
2015 _cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].bottom = top + height; |
2013 } |
2016 } |
2014 _cocoa_video_data.num_dirty_rects++; |
2017 _cocoa_video_data.num_dirty_rects++; |
2015 } |
2018 } |
2016 |
2019 |
2017 static void CocoaVideoMainLoop() |
2020 void VideoDriver_Cocoa::MainLoop() |
2018 { |
2021 { |
2019 /* Start the main event loop */ |
2022 /* Start the main event loop */ |
2020 [NSApp run]; |
2023 [NSApp run]; |
2021 } |
2024 } |
2022 |
2025 |
2023 static bool CocoaVideoChangeRes(int w, int h) |
2026 bool VideoDriver_Cocoa::ChangeResolution(int w, int h) |
2024 { |
2027 { |
2025 const char *ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen); |
2028 const char *ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen); |
2026 if (ret != NULL) { |
2029 if (ret != NULL) { |
2027 DEBUG(driver, 0, "cocoa_v: CocoaVideoChangeRes failed with message: %s", ret); |
2030 DEBUG(driver, 0, "cocoa_v: VideoDriver_Cocoa::ChangeResolution failed with message: %s", ret); |
2028 } |
2031 } |
2029 |
2032 |
2030 return ret == NULL; |
2033 return ret == NULL; |
2031 } |
2034 } |
2032 |
2035 |
2033 static void CocoaVideoFullScreen(bool full_screen) |
2036 void VideoDriver_Cocoa::ToggleFullscreen(bool full_screen) |
2034 { |
2037 { |
2035 const char *ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen); |
2038 const char *ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen); |
2036 if (ret != NULL) { |
2039 if (ret != NULL) { |
2037 DEBUG(driver, 0, "cocoa_v: CocoaVideoFullScreen failed with message: %s", ret); |
2040 DEBUG(driver, 0, "cocoa_v: VideoDriver_Cocoa::ToggleFullscreen failed with message: %s", ret); |
2038 } |
2041 } |
2039 |
2042 |
2040 _fullscreen = _cocoa_video_data.fullscreen; |
2043 _fullscreen = _cocoa_video_data.fullscreen; |
2041 } |
2044 } |
2042 |
|
2043 const HalVideoDriver _cocoa_video_driver = { |
|
2044 CocoaVideoStart, |
|
2045 CocoaVideoStop, |
|
2046 CocoaVideoMakeDirty, |
|
2047 CocoaVideoMainLoop, |
|
2048 CocoaVideoChangeRes, |
|
2049 CocoaVideoFullScreen, |
|
2050 }; |
|
2051 |
2045 |
2052 |
2046 |
2053 /* This is needed since sometimes assert is called before the videodriver is initialized */ |
2047 /* This is needed since sometimes assert is called before the videodriver is initialized */ |
2054 void CocoaDialog(const char* title, const char* message, const char* buttonLabel) |
2048 void CocoaDialog(const char* title, const char* message, const char* buttonLabel) |
2055 { |
2049 { |
2056 bool wasstarted; |
2050 bool wasstarted; |
2057 |
2051 |
2058 _cocoa_video_dialog = true; |
2052 _cocoa_video_dialog = true; |
2059 |
2053 |
2060 wasstarted = _cocoa_video_started; |
2054 wasstarted = _cocoa_video_started; |
2061 if (!_cocoa_video_started && CocoaVideoStart(NULL) != NULL) { |
2055 if (!_cocoa_video_started && VideoDriver_Cocoa::Start(NULL) != NULL) { |
2062 fprintf(stderr, "%s: %s\n", title, message); |
2056 fprintf(stderr, "%s: %s\n", title, message); |
2063 return; |
2057 return; |
2064 } |
2058 } |
2065 |
2059 |
2066 NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil); |
2060 NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil); |
2067 |
2061 |
2068 if (!wasstarted) CocoaVideoStop(); |
2062 if (!wasstarted) VideoDriver_Cocoa::Stop(); |
2069 |
2063 |
2070 _cocoa_video_dialog = false; |
2064 _cocoa_video_dialog = false; |
2071 } |
2065 } |
2072 |
2066 |
2073 /* This is needed since OS X application bundles do not have a |
2067 /* This is needed since OS X application bundles do not have a |