Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Re-ident, fix comment typo, slight re-format |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
18fbc02037a969a4dc6d952c90a6a38c |
User & Date: | atomicules@lavabit.com 2013-07-08 08:55:03 |
Original User & Date: | atomicules@lavabit.com 2013-07-08 08:55:04 |
Context
2013-07-08
| ||
08:55 |
First attempt at getting two menus side by side
Tricky bit was that have to re-create my_items. I thought I'd be able to | |
08:55 | Re-ident, fix comment typo, slight re-format check-in: 18fbc02037 user: atomicules@lavabit.com tags: origin/master, trunk | |
08:55 | Add note about where file is from/based on check-in: a7bd8579c0 user: atomicules@lavabit.com tags: origin/master, trunk | |
Changes
Changes to exposurses.c.
1 | /* This file based on menu_scroll.c from: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 104 105 106 107 108 109 110 111 112 113 | /* This file based on menu_scroll.c from: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html */ #include <curses.h> #include <menu.h> #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define CTRLD 4 char *choices[] = { "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5", "Choice 6", "Choice 7", "Choice 8", "Choice 9", "Choice 10", "Exit", (char *)NULL, }; void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); int main(){ ITEM **my_items; int c; MENU *my_menu; WINDOW *my_menu_win; int n_choices, i; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK); /* Create items */ n_choices = ARRAY_SIZE(choices); my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); for(i = 0; i < n_choices; ++i) my_items[i] = new_item(choices[i], choices[i]); /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Create the window to be associated with the menu */ my_menu_win = newwin(10, 40, 4, 4); keypad(my_menu_win, TRUE); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); set_menu_format(my_menu, 5, 1); /* Set menu mark to the string " * " */ set_menu_mark(my_menu, " * "); /* Print a border around the main window and print a title */ box(my_menu_win, 0, 0); print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); mvwaddch(my_menu_win, 2, 0, ACS_LTEE); mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); mvwaddch(my_menu_win, 2, 39, ACS_RTEE); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); attron(COLOR_PAIR(2)); mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items"); mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)"); attroff(COLOR_PAIR(2)); refresh(); while((c = wgetch(my_menu_win)) != KEY_F(1)){ switch(c){ case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; case KEY_NPAGE: menu_driver(my_menu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(my_menu, REQ_SCR_UPAGE); break; } wrefresh(my_menu_win); } /* Unpost and free all the memory taken up */ unpost_menu(my_menu); free_menu(my_menu); for(i = 0; i < n_choices; ++i) free_item(my_items[i]); endwin(); } void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color){ int length, x, y; float temp; if(win == NULL) win = stdscr; getyx(win, y, x); if(startx != 0) x = startx; |
︙ | ︙ |