events_all_targets.odin 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #+build !js
  2. package wasm_js_interface
  3. Event_Kind :: enum u32 {
  4. Invalid,
  5. Load,
  6. Unload,
  7. Error,
  8. Resize,
  9. Visibility_Change,
  10. Fullscreen_Change,
  11. Fullscreen_Error,
  12. Click,
  13. Double_Click,
  14. Mouse_Move,
  15. Mouse_Over,
  16. Mouse_Out,
  17. Mouse_Up,
  18. Mouse_Down,
  19. Key_Up,
  20. Key_Down,
  21. Key_Press,
  22. Scroll,
  23. Wheel,
  24. Focus,
  25. Submit,
  26. Blur,
  27. Change,
  28. Select,
  29. Animation_Start,
  30. Animation_End,
  31. Animation_Iteration,
  32. Animation_Cancel,
  33. Copy,
  34. Cut,
  35. Paste,
  36. // Drag,
  37. // Drag_Start,
  38. // Drag_End,
  39. // Drag_Enter,
  40. // Drag_Leave,
  41. // Drag_Over,
  42. // Drop,
  43. Pointer_Cancel,
  44. Pointer_Down,
  45. Pointer_Enter,
  46. Pointer_Leave,
  47. Pointer_Move,
  48. Pointer_Over,
  49. Pointer_Up,
  50. Got_Pointer_Capture,
  51. Lost_Pointer_Capture,
  52. Pointer_Lock_Change,
  53. Pointer_Lock_Error,
  54. Selection_Change,
  55. Selection_Start,
  56. Touch_Cancel,
  57. Touch_End,
  58. Touch_Move,
  59. Touch_Start,
  60. Transition_Start,
  61. Transition_End,
  62. Transition_Run,
  63. Transition_Cancel,
  64. Context_Menu,
  65. Custom,
  66. }
  67. event_kind_string := [Event_Kind]string{
  68. .Invalid = "",
  69. .Load = "load",
  70. .Unload = "unload",
  71. .Error = "error",
  72. .Resize = "resize",
  73. .Visibility_Change = "visibilitychange",
  74. .Fullscreen_Change = "fullscreenchange",
  75. .Fullscreen_Error = "fullscreenerror",
  76. .Click = "click",
  77. .Double_Click = "dblclick",
  78. .Mouse_Move = "mousemove",
  79. .Mouse_Over = "mouseover",
  80. .Mouse_Out = "mouseout",
  81. .Mouse_Up = "mouseup",
  82. .Mouse_Down = "mousedown",
  83. .Key_Up = "keyup",
  84. .Key_Down = "keydown",
  85. .Key_Press = "keypress",
  86. .Scroll = "scroll",
  87. .Wheel = "wheel",
  88. .Focus = "focus",
  89. .Submit = "submit",
  90. .Blur = "blur",
  91. .Change = "change",
  92. .Select = "select",
  93. .Animation_Start = "animationstart",
  94. .Animation_End = "animationend",
  95. .Animation_Iteration = "animationiteration",
  96. .Animation_Cancel = "animationcancel",
  97. .Copy = "copy",
  98. .Cut = "cut",
  99. .Paste = "paste",
  100. // .Drag, = "drag",
  101. // .Drag_Start, = "dragstart",
  102. // .Drag_End, = "dragend",
  103. // .Drag_Enter, = "dragenter",
  104. // .Drag_Leave, = "dragleave",
  105. // .Drag_Over, = "dragover",
  106. // .Drop, = "drop",
  107. .Pointer_Cancel = "pointercancel",
  108. .Pointer_Down = "pointerdown",
  109. .Pointer_Enter = "pointerenter",
  110. .Pointer_Leave = "pointerleave",
  111. .Pointer_Move = "pointermove",
  112. .Pointer_Over = "pointerover",
  113. .Pointer_Up = "pointerup",
  114. .Got_Pointer_Capture = "gotpointercapture",
  115. .Lost_Pointer_Capture = "lostpointercapture",
  116. .Pointer_Lock_Change = "pointerlockchange",
  117. .Pointer_Lock_Error = "pointerlockerror",
  118. .Selection_Change = "selectionchange",
  119. .Selection_Start = "selectionstart",
  120. .Transition_Start = "transitionstart",
  121. .Transition_End = "transitionend",
  122. .Transition_Run = "transitionrun",
  123. .Transition_Cancel = "transitioncancel",
  124. .Touch_Cancel = "touchcancel",
  125. .Touch_End = "touchend",
  126. .Touch_Move = "touchmove",
  127. .Touch_Start = "touchstart",
  128. .Context_Menu = "contextmenu",
  129. .Custom = "?custom?",
  130. }
  131. Delta_Mode :: enum u32 {
  132. Pixel = 0,
  133. Line = 1,
  134. Page = 2,
  135. }
  136. Key_Location :: enum u8 {
  137. Standard = 0,
  138. Left = 1,
  139. Right = 2,
  140. Numpad = 3,
  141. }
  142. KEYBOARD_MAX_KEY_SIZE :: 16
  143. KEYBOARD_MAX_CODE_SIZE :: 16
  144. Event_Target_Kind :: enum u32 {
  145. Element = 0,
  146. Document = 1,
  147. Window = 2,
  148. }
  149. Event_Phase :: enum u8 {
  150. None = 0,
  151. Capturing_Phase = 1,
  152. At_Target = 2,
  153. Bubbling_Phase = 3,
  154. }
  155. Event_Option :: enum u8 {
  156. Bubbles = 0,
  157. Cancelable = 1,
  158. Composed = 2,
  159. }
  160. Event_Options :: distinct bit_set[Event_Option; u8]
  161. Event :: struct {
  162. kind: Event_Kind,
  163. target_kind: Event_Target_Kind,
  164. current_target_kind: Event_Target_Kind,
  165. id: string,
  166. timestamp: f64,
  167. phase: Event_Phase,
  168. options: Event_Options,
  169. is_composing: bool,
  170. is_trusted: bool,
  171. using data: struct #raw_union #align(8) {
  172. scroll: struct {
  173. delta: [2]f64,
  174. },
  175. visibility_change: struct {
  176. is_visible: bool,
  177. },
  178. wheel: struct {
  179. delta: [3]f64,
  180. delta_mode: Delta_Mode,
  181. },
  182. key: struct {
  183. key: string,
  184. code: string,
  185. location: Key_Location,
  186. ctrl: bool,
  187. shift: bool,
  188. alt: bool,
  189. meta: bool,
  190. repeat: bool,
  191. _key_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
  192. _code_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
  193. },
  194. mouse: struct {
  195. screen: [2]i64,
  196. client: [2]i64,
  197. offset: [2]i64,
  198. page: [2]i64,
  199. movement: [2]i64,
  200. ctrl: bool,
  201. shift: bool,
  202. alt: bool,
  203. meta: bool,
  204. button: i16,
  205. buttons: bit_set[0..<16; u16],
  206. },
  207. },
  208. user_data: rawptr,
  209. callback: proc(e: Event),
  210. }
  211. add_event_listener :: proc(id: string, kind: Event_Kind, user_data: rawptr, callback: proc(e: Event), use_capture := false) -> bool {
  212. panic("vendor:wasm/js not supported on non JS targets")
  213. }
  214. remove_event_listener :: proc(id: string, kind: Event_Kind, user_data: rawptr, callback: proc(e: Event)) -> bool {
  215. panic("vendor:wasm/js not supported on non JS targets")
  216. }
  217. add_window_event_listener :: proc(kind: Event_Kind, user_data: rawptr, callback: proc(e: Event), use_capture := false) -> bool {
  218. panic("vendor:wasm/js not supported on non JS targets")
  219. }
  220. remove_window_event_listener :: proc(kind: Event_Kind, user_data: rawptr, callback: proc(e: Event)) -> bool {
  221. panic("vendor:wasm/js not supported on non JS targets")
  222. }
  223. remove_event_listener_from_event :: proc(e: Event) -> bool {
  224. panic("vendor:wasm/js not supported on non JS targets")
  225. }
  226. add_custom_event_listener :: proc(id: string, name: string, user_data: rawptr, callback: proc(e: Event), use_capture := false) -> bool {
  227. panic("vendor:wasm/js not supported on non JS targets")
  228. }
  229. remove_custom_event_listener :: proc(id: string, name: string, user_data: rawptr, callback: proc(e: Event)) -> bool {
  230. panic("vendor:wasm/js not supported on non JS targets")
  231. }