Преглед изворни кода

Added event filter support for iOS/Android.

woollybah пре 10 година
родитељ
комит
13ea20f48b
4 измењених фајлова са 72 додато и 3 уклоњено
  1. 37 0
      sdl.mod/common.bmx
  2. 2 0
      sdlsystem.mod/common.bmx
  3. 17 3
      sdlsystem.mod/glue.c
  4. 16 0
      sdlsystem.mod/sdlsystem.bmx

+ 37 - 0
sdl.mod/common.bmx

@@ -89,3 +89,40 @@ Const SDL_INIT_NOPARACHUTE:Int = $00100000  ' Don't catch fatal signals
 Const SDL_INIT_EVERYTHING:Int = SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | ..
 	SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER
 	
+Rem
+bbdoc: The application is being terminated by the OS.
+about: Called on iOS in applicationWillTerminate().
+       Called on Android in onDestroy()
+End Rem
+Const SDL_APP_TERMINATING:Int         = $101
+Rem
+bbdoc: The application is low on memory, free memory if possible.
+about: Called on iOS in applicationDidReceiveMemoryWarning().
+       Called on Android in onLowMemory()
+End Rem
+Const SDL_APP_LOWMEMORY:Int           = $102
+Rem
+bbdoc: The application is about to enter the background.
+about: Called on iOS in applicationWillResignActive().
+       Called on Android in onPause()
+End Rem
+Const SDL_APP_WILLENTERBACKGROUND:Int = $103
+Rem
+bbdoc: The application did enter the background and may not get CPU for some time.
+about: Called on iOS in applicationDidEnterBackground().
+       Called on Android in onPause()
+End Rem
+Const SDL_APP_DIDENTERBACKGROUND:Int  = $104
+Rem
+bbdoc: The application is about to enter the foreground.
+about: Called on iOS in applicationWillEnterForeground().
+       Called on Android in onResume()
+End Rem
+Const SDL_APP_WILLENTERFOREGROUND:Int = $105
+Rem
+bbdoc: The application is now interactive.
+about: Called on iOS in applicationDidBecomeActive().
+       Called on Android in onResume()
+End Rem
+Const SDL_APP_DIDENTERFOREGROUND:Int  = $106
+

+ 2 - 0
sdlsystem.mod/common.bmx

@@ -80,5 +80,7 @@ Extern
 	Function bmx_SDL_ShowMessageBox_confirm:Int(text:String, _appTitle:String, serious:Int)
 	Function bmx_SDL_ShowMessageBox_proceed:Int(text:String, _appTitle:String, serious:Int)
 
+	Function bmx_SDL_SetEventFilter(driver:Object)
+	
 End Extern
 

+ 17 - 3
sdlsystem.mod/glue.c

@@ -18,9 +18,6 @@ void bbSDLSystemEmitEvent( int id,BBObject *source,int data,int mods,int x,int y
 int mapkey(SDL_Scancode scancode);
 int mapmods(int keymods);
 
-
-
-
 int bmx_SDL_GetDisplayWidth(int display) {
 	SDL_DisplayMode mode;
 	SDL_GetCurrentDisplayMode(display, &mode);
@@ -451,3 +448,20 @@ int bmx_SDL_ShowMessageBox_proceed(BBString * text, BBString * appTitle, int ser
 	return -1;
 }
 
+int bmx_SDL_EventFilter(void * userdata, SDL_Event * event) {
+	switch (event->type) {
+		case SDL_APP_TERMINATING:
+		case SDL_APP_LOWMEMORY:
+		case SDL_APP_WILLENTERBACKGROUND:
+		case SDL_APP_DIDENTERBACKGROUND:
+		case SDL_APP_WILLENTERFOREGROUND:
+		case SDL_APP_DIDENTERFOREGROUND:
+			return sdl_sdlsystem_TSDLSystemDriver__eventFilter(userdata, event->type);
+	}
+	return 1;
+}
+
+void bmx_SDL_SetEventFilter(BBObject * obj) {
+	SDL_SetEventFilter(bmx_SDL_EventFilter, obj);
+}
+

+ 16 - 0
sdlsystem.mod/sdlsystem.bmx

@@ -39,8 +39,12 @@ Global _sdl_WarpMouse(x:Int, y:Int)
 
 Type TSDLSystemDriver Extends TSystemDriver
 
+	Field _eventFilterCallback:Int(data:Object, event:Int)
+	Field _eventFilterUserData:Object
+
 	Method New()
 		SDL_Init(SDL_INIT_EVENTS)
+		bmx_SDL_SetEventFilter(Self)
 		OnEnd(SDL_Quit)
 	End Method
 
@@ -110,7 +114,19 @@ Type TSDLSystemDriver Extends TSystemDriver
 		Return bmx_SDL_GetDisplayhertz(0)
 	End Method
 
+	Function _eventFilter:Int(driver:TSDLSystemDriver, event:Int)
+		If driver._eventFilterCallback Then
+			Return driver._eventFilterCallback(driver._eventFilterUserData, event)
+		End If
+		Return 1
+	End Function
+	 
 End Type
 
+Function SetEventFilterCallback(callback:Int(data:Object, event:Int), data:Object = Null)
+	TSDLSystemDriver(Driver)._eventFilterCallback = callback
+	TSDLSystemDriver(Driver)._eventFilterUserData = data
+End Function
+
 Driver = New TSDLSystemDriver