flipbip39_startscreen.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "FlipBIP_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, 69, 11, "Flipper-BIP");
  31. //canvas_draw_str(canvas, 57, 11, "Flipper-BIP39");
  32. //canvas_draw_str(canvas, 60, 11, "Flipper BIP39");
  33. canvas_draw_str(canvas, 72, 11, "BIP39 Tool");
  34. canvas_set_font(canvas, FontSecondary);
  35. //canvas_draw_str(canvas, 30, 23, "Crypto tools for Flipper");
  36. canvas_draw_str(canvas, 23, 22, "Crypto toolkit for Flipper");
  37. elements_button_right(canvas, "Start");
  38. }
  39. static void flipbip39_startscreen_model_init(FlipBip39StartscreenModel* const model) {
  40. model->some_value = 1;
  41. }
  42. bool flipbip39_startscreen_input(InputEvent* event, void* context) {
  43. furi_assert(context);
  44. FlipBip39Startscreen* instance = context;
  45. if (event->type == InputTypeRelease) {
  46. switch(event->key) {
  47. case InputKeyBack:
  48. with_view_model(
  49. instance->view,
  50. FlipBip39StartscreenModel * model,
  51. {
  52. UNUSED(model);
  53. instance->callback(FlipBip39CustomEventStartscreenBack, instance->context);
  54. },
  55. true);
  56. break;
  57. case InputKeyLeft:
  58. case InputKeyRight:
  59. case InputKeyUp:
  60. case InputKeyDown:
  61. case InputKeyOk:
  62. with_view_model(
  63. instance->view,
  64. FlipBip39StartscreenModel* model,
  65. {
  66. UNUSED(model);
  67. instance->callback(FlipBip39CustomEventStartscreenOk, instance->context);
  68. },
  69. true);
  70. break;
  71. case InputKeyMAX:
  72. break;
  73. }
  74. }
  75. return true;
  76. }
  77. void flipbip39_startscreen_exit(void* context) {
  78. furi_assert(context);
  79. }
  80. void flipbip39_startscreen_enter(void* context) {
  81. furi_assert(context);
  82. FlipBip39Startscreen* instance = (FlipBip39Startscreen*)context;
  83. with_view_model(
  84. instance->view,
  85. FlipBip39StartscreenModel * model,
  86. {
  87. flipbip39_startscreen_model_init(model);
  88. },
  89. true
  90. );
  91. }
  92. FlipBip39Startscreen* flipbip39_startscreen_alloc() {
  93. FlipBip39Startscreen* instance = malloc(sizeof(FlipBip39Startscreen));
  94. instance->view = view_alloc();
  95. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBip39StartscreenModel));
  96. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  97. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip39_startscreen_draw);
  98. view_set_input_callback(instance->view, flipbip39_startscreen_input);
  99. //view_set_enter_callback(instance->view, flipbip39_startscreen_enter);
  100. //view_set_exit_callback(instance->view, flipbip39_startscreen_exit);
  101. with_view_model(
  102. instance->view,
  103. FlipBip39StartscreenModel * model,
  104. {
  105. flipbip39_startscreen_model_init(model);
  106. },
  107. true
  108. );
  109. return instance;
  110. }
  111. void flipbip39_startscreen_free(FlipBip39Startscreen* instance) {
  112. furi_assert(instance);
  113. with_view_model(
  114. instance->view,
  115. FlipBip39StartscreenModel * model,
  116. {
  117. UNUSED(model);
  118. },
  119. true);
  120. view_free(instance->view);
  121. free(instance);
  122. }
  123. View* flipbip39_startscreen_get_view(FlipBip39Startscreen* instance) {
  124. furi_assert(instance);
  125. return instance->view;
  126. }