hex_viewer_custom_event.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. HexViewerCustomEventMenuPercentEntered,
  27. };
  28. #pragma pack(push, 1)
  29. typedef union {
  30. uint32_t packed_value;
  31. struct {
  32. uint16_t type;
  33. int16_t value;
  34. } content;
  35. } HexViewerCustomEventMenu;
  36. #pragma pack(pop)
  37. static inline uint32_t hex_viewer_custom_menu_event_pack(uint16_t type, int16_t value) {
  38. HexViewerCustomEventMenu event = {.content = {.type = type, .value = value}};
  39. return event.packed_value;
  40. }
  41. static inline void
  42. hex_viewer_custom_menu_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
  43. HexViewerCustomEventMenu event = {.packed_value = packed_value};
  44. if(type) *type = event.content.type;
  45. if(value) *value = event.content.value;
  46. }
  47. static inline uint16_t hex_viewer_custom_menu_event_get_type(uint32_t packed_value) {
  48. uint16_t type;
  49. hex_viewer_custom_menu_event_unpack(packed_value, &type, NULL);
  50. return type;
  51. }
  52. static inline int16_t hex_viewer_custom_menu_event_get_value(uint32_t packed_value) {
  53. int16_t value;
  54. hex_viewer_custom_menu_event_unpack(packed_value, NULL, &value);
  55. return value;
  56. }