mfc_editor_app.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "mfc_editor_app_i.h"
  2. bool mfc_editor_app_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. MfcEditorApp* instance = context;
  5. return scene_manager_handle_custom_event(instance->scene_manager, event);
  6. }
  7. bool mfc_editor_app_back_event_callback(void* context) {
  8. furi_assert(context);
  9. MfcEditorApp* instance = context;
  10. return scene_manager_handle_back_event(instance->scene_manager);
  11. }
  12. void mfc_editor_app_tick_event_callback(void* context) {
  13. furi_assert(context);
  14. MfcEditorApp* instance = context;
  15. scene_manager_handle_tick_event(instance->scene_manager);
  16. }
  17. MfcEditorApp* mfc_editor_app_alloc() {
  18. MfcEditorApp* instance = malloc(sizeof(MfcEditorApp));
  19. instance->view_dispatcher = view_dispatcher_alloc();
  20. instance->scene_manager = scene_manager_alloc(&mfc_editor_scene_handlers, instance);
  21. view_dispatcher_enable_queue(instance->view_dispatcher);
  22. view_dispatcher_set_event_callback_context(instance->view_dispatcher, instance);
  23. view_dispatcher_set_custom_event_callback(
  24. instance->view_dispatcher, mfc_editor_app_custom_event_callback);
  25. view_dispatcher_set_navigation_event_callback(
  26. instance->view_dispatcher, mfc_editor_app_back_event_callback);
  27. view_dispatcher_set_tick_event_callback(
  28. instance->view_dispatcher, mfc_editor_app_tick_event_callback, 100);
  29. instance->gui = furi_record_open(RECORD_GUI);
  30. view_dispatcher_attach_to_gui(
  31. instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
  32. instance->nfc_device = nfc_device_alloc();
  33. instance->submenu = submenu_alloc();
  34. view_dispatcher_add_view(
  35. instance->view_dispatcher, MfcEditorAppViewSubmenu, submenu_get_view(instance->submenu));
  36. return instance;
  37. }
  38. void mfc_editor_app_free(MfcEditorApp* instance) {
  39. furi_assert(instance);
  40. view_dispatcher_remove_view(instance->view_dispatcher, MfcEditorAppViewSubmenu);
  41. submenu_free(instance->submenu);
  42. view_dispatcher_free(instance->view_dispatcher);
  43. scene_manager_free(instance->scene_manager);
  44. furi_record_close(RECORD_GUI);
  45. instance->gui = NULL;
  46. nfc_device_free(instance->nfc_device);
  47. free(instance);
  48. }
  49. int32_t mfc_editor_app(void* p) {
  50. UNUSED(p);
  51. MfcEditorApp* instance = mfc_editor_app_alloc();
  52. scene_manager_next_scene(instance->scene_manager, MfcEditorSceneStart);
  53. view_dispatcher_run(instance->view_dispatcher);
  54. mfc_editor_app_free(instance);
  55. return 0;
  56. }