Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //returns a choice >= 0 if success, -1 if quit
- template<class iter>
- int create_menu(int num_options, iter it, const std::string &menu_name, bool allow_quits = false) {
- int selection = 0;
- iter start = it;
- while (1) {
- it = start;
- system("CLS");
- printf("%s\n", menu_name.c_str());
- printf("Enter 'w' to move up\n");
- printf("Enter 's' to move down\n");
- printf("Enter 'e' to select\n");
- if (allow_quits) {
- printf("Enter 'ESC' to quit\n");
- }
- printf("\n");
- if (!num_options) {
- printf("No options available!\n");
- system("PAUSE");
- return -1;
- }
- for (int a = 0; a < num_options; a++, it++) {
- if (a == selection) {
- printf(" > ");
- } else {
- printf(" ");
- }
- printf("%s\n", it->c_str());
- }
- printf("\n");
- char input = tolower(_getch());
- if (input == 'w') {
- selection = std::max(0, selection - 1);
- } else if (input == 's') {
- selection = std::min(num_options - 1, selection + 1);
- } else if (input == 'e') {
- return selection;
- } else if (allow_quits && input == KEY::ESC) {
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement