nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Menu Class Reference

List of selectable items. More...

#include <Menu.hpp>

Inheritance diagram for Menu:
Collaboration diagram for Menu:

Public Member Functions

 Menu (int x, int y, int width, int height)
 Creates a menu at x and y with width and height.
 
void add (MenuItem *item)
 
void addBlank ()
 
void removeByID (int id)
 Removes the menu item with #id.
 
void removeByLabel (std::string label)
 Removes the menu item with #label.
 
void draw (Window *window)
 Draws the whole Menu on #window.
 
void handleInput ()
 Makes the menu react to input, as seen on the global InputManager.
 
void goNext ()
 Makes the menu select the next item.
 
void goPrevious ()
 Makes the menu select the previous item.
 
void goFirst ()
 
void goLast ()
 
void goRandom ()
 
bool willQuit ()
 Tells if the user selected an item that quits the menu.
 
std::string currentLabel ()
 Returns the label of the currently selected item.
 
int currentID ()
 Returns the user-specified id of the selected item.
 
bool getBool (int id)
 Returns the bool internal value of item that has #id.
 
int getInt (int id)
 Returns the integer value of the item that has #id.
 
std::string getString (int id)
 Returns the string value of the item that has #id.
 
void reset ()
 Makes the menu able to be selected again.
 

Public Attributes

std::vector< MenuItem * > item
 Container of all the options inside the menu.
 
MenuItemcurrent
 Current item selected.
 

Protected Attributes

unsigned int currentIndex
 Index of the currently selected item.
 
int x
 
int y
 
int width
 
int height
 
bool selected
 Tells if the user selected an item (pressed Enter).
 
MenuItemselectedItem
 Specifies which item the user pressed Enter on.
 

Detailed Description

List of selectable items.

Warning
When adding items, make sure they're allocated dynamically! I mean POINTERS, damn it. Otherwise SEGFAULTS when trying to delete static stuff.
If you create a menu full of null elements (with addBlank()), it'll probably get into an infinite loop when you call goNext() or goPrevious. I still have to find a way to fix this.

Definition at line 28 of file Menu.hpp.

Constructor & Destructor Documentation

◆ Menu()

Menu::Menu ( int x,
int y,
int width,
int height )

Creates a menu at x and y with width and height.

It isn't attached to any specific Window, except when you call Menu::draw().

Definition at line 6 of file Menu.cpp.

◆ ~Menu()

Menu::~Menu ( )
virtual

Definition at line 16 of file Menu.cpp.

Member Function Documentation

◆ add()

void Menu::add ( MenuItem * item)

Definition at line 23 of file Menu.cpp.

◆ addBlank()

void Menu::addBlank ( )

Definition at line 43 of file Menu.cpp.

◆ currentID()

int Menu::currentID ( )

Returns the user-specified id of the selected item.

Definition at line 343 of file Menu.cpp.

◆ currentLabel()

std::string Menu::currentLabel ( )

Returns the label of the currently selected item.

Definition at line 336 of file Menu.cpp.

◆ draw()

void Menu::draw ( Window * window)

Draws the whole Menu on #window.

Definition at line 95 of file Menu.cpp.

◆ getBool()

bool Menu::getBool ( int id)

Returns the bool internal value of item that has #id.

Note
Meaning the item must be a MenuItemCheckbox.

Definition at line 350 of file Menu.cpp.

◆ getInt()

int Menu::getInt ( int id)

Returns the integer value of the item that has #id.

Note
Meaning the item must be a MenuItemNumberbox.

Definition at line 372 of file Menu.cpp.

◆ getString()

std::string Menu::getString ( int id)

Returns the string value of the item that has #id.

Note
Meaning the item must be a MenuItemTextbox or MenuItemTextlist.

Definition at line 394 of file Menu.cpp.

◆ goFirst()

void Menu::goFirst ( )

Definition at line 286 of file Menu.cpp.

◆ goLast()

void Menu::goLast ( )

Definition at line 304 of file Menu.cpp.

◆ goNext()

void Menu::goNext ( )

Makes the menu select the next item.

Note
This is a recursive function to guarantee we'll always point to a non-nil element.

Definition at line 226 of file Menu.cpp.

◆ goPrevious()

void Menu::goPrevious ( )

Makes the menu select the previous item.

Note
This is a recursive function to guarantee we'll always point to a non-nil element.

Definition at line 259 of file Menu.cpp.

◆ goRandom()

void Menu::goRandom ( )

Definition at line 322 of file Menu.cpp.

◆ handleInput()

void Menu::handleInput ( )

Makes the menu react to input, as seen on the global InputManager.

Definition at line 183 of file Menu.cpp.

◆ removeByID()

void Menu::removeByID ( int id)

Removes the menu item with #id.

Definition at line 47 of file Menu.cpp.

◆ removeByLabel()

void Menu::removeByLabel ( std::string label)

Removes the menu item with #label.

Note
It'll delete the first entry found with #label.
Warning
This is far more unreliable than #removeById(), provided you have unique IDs.

Definition at line 71 of file Menu.cpp.

◆ reset()

void Menu::reset ( )

Makes the menu able to be selected again.

When the user selects an item, willQuit() returns true. By calling this function, you make possible to select things again.

Definition at line 424 of file Menu.cpp.

◆ willQuit()

bool Menu::willQuit ( )

Tells if the user selected an item that quits the menu.

Definition at line 330 of file Menu.cpp.

Member Data Documentation

◆ current

MenuItem* Menu::current

Current item selected.

Note
It's public because we might want to change current item's attributes. Don't mess with the pointer itself!

Definition at line 115 of file Menu.hpp.

◆ currentIndex

unsigned int Menu::currentIndex
protected

Index of the currently selected item.

Definition at line 119 of file Menu.hpp.

◆ height

int Menu::height
protected

Definition at line 124 of file Menu.hpp.

◆ item

std::vector<MenuItem*> Menu::item

Container of all the options inside the menu.

Definition at line 109 of file Menu.hpp.

◆ selected

bool Menu::selected
protected

Tells if the user selected an item (pressed Enter).

Definition at line 127 of file Menu.hpp.

◆ selectedItem

MenuItem* Menu::selectedItem
protected

Specifies which item the user pressed Enter on.

Definition at line 130 of file Menu.hpp.

◆ width

int Menu::width
protected

Definition at line 123 of file Menu.hpp.

◆ x

int Menu::x
protected

Definition at line 121 of file Menu.hpp.

◆ y

int Menu::y
protected

Definition at line 122 of file Menu.hpp.


The documentation for this class was generated from the following files: