exposurses

Changes On Branch refs/stash
Login

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

Changes In Branch refs/stash Excluding Merge-Ins

This is equivalent to a diff from 580afe6ab4 to b1a123e70a

2013-09-18
10:33
For ref: Try wrapping menu and window creation in single function

Got this so it drew everything ok, but segfaults as soon as a key is
pressed. I obviously don't understand pointers, etc properly yet. As
although it's drawn the menus it hasn't "attached" them the the
objects/pointers I was expecting. check-in: a88f7285c1 user: base@atomicules.co.uk tags: origin/master, trunk

2013-09-11
21:41
For ref: Wrap menu and window creation in function check-in: 284f5d1a81 user: base@atomicules.co.uk tags: temp2, trunk
21:33
WIP on temp: bafe457 For ref Leaf check-in: b1a123e70a user: base@atomicules.co.uk tags: refs/stash, trunk
21:33
index on temp: bafe457 For ref check-in: d2e1d0e68b user: base@atomicules.co.uk tags: refs/stash, trunk
2013-09-10
13:40
For ref check-in: de620ef542 user: base@atomicules.co.uk tags: refs/stash, trunk
08:51
Make exposure menu functional

- Make it function so that user is constrained to exposure menu
initially and must select value there.
- Once selected, the ISO menu becomes active and user must select value
there
- Finally make both shutter and aperture menus actives (switch between
them with left/right arrow keys). Whichever is selected, the other
will be calculated.

This is not very pretty:

- I don't like having both the selection_counter and menu_counter. Seems
almost redundant. Made sense before I constrained selections and
stepped through the menu's etc (and therefore you could re-select),
but now seems annoying to have to keep it only for how last two menus
work.
- I don't like the repetitive menu creation stuff. That should be DRY-ed
up. check-in: 580afe6ab4 user: base@atomicules.co.uk tags: origin/master, trunk

2013-09-03
12:38
Add in EV menu, doesn't function yet though

- Add in free memory bits, also missed some for the other menus check-in: 6c315c3200 user: base@atomicules.co.uk tags: origin/master, trunk


Changes to Makefile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# exposurses

include config.mk

SRC = exposurses.c
OBJ = ${SRC:.c=.o}

all: options exposurses

options:
	@echo build options:
	@echo "CC       = ${CC}"

.c.o:
	@echo CC $<
	@${CC} -c $<

exposurses: ${OBJ}
	@echo CC -o $@
	@${CC} -o $@ ${OBJ} ${LDFLAGS}

clean:
	@echo cleaning
	@rm -f exposurses ${OBJ}













|
|
|

|
|
|




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# exposurses

include config.mk

SRC = exposurses.c
OBJ = ${SRC:.c=.o}

all: options exposurses

options:
	@echo build options:
	@echo "CC       = ${CC}"

exposurses: ${OBJ}
	@echo CC -o $@
	@${CC} -s ${LIBS} ${SRC} -o $@ 

debug: 
	@echo "Building with debug symbols"	
	@${CC} -g ${LIBS} ${SRC} -o exposurses

clean:
	@echo cleaning
	@rm -f exposurses ${OBJ}

Changes to config.mk.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Customize below to fit your system

# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man

# includes and libs
#INCS = -I. -I/usr/include
LIBS=-lmenu -lcurses -lm

# flags
LDFLAGS = -s ${LIBS}

# compiler and linker
CC = cc







<


<
<
<


1
2
3
4
5
6
7

8
9



10
11
# Customize below to fit your system

# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man

# includes and libs

LIBS=-lmenu -lcurses -lm




# compiler and linker
CC = cc

Changes to exposurses.c.

83
84
85
86
87
88
89

90


91
92
93
94
95
96
97
MENU *aperture_menu;
WINDOW *exposure_win;
WINDOW *iso_win;
WINDOW *shutter_win;
WINDOW *aperture_win;

void selection(char *name);

void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);


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







>

>
>







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
MENU *aperture_menu;
WINDOW *exposure_win;
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(MENU *men, 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);
double fraction_to_double(char *fraction);
/* No one will ever need more than 9 bytes! */
char exposure_sel[9] = "";
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);

	/* Create items */
	/* Lot's of repitition here. Surely can be wrapped in a function */
	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 = (ITEM **)calloc(n_exposure, sizeof(ITEM *));
	for(i = 0; i < n_exposure; ++i) {
		exposure_items[i] = new_item(exposure_array[i], exposure_array[i]);
		set_item_userptr(exposure_items[i], selection);
	}
	iso_items = (ITEM **)calloc(n_iso, sizeof(ITEM *));
	for(i = 0; i < n_iso; ++i) {
		iso_items[i] = new_item(iso_array[i], iso_array[i]);
		set_item_userptr(iso_items[i], selection);
	}
	shutter_items = (ITEM **)calloc(n_shutter, sizeof(ITEM *));
	for(i = 0; i < n_shutter; ++i) {
		shutter_items[i] = new_item(shutter_array[i], shutter_array[i]);
		set_item_userptr(shutter_items[i], selection);
	}
	aperture_items = (ITEM **)calloc(n_aperture, sizeof(ITEM *));
	for(i = 0; i < n_aperture; ++i) {
		aperture_items[i] = new_item(aperture_array[i], aperture_array[i]);
		set_item_userptr(aperture_items[i], selection);
	}

	/* Create menu */
	exposure_menu = new_menu((ITEM **)exposure_items);
	iso_menu = new_menu((ITEM **)iso_items);
	shutter_menu = new_menu((ITEM **)shutter_items);
	aperture_menu = new_menu((ITEM **)aperture_items);

	/* Create the window to be associated with the menu */
	exposure_win = newwin(10, 40, 4, 4);
	keypad(exposure_win, TRUE);
	iso_win = newwin(10, 40, 4, 45);
	keypad(iso_win, TRUE);
	shutter_win = newwin(10, 40, 4, 86);
	keypad(shutter_win, TRUE);
	aperture_win = newwin(10, 40, 4, 127);
	keypad(aperture_win, TRUE);

	/* Set main window and sub window */
	set_menu_win(exposure_menu, exposure_win);
	set_menu_sub(exposure_menu, derwin(exposure_win, 6, 38, 3, 1));
	set_menu_win(iso_menu, iso_win);
	set_menu_sub(iso_menu, derwin(iso_win, 6, 38, 3, 1));
	set_menu_win(shutter_menu, shutter_win);
	set_menu_sub(shutter_menu, derwin(shutter_win, 6, 38, 3, 1));
	set_menu_win(aperture_menu, aperture_win);
	set_menu_sub(aperture_menu, derwin(aperture_win, 6, 38, 3, 1));
	set_menu_format(exposure_menu, 5, 1);
	set_menu_format(iso_menu, 5, 1);
	set_menu_format(shutter_menu, 5, 1);
	set_menu_format(aperture_menu, 5, 1);

	/* Set menu mark to the string " * " */
	set_menu_mark(exposure_menu, " * ");
	set_menu_mark(iso_menu, " * ");
	set_menu_mark(shutter_menu, " * ");
	set_menu_mark(aperture_menu, " * ");

	/* Print a border around the main window and print a title */
	box(exposure_win, 0, 0);
	box(iso_win, 0, 0);
	box(shutter_win, 0, 0);
	box(aperture_win, 0, 0);
	print_in_middle(exposure_win, 1, 0, 40, "EV", COLOR_PAIR(1));
	print_in_middle(iso_win, 1, 0, 40, "ISO", COLOR_PAIR(1));
	print_in_middle(shutter_win, 1, 0, 40, "Shutter", COLOR_PAIR(1));
	print_in_middle(aperture_win, 1, 0, 40, "Aperture", COLOR_PAIR(1));
	mvwaddch(exposure_win, 2, 0, ACS_LTEE);
	mvwaddch(iso_win, 2, 0, ACS_LTEE);
	mvwaddch(shutter_win, 2, 0, ACS_LTEE);
	mvwaddch(aperture_win, 2, 0, ACS_LTEE);
	mvwhline(exposure_win, 2, 1, ACS_HLINE, 38);
	mvwhline(iso_win, 2, 1, ACS_HLINE, 38);
	mvwhline(shutter_win, 2, 1, ACS_HLINE, 38);
	mvwhline(aperture_win, 2, 1, ACS_HLINE, 38);
	mvwaddch(exposure_win, 2, 39, ACS_RTEE);
	mvwaddch(iso_win, 2, 39, ACS_RTEE);
	mvwaddch(shutter_win, 2, 39, ACS_RTEE);
	mvwaddch(aperture_win, 2, 39, ACS_RTEE);

	/* Post the menu */
	post_menu(exposure_menu);
	post_menu(iso_menu);
	post_menu(shutter_menu);
	post_menu(aperture_menu);
	wrefresh(exposure_win);
	wrefresh(iso_win);
	wrefresh(shutter_win);
	wrefresh(aperture_win);

	attron(COLOR_PAIR(2));
	mvprintw(LINES - 2, 0, "Select EV");
	/*mvprintw(LINES - 2, 0, "Select ISO and then one of Shutter/Aperture to calculate other of Shutter/Aperture");*/
	mvprintw(LINES - 1, 0, "Arrow keys to navigate, Enter to select, Q to exit");
	attroff(COLOR_PAIR(2));
	refresh();







|




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
<
<
<
<







120
121
122
123
124
125
126
127
128
129
130
131




















132





133









134













135





136























137
138
139
140




141
142
143
144
145
146
147
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);

	/* 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);




















	/* http://stackoverflow.com/a/2620158/208793 */





	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(exposure_menu, 4, "EV");
	iso_win = add_window(iso_menu, 45, "ISO");
	shutter_win = add_window(shutter_menu, 86, "Shutter");
	aperture_win = add_window(aperture_menu, 127, "Aperture");





	attron(COLOR_PAIR(2));
	mvprintw(LINES - 2, 0, "Select EV");
	/*mvprintw(LINES - 2, 0, "Select ISO and then one of Shutter/Aperture to calculate other of Shutter/Aperture");*/
	mvprintw(LINES - 1, 0, "Arrow keys to navigate, Enter to select, Q to exit");
	attroff(COLOR_PAIR(2));
	refresh();
251
252
253
254
255
256
257

258
259
260
261
262
263
264
			case 10: { /* ENTER */
				ITEM *cur;
				void (*p)(char *);

				cur = current_item(*menu);
				p = item_userptr(cur);
				/* Learning notes - Don't understand this bit */

				p((char *)item_name(cur));
				
				switch (selection_counter) {
					case 1: { /* Exposure selected */
						selection_counter += 1;
						menu_counter += 1;
						move(LINES - 2, 0);







>







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
			case 10: { /* ENTER */
				ITEM *cur;
				void (*p)(char *);

				cur = current_item(*menu);
				p = item_userptr(cur);
				/* Learning notes - Don't understand this bit */
				/* Is this a function pointer? */
				p((char *)item_name(cur));
				
				switch (selection_counter) {
					case 1: { /* Exposure selected */
						selection_counter += 1;
						menu_counter += 1;
						move(LINES - 2, 0);
328
329
330
331
332
333
334
335
336
337
338
339
340
341


342
343

344
345

346
347








348


349












350


351


352
353
354
355
356
357
358
359
360
361
362
						refresh();
					}
					break;
				}
			}
			break;
		}
		wrefresh(*win);
	}	
	/* Unpost and free all the memory taken up */
	unpost_menu(exposure_menu);
	unpost_menu(iso_menu);
	unpost_menu(shutter_menu);
	unpost_menu(aperture_menu);


	free_menu(exposure_menu);
	free_menu(iso_menu);

	free_menu(shutter_menu);
	free_menu(aperture_menu);

	for(i = 0; i < n_exposure; ++i)
		free_item(iso_items[i]);








	for(i = 0; i < n_iso; ++i)


		free_item(iso_items[i]);












	for(i = 0; i < n_shutter; ++i)


		free_item(shutter_items[i]);


	for(i = 0; i < n_aperture; ++i)
		free_item(aperture_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;







|


|
|
|
|
>
>
|
|
>
|
|
>
|
|
>
>
>
>
>
>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
|
|
<








253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
						refresh();
					}
					break;
				}
			}
			break;
		}
		wrefresh(win);
	}	
	/* Unpost and free all the memory taken up */
	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, " * ");
	post_menu(local_menu);
	return local_menu;
}

WINDOW *add_window(MENU *men, int xpos, char *title) {
	WINDOW *local_win;

	local_win = newwin(10, 40, 4, xpos);
	keypad(local_win, TRUE);
	set_menu_win(*men, local_win);
	set_menu_sub(*men, derwin(local_win, 6, 38, 3, 1));
	box(local_win, 0, 0);
	print_in_middle(local_win, 1, 0, 40, title, COLOR_PAIR(1));
	mvwaddch(local_win, 2, 0, ACS_LTEE);
	mvwhline(local_win, 2, 1, ACS_HLINE, 38);
	mvwaddch(local_win, 2, 39, ACS_RTEE);
	wrefresh(local_win);
	return local_win;
}

void remove_menu(ITEM **items, MENU *men, int n) {
	int i;

	unpost_menu(men);
	free_menu(men);
	for(i = 0; i < n; ++i)
		free_item(items[i]);

}

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;