1
0
Fork 0

(svn r22678) -Doc: More doxygen sprinkles in MacOSX code and cocoa video driver

release/1.2
planetmaker 2011-07-21 16:13:34 +00:00
parent b09c863e1c
commit e3d9879690
3 changed files with 155 additions and 13 deletions

View File

@ -7,6 +7,8 @@
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file macos.mm Code related to MacOSX. */
#include "../../stdafx.h" #include "../../stdafx.h"
#include "../../core/bitmath_func.hpp" #include "../../core/bitmath_func.hpp"
#include "../../rev.h" #include "../../rev.h"
@ -57,6 +59,13 @@ void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix)
#ifdef WITH_SDL #ifdef WITH_SDL
/**
* Show the system dialogue message (SDL on MacOSX).
*
* @param title Window title.
* @param message Message text.
* @param buttonLabel Button text.
*/
void ShowMacDialog(const char *title, const char *message, const char *buttonLabel) void ShowMacDialog(const char *title, const char *message, const char *buttonLabel)
{ {
NSRunAlertPanel([ NSString stringWithUTF8String:title ], [ NSString stringWithUTF8String:message ], [ NSString stringWithUTF8String:buttonLabel ], nil, nil); NSRunAlertPanel([ NSString stringWithUTF8String:title ], [ NSString stringWithUTF8String:message ], [ NSString stringWithUTF8String:buttonLabel ], nil, nil);
@ -66,6 +75,13 @@ void ShowMacDialog(const char *title, const char *message, const char *buttonLab
extern void CocoaDialog(const char *title, const char *message, const char *buttonLabel); extern void CocoaDialog(const char *title, const char *message, const char *buttonLabel);
/**
* Show the system dialogue message (Cocoa on MacOSX).
*
* @param title Window title.
* @param message Message text.
* @param buttonLabel Button text.
*/
void ShowMacDialog(const char *title, const char *message, const char *buttonLabel) void ShowMacDialog(const char *title, const char *message, const char *buttonLabel)
{ {
CocoaDialog(title, message, buttonLabel); CocoaDialog(title, message, buttonLabel);
@ -74,6 +90,13 @@ void ShowMacDialog(const char *title, const char *message, const char *buttonLab
#else #else
/**
* Show the system dialogue message (console on MacOSX).
*
* @param title Window title.
* @param message Message text.
* @param buttonLabel Button text.
*/
void ShowMacDialog(const char *title, const char *message, const char *buttonLabel) void ShowMacDialog(const char *title, const char *message, const char *buttonLabel)
{ {
fprintf(stderr, "%s: %s\n", title, message); fprintf(stderr, "%s: %s\n", title, message);
@ -82,6 +105,12 @@ void ShowMacDialog(const char *title, const char *message, const char *buttonLab
#endif #endif
/**
* Show an error message.
*
* @param buf error message text.
* @param system message text originates from OS.
*/
void ShowOSErrorBox(const char *buf, bool system) void ShowOSErrorBox(const char *buf, bool system)
{ {
/* Display the error in the best way possible. */ /* Display the error in the best way possible. */
@ -93,7 +122,9 @@ void ShowOSErrorBox(const char *buf, bool system)
} }
/** Determine the current user's locale. */ /**
* Determine and return the current user's locale.
*/
const char *GetCurrentLocale(const char *) const char *GetCurrentLocale(const char *)
{ {
static char retbuf[32] = { '\0' }; static char retbuf[32] = { '\0' };
@ -120,6 +151,13 @@ const char *GetCurrentLocale(const char *)
#ifdef WITH_COCOA #ifdef WITH_COCOA
/**
* Return the contents of the clipboard (COCOA).
*
* @param buffer Clipboard content..
* @param buff_len Length of the clipboard content..
* @return Whether clipboard is empty or not.
*/
bool GetClipboardContents(char *buffer, size_t buff_len) bool GetClipboardContents(char *buffer, size_t buff_len)
{ {
NSPasteboard *pb = [ NSPasteboard generalPasteboard ]; NSPasteboard *pb = [ NSPasteboard generalPasteboard ];

View File

@ -23,17 +23,32 @@
#include <png.h> #include <png.h>
/**
* Handle pnglib error.
*
* @param png_ptr Pointer to png struct.
* @param message Error message text.
*/
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
{ {
DEBUG(misc, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); DEBUG(misc, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr));
longjmp(png_jmpbuf(png_ptr), 1); longjmp(png_jmpbuf(png_ptr), 1);
} }
/**
* Handle warning in pnglib.
*
* @param png_ptr Pointer to png struct.
* @param message Warning message text.
*/
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
{ {
DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr));
} }
/**
* Display a splash image shown on startup (WITH_PNG).
*/
void DisplaySplashImage() void DisplaySplashImage()
{ {
FILE *f = FioFOpenFile(SPLASH_IMAGE_FILE); FILE *f = FioFOpenFile(SPLASH_IMAGE_FILE);
@ -162,6 +177,9 @@ void DisplaySplashImage()
#else /* WITH_PNG */ #else /* WITH_PNG */
/**
* Empty 'Display a splash image' routine (WITHOUT_PNG).
*/
void DisplaySplashImage() {} void DisplaySplashImage() {}
#endif /* WITH_PNG */ #endif /* WITH_PNG */

View File

@ -7,6 +7,8 @@
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file cocoa_v.mm Code related to the cocoa video driver(s). */
/****************************************************************************** /******************************************************************************
* Cocoa video driver * * Cocoa video driver *
* Known things left to do: * * Known things left to do: *
@ -56,9 +58,13 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
/* The main class of the application, the application's delegate */ /**
* The main class of the application, the application's delegate.
*/
@implementation OTTDMain @implementation OTTDMain
/* Called when the internal event loop has just started running */ /**
* Called when the internal event loop has just started running.
*/
- (void) applicationDidFinishLaunching: (NSNotification*) note - (void) applicationDidFinishLaunching: (NSNotification*) note
{ {
/* Hand off to main application code */ /* Hand off to main application code */
@ -68,7 +74,9 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
[ NSApp stop:_ottd_main ]; [ NSApp stop:_ottd_main ];
} }
/* Display the in game quit confirmation dialog */ /**
* Display the in game quit confirmation dialog.
*/
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender
{ {
@ -78,6 +86,9 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
} }
@end @end
/**
* Initialize the application menu shown in top bar.
*/
static void setApplicationMenu() static void setApplicationMenu()
{ {
NSString *appName = @"OTTD"; NSString *appName = @"OTTD";
@ -117,7 +128,9 @@ static void setApplicationMenu()
[ menuItem release ]; [ menuItem release ];
} }
/* Create a window menu */ /**
* Create a window menu.
*/
static void setupWindowMenu() static void setupWindowMenu()
{ {
NSMenu *windowMenu = [ [ NSMenu alloc ] initWithTitle:@"Window" ]; NSMenu *windowMenu = [ [ NSMenu alloc ] initWithTitle:@"Window" ];
@ -138,6 +151,9 @@ static void setupWindowMenu()
[ menuItem release ]; [ menuItem release ];
} }
/**
* Startup the application.
*/
static void setupApplication() static void setupApplication()
{ {
ProcessSerialNumber psn = { 0, kCurrentProcess }; ProcessSerialNumber psn = { 0, kCurrentProcess };
@ -167,7 +183,11 @@ static void setupApplication()
[ NSApp setDelegate:_ottd_main ]; [ NSApp setDelegate:_ottd_main ];
} }
/**
* Update the video modus.
*
* @pre _cocoa_subdriver != NULL
*/
static void QZ_UpdateVideoModes() static void QZ_UpdateVideoModes()
{ {
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
@ -183,7 +203,9 @@ static void QZ_UpdateVideoModes()
_num_resolutions = count; _num_resolutions = count;
} }
/**
* Handle a change of the display area.
*/
void QZ_GameSizeChanged() void QZ_GameSizeChanged()
{ {
if (_cocoa_subdriver == NULL) return; if (_cocoa_subdriver == NULL) return;
@ -200,7 +222,14 @@ void QZ_GameSizeChanged()
GameSizeChanged(); GameSizeChanged();
} }
/**
* Find a suitable cocoa window subdriver.
*
* @param width Width of display area.
* @param height Height of display area.
* @param bpp Colour depth of display area.
* @return Pointer to window subdriver.
*/
static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp) static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
{ {
#if defined(ENABLE_COCOA_QUARTZ) || defined(ENABLE_COCOA_QUICKDRAW) #if defined(ENABLE_COCOA_QUARTZ) || defined(ENABLE_COCOA_QUICKDRAW)
@ -238,7 +267,17 @@ static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
return NULL; return NULL;
} }
/**
* Find a suitable cocoa subdriver.
*
* @param width Width of display area.
* @param height Height of display area.
* @param bpp Colour depth of display area.
* @param fullscreen Wether a fullscreen mode is requested.
* @param fallback Whether we look for a fallback driver.
* @return Pointer to subdriver.
* @return Pointer to window subdriver.
*/
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 = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp); CocoaSubdriver *ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp);
@ -264,6 +303,9 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f
static FVideoDriver_Cocoa iFVideoDriver_Cocoa; static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
/**
* Stop the cocoa video subdriver.
*/
void VideoDriver_Cocoa::Stop() void VideoDriver_Cocoa::Stop()
{ {
if (!_cocoa_video_started) return; if (!_cocoa_video_started) return;
@ -276,6 +318,9 @@ void VideoDriver_Cocoa::Stop()
_cocoa_video_started = false; _cocoa_video_started = false;
} }
/**
* Initialize a cocoa video subdriver.
*/
const char *VideoDriver_Cocoa::Start(const char * const *parm) const char *VideoDriver_Cocoa::Start(const char * const *parm)
{ {
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.";
@ -304,6 +349,14 @@ const char *VideoDriver_Cocoa::Start(const char * const *parm)
return NULL; return NULL;
} }
/**
* Set dirty a rectangle managed by a cocoa video subdriver.
*
* @param left Left x cooordinate of the dirty rectangle.
* @param top Uppder y coordinate of the dirty rectangle.
* @param width Width of the dirty rectangle.
* @param height Height of the dirty rectangle.
*/
void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height) void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
{ {
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
@ -311,12 +364,22 @@ void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
_cocoa_subdriver->MakeDirty(left, top, width, height); _cocoa_subdriver->MakeDirty(left, top, width, height);
} }
/**
* Start the main programme loop when using a cocoa video driver.
*/
void VideoDriver_Cocoa::MainLoop() void VideoDriver_Cocoa::MainLoop()
{ {
/* Start the main event loop */ /* Start the main event loop */
[ NSApp run ]; [ NSApp run ];
} }
/**
* 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) bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
{ {
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
@ -329,6 +392,12 @@ bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
return ret; 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.
*/
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen) bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
{ {
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
@ -355,7 +424,15 @@ bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
return _cocoa_subdriver->IsFullscreen() == full_screen; return _cocoa_subdriver->IsFullscreen() == full_screen;
} }
/* This is needed since sometimes assert is called before the videodriver is initialized */ /**
* 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) void CocoaDialog(const char *title, const char *message, const char *buttonLabel)
{ {
_cocoa_video_dialog = true; _cocoa_video_dialog = true;
@ -375,8 +452,11 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
_cocoa_video_dialog = false; _cocoa_video_dialog = false;
} }
/* This is needed since OS X application bundles do not have a /** Set the application's bundle directory.
* current directory and the data files are 'somewhere' in the bundle */ *
* This is needed since OS X application bundles do not have a
* current directory and the data files are 'somewhere' in the bundle.
*/
void cocoaSetApplicationBundleDir() void cocoaSetApplicationBundleDir()
{ {
char tmp[MAXPATHLEN]; char tmp[MAXPATHLEN];
@ -391,7 +471,10 @@ void cocoaSetApplicationBundleDir()
CFRelease(url); CFRelease(url);
} }
/* These are called from main() to prevent a _NSAutoreleaseNoPool error when /**
* Setup autorelease for the application pool.
*
* These are called from main() to prevent a _NSAutoreleaseNoPool error when
* exiting before the cocoa video driver has been loaded * exiting before the cocoa video driver has been loaded
*/ */
void cocoaSetupAutoreleasePool() void cocoaSetupAutoreleasePool()
@ -399,6 +482,9 @@ void cocoaSetupAutoreleasePool()
_ottd_autorelease_pool = [ [ NSAutoreleasePool alloc ] init ]; _ottd_autorelease_pool = [ [ NSAutoreleasePool alloc ] init ];
} }
/**
* Autorelease the application pool.
*/
void cocoaReleaseAutoreleasePool() void cocoaReleaseAutoreleasePool()
{ {
[ _ottd_autorelease_pool release ]; [ _ottd_autorelease_pool release ];