exposurses

Check-in [d39151ac51]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Split out ITEM creation into separate func so can clean on exit I still hadn't got things quite right from when I'd split out the menu and window creation functions. The segfault on exit was due to the item pointers I thought existed not actually existing. Need to make sure they exist as expected as otherwise I can't free up the memory, etc. Yay, pretty much done.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: d39151ac51fec3bbda902321dafae51deaafb992ffbde42d5a81c91e28ef35a2
User & Date: base@atomicules.co.uk 2013-09-18 12:49:37
Context
2013-09-18
12:49
Clean up comments check-in: 946bdcbbb6 user: base@atomicules.co.uk tags: origin/master, trunk
12:49
Split out ITEM creation into separate func so can clean on exit I still hadn't got things quite right from when I'd split out the menu and window creation functions. The segfault on exit was due to the item pointers I thought existed not actually existing. Need to make sure they exist as expected as otherwise I can't free up the memory, etc. Yay, pretty much done. check-in: d39151ac51 user: base@atomicules.co.uk tags: origin/master, trunk
12:49
Ignore selection of OVER/UNDER in shutter/aperture menus Since this seems easier than trying to prevent selection. check-in: 4cc8e33f3c user: base@atomicules.co.uk tags: origin/master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to exposurses.c.

    89     89   WINDOW *iso_win;
    90     90   WINDOW *shutter_win;
    91     91   WINDOW *aperture_win;
    92     92   
    93     93   void selection(char *name);
    94     94   void remove_menu(ITEM **items, MENU *men, int n);
    95     95   void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
    96         -MENU *add_menu(char **array, ITEM **items, int n);
           96  +MENU *add_menu(ITEM **items);
    97     97   WINDOW *add_window(int xpos, char *title);
           98  +ITEM **add_item(char **array, int n);
    98     99   int exposure(int iso);
    99    100   double shutter(int exposure, double aperture);
   100    101   double aperture(int exposure, double shutter);
   101    102   int nearest_match(double x, int menu, int n_array);
   102    103   double fraction_to_double(char *fraction);
   103    104   /* No one will ever need more than 9 bytes! */
   104    105   char exposure_sel[9] = "";
................................................................................
   129    130   
   130    131   	/* Create items */
   131    132   	/* Can't really avoid finding array sizes here */
   132    133   	n_exposure = ARRAY_SIZE(exposure_array);
   133    134   	n_iso = ARRAY_SIZE(iso_array);
   134    135   	n_shutter = ARRAY_SIZE(shutter_array);
   135    136   	n_aperture = ARRAY_SIZE(aperture_array);
   136         -	exposure_menu = add_menu(exposure_array, exposure_items, n_exposure);
   137         -	iso_menu = add_menu(iso_array, iso_items, n_iso);
   138         -	shutter_menu = add_menu(shutter_array, shutter_items, n_shutter);
   139         -	aperture_menu = add_menu(aperture_array, aperture_items, n_aperture);
          137  +	exposure_items = add_item(exposure_array, n_exposure);
          138  +	iso_items = add_item(iso_array, n_iso);
          139  +	aperture_items = add_item(aperture_array, n_aperture);
          140  +	shutter_items = add_item(shutter_array, n_shutter);
          141  +	exposure_menu = add_menu(exposure_items);
          142  +	iso_menu = add_menu(iso_items);
          143  +	shutter_menu = add_menu(shutter_items);
          144  +	aperture_menu = add_menu(aperture_items);
   140    145   	exposure_win = add_window(4, "EV");
   141    146   	iso_win = add_window(45, "ISO");
   142    147   	shutter_win = add_window(86, "Shutter");
   143    148   	aperture_win = add_window(127, "Aperture");
   144    149   	/* Don't know how to avoid the repition below */
   145    150   	set_menu_win(exposure_menu, exposure_win);
   146    151   	set_menu_win(iso_menu, iso_win);
................................................................................
   297    302   	remove_menu(exposure_items, exposure_menu, n_exposure);
   298    303   	remove_menu(iso_items, iso_menu, n_iso);
   299    304   	remove_menu(shutter_items, shutter_menu, n_shutter);
   300    305   	remove_menu(aperture_items, aperture_menu, n_aperture);
   301    306   	endwin();
   302    307   }
   303    308   
   304         -MENU *add_menu(char **array, ITEM **items, int n) {
          309  +/* Below pointer configuration figured out from:
          310  + * https://github.com/Yurickh/Psycho-Tetris/blob/master/src/menu.c#L9 */
          311  +ITEM **add_item(char **array, int n) {
   305    312   	int i;
          313  +	ITEM **local_items;
          314  +
          315  +	local_items = (ITEM **)calloc(n, sizeof(ITEM *));
          316  +	for(i = 0; i<n; ++i) {
          317  +		local_items[i] = new_item(array[i], array[i]);
          318  +		set_item_userptr(local_items[i], selection);
          319  +	}
          320  +	return local_items;
          321  +}
          322  +
          323  +MENU *add_menu(ITEM **items) {
   306    324   	MENU *local_menu;
   307    325   
   308         -	items = (ITEM **)calloc(n, sizeof(ITEM *));
   309         -	for(i = 0; i<n; ++i) {
   310         -		items[i] = new_item(array[i], array[i]);
   311         -		set_item_userptr(items[i], selection);
   312         -	}
   313    326   	local_menu = new_menu((ITEM **)items);
   314    327   	set_menu_format(local_menu, 5, 1);
   315    328   	set_menu_mark(local_menu, " * ");
   316    329   	return local_menu;
   317    330   }
   318    331   
   319    332   WINDOW *add_window(int xpos, char *title) {