flipbip_startscreen.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "../flipbip.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 FlipBipStartscreen {
  8. View* view;
  9. FlipBipStartscreenCallback callback;
  10. void* context;
  11. };
  12. typedef struct {
  13. int some_value;
  14. } FlipBipStartscreenModel;
  15. void flipbip_startscreen_set_callback(
  16. FlipBipStartscreen* instance,
  17. FlipBipStartscreenCallback callback,
  18. void* context) {
  19. furi_assert(instance);
  20. furi_assert(callback);
  21. instance->callback = callback;
  22. instance->context = context;
  23. }
  24. void flipbip_startscreen_draw(Canvas* canvas, FlipBipStartscreenModel* 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, 39, 11, "BIP32/39/44 Tool");
  31. canvas_set_font(canvas, FontSecondary);
  32. //canvas_draw_str(canvas, 30, 23, "Crypto tools for Flipper");
  33. canvas_draw_str(canvas, 23, 22, "Crypto toolkit for Flipper");
  34. elements_button_right(canvas, "Start");
  35. }
  36. static void flipbip_startscreen_model_init(FlipBipStartscreenModel* const model) {
  37. model->some_value = 1;
  38. }
  39. bool flipbip_startscreen_input(InputEvent* event, void* context) {
  40. furi_assert(context);
  41. FlipBipStartscreen* instance = context;
  42. if (event->type == InputTypeRelease) {
  43. switch(event->key) {
  44. case InputKeyBack:
  45. with_view_model(
  46. instance->view,
  47. FlipBipStartscreenModel * model,
  48. {
  49. UNUSED(model);
  50. instance->callback(FlipBipCustomEventStartscreenBack, instance->context);
  51. },
  52. true);
  53. break;
  54. case InputKeyLeft:
  55. case InputKeyRight:
  56. case InputKeyUp:
  57. case InputKeyDown:
  58. case InputKeyOk:
  59. with_view_model(
  60. instance->view,
  61. FlipBipStartscreenModel* model,
  62. {
  63. UNUSED(model);
  64. instance->callback(FlipBipCustomEventStartscreenOk, instance->context);
  65. },
  66. true);
  67. break;
  68. case InputKeyMAX:
  69. break;
  70. }
  71. }
  72. return true;
  73. }
  74. void flipbip_startscreen_exit(void* context) {
  75. furi_assert(context);
  76. }
  77. void flipbip_startscreen_enter(void* context) {
  78. furi_assert(context);
  79. FlipBipStartscreen* instance = (FlipBipStartscreen*)context;
  80. with_view_model(
  81. instance->view,
  82. FlipBipStartscreenModel * model,
  83. {
  84. flipbip_startscreen_model_init(model);
  85. },
  86. true
  87. );
  88. }
  89. FlipBipStartscreen* flipbip_startscreen_alloc() {
  90. FlipBipStartscreen* instance = malloc(sizeof(FlipBipStartscreen));
  91. instance->view = view_alloc();
  92. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBipStartscreenModel));
  93. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  94. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip_startscreen_draw);
  95. view_set_input_callback(instance->view, flipbip_startscreen_input);
  96. //view_set_enter_callback(instance->view, flipbip_startscreen_enter);
  97. //view_set_exit_callback(instance->view, flipbip_startscreen_exit);
  98. with_view_model(
  99. instance->view,
  100. FlipBipStartscreenModel * model,
  101. {
  102. flipbip_startscreen_model_init(model);
  103. },
  104. true
  105. );
  106. return instance;
  107. }
  108. void flipbip_startscreen_free(FlipBipStartscreen* instance) {
  109. furi_assert(instance);
  110. with_view_model(
  111. instance->view,
  112. FlipBipStartscreenModel * model,
  113. {
  114. UNUSED(model);
  115. },
  116. true);
  117. view_free(instance->view);
  118. free(instance);
  119. }
  120. View* flipbip_startscreen_get_view(FlipBipStartscreen* instance) {
  121. furi_assert(instance);
  122. return instance->view;
  123. }