event.bmx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. SuperStrict
  2. Rem
  3. bbdoc: Events/Events
  4. End Rem
  5. Module BRL.Event
  6. ModuleInfo "Version: 1.08"
  7. ModuleInfo "Author: Mark Sibly, Bruce A Henderson"
  8. ModuleInfo "License: zlib/libpng"
  9. ModuleInfo "Copyright: Blitz Research Ltd"
  10. ModuleInfo "Modserver: BRL"
  11. ModuleInfo "History: 1.08"
  12. ModuleInfo "History: Added EVENT_DISPLAYMOVED."
  13. ModuleInfo "History: 1.07"
  14. ModuleInfo "History: Removed event pool."
  15. ModuleInfo "History: 1.06"
  16. ModuleInfo "History: Module is now SuperStrict"
  17. ModuleInfo "History: 1.05"
  18. ModuleInfo "History: Added EVENT_MULTIGESTURE."
  19. ModuleInfo "History: 1.04"
  20. ModuleInfo "History: Added event pool."
  21. ModuleInfo "History: Added EVENT_TOUCHDOWN, EVENT_TOUCHUP and EVENT_TOUCHMOVE."
  22. ModuleInfo "History: 1.03 Release"
  23. ModuleInfo "History: Added missing EVENT_HOTKEY ToString case"
  24. ModuleInfo "History: Added process events"
  25. ModuleInfo "History: 1.02 Release"
  26. ModuleInfo "History: Added EVENT_GADGETLOSTFOCUS"
  27. ModuleInfo "History: 1.01 Release"
  28. ModuleInfo "History: Added EVENT_KEYREPEAT"
  29. Import BRL.Hook
  30. Rem
  31. bbdoc: Hook id for emitted events
  32. about:
  33. The #EmitEventHook global variable contains a hook id for use with #AddHook.
  34. Each time #EmitEvent is called, the event is passed to all #EmitEventHook
  35. hook functions by means of the hook function @data parameter.
  36. End Rem
  37. Global EmitEventHook:Int=AllocHookId()
  38. Rem
  39. bbdoc: Event object type
  40. EndRem
  41. Type TEvent
  42. Rem
  43. bbdoc: Event identifier
  44. End Rem
  45. Field id:Int
  46. Rem
  47. bbdoc: Event source object
  48. End Rem
  49. Field source:Object
  50. Rem
  51. bbdoc: Event specific data
  52. End Rem
  53. Field data:Int
  54. Rem
  55. bbdoc: Event specific modifiers
  56. End Rem
  57. Field mods:Int
  58. Rem
  59. bbdoc: Event specific position data
  60. End Rem
  61. Field x:Int
  62. Rem
  63. bbdoc: Event specific position data
  64. End Rem
  65. Field y:Int
  66. Rem
  67. bbdoc: Event specific extra information
  68. End Rem
  69. Field extra:Object
  70. Rem
  71. bbdoc: Emit this event
  72. about:
  73. This method runs all #EmitEventHook hook function, passing @Self as
  74. the hook data.
  75. End Rem
  76. Method Emit()
  77. RunHooks EmitEventHook,Self
  78. End Method
  79. Rem
  80. bbdoc: Convert event to a string
  81. about:
  82. This method is mainly useful for debugging purposes.
  83. End Rem
  84. Method ToString:String() Override
  85. Local t:String=DescriptionForId( id )
  86. If Not t
  87. If id & EVENT_USEREVENTMASK
  88. t="UserEvent"+(id-EVENT_USEREVENTMASK)
  89. Else
  90. t="Unknown Event, id="+id
  91. EndIf
  92. EndIf
  93. Return t+": data="+data+", mods="+mods+", x="+x+", y="+y+", extra=~q"+String(extra)+"~q"
  94. End Method
  95. Rem
  96. bbdoc: Create an event object
  97. returns: A new event object
  98. End Rem
  99. Function Create:TEvent( id:Int,source:Object=Null,data:Int=0,mods:Int=0,x:Int=0,y:Int=0,extra:Object=Null)
  100. Local t:TEvent = New TEvent
  101. t.id=id
  102. t.source=source
  103. t.data=data
  104. t.mods=mods
  105. t.x=x
  106. t.y=y
  107. t.extra=extra
  108. Return t
  109. End Function
  110. Rem
  111. bbdoc: Allocate a user event id
  112. returns: A new user event id
  113. End Rem
  114. Function AllocUserId:Int()
  115. Global _id:Int=EVENT_USEREVENTMASK
  116. _id:+1
  117. Return _id
  118. End Function
  119. Function RegisterId( id:Int,description:String )
  120. _regids:+String(id)+"{"+description+"}"
  121. End Function
  122. Function DescriptionForId:String( id:Int )
  123. Local t:String="}"+String(id)+"{"
  124. Local i:Int=_regids.Find( t )
  125. If i=-1 Return Null
  126. i:+t.length
  127. Local i2:Int=_regids.Find( "}",i )
  128. If i2=-1 Return Null
  129. Return _regids[i..i2]
  130. End Function
  131. Global _regids:String="}"
  132. End Type
  133. Const EVENT_APPMASK:Int=$100
  134. Const EVENT_APPSUSPEND:Int=$101
  135. Const EVENT_APPRESUME:Int=$102
  136. Const EVENT_APPTERMINATE:Int=$103
  137. Const EVENT_APPOPENFILE:Int=$104
  138. Const EVENT_APPIDLE:Int=$105 'Reserved by Mark!
  139. Const EVENT_KEYMASK:Int=$200
  140. Const EVENT_KEYDOWN:Int=$201
  141. Const EVENT_KEYUP:Int=$202
  142. Const EVENT_KEYCHAR:Int=$203
  143. Const EVENT_KEYREPEAT:Int=$204
  144. Const EVENT_MOUSEMASK:Int=$400
  145. Const EVENT_MOUSEDOWN:Int=$401
  146. Const EVENT_MOUSEUP:Int=$402
  147. Const EVENT_MOUSEMOVE:Int=$403
  148. Const EVENT_MOUSEWHEEL:Int=$404
  149. Const EVENT_MOUSEENTER:Int=$405
  150. Const EVENT_MOUSELEAVE:Int=$406
  151. Const EVENT_TIMERMASK:Int=$800
  152. Const EVENT_TIMERTICK:Int=$801
  153. Const EVENT_HOTKEYMASK:Int=$1000
  154. Const EVENT_HOTKEYHIT:Int=$1001
  155. Const EVENT_GADGETMASK:Int=$2000
  156. Const EVENT_GADGETACTION:Int=$2001
  157. Const EVENT_GADGETPAINT:Int=$2002
  158. Const EVENT_GADGETSELECT:Int=$2003
  159. Const EVENT_GADGETMENU:Int=$2004
  160. Const EVENT_GADGETOPEN:Int=$2005
  161. Const EVENT_GADGETCLOSE:Int=$2006
  162. Const EVENT_GADGETDONE:Int=$2007
  163. Const EVENT_GADGETLOSTFOCUS:Int=$2008
  164. Const EVENT_GADGETSHAPE:Int=$2009 'reserved by Mark!
  165. Const EVENT_WINDOWMASK:Int=$4000
  166. Const EVENT_WINDOWMOVE:Int=$4001
  167. Const EVENT_WINDOWSIZE:Int=$4002
  168. Const EVENT_WINDOWCLOSE:Int=$4003
  169. Const EVENT_WINDOWACTIVATE:Int=$4004
  170. Const EVENT_WINDOWACCEPT:Int=$4005
  171. Const EVENT_WINDOWMINIMIZE:Int=$4006
  172. Const EVENT_WINDOWMAXIMIZE:Int=$4007
  173. Const EVENT_WINDOWRESTORE:Int=$4008
  174. Const EVENT_WINDOWDISPLAYCHANGE:Int=$4009
  175. Const EVENT_WINDOWICCPROFCHANGE:Int=$400A
  176. Const EVENT_DISPLAYORIENTATION:Int=$4020
  177. Const EVENT_DISPLAYCONNECT:Int=$4021
  178. Const EVENT_DISPLAYDISCONNECT:Int=$4022
  179. Const EVENT_DISPLAYMOVED:Int=$4023
  180. Const EVENT_MENUMASK:Int=$8000
  181. Const EVENT_MENUACTION:Int=$8001
  182. Const EVENT_STREAMMASK:Int=$10000
  183. Const EVENT_STREAMEOF:Int=$10001
  184. Const EVENT_STREAMAVAIL:Int=$10002
  185. Const EVENT_PROCESSMASK:Int=$20000
  186. Const EVENT_PROCESSEXIT:Int=$20001
  187. Const EVENT_TOUCHMASK:Int=$40000
  188. Const EVENT_TOUCHDOWN:Int=$40001
  189. Const EVENT_TOUCHUP:Int=$40002
  190. Const EVENT_TOUCHMOVE:Int=$40003
  191. Const EVENT_MULTIGESTURE:Int=$80000
  192. Const EVENT_USEREVENTMASK:Int=$80000000
  193. TEvent.RegisterId EVENT_APPSUSPEND,"AppSuspend"
  194. TEvent.RegisterId EVENT_APPRESUME,"AppResume"
  195. TEvent.RegisterId EVENT_APPTERMINATE,"AppTerminate"
  196. TEvent.RegisterId EVENT_APPOPENFILE,"AppOpenFile"
  197. TEvent.RegisterId EVENT_APPIDLE,"AppIdle"
  198. TEvent.RegisterId EVENT_KEYDOWN,"KeyDown"
  199. TEvent.RegisterId EVENT_KEYUP,"KeyUp"
  200. TEvent.RegisterId EVENT_KEYCHAR,"KeyChar"
  201. TEvent.RegisterId EVENT_KEYREPEAT,"KeyRepeat"
  202. TEvent.RegisterId EVENT_MOUSEDOWN,"MouseDown"
  203. TEvent.RegisterId EVENT_MOUSEUP,"MouseUp"
  204. TEvent.RegisterId EVENT_MOUSEMOVE,"MouseMove"
  205. TEvent.RegisterId EVENT_MOUSEWHEEL,"MouseWheel"
  206. TEvent.RegisterId EVENT_MOUSEENTER,"MouseEnter"
  207. TEvent.RegisterId EVENT_MOUSELEAVE,"MouseLeave"
  208. TEvent.RegisterId EVENT_TIMERTICK,"TimerTick"
  209. TEvent.RegisterId EVENT_HOTKEYHIT,"HotkeyHit"
  210. TEvent.RegisterId EVENT_GADGETACTION,"GadgetAction"
  211. TEvent.RegisterId EVENT_GADGETPAINT,"GadgetPaint"
  212. TEvent.RegisterId EVENT_GADGETSELECT,"GadgetSelect"
  213. TEvent.RegisterId EVENT_GADGETMENU,"GadgetMenu"
  214. TEvent.RegisterId EVENT_GADGETOPEN,"GadgetOpen"
  215. TEvent.RegisterId EVENT_GADGETCLOSE,"GadgetClose"
  216. TEvent.RegisterId EVENT_GADGETDONE,"GadgetDone"
  217. TEvent.RegisterId EVENT_GADGETLOSTFOCUS,"GadgetLostFocus"
  218. TEvent.RegisterId EVENT_GADGETSHAPE,"GadgetShape"
  219. TEvent.RegisterId EVENT_WINDOWMOVE,"WindowMove"
  220. TEvent.RegisterId EVENT_WINDOWSIZE,"WindowSize"
  221. TEvent.RegisterId EVENT_WINDOWCLOSE,"WindowClose"
  222. TEvent.RegisterId EVENT_WINDOWACTIVATE,"WindowActivate"
  223. TEvent.RegisterId EVENT_WINDOWACCEPT,"WindowAccept"
  224. TEvent.RegisterId EVENT_WINDOWMINIMIZE,"WindowMinimize"
  225. TEvent.RegisterId EVENT_WINDOWMAXIMIZE,"WindowMaximize"
  226. TEvent.RegisterId EVENT_WINDOWRESTORE,"WindowRestore"
  227. TEvent.RegisterId EVENT_WINDOWDISPLAYCHANGE,"WindowDisplayChange"
  228. TEvent.RegisterId EVENT_WINDOWICCPROFCHANGE,"WindowICCProfChange"
  229. TEvent.RegisterId EVENT_DISPLAYORIENTATION,"DisplayOrientation"
  230. TEvent.RegisterId EVENT_DISPLAYCONNECT,"DisplayConnect"
  231. TEvent.RegisterId EVENT_DISPLAYDISCONNECT,"DisplayDisconnect"
  232. TEvent.RegisterId EVENT_DISPLAYMOVED,"DisplayMoved"
  233. TEvent.RegisterId EVENT_MENUACTION,"MenuAction"
  234. TEvent.RegisterId EVENT_STREAMEOF,"StreamEof"
  235. TEvent.RegisterId EVENT_STREAMAVAIL,"StreamAvail"
  236. TEvent.RegisterId EVENT_PROCESSEXIT,"ProcessExit"
  237. TEvent.RegisterId EVENT_TOUCHDOWN,"TouchDown"
  238. TEvent.RegisterId EVENT_TOUCHUP,"TouchUp"
  239. TEvent.RegisterId EVENT_TOUCHMOVE,"TouchMove"
  240. TEvent.RegisterId EVENT_MULTIGESTURE,"MultiGesture"
  241. Rem
  242. bbdoc: Emit an event
  243. about:
  244. Runs all #EmitEventHook hooks, passing @event as the hook data.
  245. End Rem
  246. Function EmitEvent( event:TEvent )
  247. event.Emit
  248. End Function
  249. Rem
  250. bbdoc: Create an event object
  251. returns: A new event object
  252. End Rem
  253. Function CreateEvent:TEvent( id:Int,source:Object=Null,data:Int=0,mods:Int=0,x:Int=0,y:Int=0,extra:Object=Null)
  254. Return TEvent.Create( id,source,data,mods,x,y,extra)
  255. End Function
  256. Rem
  257. bbdoc: Allocate a user event id
  258. returns: A new user event id
  259. End Rem
  260. Function AllocUserEventId:Int( description:String="" )
  261. Local id:Int=TEvent.AllocUserId()
  262. If description TEvent.RegisterId id,description
  263. Return id
  264. End Function