flipbip_startscreen.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, 18, 11, "FlipBIP - BIP32/39/44");
  31. canvas_set_font(canvas, FontSecondary);
  32. canvas_draw_str(canvas, 23, 22, "Crypto toolkit for Flipper");
  33. canvas_draw_str(canvas, 99, 34, FLIPBIP_VERSION);
  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. { flipbip_startscreen_model_init(model); },
  84. true);
  85. }
  86. FlipBipStartscreen* flipbip_startscreen_alloc() {
  87. FlipBipStartscreen* instance = malloc(sizeof(FlipBipStartscreen));
  88. instance->view = view_alloc();
  89. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBipStartscreenModel));
  90. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  91. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip_startscreen_draw);
  92. view_set_input_callback(instance->view, flipbip_startscreen_input);
  93. //view_set_enter_callback(instance->view, flipbip_startscreen_enter);
  94. //view_set_exit_callback(instance->view, flipbip_startscreen_exit);
  95. with_view_model(
  96. instance->view,
  97. FlipBipStartscreenModel * model,
  98. { flipbip_startscreen_model_init(model); },
  99. true);
  100. return instance;
  101. }
  102. void flipbip_startscreen_free(FlipBipStartscreen* instance) {
  103. furi_assert(instance);
  104. with_view_model(
  105. instance->view, FlipBipStartscreenModel * model, { UNUSED(model); }, true);
  106. view_free(instance->view);
  107. free(instance);
  108. }
  109. View* flipbip_startscreen_get_view(FlipBipStartscreen* instance) {
  110. furi_assert(instance);
  111. return instance->view;
  112. }