sdlsystem.bmx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ' Copyright (c) 2014 Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. '
  16. ' 2. Altered source versions must be plainly marked as such, and must not be
  17. ' misrepresented as being the original software.
  18. '
  19. ' 3. This notice may not be removed or altered from any source
  20. ' distribution.
  21. '
  22. Strict
  23. Rem
  24. bbdoc: SDL System driver
  25. End Rem
  26. Module SDL.SDLSystem
  27. Import SDL.SDL
  28. Import BRL.System
  29. Import "common.bmx"
  30. Global _sdl_WarpMouse(x:Int, y:Int)
  31. Type TSDLSystemDriver Extends TSystemDriver
  32. Field _eventFilterCallback:Int(data:Object, event:Int)
  33. Field _eventFilterUserData:Object
  34. Method New()
  35. SDL_Init(SDL_INIT_EVENTS)
  36. bmx_SDL_SetEventFilter(Self)
  37. OnEnd(SDL_Quit)
  38. End Method
  39. Method Poll()
  40. bmx_SDL_Poll()
  41. End Method
  42. Method Wait()
  43. bmx_SDL_WaitEvent()
  44. End Method
  45. Method Emit( osevent:Byte Ptr,source:Object )
  46. ' TODO
  47. End Method
  48. Method SetMouseVisible( visible )
  49. SDL_ShowCursor(visible)
  50. End Method
  51. Method MoveMouse( x,y )
  52. If _sdl_WarpMouse Then
  53. _sdl_WarpMouse(x, y)
  54. End If
  55. End Method
  56. Method Notify( Text$,serious )
  57. Local res:Int = bmx_SDL_ShowSimpleMessageBox(Text, AppTitle, serious)
  58. ' failed to display message box?
  59. If res Then
  60. WriteStdout Text+"~r~n"
  61. End If
  62. End Method
  63. Method Confirm( Text$,serious )
  64. Return bmx_SDL_ShowMessageBox_confirm(Text, AppTitle, serious)
  65. End Method
  66. Method Proceed( Text$,serious )
  67. Return bmx_SDL_ShowMessageBox_proceed(Text, AppTitle, serious)
  68. End Method
  69. Method RequestFile$( Text$,exts$,save,file$ )
  70. ' TODO
  71. End Method
  72. Method RequestDir$( Text$,path$ )
  73. ' TODO
  74. End Method
  75. Method OpenURL( url$ )
  76. ' TODO
  77. End Method
  78. Method DesktopWidth:Int()
  79. Return bmx_SDL_GetDisplayWidth(0)
  80. End Method
  81. Method DesktopHeight:Int()
  82. Return bmx_SDL_GetDisplayHeight(0)
  83. End Method
  84. Method DesktopDepth:Int()
  85. Return bmx_SDL_GetDisplayDepth(0)
  86. End Method
  87. Method DesktopHertz:Int()
  88. Return bmx_SDL_GetDisplayhertz(0)
  89. End Method
  90. Function _eventFilter:Int(driver:TSDLSystemDriver, event:Int) { nomangle }
  91. If driver._eventFilterCallback Then
  92. Return driver._eventFilterCallback(driver._eventFilterUserData, event)
  93. End If
  94. Return 1
  95. End Function
  96. End Type
  97. Rem
  98. bbdoc:
  99. End Rem
  100. Function SetEventFilterCallback(callback:Int(data:Object, event:Int), data:Object = Null)
  101. TSDLSystemDriver(Driver)._eventFilterCallback = callback
  102. TSDLSystemDriver(Driver)._eventFilterUserData = data
  103. End Function
  104. Driver = New TSDLSystemDriver
  105. Rem
  106. bbdoc: Information about multiple finger gestures.
  107. End Rem
  108. Type TSDLMultiGesture
  109. Rem
  110. bbdoc: The touch device id.
  111. End Rem
  112. Field touchId:Long
  113. Rem
  114. bbdoc: The center of the gesture.
  115. End Rem
  116. Field x:Int
  117. Rem
  118. bbdoc: The center of the gesture.
  119. End Rem
  120. Field y:Int
  121. Rem
  122. bbdoc: The amount that the fingers rotated during this motion.
  123. End Rem
  124. Field dTheta:Float
  125. Rem
  126. bbdoc: The amount that the fingers pinched during this motion.
  127. End Rem
  128. Field dDist:Float
  129. Rem
  130. bbdoc: The number of fingers used in the gesture.
  131. End Rem
  132. Field numFingers:Int
  133. Global _gestures:TList = New TList
  134. Function _getGesture:TSDLMultiGesture(touchId:Long, x:Int, y:Int, dTheta:Float, dDist:Float, numFingers:Int) { nomangle }
  135. Local gesture:TSDLMultiGesture = TSDLMultiGesture(_gestures.RemoveFirst())
  136. If Not gesture Then
  137. gesture = New TSDLMultiGesture
  138. End If
  139. gesture.touchId = touchId
  140. gesture.x = x
  141. gesture.y = y
  142. gesture.dTheta = dTheta
  143. gesture.dDist = dDist
  144. gesture.numFingers = numFingers
  145. Return gesture
  146. End Function
  147. Function _freeGesture(gesture:TSDLMultiGesture) { nomangle }
  148. _gestures.AddLast(gesture)
  149. End Function
  150. End Type