src/video/cocoa/SDL_cocoavideo.m
changeset 7454 05595e5359af
parent 7191 75360622e65f
child 7719 31b5f9ff36ca
equal deleted inserted replaced
7453:91c3bb321036 7454:05595e5359af
   230 void SDL_NSLog(const char *text)
   230 void SDL_NSLog(const char *text)
   231 {
   231 {
   232     NSLog(@"%s", text);
   232     NSLog(@"%s", text);
   233 }
   233 }
   234 
   234 
   235 /*
       
   236  * Mac OS X assertion support.
       
   237  *
       
   238  * This doesn't really have aything to do with the interfaces of the SDL video
       
   239  *  subsystem, but we need to stuff this into an Objective-C source code file.
       
   240  */
       
   241 
       
   242 SDL_assert_state
       
   243 SDL_PromptAssertion_cocoa(const SDL_assert_data *data)
       
   244 {
       
   245     const int initialized = (SDL_WasInit(SDL_INIT_VIDEO) != 0);
       
   246     if (!initialized) {
       
   247         if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
       
   248             fprintf(stderr, "Assertion failed AND couldn't init video mode!\n");
       
   249             return SDL_ASSERTION_BREAK;  /* oh well, crash hard. */
       
   250         }
       
   251     }
       
   252 
       
   253     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
   254 
       
   255     NSString *msg = [NSString stringWithFormat:
       
   256             @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
       
   257                 data->function, data->filename, data->linenum,
       
   258                 data->trigger_count, (data->trigger_count == 1) ? "" : "s",
       
   259                 data->condition];
       
   260 
       
   261     NSLog(@"%@", msg);
       
   262 
       
   263     /*
       
   264      * !!! FIXME: this code needs to deal with fullscreen modes:
       
   265      * !!! FIXME:  reset to default desktop, runModal, reset to current?
       
   266      */
       
   267 
       
   268     NSAlert* alert = [[NSAlert alloc] init];
       
   269     [alert setAlertStyle:NSCriticalAlertStyle];
       
   270     [alert setMessageText:msg];
       
   271     [alert addButtonWithTitle:@"Retry"];
       
   272     [alert addButtonWithTitle:@"Break"];
       
   273     [alert addButtonWithTitle:@"Abort"];
       
   274     [alert addButtonWithTitle:@"Ignore"];
       
   275     [alert addButtonWithTitle:@"Always Ignore"];
       
   276     const NSInteger clicked = [alert runModal];
       
   277     [alert release];
       
   278 
       
   279     [pool release];
       
   280 
       
   281     if (!initialized) {
       
   282         SDL_QuitSubSystem(SDL_INIT_VIDEO);
       
   283     }
       
   284 
       
   285     return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
       
   286 }
       
   287 
       
   288 #endif /* SDL_VIDEO_DRIVER_COCOA */
   235 #endif /* SDL_VIDEO_DRIVER_COCOA */
   289 
   236 
   290 /* vim: set ts=4 sw=4 expandtab: */
   237 /* vim: set ts=4 sw=4 expandtab: */