COLOR_PAIR(n) Color-pair number n
</pre>
<p>The last one is the most colorful one :-) Colors are
- explained in the <a href="#COLOR" target="_top">next
+ explained in the <a href="#color" target="_top">next
sections</a>.</p>
<p>We can OR(|) any number of above attributes to get a
#include <curses.h>
#define WIDTH 30
-#define HEIGHT 10
+#define HEIGHT 10
int startx = 0;
int starty = 0;
/* Try to put the window in the middle of screen */
startx = (80 - WIDTH) / 2;
starty = (24 - HEIGHT) / 2;
-
+
attron(A_REVERSE);
mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
refresh();
/* Print the menu for the first time */
menu_win = newwin(HEIGHT, WIDTH, starty, startx);
+ keypad(menu_win, TRUE);
print_menu(menu_win, 1);
/* Get all the mouse events */
mousemask(ALL_MOUSE_EVENTS, NULL);
-
+
while(1)
{ c = wgetch(menu_win);
switch(c)
if(choice == -1) //Exit chosen
goto end;
mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]);
- refresh();
+ refresh();
}
}
print_menu(menu_win, choice);
break;
}
- }
+ }
end:
endwin();
return 0;
void print_menu(WINDOW *menu_win, int highlight)
{
- int x, y, i;
+ int x, y, i;
x = 2;
y = 2;
box(menu_win, 0, 0);
for(i = 0; i < n_choices; ++i)
{ if(highlight == i + 1)
- { wattron(menu_win, A_REVERSE);
+ { wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, y, x, "%s", choices[i]);
wattroff(menu_win, A_REVERSE);
}
i = startx + 2;
j = starty + 3;
-
+
for(choice = 0; choice < n_choices; ++choice)
if(mouse_y == j + choice && mouse_x >= i && mouse_x <= i + strlen(choices[choice]))
{ if(choice == n_choices - 1)
- *p_choice = -1;
+ *p_choice = -1;
else
- *p_choice = choice + 1;
+ *p_choice = choice + 1;
break;
}
}</span></pre>
for(i = 0; i < n_choices; ++i)
my_items[i] = new_item(choices[i], choices[i]);
- /* Crate menu */
+ /* Create menu */
my_menu = new_menu((ITEM **)my_items);
/* Create the window to be associated with the menu */
for(i = 0; i < n_choices; ++i)
my_items[i] = new_item(choices[i], choices[i]);
- /* Crate menu */
+ /* Create menu */
my_menu = new_menu((ITEM **)my_items);
/* Create the window to be associated with the menu */
for(i = 0; i < n_choices; ++i)
my_items[i] = new_item(choices[i], choices[i]);
- /* Crate menu */
+ /* Create menu */
my_menu = new_menu((ITEM **)my_items);
/* Set menu option not to show the description */
/* Post the menu */
mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
- mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
+ mvprintw(LINES - 2, 0, "Up and Down arrow keys to navigate (F1 to Exit)");
post_menu(my_menu);
refresh();
/* Post the menu */
mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
- mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
+ mvprintw(LINES - 2, 0, "Up and Down arrow keys to navigate (F1 to Exit)");
post_menu(my_menu);
refresh();