events.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright (C) 2014 Olivier Marty <olivier.marty.m at gmail.com>
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. */
  15. #ifndef H_EVENTS
  16. #define H_EVENTS
  17. #include "rich_text.h"
  18. #include "time.h"
  19. enum _e_type { T_NONE, T_KEYPRESSED, T_SHOW, T_HIDE };
  20. typedef enum _e_type e_type;
  21. struct eventAny {
  22. e_type type;
  23. mytime time;
  24. };
  25. struct eventKeyPressed {
  26. e_type type;
  27. mytime time;
  28. int key;
  29. };
  30. struct eventShow {
  31. e_type type;
  32. mytime time;
  33. int id;
  34. struct richText *rt;
  35. };
  36. struct eventHide {
  37. e_type type;
  38. mytime time;
  39. int id;
  40. struct richText *rt;
  41. };
  42. union _t_event {
  43. e_type type;
  44. struct eventAny any;
  45. struct eventKeyPressed keyPressed;
  46. struct eventShow show;
  47. struct eventHide hide;
  48. };
  49. typedef union _t_event t_event;
  50. // should be implemented as a priority queue
  51. struct _t_events {
  52. int size;
  53. int maxsize;
  54. t_event *events;
  55. };
  56. typedef struct _t_events t_events;
  57. mytime eventsNextTime(t_events events);
  58. // events must be non empty
  59. void eventsPush(t_events *events, t_event e);
  60. t_event eventsPop(t_events *events);
  61. t_events eventsInit(int initSize);
  62. int eventsEmpty(t_events events);
  63. #endif