iOS System Callback (attn: Piotr Drapich) |
Brian Barnes
Guest
|
I'm finally getting back to this. Has there been any movement or additional thought on Poitr's patch? The original message:
http://forums.libsdl.org/viewtopic.php?t=7733&sid=21dffacbd29855581fe66d8a1126a1df Piotr, do you have a new version of this patch that conforms with the current trunk of SDL2? I'll retest it for you. [>] Brian _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||
|
iOS System Callback (attn: Piotr Drapich) |
sdl
Guest
|
Hi Briam,
Yes, I finally started to port my apps to android and I will be implementing the same callback inteface and functionality there. I have this merged with the lastest SDL2, I'll try to make a diff and post it here tomorrow. regards, Piotr On Sun, 18 Mar 2012, Brian Barnes wrote:
_______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
iOS System Callback (attn: Piotr Drapich) |
Brian Barnes
Guest
|
Piotr, can you put the patch up somewhere I can grab it as a file? My
cut-n-paste job from the mail doesn't give me a file I can patch with -- whatever it is, line endings, etc, I don't know. I'd like to get to testing this ASAP. [>] Brian _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||
|
iOS System Callback (attn: Piotr Drapich) |
sdl
Guest
|
HI Brian,
Unfortunately I dont have such space available now, I'm posting below the latest version of my callback implementation - let me know if you can use to patch SDL source successfully. Btw: this is the latest version, with new SDL_SYSEVENT_ORIENTATION_CHANGED event and Android support. regards, Piotr On Fri, 30 Mar 2012, Brian Barnes wrote:
diff -r 6bb657898f55 include/SDL_events.h --- a/include/SDL_events.h Tue Feb 28 21:58:36 2012 -0500 +++ b/include/SDL_events.h Sun Apr 01 03:37:26 2012 +0200 @@ -106,6 +106,16 @@ /* Clipboard events */ SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */ + /* System events */ + + SDL_SYSEVENT_TERMINATE = 0xa00, + SDL_SYSEVENT_WILL_SUSPEND, + SDL_SYSEVENT_SUSPEND, + SDL_SYSEVENT_WILL_RESUME, + SDL_SYSEVENT_RESUME, + SDL_SYSEVENT_LOWMEMORY, + SDL_SYSEVENT_ORIENTATION_CHANGED, + /* Drag and drop events */ SDL_DROPFILE = 0x1000, /**< The system requests a file open */ @@ -382,6 +392,22 @@ Uint32 timestamp; } SDL_QuitEvent; +/** + * \brief System event + */ + +typedef struct SDL_SystemEvent +{ + Uint32 type; + Uint32 timestamp; + void *data; +} SDL_SystemEvent; + +typedef enum +{ + SDL_ORIENTATION_PORTRAIT, + SDL_ORIENTATION_LANDSCAPE +} SDL_DeviceOrientation; /** * \brief A user-defined event type (event.user.*) @@ -438,6 +464,7 @@ SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */ SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */ SDL_DropEvent drop; /**< Drag and drop event data */ + SDL_SystemEvent sysevent; /**< System event data */ } SDL_Event; @@ -619,6 +646,16 @@ */ extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents); +/** + * Set system event hook + * + */ +typedef int (SDLCALL * SDL_SystemEventHandler) (SDL_Event* event); + +extern DECLSPEC void SDLCALL SDL_SetSystemEventHook(SDL_SystemEventHandler handler); + + + /* Ends C function definitions when using C++ */ #ifdef __cplusplus /* *INDENT-OFF* */ diff -r 6bb657898f55 src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp Tue Feb 28 21:58:36 2012 -0500 +++ b/src/core/android/SDL_android.cpp Sun Apr 01 03:37:26 2012 +0200 @@ -168,14 +168,28 @@ JNIEnv* env, jclass cls) { // Inject a SDL_QUIT event - SDL_SendQuit(); + SDL_Event event; + event.type=SDL_SYSEVENT_TERMINATE; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else SDL_SendQuit(); } // Pause extern "C" void Java_org_libsdl_app_SDLActivity_nativePause( JNIEnv* env, jclass cls) { - if (Android_Window) { + SDL_Event event; + event.type=SDL_SYSEVENT_WILL_SUSPEND; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + event.type=SDL_SYSEVENT_SUSPEND; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else if (Android_Window) { SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); } @@ -185,7 +199,16 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume( JNIEnv* env, jclass cls) { - if (Android_Window) { + SDL_Event event; + event.type=SDL_SYSEVENT_WILL_RESUME; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + event.type=SDL_SYSEVENT_RESUME; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else if (Android_Window) { SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0); } diff -r 6bb657898f55 src/events/SDL_events.c --- a/src/events/SDL_events.c Tue Feb 28 21:58:36 2012 -0500 +++ b/src/events/SDL_events.c Sun Apr 01 03:37:26 2012 +0200 @@ -36,6 +36,7 @@ /* Public data -- the event filter */ SDL_EventFilter SDL_EventOK = NULL; void *SDL_EventOKParam; +SDL_SystemEventHandler SDL_SysEventHandler = NULL; typedef struct SDL_EventWatcher { SDL_EventFilter callback; @@ -529,4 +530,13 @@ return (posted); } +void +SDL_SetSystemEventHook(SDL_SystemEventHandler handler) +{ + if (handler) + { + SDL_SysEventHandler=handler; + } +} + /* vi: set ts=4 sw=4 expandtab: */ diff -r 6bb657898f55 src/events/SDL_events_c.h --- a/src/events/SDL_events_c.h Tue Feb 28 21:58:36 2012 -0500 +++ b/src/events/SDL_events_c.h Sun Apr 01 03:37:26 2012 +0200 @@ -1,6 +1,7 @@ /* Simple DirectMedia Layer Copyright (C) 1997-2012 Sam Lantinga + Copyright (C) 1997-2011 Sam Lantinga This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -46,4 +47,7 @@ extern SDL_EventFilter SDL_EventOK; extern void *SDL_EventOKParam; +/* The system event hook function */ +extern SDL_SystemEventHandler SDL_SysEventHandler; + /* vi: set ts=4 sw=4 expandtab: */ diff -r 6bb657898f55 src/video/uikit/SDL_uikitappdelegate.m --- a/src/video/uikit/SDL_uikitappdelegate.m Tue Feb 28 21:58:36 2012 -0500 +++ b/src/video/uikit/SDL_uikitappdelegate.m Sun Apr 01 03:37:26 2012 +0200 @@ -123,7 +123,12 @@ - (void)applicationWillTerminate:(UIApplication *)application { - SDL_SendQuit(); + SDL_Event event; + event.type=SDL_SYSEVENT_TERMINATE; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else SDL_SendQuit(); /* hack to prevent automatic termination. See SDL_uikitevents.m for details */ longjmp(*(jump_env()), 1); } @@ -131,37 +136,82 @@ - (void) applicationWillResignActive:(UIApplication*)application { //NSLog(@"%@", NSStringFromSelector(_cmd)); + SDL_Event event; + event.type=SDL_SYSEVENT_WILL_SUSPEND; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else { + // Send every window on every screen a MINIMIZED event. + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (!_this) { + return; + } - // Send every window on every screen a MINIMIZED event. - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { - return; + SDL_Window *window; + for (window = _this->windows; window != nil; window = window->next) { + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); + } } +} - SDL_Window *window; - for (window = _this->windows; window != nil; window = window->next) { - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); - } +- (void)applicationDidEnterBackground:(UIApplication*)application +{ + //NSLog(@"%@", NSStringFromSelector(_cmd)); + + SDL_Event event; + event.type=SDL_SYSEVENT_SUSPEND; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); +} + +- (void)applicationWillEnterForeground:(UIApplication*)application +{ + //NSLog(@"%@", NSStringFromSelector(_cmd)); + + SDL_Event event; + event.type=SDL_SYSEVENT_WILL_RESUME; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); } - (void) applicationDidBecomeActive:(UIApplication*)application { //NSLog(@"%@", NSStringFromSelector(_cmd)); - // Send every window on every screen a RESTORED event. - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { - return; - } + SDL_Event event; + event.type=SDL_SYSEVENT_RESUME; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else { + // Send every window on every screen a RESTORED event. + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (!_this) { + return; + } - SDL_Window *window; - for (window = _this->windows; window != nil; window = window->next) { - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); + SDL_Window *window; + for (window = _this->windows; window != nil; window = window->next) { + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); + } } } +- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application +{ + //NSLog(@"%@", NSStringFromSelector(_cmd)); + + SDL_Event event; + event.type=SDL_SYSEVENT_LOWMEMORY; + event.sysevent.data=NULL; + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); +} @end #endif /* SDL_VIDEO_DRIVER_UIKIT */ diff -r 6bb657898f55 src/video/uikit/SDL_uikitviewcontroller.m --- a/src/video/uikit/SDL_uikitviewcontroller.m Tue Feb 28 21:58:36 2012 -0500 +++ b/src/video/uikit/SDL_uikitviewcontroller.m Sun Apr 01 03:37:26 2012 +0200 @@ -121,18 +121,23 @@ CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame]; const CGSize size = frame.size; int w, h; + SDL_Event event; + event.type=SDL_SYSEVENT_ORIENTATION_CHANGED; + event.sysevent.data=NULL; switch (toInterfaceOrientation) { case UIInterfaceOrientationPortrait: case UIInterfaceOrientationPortraitUpsideDown: w = (size.width < size.height) ? size.width : size.height; h = (size.width > size.height) ? size.width : size.height; + event.sysevent.data=(void*)SDL_ORIENTATION_PORTRAIT; break; case UIInterfaceOrientationLandscapeLeft: case UIInterfaceOrientationLandscapeRight: w = (size.width > size.height) ? size.width : size.height; h = (size.width < size.height) ? size.width : size.height; + event.sysevent.data=(void*)SDL_ORIENTATION_LANDSCAPE; break; default: @@ -140,13 +145,18 @@ return; } + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + w = (int)(w * displaymodedata->scale); h = (int)(h * displaymodedata->scale); [uiwindow setFrame:frame]; [data->view setFrame:frame]; [data->view updateFrame]; - SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h); + if (SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h); } #endif /* SDL_VIDEO_DRIVER_UIKIT */ _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|