|
@@ -0,0 +1,100 @@
|
|
|
|
|
+#include <gui/modules/menu.h>
|
|
|
|
|
+#include <gui/modules/popup.h>
|
|
|
|
|
+
|
|
|
|
|
+#include "main_menu.h"
|
|
|
|
|
+#include "../app_context.h"
|
|
|
|
|
+#include "../tone_gen.h"
|
|
|
|
|
+#include "../utils/linked_list.h"
|
|
|
|
|
+
|
|
|
|
|
+/** indices for menu items */
|
|
|
|
|
+typedef enum {
|
|
|
|
|
+ ToneGenAppMenuSelection_Play,
|
|
|
|
|
+ ToneGenAppMenuSelection_Adjust
|
|
|
|
|
+} ToneGenAppMenuSelection;
|
|
|
|
|
+
|
|
|
|
|
+/** main menu callback - sends a custom event to the scene manager based on the menu selection */
|
|
|
|
|
+void menu_callback_main_menu(void* context, uint32_t index) {
|
|
|
|
|
+ FURI_LOG_I(TAG, "menu_callback_main_menu");
|
|
|
|
|
+ UNUSED(context);
|
|
|
|
|
+ // struct AppContext_t* app = context;
|
|
|
|
|
+ switch(index) {
|
|
|
|
|
+ case ToneGenAppMenuSelection_Play:
|
|
|
|
|
+ FURI_LOG_I(TAG, "selection one");
|
|
|
|
|
+ // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_StartPlayback);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case ToneGenAppMenuSelection_Adjust:
|
|
|
|
|
+ FURI_LOG_I(TAG, "selection two");
|
|
|
|
|
+ // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_AdjustTone);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** resets the menu, gives it content, callbacks and selection enums */
|
|
|
|
|
+void scene_on_enter_main_menu(void* context) {
|
|
|
|
|
+ FURI_LOG_I(TAG, "scene_on_enter_main_menu");
|
|
|
|
|
+ struct AppContext_t* app = (struct AppContext_t*)context;
|
|
|
|
|
+ // Setup our menu
|
|
|
|
|
+ FURI_LOG_D(TAG, "Adding view menu");
|
|
|
|
|
+ struct View_t* menuView = malloc(sizeof(struct View_t));
|
|
|
|
|
+ menuView->viewData = menu_alloc();
|
|
|
|
|
+ menuView->viewId = ToneGenAppView_Menu;
|
|
|
|
|
+ menuView->type = MENU;
|
|
|
|
|
+ view_dispatcher_add_view(
|
|
|
|
|
+ app->view_dispatcher, ToneGenAppView_Menu, menu_get_view(menuView->viewData));
|
|
|
|
|
+
|
|
|
|
|
+ // Set the currently active view
|
|
|
|
|
+ addNode(&app->activeViews, menuView);
|
|
|
|
|
+ menu_reset(menuView->viewData);
|
|
|
|
|
+
|
|
|
|
|
+ // NB. icons are specified as NULL below, because:
|
|
|
|
|
+ // * icons are _always_ animated by the menu
|
|
|
|
|
+ // * the icons provided (&I_one, &I_two) are generated by the build process
|
|
|
|
|
+ // * these icons do not have a framerate (resulting in a division by zero)
|
|
|
|
|
+ menu_add_item(
|
|
|
|
|
+ menuView->viewData,
|
|
|
|
|
+ "Play Tone",
|
|
|
|
|
+ NULL,
|
|
|
|
|
+ ToneGenAppMenuSelection_Play,
|
|
|
|
|
+ menu_callback_main_menu,
|
|
|
|
|
+ app);
|
|
|
|
|
+ menu_add_item(
|
|
|
|
|
+ menuView->viewData,
|
|
|
|
|
+ "Adjust Tone",
|
|
|
|
|
+ NULL,
|
|
|
|
|
+ ToneGenAppMenuSelection_Adjust,
|
|
|
|
|
+ menu_callback_main_menu,
|
|
|
|
|
+ app);
|
|
|
|
|
+ view_dispatcher_switch_to_view(app->view_dispatcher, ToneGenAppView_Menu);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** main menu event handler - switches scene based on the event */
|
|
|
|
|
+bool scene_on_event_main_menu(void* context, SceneManagerEvent event) {
|
|
|
|
|
+ FURI_LOG_I(TAG, "scene_on_event_main_menu");
|
|
|
|
|
+ UNUSED(context);
|
|
|
|
|
+ // struct AppContext_t* app = context;
|
|
|
|
|
+ bool consumed = false;
|
|
|
|
|
+ switch(event.type) {
|
|
|
|
|
+ case SceneManagerEventTypeCustom:
|
|
|
|
|
+ // switch(event.event) {
|
|
|
|
|
+ // case ToneGenAppEvent_StartPlayback:
|
|
|
|
|
+ // scene_manager_next_scene(app->scene_manager, ToneGenAppScene_Playback);
|
|
|
|
|
+ // consumed = true;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // case ToneGenAppEvent_AdjustTone:
|
|
|
|
|
+ // scene_manager_next_scene(app->scene_manager, ToneGenAppScene_AdjustTone);
|
|
|
|
|
+ // consumed = true;
|
|
|
|
|
+ // break;
|
|
|
|
|
+ // }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default: // eg. SceneManagerEventTypeBack, SceneManagerEventTypeTick
|
|
|
|
|
+ consumed = false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return consumed;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void scene_on_exit_main_menu(void* context) {
|
|
|
|
|
+ FURI_LOG_I(TAG, "scene_on_exit_main_menu");
|
|
|
|
|
+ struct AppContext_t* app = context;
|
|
|
|
|
+ freeAppContextViews(&app);
|
|
|
|
|
+}
|