XM_event.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef XM_EVENT_H
  2. #define XM_EVENT_H
  3. enum {
  4. XM_EVENT_FIRST = 0,
  5. XM_EVENT_KEYDOWN = 0,
  6. XM_EVENT_KEYUP,
  7. XM_EVENT_TOUCHDOWN,
  8. XM_EVENT_TOUCHUP,
  9. XM_EVENT_TOUCHMOVE,
  10. XM_EVENT_TEXTINPUT,
  11. XM_EVENT_TIMER,
  12. XM_EVENT_LAST
  13. };
  14. typedef struct XM_KeyboardEvent
  15. {
  16. unsigned int type; // KEYDOWN or KEYUP
  17. unsigned int timestamp; // In milliseconds
  18. unsigned int scancode;
  19. unsigned char press; // PRESSED or RELEASED
  20. unsigned char repeat; // Non-zero if this is a key repeat
  21. } XM_KeyboardEvent;
  22. typedef struct XM_TouchEvent
  23. {
  24. unsigned int type; // MOUSEMOTION
  25. unsigned int timestamp; // In milliseconds
  26. //unsigned int press; // PRESSED
  27. int x; /**< X coordinate, relative to window */
  28. int y; /**< Y coordinate, relative to window */
  29. int xrel; /**< The relative motion in the X direction */
  30. int yrel; /**< The relative motion in the Y direction */
  31. } XM_TouchEvent;
  32. #define XM_TEXTINPUTEVENT_TEXT_SIZE (32)
  33. /**
  34. * \brief Keyboard text input event structure (event.text.*)
  35. */
  36. typedef struct XM_TextInputEvent
  37. {
  38. unsigned int type; /**< ::SDL_TEXTINPUT */
  39. unsigned int timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
  40. char text[XM_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */
  41. } XM_TextInputEvent;
  42. typedef struct _XM_EVENT {
  43. unsigned int type;
  44. union {
  45. XM_KeyboardEvent key;
  46. XM_TouchEvent tp;
  47. XM_TextInputEvent text;
  48. };
  49. } XM_EVENT;
  50. // 投递触摸事件到事件消息队列
  51. // 返回值定义
  52. // 1 事件投递到事件缓冲队列成功
  53. // 0 事件投递到事件缓冲队列失败
  54. int XM_TpEventProc (unsigned int tp_event, unsigned int xPos, unsigned int yPos, unsigned int ticket);
  55. // 投递按键事件到事件消息队列
  56. // scancode 扫描码
  57. // press 按键是否按下 1 按下 0 释放
  58. // repeat 是否重复键
  59. // 返回值定义
  60. // 1 事件投递到事件缓冲队列成功
  61. // 0 事件投递到事件缓冲队列失败
  62. int XM_KeyEventProc(unsigned int key_event, unsigned int scancode, unsigned char press, unsigned char repeat, unsigned int ticket);
  63. // 投递UTF8字符串事件到事件消息队列
  64. // text UTF8编码的字符串, 以'\0'结束
  65. int XM_TextInputEventProc(const char *text, unsigned int ticket);
  66. // 等待外部事件
  67. int XM_WaitEvent (XM_EVENT *event, unsigned int timeout);
  68. #endif