/src/backend/sdl/ftk_source_sdl.c

http://ftk.googlecode.com/ · C · 97 lines · 84 code · 12 blank · 1 comment · 9 complexity · abf35a1f68c64e951e41e064b3c9b902 MD5 · raw file

  1. #include "ftk.h"
  2. #include "ftk_typedef.h"
  3. #include "ftk_source_sdl.h"
  4. #include <SDL.h>
  5. typedef struct _PrivInfo
  6. {
  7. FtkEvent event;
  8. }PrivInfo;
  9. static int ftk_source_sdl_get_fd(FtkSource* thiz)
  10. {
  11. return -1;
  12. }
  13. static int ftk_source_sdl_check(FtkSource* thiz)
  14. {
  15. return 0;
  16. }
  17. static Ret ftk_source_sdl_dispatch(FtkSource* thiz)
  18. {
  19. SDL_Event event;
  20. DECL_PRIV(thiz, priv);
  21. do
  22. {
  23. if(!SDL_PollEvent(&event))
  24. {
  25. usleep(20000);
  26. break;
  27. }
  28. /* TODO: event.type */
  29. switch(event.type)
  30. {
  31. case SDL_KEYDOWN:
  32. break;
  33. case SDL_KEYUP:
  34. break;
  35. case SDL_MOUSEBUTTONDOWN:
  36. priv->event.type = FTK_EVT_MOUSE_DOWN;
  37. priv->event.u.mouse.x = event.button.x;
  38. priv->event.u.mouse.y = event.button.y;
  39. ftk_wnd_manager_queue_event_auto_rotate(ftk_default_wnd_manager(), &priv->event);
  40. break;
  41. case SDL_MOUSEBUTTONUP:
  42. priv->event.type = FTK_EVT_MOUSE_UP;
  43. priv->event.u.mouse.x = event.button.x;
  44. priv->event.u.mouse.y = event.button.y;
  45. ftk_wnd_manager_queue_event_auto_rotate(ftk_default_wnd_manager(), &priv->event);
  46. break;
  47. case SDL_MOUSEMOTION:
  48. if(event.motion.state != SDL_PRESSED)
  49. {
  50. break;
  51. }
  52. priv->event.type = FTK_EVT_MOUSE_MOVE;
  53. priv->event.u.mouse.x = event.motion.x;
  54. priv->event.u.mouse.y = event.motion.y;
  55. ftk_wnd_manager_queue_event_auto_rotate(ftk_default_wnd_manager(), &priv->event);
  56. break;
  57. case SDL_QUIT:
  58. FTK_QUIT();
  59. break;
  60. default:
  61. break;
  62. }
  63. } while(1);
  64. return RET_OK;
  65. }
  66. static void ftk_source_sdl_destroy(FtkSource* thiz)
  67. {
  68. if(thiz != NULL)
  69. {
  70. FTK_ZFREE(thiz, sizeof(FtkSource) + sizeof(PrivInfo));
  71. }
  72. }
  73. FtkSource* ftk_source_sdl_create(void)
  74. {
  75. FtkSource* thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo));
  76. if(thiz != NULL)
  77. {
  78. thiz->get_fd = ftk_source_sdl_get_fd;
  79. thiz->check = ftk_source_sdl_check;
  80. thiz->dispatch = ftk_source_sdl_dispatch;
  81. thiz->destroy = ftk_source_sdl_destroy;
  82. thiz->ref = 1;
  83. }
  84. return thiz;
  85. }