input.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include <switch.h>
  4. #include "nx/input.h"
  5. bool g_touch_lock = false;
  6. PadState padState = { 0 };
  7. HidTouchScreenState hidState = { 0 };
  8. void init_input(void)
  9. {
  10. padConfigureInput(1, HidNpadStyleSet_NpadStandard);
  11. padInitializeDefault(&padState);
  12. }
  13. input_t get_input(void)
  14. {
  15. padUpdate(&padState);
  16. hidGetTouchScreenStates(&hidState, 1);
  17. input_t input = { 0 };
  18. input.down = padGetButtonsDown(&padState);
  19. input.held = padGetButtons(&padState);
  20. input.t_count = hidState.count;
  21. if (input.t_count) {
  22. input.t_pos = hidState.touches[0];
  23. }
  24. return input;
  25. }
  26. bool is_touch(void)
  27. {
  28. input_t input = get_input();
  29. return input.t_count > 0;
  30. }
  31. int check_if_touch_yesno(const input_t *input)
  32. {
  33. if (input->t_count)
  34. {
  35. for (uint16_t i = 0, x = 255; !g_touch_lock && i < 2; i++, x += 770 / 2)
  36. {
  37. if (input->t_pos.x > x && input->t_pos.x < x + (770 / 2) && input->t_pos.y > 210 + 295 - 72 && input->t_pos.y < 210 + 295)
  38. {
  39. g_touch_lock = true;
  40. return i;
  41. }
  42. }
  43. g_touch_lock = true;
  44. }
  45. else
  46. {
  47. g_touch_lock = false;
  48. }
  49. return -1;
  50. }
  51. bool check_if_touch_error(void)
  52. {
  53. input_t input = get_input();
  54. if (input.t_count)
  55. {
  56. if (!g_touch_lock && input.t_pos.x > 455 && input.t_pos.x < 455 + 365 && input.t_pos.y > 470 && input.t_pos.y < 470 + 65)
  57. return true;
  58. g_touch_lock = true;
  59. }
  60. else
  61. {
  62. g_touch_lock = false;
  63. }
  64. if ((input.down & HidNpadButton_A || input.down & HidNpadButton_B))
  65. return true;
  66. return false;
  67. }
  68. int check_if_option(const input_t *input)
  69. {
  70. if (input->t_count)
  71. {
  72. for (uint16_t i = 0, y = 300; !g_touch_lock && i < 3; i++, y += 125)
  73. {
  74. if (input->t_pos.x > 475 && input->t_pos.x < 475 + 720 && input->t_pos.y > y && input->t_pos.y < y + 70)
  75. {
  76. g_touch_lock = true;
  77. return i;
  78. }
  79. }
  80. g_touch_lock = true;
  81. }
  82. else
  83. {
  84. g_touch_lock = false;
  85. }
  86. return -1;
  87. }
  88. uint32_t move_cursor_up(uint32_t cursor, uint32_t cursor_max)
  89. {
  90. return cursor == 0 ? cursor_max - 1 : --cursor;
  91. }
  92. uint32_t move_cursor_down(uint32_t cursor, uint32_t cursor_max)
  93. {
  94. return cursor == cursor_max - 1 ? 0 : ++cursor;
  95. }