Compare commits
4 Commits
a4f0f0e1f9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a41544d82 | |||
| 1ca75cb587 | |||
| 428d40b0ef | |||
| 640ea1b267 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class Menu {
|
class Menu {
|
||||||
public:
|
public:
|
||||||
Menu(std::string text, char trigger, std::string *items, int num_items)
|
Menu(std::string text, int trigger, std::string *items, int num_items)
|
||||||
{
|
{
|
||||||
this->text = text;
|
this->text = text;
|
||||||
this->trigger = trigger;
|
this->trigger = trigger;
|
||||||
@@ -16,7 +16,7 @@ class Menu {
|
|||||||
}
|
}
|
||||||
int start_x;
|
int start_x;
|
||||||
std::string text;
|
std::string text;
|
||||||
char trigger;
|
int trigger;
|
||||||
std::string *items;
|
std::string *items;
|
||||||
int num_items;
|
int num_items;
|
||||||
int selected_item;
|
int selected_item;
|
||||||
@@ -56,6 +56,26 @@ class MenuBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(WINDOW *new_win)
|
||||||
|
{
|
||||||
|
delwin(menuwin);
|
||||||
|
|
||||||
|
this->win = new_win;
|
||||||
|
|
||||||
|
int yMax,xMax,yBeg,xBeg;
|
||||||
|
getmaxyx(win,yMax,xMax);
|
||||||
|
getbegyx(win,yBeg,xBeg);
|
||||||
|
|
||||||
|
menuwin = newwin(yMax-2,xMax-2,yBeg+1,xBeg+1);
|
||||||
|
|
||||||
|
int current_pos = 2;
|
||||||
|
for (int i = 0; i < num_menus; i++)
|
||||||
|
{
|
||||||
|
menus[i].start_x = current_pos;
|
||||||
|
current_pos += menus[i].text.length() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < num_menus; i++)
|
for (int i = 0; i < num_menus; i++)
|
||||||
@@ -90,29 +110,32 @@ class MenuBar {
|
|||||||
{
|
{
|
||||||
wattroff(win, A_STANDOUT);
|
wattroff(win, A_STANDOUT);
|
||||||
}
|
}
|
||||||
|
if(!is_selected)
|
||||||
|
return;
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
|
|
||||||
char ch;
|
char ch;
|
||||||
drawMenuItems(menu);
|
drawMenuItems(menu);
|
||||||
wrefresh(menuwin);
|
wrefresh(menuwin);
|
||||||
while(is_selected && (ch = wgetch(menuwin)))
|
while((ch = wgetch(menuwin)))
|
||||||
{
|
{
|
||||||
switch(ch)
|
switch(ch)
|
||||||
{
|
{
|
||||||
case 'k':
|
case 'j':
|
||||||
menu.selectNextItem();
|
menu.selectNextItem();
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'k':
|
||||||
menu.selectPrevItem();
|
menu.selectPrevItem();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
is_selected = false;
|
|
||||||
}
|
|
||||||
drawMenuItems(menu);
|
|
||||||
}
|
|
||||||
werase(menuwin);
|
werase(menuwin);
|
||||||
wrefresh(menuwin);
|
wrefresh(menuwin);
|
||||||
reset();
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
drawMenuItems(menu);
|
||||||
|
wrefresh(menuwin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMenuItems(Menu menu)
|
void drawMenuItems(Menu menu)
|
||||||
|
|||||||
@@ -17,33 +17,45 @@ int main(int argc, char **argv){
|
|||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_WHITE,COLOR_BLUE);
|
init_pair(1, COLOR_WHITE,COLOR_BLUE);
|
||||||
|
|
||||||
int yMax,xMax;
|
int term_yMax,term_xMax;
|
||||||
getmaxyx(stdscr,yMax,xMax);
|
getmaxyx(stdscr,term_yMax,term_xMax);
|
||||||
|
|
||||||
WINDOW *win = newwin(yMax-1,xMax-1,yMax-yMax+1,xMax-xMax+1);
|
WINDOW *main_win = newwin(term_yMax-1,term_xMax-1,1,1);
|
||||||
box(win,0,0);
|
box(main_win,0,0);
|
||||||
|
|
||||||
string menu1[] = {"New","Open","Save","Exit"};
|
string File_Menu[] = {"Connect","Disconnect","Exit"};
|
||||||
string menu2[] = {"Copy","Cut","Paste"};
|
string View_Menu[] = {"Info","Machines","Log"};
|
||||||
string menu3[] = {"Sidebar","Terminal"};
|
|
||||||
|
|
||||||
Menu menus[3] = {
|
Menu main_menus[2] = {
|
||||||
Menu("File",'f',menu1,4),
|
Menu("File",'f',File_Menu,3),
|
||||||
Menu("Edit",'e',menu2,3),
|
Menu("View",'v',View_Menu,3),
|
||||||
Menu("View",'v',menu3,2),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MenuBar menubar = MenuBar(win,menus,3);
|
MenuBar main_menubar = MenuBar(main_win,main_menus,2);
|
||||||
menubar.draw();
|
main_menubar.draw();
|
||||||
|
|
||||||
char ch;
|
keypad(main_win, TRUE);
|
||||||
while((ch = wgetch(win))){
|
int main_menus_input;
|
||||||
menubar.handleTrigger(ch);
|
while((main_menus_input = wgetch(main_win))){
|
||||||
menubar.draw();
|
if(main_menus_input <= 255)
|
||||||
|
{
|
||||||
|
main_menubar.handleTrigger(main_menus_input);
|
||||||
|
main_menubar.draw();
|
||||||
|
}
|
||||||
|
else if(main_menus_input == KEY_RESIZE)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
refresh();
|
||||||
|
delwin(main_win);
|
||||||
|
getmaxyx(stdscr,term_yMax,term_xMax);
|
||||||
|
main_win = newwin(term_yMax-1,term_xMax-1,1,1);
|
||||||
|
box(main_win,0,0);
|
||||||
|
main_menubar.resize(main_win);
|
||||||
|
main_menubar.draw();
|
||||||
|
wrefresh(main_win);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endwin();
|
endwin();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user