flipbip_startscreen.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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, 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 flipbip_startscreen_model_init(FlipBipStartscreenModel* const model) {
  40. model->some_value = 1;
  41. }
  42. bool flipbip_startscreen_input(InputEvent* event, void* context) {
  43. furi_assert(context);
  44. FlipBipStartscreen* instance = context;
  45. if (event->type == InputTypeRelease) {
  46. switch(event->key) {
  47. case InputKeyBack:
  48. with_view_model(
  49. instance->view,
  50. FlipBipStartscreenModel * model,
  51. {
  52. UNUSED(model);
  53. instance->callback(FlipBipCustomEventStartscreenBack, 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. FlipBipStartscreenModel* model,
  65. {
  66. UNUSED(model);
  67. instance->callback(FlipBipCustomEventStartscreenOk, instance->context);
  68. },
  69. true);
  70. break;
  71. case InputKeyMAX:
  72. break;
  73. }
  74. }
  75. return true;
  76. }
  77. void flipbip_startscreen_exit(void* context) {
  78. furi_assert(context);
  79. }
  80. void flipbip_startscreen_enter(void* context) {
  81. furi_assert(context);
  82. FlipBipStartscreen* instance = (FlipBipStartscreen*)context;
  83. with_view_model(
  84. instance->view,
  85. FlipBipStartscreenModel * model,
  86. {
  87. flipbip_startscreen_model_init(model);
  88. },
  89. true
  90. );
  91. }
  92. FlipBipStartscreen* flipbip_startscreen_alloc() {
  93. FlipBipStartscreen* instance = malloc(sizeof(FlipBipStartscreen));
  94. instance->view = view_alloc();
  95. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBipStartscreenModel));
  96. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  97. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip_startscreen_draw);
  98. view_set_input_callback(instance->view, flipbip_startscreen_input);
  99. //view_set_enter_callback(instance->view, flipbip_startscreen_enter);
  100. //view_set_exit_callback(instance->view, flipbip_startscreen_exit);
  101. with_view_model(
  102. instance->view,
  103. FlipBipStartscreenModel * model,
  104. {
  105. flipbip_startscreen_model_init(model);
  106. },
  107. true
  108. );
  109. return instance;
  110. }
  111. void flipbip_startscreen_free(FlipBipStartscreen* instance) {
  112. furi_assert(instance);
  113. with_view_model(
  114. instance->view,
  115. FlipBipStartscreenModel * model,
  116. {
  117. UNUSED(model);
  118. },
  119. true);
  120. view_free(instance->view);
  121. free(instance);
  122. }
  123. View* flipbip_startscreen_get_view(FlipBipStartscreen* instance) {
  124. furi_assert(instance);
  125. return instance->view;
  126. }