exposurses

Check-in [4b63a4b0a2]
Login

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

Overview
Comment:Add in values for the three menus
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 4b63a4b0a258890ee0572ff8dcee395718f846c98db4305380402fc15deb2e1c
User & Date: atomicules@lavabit.com 2013-07-08 08:55:04
Context
2013-07-08
08:58
Add Makefile and config.mk Probably overkill for such a tiny file, but good practice for me. check-in: fc1d33f903 user: atomicules@lavabit.com tags: origin/master, trunk
08:55
Add in values for the three menus check-in: 4b63a4b0a2 user: atomicules@lavabit.com tags: origin/master, trunk
08:55
Enable switching between windows with left/right keys - Oh my, I've ended up using pointers to pointers already! Use this so can switch the menu/win "pointing" at with left and right keys and then scroll up down the active one. - Also means need to just use plain getch and not wgetch as don't want to limit input to one window. I still don't get what determines an active window. Is it just cursor position? check-in: db667542ca user: atomicules@lavabit.com tags: origin/master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to exposurses.c.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


130
131
132




133
134
135
136
137
138
139
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_items1;
	/*Weird, can't just re-use my_items. Must recreate that as well*/
	ITEM **my_items2;

	int c;
	MENU *my_menu1;
	MENU *my_menu2;


	MENU **my_menu;
	WINDOW *my_menu_win1;
	WINDOW *my_menu_win2;

	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_items1 = (ITEM **)calloc(n_choices, sizeof(ITEM *));
	for(i = 0; i < n_choices; ++i)
		my_items1[i] = new_item(choices[i], choices[i]);

	my_items2 = (ITEM **)calloc(n_choices, sizeof(ITEM *));
	for(i = 0; i < n_choices; ++i)
		my_items2[i] = new_item(choices[i], choices[i]);





	/* Create menu */
	my_menu1 = new_menu((ITEM **)my_items1);
	my_menu2 = new_menu((ITEM **)my_items2);


	/* Create the window to be associated with the menu */
	my_menu_win1 = newwin(10, 40, 4, 4);
	keypad(my_menu_win1, TRUE);

	my_menu_win2 = newwin(10, 40, 4, 45);
	keypad(my_menu_win2, TRUE);




	/* Set main window and sub window */
	set_menu_win(my_menu1, my_menu_win1);
	set_menu_sub(my_menu1, derwin(my_menu_win1, 6, 38, 3, 1));
	set_menu_win(my_menu2, my_menu_win2);
	set_menu_sub(my_menu2, derwin(my_menu_win2, 6, 38, 3, 1));





	set_menu_format(my_menu1, 5, 1);
	set_menu_format(my_menu2, 5, 1);


	/* Set menu mark to the string " * " */
	set_menu_mark(my_menu1, " * ");
	set_menu_mark(my_menu2, " * ");


	/* Print a border around the main window and print a title */
	box(my_menu_win1, 0, 0);
	box(my_menu_win2, 0, 0);
	print_in_middle(my_menu_win1, 1, 0, 40, "My Menu1", COLOR_PAIR(1));
	print_in_middle(my_menu_win2, 1, 0, 40, "My Menu2", COLOR_PAIR(1));





	mvwaddch(my_menu_win1, 2, 0, ACS_LTEE);
	mvwaddch(my_menu_win2, 2, 0, ACS_LTEE);

	mvwhline(my_menu_win1, 2, 1, ACS_HLINE, 38);
	mvwhline(my_menu_win2, 2, 1, ACS_HLINE, 38);

	mvwaddch(my_menu_win1, 2, 39, ACS_RTEE);
	mvwaddch(my_menu_win2, 2, 39, ACS_RTEE);


	/* Post the menu */
	post_menu(my_menu1);
	post_menu(my_menu2);

	wrefresh(my_menu_win1);
	wrefresh(my_menu_win2);


	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 = getch())){
		switch(c){
			case KEY_LEFT:
				my_menu = &my_menu1;
				my_menu_win = &my_menu_win1;
					break;
			case KEY_RIGHT:
				my_menu = &my_menu2;
				my_menu_win = &my_menu_win2;
				 break;
			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_menu1);


	free_menu(my_menu1);
	for(i = 0; i < n_choices; ++i)
		free_item(my_items1[i]);




	endwin();
}

void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color){
	int length, x, y;
	float temp;








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





|
<
|
>

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











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


|
|
>


|
<
>
|
<
>
>
>


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


|
|
>


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


|
|
>
|
|
>











|
|


|
|


|


|


|


|


|


|
>
>
|
|
|
>
>
>
>







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
114
115
116
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
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 *iso[] = {
	"50",
	"100",
	"200",
	"400",
	"800",
	"1600",
	"3200",
	(char *)NULL,
};

char *shutter[] = {
	"1/1000",
	"1/500",
	"1/250",
	"1/125",
	"1/60",
	"1/30",
	"1/15",
	"1/8",
	"1/4",
	"1/2",
	"1",
	(char *)NULL,
};

char *aperture[] = {
	"f/1.4",
	"f/2",

	"f/2.8",
	"f/4",



	"f/5.6",
	"f/8",



	"f/11",
	"f/16",
	(char *)NULL,
};
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);

int main(){
	ITEM **iso_items;

	ITEM **shutter_items;
	ITEM **aperture_items;
	int c;
	MENU *iso_menu;

	MENU *shutter_menu;
	MENU **aperture_menu;
	MENU **menu;
	WINDOW *iso_win;
	WINDOW *shutter_win;
	WINDOW **aperture_win;
	WINDOW **win;
	int n_iso, i;
	int n_shutter, j;
	int n_aperture, k;

	/* 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_iso = ARRAY_SIZE(iso);
	n_shutter = ARRAY_SIZE(shutter);
	n_aperture = ARRAY_SIZE(aperture);
	iso_items = (ITEM **)calloc(n_iso, sizeof(ITEM *));
	for(i = 0; i < n_iso; ++i)

		iso_items[i] = new_item(iso[i], iso[i]);
	shutter_items = (ITEM **)calloc(n_shutter, sizeof(ITEM *));
	for(i = 0; i < n_shutter; ++i)

		shutter_items[i] = new_item(shutter[i], shutter[i]);
	aperture_items = (ITEM **)calloc(n_aperture, sizeof(ITEM *));
	for(i = 0; i < n_aperture; ++i)
		aperture_items[i] = new_item(aperture[i], aperture[i]);

	/* Create menu */
	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 */
	iso_win = newwin(10, 40, 4, 4);

	keypad(iso_win, TRUE);
	shutter_win = newwin(10, 40, 4, 45);

	keypad(shutter_win, TRUE);
	aperture_win = newwin(10, 40, 4, 86);
	keypad(aperture_win, TRUE);

	/* Set main window and sub window */
	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(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(iso_menu, " * ");
	set_menu_mark(shutter_menu, " * ");
	set_menu_mark(aperture_menu, " * ");

	/* Print a border around the main window and print a title */
	box(iso_win, 0, 0);



	box(shutter_win, 0, 0);
	box(aperture_win, 0, 0);
	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(iso_win, 2, 0, ACS_LTEE);
	mvwaddch(shutter_win, 2, 0, ACS_LTEE);
	mvwaddch(aperture_win, 2, 0, ACS_LTEE);
	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(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(iso_menu);
	post_menu(shutter_menu);
	post_menu(aperture_menu);
	wrefresh(iso_win);
	wrefresh(shutter_win);
	wrefresh(aperture_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 = getch())){
		switch(c){
			case KEY_LEFT:
				menu = &iso_menu;
				win = &iso_win;
					break;
			case KEY_RIGHT:
				menu = &shutter_menu;
				win = &shutter_win;
				 break;
			case KEY_DOWN:
			menu_driver(*menu, REQ_DOWN_ITEM);
			break;
			case KEY_UP:
			menu_driver(*menu, REQ_UP_ITEM);
			break;
			case KEY_NPAGE:
			menu_driver(*menu, REQ_SCR_DPAGE);
			break;
			case KEY_PPAGE:
			menu_driver(*menu, REQ_SCR_UPAGE);
			break;
		}
		wrefresh(*win);
	}	
	/* Unpost and free all the memory taken up */
	unpost_menu(iso_menu);
	unpost_menu(shutter_menu);
	unpost_menu(aperture_menu);
	free_menu(iso_menu);
	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;