Added mobile application events, with implementations for iOS and Android
This commit is contained in:
parent
2ff60371f5
commit
2ac8624930
9 changed files with 182 additions and 44 deletions
|
@ -181,12 +181,20 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
|
|||
bHasNewData = true;
|
||||
}
|
||||
|
||||
// Low memory
|
||||
extern "C" void Java_org_libsdl_app_SDLActivity_nativeLowMemory(
|
||||
JNIEnv* env, jclass cls)
|
||||
{
|
||||
SDL_SendAppEvent(SDL_APP_LOWMEMORY);
|
||||
}
|
||||
|
||||
// Quit
|
||||
extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit(
|
||||
JNIEnv* env, jclass cls)
|
||||
{
|
||||
// Inject a SDL_QUIT event
|
||||
SDL_SendQuit();
|
||||
SDL_SendAppEvent(SDL_APP_TERMINATING);
|
||||
}
|
||||
|
||||
// Pause
|
||||
|
@ -199,12 +207,20 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativePause(
|
|||
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
|
||||
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
||||
}
|
||||
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
|
||||
SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
|
||||
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
|
||||
}
|
||||
|
||||
// Resume
|
||||
extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume(
|
||||
JNIEnv* env, jclass cls)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
|
||||
SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
|
||||
SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
|
||||
|
||||
if (Android_Window) {
|
||||
/* Signal the resume semaphore so the event loop knows to resume and restore the GL Context
|
||||
* We can't restore the GL Context here because it needs to be done on the SDL main thread
|
||||
|
@ -616,7 +632,9 @@ static int Android_JNI_FileOpen(SDL_RWops* ctx)
|
|||
|
||||
if (false) {
|
||||
fallback:
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file");
|
||||
// Disabled log message because of spam on the Nexus 7
|
||||
//__android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file");
|
||||
|
||||
/* Try the old method using InputStream */
|
||||
ctx->hidden.androidio.assetFileDescriptorRef = NULL;
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ SDL_StopEventLoop(void)
|
|||
SDL_event_watchers = tmp->next;
|
||||
SDL_free(tmp);
|
||||
}
|
||||
SDL_EventOK = NULL;
|
||||
}
|
||||
|
||||
/* This function (and associated calls) may be called more than once */
|
||||
|
@ -133,8 +134,7 @@ SDL_StartEventLoop(void)
|
|||
}
|
||||
#endif /* !SDL_THREADS_DISABLED */
|
||||
|
||||
/* No filter to start with, process most event types */
|
||||
SDL_EventOK = NULL;
|
||||
/* Process most event types */
|
||||
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
|
||||
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
|
||||
SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
|
||||
|
@ -365,7 +365,9 @@ int
|
|||
SDL_PushEvent(SDL_Event * event)
|
||||
{
|
||||
SDL_EventWatcher *curr;
|
||||
|
||||
event->common.timestamp = SDL_GetTicks();
|
||||
|
||||
if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -516,8 +518,20 @@ SDL_RegisterEvents(int numevents)
|
|||
return event_base;
|
||||
}
|
||||
|
||||
/* This is a generic event handler.
|
||||
*/
|
||||
int
|
||||
SDL_SendAppEvent(SDL_EventType eventType)
|
||||
{
|
||||
int posted;
|
||||
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(eventType) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = eventType;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return (posted);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendSysWMEvent(SDL_SysWMmsg * message)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@ extern int SDL_StartEventLoop(void);
|
|||
extern void SDL_StopEventLoop(void);
|
||||
extern void SDL_QuitInterrupt(void);
|
||||
|
||||
extern int SDL_SendAppEvent(SDL_EventType eventType);
|
||||
extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
|
||||
|
||||
extern int SDL_QuitInit(void);
|
||||
|
|
|
@ -114,15 +114,7 @@ SDL_QuitQuit(void)
|
|||
int
|
||||
SDL_SendQuit(void)
|
||||
{
|
||||
int posted;
|
||||
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_QUIT) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return (posted);
|
||||
return SDL_SendAppEvent(SDL_QUIT);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -228,42 +228,48 @@ static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue,
|
|||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application
|
||||
{
|
||||
SDL_SendQuit();
|
||||
/* hack to prevent automatic termination. See SDL_uikitevents.m for details */
|
||||
longjmp(*(jump_env()), 1);
|
||||
SDL_SendAppEvent(SDL_APP_TERMINATING);
|
||||
}
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
|
||||
{
|
||||
SDL_SendAppEvent(SDL_APP_LOWMEMORY);
|
||||
}
|
||||
|
||||
- (void) applicationWillResignActive:(UIApplication*)application
|
||||
{
|
||||
//NSLog(@"%@", NSStringFromSelector(_cmd));
|
||||
|
||||
// Send every window on every screen a MINIMIZED event.
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
if (!_this) {
|
||||
return;
|
||||
if (_this) {
|
||||
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_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
|
||||
}
|
||||
|
||||
- (void) applicationWillEnterForeground:(UIApplication*)application
|
||||
{
|
||||
SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
|
||||
}
|
||||
|
||||
- (void) applicationDidBecomeActive:(UIApplication*)application
|
||||
{
|
||||
//NSLog(@"%@", NSStringFromSelector(_cmd));
|
||||
SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
|
||||
|
||||
// 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);
|
||||
if (_this) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,8 +91,10 @@ void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
|
|||
}
|
||||
[data->view swapBuffers];
|
||||
|
||||
/* we need to let the event cycle run, or the OS won't update the OpenGL view! */
|
||||
SDL_PumpEvents();
|
||||
/* You need to pump events in order for the OS to make changes visible.
|
||||
We don't pump events here because we don't want iOS application events
|
||||
(low memory, terminate, etc.) to happen inside low level rendering.
|
||||
*/
|
||||
}
|
||||
|
||||
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue