Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Try separate win and menu functions instead of trying to wrap everything in one. This way I know I can return the correct thing and I know I'm setting things as expected. As opposed to previous attempt where I was (trying) to use variable pointers, but with pointers to pointers, etc. And was obviously a bit beyond me. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e4268c4b4e059e265512870413710185 |
User & Date: | base@atomicules.co.uk 2013-09-18 11:01:28 |
Context
2013-09-18
| ||
11:01 | Make the add_menu and add_win subs work I was still using the "variable pointers" technique, well trying to, and it wasn't working for things like `set_menu_win` so pull this back out into main. Seg faults on exit, but haven't fixed that bit yet. check-in: c2741c67e7 user: base@atomicules.co.uk tags: origin/master, trunk | |
11:01 | Try separate win and menu functions instead of trying to wrap everything in one. This way I know I can return the correct thing and I know I'm setting things as expected. As opposed to previous attempt where I was (trying) to use variable pointers, but with pointers to pointers, etc. And was obviously a bit beyond me. check-in: e4268c4b4e user: base@atomicules.co.uk tags: origin/master, trunk | |
10:44 | Add debug options to Makefile Not as simple as adding `-g` option as also need to ensure not calling the `-s` option which strips the debug info. Decided to change so have a `make` and a `make debug` check-in: 86fd753f70 user: base@atomicules.co.uk tags: origin/master, trunk | |
Changes
Changes to exposurses.c.
83 83 MENU *aperture_menu; 84 84 WINDOW *exposure_win; 85 85 WINDOW *iso_win; 86 86 WINDOW *shutter_win; 87 87 WINDOW *aperture_win; 88 88 89 89 void selection(char *name); 90 -void add_menu(char **array, ITEM **items, MENU *men, WINDOW *win, int n, int xpos, char *title); 91 90 void remove_menu(ITEM **items, MENU *men, int n); 92 91 void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); 92 +MENU *add_menu(char **array, ITEM **items, int n); 93 +WINDOW *add_window(MENU *men, int xpos, char *title); 93 94 int exposure(int iso); 94 95 double shutter(int exposure, double aperture); 95 96 double aperture(int exposure, double shutter); 96 97 int nearest_match(double x, int menu); 97 98 double fraction_to_double(char *fraction); 98 99 /* No one will ever need more than 9 bytes! */ 99 100 char exposure_sel[9] = ""; ................................................................................ 124 125 125 126 /* Create items */ 126 127 /* Can't really avoid finding array sizes here */ 127 128 n_exposure = ARRAY_SIZE(exposure_array); 128 129 n_iso = ARRAY_SIZE(iso_array); 129 130 n_shutter = ARRAY_SIZE(shutter_array); 130 131 n_aperture = ARRAY_SIZE(aperture_array); 131 - add_menu(exposure_array, exposure_items, exposure_menu, exposure_win, n_exposure, 4, "EV"); 132 - add_menu(iso_array, iso_items, iso_menu, iso_win, n_iso, 45, "ISO"); 133 - add_menu(shutter_array, shutter_items, shutter_menu, shutter_win, n_shutter, 86, "Shutter"); 134 - add_menu(aperture_array, aperture_items, aperture_menu, aperture_win, n_aperture, 127, "Aperture"); 132 + exposure_menu = add_menu(exposure_array, exposure_items, n_exposure); 133 + iso_menu = add_menu(iso_array, iso_items, n_iso); 134 + shutter_menu = add_menu(shutter_array, shutter_items, n_shutter); 135 + aperture_menu = add_menu(aperture_array, aperture_items, n_aperture); 136 + exposure_win = add_window(exposure_menu, 4, "EV"); 137 + iso_win = add_window(iso_menu, 45, "ISO"); 138 + shutter_win = add_window(shutter_menu, 86, "Shutter"); 139 + aperture_win = add_window(aperture_menu, 127, "Aperture"); 135 140 136 141 attron(COLOR_PAIR(2)); 137 142 mvprintw(LINES - 2, 0, "Select EV"); 138 143 /*mvprintw(LINES - 2, 0, "Select ISO and then one of Shutter/Aperture to calculate other of Shutter/Aperture");*/ 139 144 mvprintw(LINES - 1, 0, "Arrow keys to navigate, Enter to select, Q to exit"); 140 145 attroff(COLOR_PAIR(2)); 141 146 refresh(); ................................................................................ 257 262 remove_menu(exposure_items, exposure_menu, n_exposure); 258 263 remove_menu(iso_items, iso_menu, n_iso); 259 264 remove_menu(shutter_items, shutter_menu, n_shutter); 260 265 remove_menu(aperture_items, aperture_menu, n_aperture); 261 266 endwin(); 262 267 } 263 268 264 -void add_menu(char **array, ITEM **items, MENU *men, WINDOW *win, int n, int xpos, char *title) { 269 +MENU *add_menu(char **array, ITEM **items, int n) { 265 270 int i; 271 + MENU *local_menu; 266 272 267 273 items = (ITEM **)calloc(n, sizeof(ITEM *)); 268 274 for(i = 0; i<n; ++i) { 269 275 items[i] = new_item(array[i], array[i]); 270 276 set_item_userptr(items[i], selection); 271 277 } 272 - men = new_menu((ITEM **)items); 273 - win = newwin(10, 40, 4, xpos); 274 - keypad(win, TRUE); 275 - set_menu_win(men, win); 276 - set_menu_sub(men, derwin(win, 6, 38, 3, 1)); 277 - set_menu_format(men, 5, 1); 278 - set_menu_mark(men, " * "); 279 - box(win, 0, 0); 280 - print_in_middle(win, 1, 0, 40, title, COLOR_PAIR(1)); 281 - mvwaddch(win, 2, 0, ACS_LTEE); 282 - mvwhline(win, 2, 1, ACS_HLINE, 38); 283 - mvwaddch(win, 2, 39, ACS_RTEE); 284 - post_menu(men); 285 - wrefresh(win); 278 + local_menu = new_menu((ITEM **)items); 279 + set_menu_format(local_menu, 5, 1); 280 + set_menu_mark(local_menu, " * "); 281 + post_menu(local_menu); 282 + return local_menu; 283 +} 284 + 285 +WINDOW *add_window(MENU *men, int xpos, char *title) { 286 + WINDOW *local_win; 287 + 288 + local_win = newwin(10, 40, 4, xpos); 289 + keypad(local_win, TRUE); 290 + set_menu_win(*men, local_win); 291 + set_menu_sub(*men, derwin(local_win, 6, 38, 3, 1)); 292 + box(local_win, 0, 0); 293 + print_in_middle(local_win, 1, 0, 40, title, COLOR_PAIR(1)); 294 + mvwaddch(local_win, 2, 0, ACS_LTEE); 295 + mvwhline(local_win, 2, 1, ACS_HLINE, 38); 296 + mvwaddch(local_win, 2, 39, ACS_RTEE); 297 + wrefresh(local_win); 298 + return local_win; 286 299 } 287 300 288 301 void remove_menu(ITEM **items, MENU *men, int n) { 289 302 int i; 290 303 291 304 unpost_menu(men); 292 305 free_menu(men);