From 1298c791961af7d23eafdda85b89bdabd3dfdc1a Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Sun, 31 Oct 2021 09:41:21 -0400 Subject: [PATCH] Menu switching text --- src/menu.cpp | 27 ++++++++++++++------------- src/menu.h | 26 +++++++++++--------------- src/menu_item.cpp | 18 ++++++++++++++++++ src/menu_item.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 28 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index 61524b1..d6f3c3d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -8,21 +8,22 @@ Menu::Menu(DaisyPatch* m_patch, manager = m_manager; head = new MenuItem(MenuState::kSplit, "Split"); - head->AddItemEnd(new MenuItem(MenuState::kChange, "Right")); + head->AddItemEnd(new MenuItem(MenuState::kChange, "")); head->AddItemEnd(new MenuItem(MenuState::kVCO, "VCO")); head->AddItemEnd(new MenuItem(MenuState::kNoise, "Noise")); + selected = head; buffer = selected; highlighted = selected; + + head->SetStateVisibility(MenuState::kChange, false); + + if (state == DropletState::kLeft) { + head->SetStateTitle(MenuState::kChange, "Right"); + } else if (state == DropletState::kRight) { + head->SetStateTitle(MenuState::kChange, "Left"); + } } -const std::string MENU_ITEMS[] = {"Split", - "Change", - "VCO", - "Noise"}; -const int MENU_SIZE = sizeof(MENU_ITEMS)/sizeof(*MENU_ITEMS); -const int MAX_CHAR_LENGTH = 15; -const int MENU_X[] = {0, 5, 10, 5, 0}; -const int MENU_Y[] = {0, 11, 22, 41, 52}; bool Menu::InMenu() { return this->inMenu; @@ -53,12 +54,12 @@ void Menu::ProcessMenuOled() { CreateMenuItem(highlighted->GetTitle(), 3, true); // Item 2 - ptr = highlighted->GetPrevious(); + ptr = highlighted->GetPreviousVisible(); if (ptr == NULL) { CreateMenuItem("", 2, false); } else { CreateMenuItem(ptr->GetTitle(), 2, false); - ptr = ptr->GetPrevious(); + ptr = ptr->GetPreviousVisible(); } // Item 1 if (ptr == NULL) { @@ -68,12 +69,12 @@ void Menu::ProcessMenuOled() { } // Item 4 - ptr = highlighted->GetNext(); + ptr = highlighted->GetNextVisible(); if (ptr == NULL) { CreateMenuItem("", 4, false); } else { CreateMenuItem(ptr->GetTitle(), 4, false); - ptr = ptr->GetNext(); + ptr = ptr->GetNextVisible(); } // Item 5 diff --git a/src/menu.h b/src/menu.h index 19ca54e..4d1e50c 100644 --- a/src/menu.h +++ b/src/menu.h @@ -12,6 +12,10 @@ using namespace daisy; +const int MAX_CHAR_LENGTH = 15; +const int MENU_X[] = {0, 5, 10, 5, 0}; +const int MENU_Y[] = {0, 11, 22, 41, 52}; + class Menu { private: DaisyPatch* patch; @@ -24,12 +28,15 @@ class Menu { bool inMenu = false; /* - * Converts a number to the related menu state. + * Draws a menu item on screen. * - * @param menu_state state number - * @return menu state + * @param text menu item name + * @param position menu items position in the menu + * @param highlighted state of menu items selection */ - MenuState ConvertState(int menu_state); + void CreateMenuItem(std::string text, + int position, + bool highlighted); public: /* * Constructor for a menu system to control the state of the patch. @@ -54,17 +61,6 @@ class Menu { */ void SetInMenu(bool); - /* - * Draws a menu item on screen. - * - * @param text menu item name - * @param position menu items position in the menu - * @param highlighted state of menu items selection - */ - void CreateMenuItem(std::string text, - int position, - bool highlighted); - /* * Draws droplet information on the screen. */ diff --git a/src/menu_item.cpp b/src/menu_item.cpp index 0f8b522..cda63e3 100644 --- a/src/menu_item.cpp +++ b/src/menu_item.cpp @@ -62,6 +62,24 @@ void MenuItem::ToggleVisibility() { visible = !visible; } +void MenuItem::SetStateVisibility(MenuState m_state, bool visibility) { + if (this->GetState() == m_state) { + this->SetVisibility(visibility); + } + if (this->GetNext() != NULL) { + this->GetNext()->SetStateVisibility(m_state, visibility); + } +} + +void MenuItem::SetStateTitle(MenuState m_state, std::string m_title) { + if (this->GetState() == m_state) { + this->SetTitle(m_title); + } + if (this->GetNext() != NULL) { + this->GetNext()->SetStateTitle(m_state, m_title); + } +} + MenuState MenuItem::GetState() { return state; } diff --git a/src/menu_item.h b/src/menu_item.h index e6ac39e..e9c00fa 100644 --- a/src/menu_item.h +++ b/src/menu_item.h @@ -91,11 +91,42 @@ class MenuItem { */ void ToggleVisibility(); + void SetStateVisibility(MenuState m_state, bool visibility); + void SetStateTitle(MenuState m_state, std::string m_title); + + /* + * Returns the state of the menu item. + * + * @return state + */ MenuState GetState(); + /* + * Add menu item before other menu item. + * + * @param menu item to be added + */ void AddItemBefore(MenuItem* item); + + /* + * Add menu item after other menu item. + * + * @param menu item to be added + */ void AddItemAfter(MenuItem* item); + + /* + * Add menu item at the beginning of a a menu item list. + * + * @param menu item to be added + */ void AddItemStart(MenuItem* item); + + /* + * Add menu item at the end of a a menu item list. + * + * @param menu item to be added + */ void AddItemEnd(MenuItem* item); };