scene_director.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "../types/common.h"
  2. #include "scene_director.h"
  3. #include "scenes/authenticate/totp_scene_authenticate.h"
  4. #include "scenes/generate_token/totp_scene_generate_token.h"
  5. #include "scenes/add_new_token/totp_scene_add_new_token.h"
  6. #include "scenes/token_menu/totp_scene_token_menu.h"
  7. #include "scenes/app_settings/totp_app_settings.h"
  8. #include "scenes/standby/standby.h"
  9. void totp_scene_director_activate_scene(PluginState* const plugin_state, Scene scene) {
  10. totp_scene_director_deactivate_active_scene(plugin_state);
  11. switch(scene) {
  12. case TotpSceneGenerateToken:
  13. totp_scene_generate_token_activate(plugin_state);
  14. break;
  15. case TotpSceneAuthentication:
  16. totp_scene_authenticate_activate(plugin_state);
  17. break;
  18. case TotpSceneAddNewToken:
  19. totp_scene_add_new_token_activate(plugin_state);
  20. break;
  21. case TotpSceneTokenMenu:
  22. totp_scene_token_menu_activate(plugin_state);
  23. break;
  24. case TotpSceneAppSettings:
  25. totp_scene_app_settings_activate(plugin_state);
  26. break;
  27. case TotpSceneNone:
  28. case TotpSceneStandby:
  29. break;
  30. default:
  31. break;
  32. }
  33. plugin_state->current_scene = scene;
  34. }
  35. void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state) {
  36. Scene current_scene = plugin_state->current_scene;
  37. plugin_state->current_scene = TotpSceneNone;
  38. switch(current_scene) {
  39. case TotpSceneGenerateToken:
  40. totp_scene_generate_token_deactivate(plugin_state);
  41. break;
  42. case TotpSceneAuthentication:
  43. totp_scene_authenticate_deactivate(plugin_state);
  44. break;
  45. case TotpSceneAddNewToken:
  46. totp_scene_add_new_token_deactivate(plugin_state);
  47. break;
  48. case TotpSceneTokenMenu:
  49. totp_scene_token_menu_deactivate(plugin_state);
  50. break;
  51. case TotpSceneAppSettings:
  52. totp_scene_app_settings_deactivate(plugin_state);
  53. break;
  54. case TotpSceneNone:
  55. case TotpSceneStandby:
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state) {
  62. switch(plugin_state->current_scene) {
  63. case TotpSceneGenerateToken:
  64. totp_scene_generate_token_render(canvas, plugin_state);
  65. break;
  66. case TotpSceneAuthentication:
  67. totp_scene_authenticate_render(canvas, plugin_state);
  68. break;
  69. case TotpSceneAddNewToken:
  70. totp_scene_add_new_token_render(canvas, plugin_state);
  71. break;
  72. case TotpSceneTokenMenu:
  73. totp_scene_token_menu_render(canvas, plugin_state);
  74. break;
  75. case TotpSceneAppSettings:
  76. totp_scene_app_settings_render(canvas, plugin_state);
  77. break;
  78. case TotpSceneNone:
  79. break;
  80. case TotpSceneStandby:
  81. totp_scene_standby_render(canvas);
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* const plugin_state) {
  88. bool processing = true;
  89. switch(plugin_state->current_scene) {
  90. case TotpSceneGenerateToken:
  91. processing = totp_scene_generate_token_handle_event(event, plugin_state);
  92. break;
  93. case TotpSceneAuthentication:
  94. processing = totp_scene_authenticate_handle_event(event, plugin_state);
  95. break;
  96. case TotpSceneAddNewToken:
  97. processing = totp_scene_add_new_token_handle_event(event, plugin_state);
  98. break;
  99. case TotpSceneTokenMenu:
  100. processing = totp_scene_token_menu_handle_event(event, plugin_state);
  101. break;
  102. case TotpSceneAppSettings:
  103. processing = totp_scene_app_settings_handle_event(event, plugin_state);
  104. break;
  105. case TotpSceneNone:
  106. case TotpSceneStandby:
  107. break;
  108. default:
  109. break;
  110. }
  111. return processing;
  112. }