|
| 1 | +#include <gui/modules/menu.h> |
| 2 | +#include <gui/modules/popup.h> |
| 3 | + |
| 4 | +#include "main_menu.h" |
| 5 | +#include "../app_context.h" |
| 6 | +#include "../tone_gen.h" |
| 7 | +#include "../utils/linked_list.h" |
| 8 | + |
| 9 | +/** indices for menu items */ |
| 10 | +typedef enum { |
| 11 | + ToneGenAppMenuSelection_Play, |
| 12 | + ToneGenAppMenuSelection_Adjust |
| 13 | +} ToneGenAppMenuSelection; |
| 14 | + |
| 15 | +/** main menu callback - sends a custom event to the scene manager based on the menu selection */ |
| 16 | +void menu_callback_main_menu(void* context, uint32_t index) { |
| 17 | + FURI_LOG_I(TAG, "menu_callback_main_menu"); |
| 18 | + UNUSED(context); |
| 19 | + // struct AppContext_t* app = context; |
| 20 | + switch(index) { |
| 21 | + case ToneGenAppMenuSelection_Play: |
| 22 | + FURI_LOG_I(TAG, "selection one"); |
| 23 | + // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_StartPlayback); |
| 24 | + break; |
| 25 | + case ToneGenAppMenuSelection_Adjust: |
| 26 | + FURI_LOG_I(TAG, "selection two"); |
| 27 | + // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_AdjustTone); |
| 28 | + break; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +/** resets the menu, gives it content, callbacks and selection enums */ |
| 33 | +void scene_on_enter_main_menu(void* context) { |
| 34 | + FURI_LOG_I(TAG, "scene_on_enter_main_menu"); |
| 35 | + struct AppContext_t* app = (struct AppContext_t*)context; |
| 36 | + // Setup our menu |
| 37 | + FURI_LOG_D(TAG, "Adding view menu"); |
| 38 | + struct View_t* menuView = malloc(sizeof(struct View_t)); |
| 39 | + menuView->viewData = menu_alloc(); |
| 40 | + menuView->viewId = ToneGenAppView_Menu; |
| 41 | + menuView->type = MENU; |
| 42 | + view_dispatcher_add_view( |
| 43 | + app->view_dispatcher, ToneGenAppView_Menu, menu_get_view(menuView->viewData)); |
| 44 | + |
| 45 | + // Set the currently active view |
| 46 | + addNode(&app->activeViews, menuView); |
| 47 | + menu_reset(menuView->viewData); |
| 48 | + |
| 49 | + // NB. icons are specified as NULL below, because: |
| 50 | + // * icons are _always_ animated by the menu |
| 51 | + // * the icons provided (&I_one, &I_two) are generated by the build process |
| 52 | + // * these icons do not have a framerate (resulting in a division by zero) |
| 53 | + menu_add_item( |
| 54 | + menuView->viewData, |
| 55 | + "Play Tone", |
| 56 | + NULL, |
| 57 | + ToneGenAppMenuSelection_Play, |
| 58 | + menu_callback_main_menu, |
| 59 | + app); |
| 60 | + menu_add_item( |
| 61 | + menuView->viewData, |
| 62 | + "Adjust Tone", |
| 63 | + NULL, |
| 64 | + ToneGenAppMenuSelection_Adjust, |
| 65 | + menu_callback_main_menu, |
| 66 | + app); |
| 67 | + view_dispatcher_switch_to_view(app->view_dispatcher, ToneGenAppView_Menu); |
| 68 | +} |
| 69 | + |
| 70 | +/** main menu event handler - switches scene based on the event */ |
| 71 | +bool scene_on_event_main_menu(void* context, SceneManagerEvent event) { |
| 72 | + FURI_LOG_I(TAG, "scene_on_event_main_menu"); |
| 73 | + UNUSED(context); |
| 74 | + // struct AppContext_t* app = context; |
| 75 | + bool consumed = false; |
| 76 | + switch(event.type) { |
| 77 | + case SceneManagerEventTypeCustom: |
| 78 | + // switch(event.event) { |
| 79 | + // case ToneGenAppEvent_StartPlayback: |
| 80 | + // scene_manager_next_scene(app->scene_manager, ToneGenAppScene_Playback); |
| 81 | + // consumed = true; |
| 82 | + // break; |
| 83 | + // case ToneGenAppEvent_AdjustTone: |
| 84 | + // scene_manager_next_scene(app->scene_manager, ToneGenAppScene_AdjustTone); |
| 85 | + // consumed = true; |
| 86 | + // break; |
| 87 | + // } |
| 88 | + break; |
| 89 | + default: // eg. SceneManagerEventTypeBack, SceneManagerEventTypeTick |
| 90 | + consumed = false; |
| 91 | + break; |
| 92 | + } |
| 93 | + return consumed; |
| 94 | +} |
| 95 | + |
| 96 | +void scene_on_exit_main_menu(void* context) { |
| 97 | + FURI_LOG_I(TAG, "scene_on_exit_main_menu"); |
| 98 | + struct AppContext_t* app = context; |
| 99 | + freeAppContextViews(&app); |
| 100 | +} |
0 commit comments