subbrute_scene_select_field.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "subbrute_scene_select_field.h"
  2. void center_displayed_key(SubBruteState* context, uint8_t index) {
  3. const char* key_cstr = string_get_cstr(context->key);
  4. uint8_t str_index = (index * 3);
  5. char display_menu[17] = {
  6. 'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'};
  7. if(index > 1) {
  8. display_menu[0] = key_cstr[str_index - 6];
  9. display_menu[1] = key_cstr[str_index - 5];
  10. } else {
  11. display_menu[0] = ' ';
  12. display_menu[1] = ' ';
  13. }
  14. if(index > 0) {
  15. display_menu[3] = key_cstr[str_index - 3];
  16. display_menu[4] = key_cstr[str_index - 2];
  17. } else {
  18. display_menu[3] = ' ';
  19. display_menu[4] = ' ';
  20. }
  21. display_menu[7] = key_cstr[str_index];
  22. display_menu[8] = key_cstr[str_index + 1];
  23. if((str_index + 4) <= (uint8_t)strlen(key_cstr)) {
  24. display_menu[11] = key_cstr[str_index + 3];
  25. display_menu[12] = key_cstr[str_index + 4];
  26. } else {
  27. display_menu[11] = ' ';
  28. display_menu[12] = ' ';
  29. }
  30. if((str_index + 8) <= (uint8_t)strlen(key_cstr)) {
  31. display_menu[14] = key_cstr[str_index + 6];
  32. display_menu[15] = key_cstr[str_index + 7];
  33. } else {
  34. display_menu[14] = ' ';
  35. display_menu[15] = ' ';
  36. }
  37. string_reset(context->notification_msg);
  38. string_set_str(context->notification_msg, display_menu);
  39. }
  40. void subbrute_scene_select_field_on_enter(SubBruteState* context) {
  41. string_clear(context->notification_msg);
  42. }
  43. void subbrute_scene_select_field_on_exit(SubBruteState* context) {
  44. UNUSED(context);
  45. }
  46. void subbrute_scene_select_field_on_tick(SubBruteState* context) {
  47. UNUSED(context);
  48. }
  49. void subbrute_scene_select_field_on_event(SubBruteEvent event, SubBruteState* context) {
  50. if(event.evt_type == EventTypeKey) {
  51. if(event.input_type == InputTypeShort) {
  52. //const char* key_cstr = string_get_cstr(context->key);
  53. // don't look, it's ugly but I'm a python dev so...
  54. /*uint8_t nb_bytes = 0;
  55. for(uint8_t i = 0; i < strlen(key_cstr); i++) {
  56. if(' ' == key_cstr[i]) {
  57. nb_bytes++;
  58. }
  59. }*/
  60. switch(event.key) {
  61. case InputKeyDown:
  62. case InputKeyUp:
  63. break;
  64. case InputKeyLeft:
  65. if(context->key_index > 0) {
  66. context->key_index--;
  67. }
  68. break;
  69. case InputKeyRight:
  70. if(context->key_index < 7) {
  71. context->key_index++;
  72. }
  73. break;
  74. case InputKeyOk:
  75. string_reset(context->notification_msg);
  76. context->current_scene = SceneAttack;
  77. break;
  78. case InputKeyBack:
  79. string_reset(context->notification_msg);
  80. context->current_scene = SceneSelectFile;
  81. break;
  82. }
  83. //FURI_LOG_D(TAG, "Position: %d/%d", context->key_index, nb_bytes);
  84. }
  85. }
  86. }
  87. void subbrute_scene_select_field_on_draw(Canvas* canvas, SubBruteState* context) {
  88. canvas_clear(canvas);
  89. canvas_set_color(canvas, ColorBlack);
  90. // Frame
  91. //canvas_draw_frame(canvas, 0, 0, 128, 64);
  92. // Title
  93. canvas_set_font(canvas, FontPrimary);
  94. canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignTop, "use < > to select field");
  95. char msg_index[18];
  96. snprintf(msg_index, sizeof(msg_index), "Field index : %d", context->key_index);
  97. canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, msg_index);
  98. center_displayed_key(context, context->key_index);
  99. canvas_set_font(canvas, FontSecondary);
  100. canvas_draw_str_aligned(
  101. canvas, 64, 40, AlignCenter, AlignTop, string_get_cstr(context->notification_msg));
  102. }