From 9c7057eab79d5326b4d87fb8d2b1f18d40be3709 Mon Sep 17 00:00:00 2001 From: Thomas BERNARD Date: Tue, 5 May 2020 23:42:49 +0200 Subject: [PATCH] Implementation of GFX2_MessageBox() for SDL1.2.x and Mac OS X --- src/screen.h | 4 ++++ src/sdlscreen.c | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/screen.h b/src/screen.h index 8b3ef9dd..f1102ea8 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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 diff --git a/src/sdlscreen.c b/src/sdlscreen.c index bf4537d0..e21998be 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -34,6 +34,9 @@ #ifndef __GP2X__ #include #endif +#if defined(__macosx__) +#import +#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 }