Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

76 строки
2.0 KiB

  1. #include "core/common.h"
  2. #include "core/buttons.h"
  3. #include "core/display.h"
  4. #include <epaper/EPD.h>
  5. #include "ModeRunner.h"
  6. #include "ReaderMode.h"
  7. #include "AbstractMenuMode.h"
  8. static int baseY = 35;
  9. static int x = 20;
  10. void draw_menu_option(char* text, int textX, int textHeight, int line, bool selected)
  11. {
  12. EPD_print(text, textX, baseY + line * textHeight);
  13. }
  14. void draw_menu_cursor(int cursor, int textHeight)
  15. {
  16. EPD_drawRect(x, baseY + cursor * textHeight,
  17. EPD_DISPLAY_WIDTH - 2*x, textHeight + 1, 0x0F);
  18. }
  19. void AbstractMenuMode::start()
  20. {}
  21. void AbstractMenuMode::loop()
  22. {
  23. display_clear();
  24. EPD_setFont(COMIC24_FONT, NULL);
  25. EPD_print(this->getTitle(), CENTER, 0);
  26. int line = 0;
  27. EPD_setFont(this->getOptionsFont(), NULL);
  28. int menu_option_height = EPD_getfontheight() + 1;
  29. int menu_options_limit = (EPD_DISPLAY_HEIGHT - baseY) / (EPD_getfontheight() + 1);
  30. char** options = this->getOptions();
  31. int menu_options_size = this->getOptionsSize();
  32. int start = (this->cursor / menu_options_limit) * menu_options_limit;
  33. int stop = ((this->cursor / menu_options_limit) + 1) * menu_options_limit;
  34. for (int line = start; line < menu_options_size && line < stop; line++) {
  35. draw_menu_option(options[line], this->getOptionsX(), menu_option_height,
  36. line % menu_options_limit, this->cursor == line);
  37. }
  38. draw_menu_cursor(this->cursor % menu_options_limit, menu_option_height);
  39. display_update();
  40. while(1) {
  41. delay(5);
  42. if (buttons_pressed_ok()) {
  43. this->onOptionSelected(this->cursor);
  44. break;
  45. }
  46. if (buttons_pressed_minus()) {
  47. this->cursor = (this->cursor + menu_options_size - 1) % menu_options_size;
  48. break;
  49. }
  50. if (buttons_pressed_plus()) {
  51. this->cursor = (this->cursor + 1) % menu_options_size;
  52. break;
  53. }
  54. }
  55. }
  56. void AbstractMenuMode::finish()
  57. {}
  58. int AbstractMenuMode::getOptionsX()
  59. {
  60. return CENTER;
  61. }
  62. int AbstractMenuMode::getOptionsFont()
  63. {
  64. return DEJAVU18_FONT;
  65. }