hex_viewer_custom_event.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. typedef enum {
  3. HexViewerCustomEventStartscreenUp,
  4. HexViewerCustomEventStartscreenDown,
  5. HexViewerCustomEventStartscreenLeft,
  6. HexViewerCustomEventStartscreenRight,
  7. HexViewerCustomEventStartscreenOk,
  8. HexViewerCustomEventStartscreenBack,
  9. HexViewerCustomEventScene1Up,
  10. HexViewerCustomEventScene1Down,
  11. HexViewerCustomEventScene1Left,
  12. HexViewerCustomEventScene1Right,
  13. HexViewerCustomEventScene1Ok,
  14. HexViewerCustomEventScene1Back,
  15. HexViewerCustomEventScene2Up,
  16. HexViewerCustomEventScene2Down,
  17. HexViewerCustomEventScene2Left,
  18. HexViewerCustomEventScene2Right,
  19. HexViewerCustomEventScene2Ok,
  20. HexViewerCustomEventScene2Back,
  21. } HexViewerCustomEvent;
  22. enum HexViewerCustomEventType {
  23. // Reserve first 100 events for button types and indexes, starting from 0
  24. HexViewerCustomEventMenuVoid,
  25. HexViewerCustomEventMenuSelected,
  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. } HexViewerCustomEventMenu;
  35. #pragma pack(pop)
  36. static inline uint32_t hex_viewer_custom_menu_event_pack(uint16_t type, int16_t value) {
  37. HexViewerCustomEventMenu event = {.content = {.type = type, .value = value}};
  38. return event.packed_value;
  39. }
  40. static inline void hex_viewer_custom_menu_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
  41. HexViewerCustomEventMenu event = {.packed_value = packed_value};
  42. if(type) *type = event.content.type;
  43. if(value) *value = event.content.value;
  44. }
  45. static inline uint16_t hex_viewer_custom_menu_event_get_type(uint32_t packed_value) {
  46. uint16_t type;
  47. hex_viewer_custom_menu_event_unpack(packed_value, &type, NULL);
  48. return type;
  49. }
  50. static inline int16_t hex_viewer_custom_menu_event_get_value(uint32_t packed_value) {
  51. int16_t value;
  52. hex_viewer_custom_menu_event_unpack(packed_value, NULL, &value);
  53. return value;
  54. }