Repository navigation
Expand file tree
/
Copy pathmenu.cpp
More file actions
103 lines (84 loc) · 2.51 KB
/
Copy pathmenu.cpp
File metadata and controls
103 lines (84 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <ncurses.h>
#include <string>
#include "menu.h"
#include "creature.h"
using namespace std;
int N = 3;
string choices[3] = { "feed", "play", "study" };
int menu( int max_x, int max_y ) {
WINDOW * menu;
use_default_colors();
Creature* bob = new Creature();
// Calculate placement of new window
int y, x, height, width;
//getmaxyx( stdscr, y, x ); <-- max_x and max_y replace these values
height = 6, width = 5;
printw( "Press F1 to kill Bob." );
refresh();
// Create window for input
menu = newwin(max_y/3, max_x, max_y-8, 0);
box( menu, 0, 0 );
refresh();
wrefresh( menu );
keypad( menu, true );
//print_selections( menu, 0 );
//printw( menu, 0+1, 1, choices[0].c_str() );
//
int user_input;
int highlight = 0;
while ( 1 ) {
print_selections( menu, highlight );
user_input = wgetch(menu);
//mvprintw(0,0,"Use arrow keys to go up and down, enter to make a choice");
wmove( menu, 4, 0 );
mvprintw( 4, 0, "B" );
// refresh();
switch( user_input ) {
case KEY_UP:
if ( highlight == 0 ) { highlight = N-1; break; }
else { highlight--; break; }
case KEY_DOWN:
if ( highlight == N-1 ) { highlight = 0; break; }
else { highlight++; break; }
case KEY_F(1):
if ( user_input == KEY_F(1) ) { wclrtoeol( menu ); bob->murder(menu);}
case 10:
if ( highlight == 0 ) { wclrtoeol( menu ); bob->feed(menu); break; }
if ( highlight == 1 ) { wclrtoeol( menu ); bob->play(menu); break; }
if ( highlight == 2 ) { wclrtoeol( menu ); bob->study(menu); break; }
default:
break;
} //print_selections( menu, highlight );
}
endwin();
delete bob;
return 0;
}
/*
WINDOW * new_window( int height, int width, int starty, int startx ) {
WINDOW * menuwin = newwin( height, width, starty, startx );
box( menuwin, 0, 0 );
wrefresh( menuwin );
keypad( menuwin, true );
print_selections( menuwin, 0 );
return menuwin;
}
*/
void close_window( WINDOW * menu_win ) {
wrefresh( menu_win );
delwin( menu_win );
}
void print_selections(WINDOW * menu, int highlight ) {
start_color();
init_pair( 1 , 0, COLOR_BLUE );
for ( int i = 0; i < N; i++ ) {
if ( i == highlight ) {
//attron( COLOR_PAIR(1) );
wattron( menu, COLOR_PAIR(1) );
//wattron( menu, A_REVERSE );
}
mvwprintw( menu, i+1, 1, choices[i].c_str() );
wattroff( menu, COLOR_PAIR(1) );
wrefresh(menu);
}
}