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 Unified Diffs Ignore Whitespace Patch

Changes to exposurses.c.

89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
...
129
130
131
132
133
134
135




136
137
138
139
140
141
142
143
144
145
146
...
297
298
299
300
301
302
303
304


305
306

307
308
309
310
311
312






313
314
315
316
317
318
319
WINDOW *iso_win;
WINDOW *shutter_win;
WINDOW *aperture_win;

void selection(char *name);
void remove_menu(ITEM **items, MENU *men, int n);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
MENU *add_menu(char **array, ITEM **items, int n);
WINDOW *add_window(int xpos, char *title);

int exposure(int iso);
double shutter(int exposure, double aperture);
double aperture(int exposure, double shutter);
int nearest_match(double x, int menu, int n_array);
double fraction_to_double(char *fraction);
/* No one will ever need more than 9 bytes! */
char exposure_sel[9] = "";
................................................................................

	/* Create items */
	/* Can't really avoid finding array sizes here */
	n_exposure = ARRAY_SIZE(exposure_array);
	n_iso = ARRAY_SIZE(iso_array);
	n_shutter = ARRAY_SIZE(shutter_array);
	n_aperture = ARRAY_SIZE(aperture_array);




	exposure_menu = add_menu(exposure_array, exposure_items, n_exposure);
	iso_menu = add_menu(iso_array, iso_items, n_iso);
	shutter_menu = add_menu(shutter_array, shutter_items, n_shutter);
	aperture_menu = add_menu(aperture_array, aperture_items, n_aperture);
	exposure_win = add_window(4, "EV");
	iso_win = add_window(45, "ISO");
	shutter_win = add_window(86, "Shutter");
	aperture_win = add_window(127, "Aperture");
	/* Don't know how to avoid the repition below */
	set_menu_win(exposure_menu, exposure_win);
	set_menu_win(iso_menu, iso_win);
................................................................................
	remove_menu(exposure_items, exposure_menu, n_exposure);
	remove_menu(iso_items, iso_menu, n_iso);
	remove_menu(shutter_items, shutter_menu, n_shutter);
	remove_menu(aperture_items, aperture_menu, n_aperture);
	endwin();
}

MENU *add_menu(char **array, ITEM **items, int n) {


	int i;
	MENU *local_menu;


	items = (ITEM **)calloc(n, sizeof(ITEM *));
	for(i = 0; i<n; ++i) {
		items[i] = new_item(array[i], array[i]);
		set_item_userptr(items[i], selection);
	}






	local_menu = new_menu((ITEM **)items);
	set_menu_format(local_menu, 5, 1);
	set_menu_mark(local_menu, " * ");
	return local_menu;
}

WINDOW *add_window(int xpos, char *title) {







|

>







 







>
>
>
>
|
|
|
|







 







|
>
>

<
>

|

|
|

>
>
>
>
>
>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
302
303
304
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
WINDOW *iso_win;
WINDOW *shutter_win;
WINDOW *aperture_win;

void selection(char *name);
void remove_menu(ITEM **items, MENU *men, int n);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
MENU *add_menu(ITEM **items);
WINDOW *add_window(int xpos, char *title);
ITEM **add_item(char **array, int n);
int exposure(int iso);
double shutter(int exposure, double aperture);
double aperture(int exposure, double shutter);
int nearest_match(double x, int menu, int n_array);
double fraction_to_double(char *fraction);
/* No one will ever need more than 9 bytes! */
char exposure_sel[9] = "";
................................................................................

	/* Create items */
	/* Can't really avoid finding array sizes here */
	n_exposure = ARRAY_SIZE(exposure_array);
	n_iso = ARRAY_SIZE(iso_array);
	n_shutter = ARRAY_SIZE(shutter_array);
	n_aperture = ARRAY_SIZE(aperture_array);
	exposure_items = add_item(exposure_array, n_exposure);
	iso_items = add_item(iso_array, n_iso);
	aperture_items = add_item(aperture_array, n_aperture);
	shutter_items = add_item(shutter_array, n_shutter);
	exposure_menu = add_menu(exposure_items);
	iso_menu = add_menu(iso_items);
	shutter_menu = add_menu(shutter_items);
	aperture_menu = add_menu(aperture_items);
	exposure_win = add_window(4, "EV");
	iso_win = add_window(45, "ISO");
	shutter_win = add_window(86, "Shutter");
	aperture_win = add_window(127, "Aperture");
	/* Don't know how to avoid the repition below */
	set_menu_win(exposure_menu, exposure_win);
	set_menu_win(iso_menu, iso_win);
................................................................................
	remove_menu(exposure_items, exposure_menu, n_exposure);
	remove_menu(iso_items, iso_menu, n_iso);
	remove_menu(shutter_items, shutter_menu, n_shutter);
	remove_menu(aperture_items, aperture_menu, n_aperture);
	endwin();
}

/* Below pointer configuration figured out from:
 * https://github.com/Yurickh/Psycho-Tetris/blob/master/src/menu.c#L9 */
ITEM **add_item(char **array, int n) {
	int i;

	ITEM **local_items;

	local_items = (ITEM **)calloc(n, sizeof(ITEM *));
	for(i = 0; i<n; ++i) {
		local_items[i] = new_item(array[i], array[i]);
		set_item_userptr(local_items[i], selection);
	}
	return local_items;
}

MENU *add_menu(ITEM **items) {
	MENU *local_menu;

	local_menu = new_menu((ITEM **)items);
	set_menu_format(local_menu, 5, 1);
	set_menu_mark(local_menu, " * ");
	return local_menu;
}

WINDOW *add_window(int xpos, char *title) {