flipbip39_startscreen.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "../flipbip39.h"
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #include <input/input.h>
  5. #include <gui/elements.h>
  6. #include "flipbip39_icons.h"
  7. struct FlipBip39Startscreen {
  8. View* view;
  9. FlipBip39StartscreenCallback callback;
  10. void* context;
  11. };
  12. typedef struct {
  13. int some_value;
  14. } FlipBip39StartscreenModel;
  15. void flipbip39_startscreen_set_callback(
  16. FlipBip39Startscreen* instance,
  17. FlipBip39StartscreenCallback callback,
  18. void* context) {
  19. furi_assert(instance);
  20. furi_assert(callback);
  21. instance->callback = callback;
  22. instance->context = context;
  23. }
  24. void flipbip39_startscreen_draw(Canvas* canvas, FlipBip39StartscreenModel* model) {
  25. UNUSED(model);
  26. canvas_clear(canvas);
  27. canvas_set_color(canvas, ColorBlack);
  28. canvas_draw_icon(canvas, 1, 33, &I_Auth_62x31);
  29. canvas_set_font(canvas, FontPrimary);
  30. canvas_draw_str(canvas, 74, 11, "Flip-BIP39");
  31. canvas_set_font(canvas, FontSecondary);
  32. canvas_draw_str(canvas, 30, 23, "Crypto tools for Flipper");
  33. elements_button_right(canvas, "Start");
  34. }
  35. static void flipbip39_startscreen_model_init(FlipBip39StartscreenModel* const model) {
  36. model->some_value = 1;
  37. }
  38. bool flipbip39_startscreen_input(InputEvent* event, void* context) {
  39. furi_assert(context);
  40. FlipBip39Startscreen* instance = context;
  41. if (event->type == InputTypeRelease) {
  42. switch(event->key) {
  43. case InputKeyBack:
  44. with_view_model(
  45. instance->view,
  46. FlipBip39StartscreenModel * model,
  47. {
  48. UNUSED(model);
  49. instance->callback(FlipBip39CustomEventStartscreenBack, instance->context);
  50. },
  51. true);
  52. break;
  53. case InputKeyLeft:
  54. case InputKeyRight:
  55. case InputKeyUp:
  56. case InputKeyDown:
  57. case InputKeyOk:
  58. with_view_model(
  59. instance->view,
  60. FlipBip39StartscreenModel* model,
  61. {
  62. UNUSED(model);
  63. instance->callback(FlipBip39CustomEventStartscreenOk, instance->context);
  64. },
  65. true);
  66. break;
  67. case InputKeyMAX:
  68. break;
  69. }
  70. }
  71. return true;
  72. }
  73. void flipbip39_startscreen_exit(void* context) {
  74. furi_assert(context);
  75. }
  76. void flipbip39_startscreen_enter(void* context) {
  77. furi_assert(context);
  78. FlipBip39Startscreen* instance = (FlipBip39Startscreen*)context;
  79. with_view_model(
  80. instance->view,
  81. FlipBip39StartscreenModel * model,
  82. {
  83. flipbip39_startscreen_model_init(model);
  84. },
  85. true
  86. );
  87. }
  88. FlipBip39Startscreen* flipbip39_startscreen_alloc() {
  89. FlipBip39Startscreen* instance = malloc(sizeof(FlipBip39Startscreen));
  90. instance->view = view_alloc();
  91. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBip39StartscreenModel));
  92. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  93. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip39_startscreen_draw);
  94. view_set_input_callback(instance->view, flipbip39_startscreen_input);
  95. //view_set_enter_callback(instance->view, flipbip39_startscreen_enter);
  96. //view_set_exit_callback(instance->view, flipbip39_startscreen_exit);
  97. with_view_model(
  98. instance->view,
  99. FlipBip39StartscreenModel * model,
  100. {
  101. flipbip39_startscreen_model_init(model);
  102. },
  103. true
  104. );
  105. return instance;
  106. }
  107. void flipbip39_startscreen_free(FlipBip39Startscreen* instance) {
  108. furi_assert(instance);
  109. with_view_model(
  110. instance->view,
  111. FlipBip39StartscreenModel * model,
  112. {
  113. UNUSED(model);
  114. },
  115. true);
  116. view_free(instance->view);
  117. free(instance);
  118. }
  119. View* flipbip39_startscreen_get_view(FlipBip39Startscreen* instance) {
  120. furi_assert(instance);
  121. return instance->view;
  122. }