Menu switching text

This commit is contained in:
Christian Colglazier 2021-10-31 09:41:21 -04:00
parent e62bc0c51f
commit 1298c79196
4 changed files with 74 additions and 28 deletions

View File

@ -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

View File

@ -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.
*/

View File

@ -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;
}

View File

@ -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);
};