menu.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef _MENU_H
  2. #define _MENU_H
  3. #include "u8g2.h"
  4. //#define D12832
  5. #define D12864
  6. #ifdef D12832
  7. #define MENU_SMALL_FONT u8g2_font_baby_tr
  8. #define MENU_NORMAL_FONT u8g2_font_ncenR08_tf
  9. #define MENU_LARGE_FONT u8g2_font_ncenR08_tf
  10. #define MENU_BIG_NUM u8g2_font_ncenR18_tn
  11. #define MENU_BIG_NUM_FOCUS_XO 0
  12. #define MENU_BIG_NUM_FOCUS_EXTRAX 0
  13. #endif
  14. #ifdef D12864
  15. #define MENU_SMALL_FONT u8g2_font_baby_tr
  16. #define MENU_NORMAL_FONT u8g2_font_ncenR08_tf
  17. #define MENU_LARGE_FONT u8g2_font_ncenR10_tf
  18. #define MENU_BIG_NUM u8g2_font_ncenR24_tn
  19. #define MENU_BIG_NUM_FOCUS_XO 0
  20. #define MENU_BIG_NUM_FOCUS_EXTRAX 1
  21. #endif
  22. typedef struct _menu_struct menu_t;
  23. typedef struct _me_struct me_t;
  24. typedef int (*me_cb)(menu_t *menu, const me_t *me, uint8_t msg);
  25. struct _me_struct
  26. {
  27. me_cb cb;
  28. void *val;
  29. void *arg;
  30. u8g2_uint_t x;
  31. u8g2_uint_t y;
  32. };
  33. /* return 1, if this element can have focus */
  34. #define ME_MSG_IS_FOCUS 1
  35. /* draw focus graphics for the element */
  36. #define ME_MSG_DRAW_FOCUS 2
  37. /* user has pressed the select key */
  38. #define ME_MSG_SELECT 3
  39. /* advice for drawing */
  40. #define ME_MSG_DRAW 4
  41. struct _menu_struct
  42. {
  43. u8g2_t *u8g2;
  44. volatile uint16_t current_index; /* element which is processed right now */
  45. uint16_t focus_index; /* element which has the focus at the moment */
  46. uint16_t radio_index; /* if elements for a radio selection, then this is set by the cb */
  47. uint16_t me_count; /* total number of elements in the list */
  48. /* pointer to the list of menu elements */
  49. const me_t *me_list;
  50. };
  51. void menu_SetEdgePixel(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  52. void menu_ClearEdgePixel(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  53. void menu_DrawBoxFocus(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  54. void menu_DrawFrameFocus(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  55. void menu_Init(menu_t *menu, u8g2_t *u8g2);
  56. void menu_SetMEList(menu_t *menu, const me_t *me_list, uint16_t initial_focus);
  57. void menu_Draw(menu_t *menu);
  58. void menu_NextFocus(menu_t *menu);
  59. void menu_Select(menu_t *menu);
  60. int me_cb_null(menu_t *menu, const me_t *me, uint8_t msg);
  61. int me_cb_big_toggle(menu_t *menu, const me_t *me, uint8_t msg);
  62. int me_cb_wd_toggle(menu_t *menu, const me_t *me, uint8_t msg);
  63. int me_cb_0_5(menu_t *menu, const me_t *me, uint8_t msg);
  64. int me_cb_0_9(menu_t *menu, const me_t *me, uint8_t msg);
  65. int me_cb_0_9_ro(menu_t *menu, const me_t *me, uint8_t msg);
  66. int me_cb_0_23(menu_t *menu, const me_t *me, uint8_t msg);
  67. int me_cb_0_23_ro(menu_t *menu, const me_t *me, uint8_t msg);
  68. int me_cb_0_9_small_ro(menu_t *menu, const me_t *me, uint8_t msg);
  69. int me_cb_0_55(menu_t *menu, const me_t *me, uint8_t msg);
  70. int me_cb_1_12(menu_t *menu, const me_t *me, uint8_t msg);
  71. int me_cb_1_31(menu_t *menu, const me_t *me, uint8_t msg);
  72. int me_cb_num_label(menu_t *menu, const me_t *me, uint8_t msg);
  73. int me_cb_button_full_line(menu_t *menu, const me_t *me, uint8_t msg);
  74. int me_cb_button_half_line(menu_t *menu, const me_t *me, uint8_t msg);
  75. int me_cb_button_empty(menu_t *menu, const me_t *me, uint8_t msg);
  76. int me_cb_scale_1_7(menu_t *menu, const me_t *me, uint8_t msg);
  77. int me_cb_label(menu_t *menu, const me_t *me, uint8_t msg);
  78. int me_cb_inv_label(menu_t *menu, const me_t *me, uint8_t msg);
  79. int me_cb_16x16_bitmap_button(menu_t *menu, const me_t *me, uint8_t msg);
  80. #endif