-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
426 lines (368 loc) · 8.27 KB
/
menu.c
1
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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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
317
318
319
320
321
322
323
324
325
326
327
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
/*
* menu.c
*
* CAVE WALL - Colored Ascii Visual Editor Without Any Loathsome Limitations
* General routines
*
* Copyright (C) 2006 Kuki <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <curses.h>
#include <stdlib.h>
#include "menu.h"
#include "block.h"
#include "cave.h"
#include "conffile.h"
#include "color.h"
#include "config.h"
#include "cursor.h"
#include "status.h"
#include "import.h"
#include "cursor.h"
#include "export.h"
#ifdef BANNER
#include "banner.h"
#endif
extern struct config
{
int defcolor, defbgnd, defattr, defmode, fromzero,
key_up, key_down, key_left, key_right,
key_leftborder, key_rightborder, key_upborder, key_downborder,
key_delch, key_backspc, key_addattribs,
key_export, key_import, key_color, key_bgnd, key_attrib, key_mode, key_clear, key_block, key_paste, key_undo, key_menu, key_unknown;
} conf;
// ===== GLOBAL VARIABLES =====
WINDOW *menuw, *dialogw;
// ==== FUNCTIONS ====
//
/* shows help screen */
//
void help_screen(void)
{
wclear(menuw);
attron(A_BOLD);
mvwprintw(menuw,1,xsize/2-2,"HELP");
attroff(A_BOLD);
mvwprintw(menuw,3,2,"F1 - show menu");
mvwprintw(menuw,4,2,"F2 - export");
mvwprintw(menuw,5,2,"F3 - import");
mvwprintw(menuw,6,2,"F4 - block operations");
mvwprintw(menuw,7,2,"F5 - select foreground/background color");
mvwprintw(menuw,8,2,"F6 - select attributes");
mvwprintw(menuw,9,2,"F7 - select cursor step mode");
mvwprintw(menuw,12,2,"F10 - paste from clipboard");
mvwprintw(menuw,13,2,"F11 - undo");
mvwprintw(menuw,14,2,"F12 - clear screen");
mvwprintw(menuw,16,(xsize-2)/2-13,"Press any key to continue.");
wrefresh(menuw);
getch();
return;
}
//
/* menu and dialogs handling */
//
char menu_handle(char last, char choice, const short int x0, const unsigned int y0, WINDOW *dialogwindow)
{
short int x=choice+x0;
int key;
mvwprintw(dialogwindow,x,y0,"->");
wrefresh(dialogwindow);
do
{
key=getch();
if (key==conf.key_up)
{
mvwprintw(dialogwindow,x,y0," ");
x-=1;
if (x<=x0) x=x0;
mvwprintw(dialogwindow,x,y0,"->");
wrefresh(dialogwindow);
}
if (key==conf.key_down)
{
mvwprintw(dialogwindow,x,y0," ");
x+=1;
if (x>=last+x0) x=x0+last-1;
mvwprintw(dialogwindow,x,y0,"->");
wrefresh(dialogwindow);
}
if (key==conf.key_upborder)
{
mvwprintw(dialogwindow,x,y0," ");
x=x0;
mvwprintw(dialogwindow,x,y0,"->");
wrefresh(dialogwindow);
}
if (key==conf.key_downborder)
{
mvwprintw(dialogwindow,x,y0," ");
x=x0+last-1;
mvwprintw(dialogwindow,x,y0,"->");
wrefresh(dialogwindow);
}
if (last<=10)
{
if ((key<'0'+last) && (key>='0'))
{
mvwprintw(dialogwindow,x,y0," ");
x=x0+key-'0';
mvwprintw(dialogwindow,x,y0,"->");
wrefresh(dialogwindow);
}
}
if (key==10) // enter
{
choice=x-x0;
}
} while (key!=10); // inner loop - for moving around in the menu and choosing menu positions
return choice;
}
//
/* attribute selection dialog */
//
void attr_dialog(void)
{
if ((dialogw = newwin(NUMATTRS+1,15, 0, 0)) == NULL) printf("error creating dialog window\n");
int i;
unsigned short choice=0;
wclear(dialogw);
if (NUMATTRS<=10)
{
for (i=0; i<NUMATTRS; i++)
{
mvwaddch(dialogw,i,2,'0'+i);
mvwaddch(dialogw,i,3,'.');
mvwprintw(dialogw,i,4,"%c%s", ( attribute & avals[i] ? '*' : ' '), attrs[i]);
}
mvwaddch(dialogw,i,2,'0'+i);
mvwaddch(dialogw,i,3,'.');
mvwprintw(dialogw,i,5,"Exit" );
}
else
{
for (i=0; i<NUMATTRS; i++)
{
mvwprintw(dialogw,i,4,"%c%s", ( attribute & avals[i] ? '*' : ' '), attrs[i]);
}
mvwprintw(dialogw,i,5,"Exit" );
}
// Allow user to move around
do
{
choice=menu_handle(NUMATTRS+1,choice,0,0,dialogw);
if (choice==0)
{
attribute=A_NORMAL;
for (i=0; i<NUMATTRS; i++) mvwaddch(dialogw,i,4,' ');
update_status();
}
else if (!(choice==NUMATTRS))
{
if (attribute & avals[choice]) {attribute = attribute & ~(avals[choice]); mvwaddch(dialogw,choice,4,' ');}
else { attribute = attribute | avals[choice]; mvwaddch(dialogw,choice,4,'*'); }
update_status();
}
} while (choice!=NUMATTRS);
touchwin(editp);
editprefresh();
delwin(dialogw);
return;
}
//
/* color selection dialog */
//
void color_dialog(void)
{
if ((dialogw = newwin(11,29, 0, 0)) == NULL) printf("error creating dialog window\n");
// draw the color box
int i, j;
wclear(dialogw);
mvwprintw(dialogw,0,15,"FG");
mvwprintw(dialogw,5,0,"B");
mvwprintw(dialogw,6,0,"G");
mvwprintw(dialogw,1,4," 0 1 2 3 4 5 6 7");
for (i=0; i<8; i++)
{
for (j=0; j<8; j++)
{
mvwaddch(dialogw,i+2,3*j+5,'#' | COLOR_PAIR(find_pair(i,j)) | attribute );
}
mvwaddch(dialogw,i+2,2,'0'+i);
}
wrefresh(dialogw);
// Allow user to move around
char y=(color+1)*3;
char x=background+2;
int key;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
do
{
key=getch();
if (key==conf.key_left)
{
mvwprintw(dialogw,x,y," ");
y-=3;
if (y<3) y=3;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_right)
{
mvwprintw(dialogw,x,y," ");
y+=3;
if (y>24) y=24;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_up)
{
mvwprintw(dialogw,x,y," ");
x-=1;
if (x<2) x=2;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_down)
{
mvwprintw(dialogw,x,y," ");
x+=1;
if (x>9) x=9;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_upborder)
{
mvwprintw(dialogw,x,y," ");
x=2;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_downborder)
{
mvwprintw(dialogw,x,y," ");
x=9;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_leftborder)
{
mvwprintw(dialogw,x,y," ");
y=3;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==conf.key_rightborder)
{
mvwprintw(dialogw,x,y," ");
y=24;
mvwprintw(dialogw,x,y,"->");
wrefresh(dialogw);
}
if (key==10) // enter
{
color=y/3-1;
background=x-2;
pair=find_pair(y/3-1,x-2);
update_status();
}
} while (key!=10); // inner loop - for moving around in the menu and choosing menu positions
delwin(dialogw);
touchwin(editp);
editprefresh();
return;
}
//
/* step mode selection dialog */
//
void step_dialog(void)
{
if ((dialogw = newwin(NUMMODES,14, 0, 0)) == NULL) printf("error creating dialog window\n");
int i;
wclear(dialogw);
if (NUMMODES<=10)
{
for (i=0; i<NUMMODES; i++)
{
mvwaddch(dialogw,i,2,'0'+i);
mvwaddch(dialogw,i,3,'.');
mvwprintw(dialogw,i,4,modes[i]);
}
}
else
{
for (i=0; i<NUMMODES; i++)
{
mvwprintw(dialogw,i,2,modes[i]);
}
}
// Allow user to move around
mode=menu_handle(NUMMODES,mode,0,0,dialogw);
update_status();
touchwin(editp);
editprefresh();
delwin(dialogw);
return;
}
//
/* show usable menu window */
//
void menu_screen(void)
{
bool exit_menu=false;
char choice=0;
const int MAXPOSITION=7;
if ((menuw = newwin(ysize-1,xsize, 0, 0)) == NULL) printf("error creating menu window\n");
do
{
wclear(menuw);
attron(A_BOLD);
mvwprintw(menuw,1,xsize/2-2,"MENU");
mvwprintw(menuw,2,xsize/2-3,"------");
attroff(A_BOLD);
mvwprintw(menuw,3,3,"0. Help");
mvwprintw(menuw,4,3,"1. Select fg/bg color");
mvwprintw(menuw,5,3,"2. Select attributes");
mvwprintw(menuw,6,3,"3. Select step mode");
#ifdef FIGLET
mvwprintw(menuw,7,3,"4. Insert FIGletters");
#else
mvwprintw(menuw,7,3,"4. Insert FIGletters (OFF)");
#endif
mvwprintw(menuw,8,3,"5. Exit menu");
mvwprintw(menuw,9,3,"6. Quit CAVE WALL");
wrefresh(menuw);
choice=menu_handle(MAXPOSITION,choice,3,1,menuw);
switch (choice)
{
case 0: // show help screen
help_screen();
break;
case 1: // color selection dialog
color_dialog();
break;
case 2: // attributes selection dialog
attr_dialog();
break;
case 3: // step mode selection dialog
step_dialog();
break;
case 5: // exit menu - handled in the while loop
exit_menu=true;
break;
case 6: // maxposition - quit program
exit_program=true;
break;
}
} while (exit_menu==false && exit_program==false); // outer loop - shows menu
delwin(menuw);
if (exit_program==false) // when exiting menu only
{
touchwin(editp);
editprefresh();
}
return;
}