boilerplate_custom_event.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. typedef enum {
  3. BoilerplateCustomEventStartscreenUp,
  4. BoilerplateCustomEventStartscreenDown,
  5. BoilerplateCustomEventStartscreenLeft,
  6. BoilerplateCustomEventStartscreenRight,
  7. BoilerplateCustomEventStartscreenOk,
  8. BoilerplateCustomEventStartscreenBack,
  9. BoilerplateCustomEventScene1Up,
  10. BoilerplateCustomEventScene1Down,
  11. BoilerplateCustomEventScene1Left,
  12. BoilerplateCustomEventScene1Right,
  13. BoilerplateCustomEventScene1Ok,
  14. BoilerplateCustomEventScene1Back,
  15. BoilerplateCustomEventScene2Up,
  16. BoilerplateCustomEventScene2Down,
  17. BoilerplateCustomEventScene2Left,
  18. BoilerplateCustomEventScene2Right,
  19. BoilerplateCustomEventScene2Ok,
  20. BoilerplateCustomEventScene2Back,
  21. } BoilerplateCustomEvent;
  22. enum BoilerplateCustomEventType {
  23. // Reserve first 100 events for button types and indexes, starting from 0
  24. BoilerplateCustomEventMenuVoid,
  25. BoilerplateCustomEventMenuSelected,
  26. };
  27. #pragma pack(push, 1)
  28. typedef union {
  29. uint32_t packed_value;
  30. struct {
  31. uint16_t type;
  32. int16_t value;
  33. } content;
  34. } BoilerplateCustomEventMenu;
  35. #pragma pack(pop)
  36. static inline uint32_t boilerplate_custom_menu_event_pack(uint16_t type, int16_t value) {
  37. BoilerplateCustomEventMenu event = {.content = {.type = type, .value = value}};
  38. return event.packed_value;
  39. }
  40. static inline void
  41. boilerplate_custom_menu_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
  42. BoilerplateCustomEventMenu event = {.packed_value = packed_value};
  43. if(type) *type = event.content.type;
  44. if(value) *value = event.content.value;
  45. }
  46. static inline uint16_t boilerplate_custom_menu_event_get_type(uint32_t packed_value) {
  47. uint16_t type;
  48. boilerplate_custom_menu_event_unpack(packed_value, &type, NULL);
  49. return type;
  50. }
  51. static inline int16_t boilerplate_custom_menu_event_get_value(uint32_t packed_value) {
  52. int16_t value;
  53. boilerplate_custom_menu_event_unpack(packed_value, NULL, &value);
  54. return value;
  55. }