Implementation of GFX2_MessageBox() for SDL1.2.x and Mac OS X

This commit is contained in:
Thomas BERNARD 2020-05-05 23:42:49 +02:00
parent b0f1117bbc
commit 9c7057eab7
2 changed files with 22 additions and 1 deletions

View File

@ -102,6 +102,10 @@ int GFX2_GetScreenSize(int * width, int * height);
#define GFX2_MB_INFO MB_OK
#define GFX2_MB_ERROR (MB_OK|MB_ICONERROR)
#define GFX2_MB_WARNING (MB_OK|MB_ICONWARNING)
#elif defined(__macosx__)
#define GFX2_MB_INFO (unsigned)kCFUserNotificationPlainAlertLevel
#define GFX2_MB_ERROR (unsigned)kCFUserNotificationStopAlertLevel
#define GFX2_MB_WARNING (unsigned)kCFUserNotificationCautionAlertLevel
#else
#define GFX2_MB_INFO 1
#define GFX2_MB_ERROR 2

View File

@ -34,6 +34,9 @@
#ifndef __GP2X__
#include <SDL_syswm.h>
#endif
#if defined(__macosx__)
#import <CoreFoundation/CoreFoundation.h>
#endif
#include "global.h"
#include "sdlscreen.h"
@ -803,6 +806,20 @@ int GFX2_MessageBox(const char * text, const char * caption, unsigned int type)
return SDL_ShowSimpleMessageBox(type, caption, text, Window_SDL);
#elif defined(WIN32)
return MessageBoxA(GFX2_Get_Window_Handle(), text, caption, type);
#endif
#elif defined(__macosx__)
// TODO : display for MacOS : http://blog.jorgearimany.com/2010/05/messagebox-from-windows-to-mac.html
int r;
CFOptionFlags result;
CFStringRef text_ref = CFStringCreateWithCString(NULL, text, strlen(text));
CFStringRef caption_ref = CFStringCreateWithCString(NULL, caption, strlen(text));
r = CFUserNotificationDisplayAlert(0, (CFOptionFlags)type,
NULL, NULL, NULL,
caption_ref, text_ref,
NULL, NULL, NULL, &result);
CFRelease(text_ref);
CFRelease(caption_ref);
return (r == 0);
#else
return 0;
#endif
}