gesture.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * File : gesture.h
  3. * COPYRIGHT (C) 2012-2017, Shanghai Real-Thread Technology Co., Ltd
  4. *
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2017-11-05 realthread the first version
  8. */
  9. #pragma once
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #include <rtgui/event.h>
  14. struct rtgui_gesture
  15. {
  16. struct rtgui_object *owner;
  17. rt_uint32_t touch_id;
  18. enum rtgui_gesture_type interest;
  19. /* Public info. Read only for application and recognizer. */
  20. struct
  21. {
  22. /* Pixel per second. */
  23. int x, y;
  24. } speed;
  25. /* FIXME: Need acceleration? */
  26. /* @last will behold while recognizing the gesture. It should never be
  27. * updated by the recognizer. The @current is the most recent point and
  28. * timestamp is read-only to the recognizer too. These members will be
  29. * updated by the gesture framwork. */
  30. struct
  31. {
  32. rt_uint16_t x, y;
  33. rt_tick_t ts;
  34. } start, last, current;
  35. /* Private info. Read/write for recognizer. */
  36. struct rtgui_timer *timer;
  37. rt_uint32_t start_stat;
  38. rt_uint32_t finish_stat;
  39. };
  40. int rtgui_gesture_init(struct rtgui_gesture *gest,
  41. struct rtgui_object *owner,
  42. enum rtgui_gesture_type inter);
  43. void rtgui_gesture_cleanup(struct rtgui_gesture *gest);
  44. /** Try to recognize gestures from the @eve.
  45. *
  46. * @eve should be a mouse event(either RTGUI_EVENT_MOUSE_BUTTON or
  47. * RTGUI_EVENT_MOUSE_MOTION) and every mouse event should be feed into this
  48. * function to get a possible gesture.
  49. *
  50. * When a gesture is recognized, it will return RT_TRUE. Otherwise, it will
  51. * return RT_FALSE. The event handler of the @owner will be called once a
  52. * gesture is recognized, with a rtgui_event_gesture event.
  53. */
  54. rt_bool_t rtgui_gesture_recognize(struct rtgui_gesture *gest,
  55. const struct rtgui_event *eve);
  56. #ifdef __cplusplus
  57. }
  58. #endif