📄 prompts1.c
字号:
/*
Various routines that prompt for things.
This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifndef XFRACT
#include <dos.h>
#elif !defined(__386BSD__)
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
#endif
#ifdef __TURBOC__
#include <alloc.h>
#elif !defined(__386BSD__)
#include <malloc.h>
#endif
#ifdef __hpux
#include <sys/param.h>
#define getwd(a) getcwd(a,MAXPATHLEN)
#endif
#include "fractint.h"
#include "fractype.h"
#include "helpdefs.h"
#include "prototyp.h"
extern int Targa_Overlay;
extern int Targa_Out;
extern BYTE back_color[];
extern float screenaspect;
/* Routines defined in prompts2.c */
extern int get_corners(void);
extern int edit_ifs_params(void );
extern int lccompare(VOIDCONSTPTR, VOIDCONSTPTR);
/* Routines used in prompts2.c */
int prompt_checkkey(int curkey);
long get_file_entry(int,char *,char *,char *,char *);
/* Routines in this module */
static int prompt_valuestring(char *buf,struct fullscreenvalues *val);
static int input_field_list(int attr,char *fld,int vlen,char **list,int llen,
int row,int col,int (*checkkey)(int));
static int select_fracttype(int t);
static int sel_fractype_help(int curkey, int choice);
int select_type_params(int newfractype,int oldfractype);
void set_default_parms(void);
static long gfe_choose_entry(int,char *,char *,char *);
static int check_gfe_key(int curkey,int choice);
static void load_entry_text(FILE *entfile,char far *buf,int maxlines);
static void format_parmfile_line(int,char *);
static int get_light_params(void );
static int check_mapfile(void );
static int get_funny_glasses_params(void );
int julibrot; /* flag for julibrot */
extern int numtrigfn;
extern int bailout;
extern struct moreparams far moreparams[];
static char funnyglasses_map_name[16];
extern char temp1[256]; /* temporary strings */
extern int previewfactor;
extern int xtrans, ytrans;
extern int red_crop_left, red_crop_right;
extern int blue_crop_left, blue_crop_right;
extern int red_bright, blue_bright;
extern char showbox; /* flag to show box and vector in preview */
extern SEGTYPE extraseg;
extern int whichimage;
extern int xadjust;
extern int eyeseparation;
extern int glassestype;
char MAP_name[80] = "";
int mapset = 0;
extern int overlay3d; /* 3D overlay flag: 0 = OFF */
extern int lookatmouse;
extern int haze;
extern int RANDOMIZE;
extern char light_name[];
extern int Ambient;
extern int RAY;
extern int BRIEF;
extern char ray_name[];
extern int init3d[20]; /* '3d=nn/nn/nn/...' values */
extern double xxmin,xxmax; /* initial corner values */
extern double yymin,yymax; /* initial corner values */
extern double xx3rd,yy3rd; /* initial corner values */
extern int invert; /* non-zero if inversion active */
extern double inversion[3]; /* radius, xcenter, ycenter */
extern double param[]; /* up to six parameters */
extern double potparam[3]; /* three potential parameters*/
extern int fractype; /* if == 0, use Mandelbrot */
extern char preview; /* 3D preview mode flag */
extern int transparent[]; /* transparency values */
extern int usr_biomorph; /* Biomorph flag */
extern int viewcrop;
extern float finalaspectratio;
extern int textcbase;
extern char boxy[];
extern int display3d;
extern char LFileName[]; /* file to find the formulas in */
extern char LName[]; /* Name of the Formula (if not null) */
extern char FormFileName[];
extern char FormName[];
extern char IFSFileName[];
extern char IFSName[];
extern float far *ifs_defn;
extern int ifs_type;
extern int ifs_changed;
/* fullscreen_choice options */
#define CHOICEHELP 4
#define GETFORMULA 0
#define GETLSYS 1
#define GETIFS 2
#define GETPARM 3
char ifsmask[13] = {"*.ifs"};
char formmask[13] = {"*.frm"};
char lsysmask[13] = {"*.l"};
char Glasses1Map[] = "glasses1.map";
void prompts1_overlay() { } /* for restore_active_ovly */
/* --------------------------------------------------------------------- */
int promptfkeys;
int fullscreen_prompt( /* full-screen prompting routine */
char far *hdg, /* heading, lines separated by \n */
int numprompts, /* there are this many prompts (max) */
char far **prompts, /* array of prompting pointers */
struct fullscreenvalues *values, /* array of values */
int options, /* for future */
int fkeymask, /* bit n on if Fn to cause return */
char far *extrainfo /* extra info box to display, \n separated */
)
{
char far *hdgscan;
int titlelines,titlewidth,titlerow;
int maxpromptwidth,maxfldwidth,maxcomment;
int boxrow,boxlines;
int boxcol,boxwidth;
int extralines,extrawidth,extrarow;
int instrrow;
int promptrow,promptcol,valuecol;
int curchoice;
int done, i, j;
int anyinput;
int savelookatmouse;
int curtype, curlen;
char buf[81];
#ifndef XFRACT
static char far instr1[] = {"Use " UPARR " and " DNARR " to select values to change"};
static char far instr2a[] = {"Type in replacement value for selected field"};
static char far instr2b[] = {"Use " LTARR " or " RTARR " to change value of selected field"};
#else
/* Some compilers don't accept "a" "b", so we have to fill in UPARR ourself. */
static char far instr1[] = {"Use up(K) and down(J) to select values to change"};
static char far instr2a[] = {"Type in replacement value for selected field"};
static char far instr2b[] = {"Use left(H) or right(L) to change value of selected field"};
#endif
static char far instr3a[] = {"Press ENTER when finished (or ESCAPE to back out)"};
static char far instr3b[] = {"Press ENTER when finished, ESCAPE to back out, or F1 for help"};
static char far instr0a[] = {"No changeable parameters; press ENTER to exit"};
static char far instr0b[] = {"No changeable parameters; press ENTER to exit or F1 for help"};
ENTER_OVLY(OVLY_PROMPTS1);
if (numprompts <= 0) { /* ?? nothing to do! */
EXIT_OVLY;
return(0);
}
savelookatmouse = lookatmouse;
lookatmouse = 0;
promptfkeys = fkeymask;
helptitle(); /* clear screen, display title line */
setattr(1,0,C_PROMPT_BKGRD,24*80); /* init rest of screen to background */
hdgscan = hdg; /* count title lines, find widest */
i = titlewidth = 0;
titlelines = 1;
while (*hdgscan) {
if (*(hdgscan++) == '\n') {
++titlelines;
i = -1;
}
if (++i > titlewidth)
titlewidth = i;
}
extralines = extrawidth = i = 0;
if ((hdgscan = extrainfo))
if (*hdgscan == 0)
extrainfo = NULL;
else { /* count extra lines, find widest */
extralines = 3;
while (*hdgscan) {
if (*(hdgscan++) == '\n') {
if (extralines + numprompts + titlelines >= 20) {
*hdgscan = 0; /* full screen, cut off here */
break;
}
++extralines;
i = -1;
}
if (++i > extrawidth)
extrawidth = i;
}
}
/* work out vertical positioning */
i = numprompts + titlelines + extralines + 3; /* total rows required */
j = (25 - i) / 2; /* top row of it all when centered */
j -= j / 4; /* higher is better if lots extra */
boxlines = numprompts;
titlerow = 1 + j;
promptrow = boxrow = titlerow + titlelines;
if (titlerow > 2) { /* room for blank between title & box? */
--titlerow;
--boxrow;
++boxlines;
}
instrrow = boxrow+boxlines;
if (instrrow + 3 + extralines < 25) {
++boxlines; /* blank at bottom of box */
++instrrow;
if (instrrow + 3 + extralines < 25)
++instrrow; /* blank before instructions */
}
extrarow = instrrow + 2;
if (numprompts > 1) /* 3 instructions lines */
++extrarow;
if (extrarow + extralines < 25)
++extrarow;
/* work out horizontal positioning */
maxfldwidth = maxpromptwidth = maxcomment = anyinput = 0;
for (i = 0; i < numprompts; i++) {
if (values[i].type == 'y') {
static char *noyes[2] = {"no","yes"};
values[i].type = 'l';
values[i].uval.ch.vlen = 3;
values[i].uval.ch.list = noyes;
values[i].uval.ch.llen = 2;
}
j = far_strlen(prompts[i]);
if (values[i].type == '*') {
if (j > maxcomment) maxcomment = j;
}
else {
anyinput = 1;
if (j > maxpromptwidth) maxpromptwidth = j;
j = prompt_valuestring(buf,&values[i]);
if (j > maxfldwidth) maxfldwidth = j;
}
}
boxwidth = maxpromptwidth + maxfldwidth + 2;
if (maxcomment > boxwidth) boxwidth = maxcomment;
if ((boxwidth += 4) > 80) boxwidth = 80;
boxcol = (80 - boxwidth) / 2; /* center the box */
promptcol = boxcol + 2;
valuecol = boxcol + boxwidth - maxfldwidth - 2;
if (boxwidth <= 76) { /* make margin a bit wider if we can */
boxwidth += 2;
--boxcol;
}
if ((j = titlewidth) < extrawidth)
j = extrawidth;
if ((i = j + 4 - boxwidth) > 0) { /* expand box for title/extra */
if (boxwidth + i > 80)
i = 80 - boxwidth;
boxwidth += i;
boxcol -= i / 2;
}
i = (90 - boxwidth) / 20;
boxcol -= i;
promptcol -= i;
valuecol -= i;
/* display box heading */
for (i = titlerow; i < boxrow; ++i)
setattr(i,boxcol,C_PROMPT_HI,boxwidth);
textcbase = boxcol + (boxwidth - titlewidth) / 2;
putstring(titlerow,0,C_PROMPT_HI,hdg);
/* display extra info */
if (extrainfo) {
#ifndef XFRACT
#define S1 '\xC4'
#define S2 "\xC0"
#define S3 "\xD9"
#define S4 "\xB3"
#define S5 "\xDA"
#define S6 "\xBF"
#else
#define S1 '-'
#define S2 "+" /* ll corner */
#define S3 "+" /* lr corner */
#define S4 "|"
#define S5 "+" /* ul corner */
#define S6 "+" /* ur corner */
#endif
memset(buf,S1,80); buf[boxwidth-2] = 0;
textcbase = boxcol + 1;
putstring(extrarow,0,C_PROMPT_BKGRD,buf);
putstring(extrarow+extralines-1,0,C_PROMPT_BKGRD,buf);
--textcbase;
putstring(extrarow,0,C_PROMPT_BKGRD,S5);
putstring(extrarow+extralines-1,0,C_PROMPT_BKGRD,S2);
textcbase += boxwidth - 1;
putstring(extrarow,0,C_PROMPT_BKGRD,S6);
putstring(extrarow+extralines-1,0,C_PROMPT_BKGRD,S3);
textcbase = boxcol;
for (i = 1; i < extralines-1; ++i) {
putstring(extrarow+i,0,C_PROMPT_BKGRD,S4);
putstring(extrarow+i,boxwidth-1,C_PROMPT_BKGRD,S4);
}
textcbase += (boxwidth - extrawidth) / 2;
putstring(extrarow+1,0,C_PROMPT_TEXT,extrainfo);
}
textcbase = 0;
/* display empty box */
for (i = 0; i < boxlines; ++i)
setattr(boxrow+i,boxcol,C_PROMPT_LO,boxwidth);
/* display initial values */
for (i = 0; i < numprompts; i++) {
putstring(promptrow+i, promptcol, C_PROMPT_LO, prompts[i]);
prompt_valuestring(buf,&values[i]);
putstring(promptrow+i, valuecol, C_PROMPT_LO, buf);
}
if (!anyinput) {
putstringcenter(instrrow,0,80,C_PROMPT_BKGRD,
(helpmode > 0) ? instr0b : instr0a);
movecursor(25,80);
while (1) {
while (!keypressed()) { }
done = getakey();
switch(done) {
case ESC:
done = -1;
case ENTER:
case ENTER_2:
goto fullscreen_exit;
case F2:
case F3:
case F4:
case F5:
case F6:
case F7:
case F8:
case F9:
case F10:
if (promptfkeys & (1<<(done+1-F1)) )
goto fullscreen_exit;
}
}
}
/* display footing */
if (numprompts > 1)
putstringcenter(instrrow++,0,80,C_PROMPT_BKGRD,instr1);
putstringcenter(instrrow+1,0,80,C_PROMPT_BKGRD,
(helpmode > 0) ? instr3b : instr3a);
curchoice = done = 0;
while (values[curchoice].type == '*') ++curchoice;
while (!done) {
curtype = values[curchoice].type;
curlen = prompt_valuestring(buf,&values[curchoice]);
putstringcenter(instrrow,0,80,C_PROMPT_BKGRD,
(curtype == 'l') ? instr2b : instr2a);
putstring(promptrow+curchoice,promptcol,C_PROMPT_HI,prompts[curchoice]);
if (curtype == 'l') {
i = input_field_list(
C_PROMPT_CHOOSE, buf, curlen,
values[curchoice].uval.ch.list, values[curchoice].uval.ch.llen,
promptrow+curchoice,valuecol, prompt_checkkey);
for (j = 0; j < values[curchoice].uval.ch.llen; ++j)
if (strcmp(buf,values[curchoice].uval.ch.list[j]) == 0) break;
values[curchoice].uval.ch.val = j;
}
else {
j = 0;
if (curtype == 'i') j = 3;
if (curtype == 'd') j = 5;
if (curtype == 'D') j = 7;
if (curtype == 'f') j = 1;
i = input_field(j, C_PROMPT_INPUT, buf, curlen,
promptrow+curchoice,valuecol,prompt_checkkey);
switch (values[curchoice].type) {
case 'd':
case 'D':
values[curchoice].uval.dval = atof(buf);
break;
case 'f':
values[curchoice].uval.dval = atof(buf);
roundfloatd(&values[curchoice].uval.dval);
break;
case 'i':
values[curchoice].uval.ival = atoi(buf);
break;
case 's':
strncpy(values[curchoice].uval.sval,buf,16);
break;
default: /* assume 0x100+n */
strcpy(values[curchoice].uval.sbuf,buf);
}
}
putstring(promptrow+curchoice,promptcol,C_PROMPT_LO,prompts[curchoice]);
j = strlen(buf);
memset(&buf[j],' ',80-j); buf[curlen] = 0;
putstring(promptrow+curchoice, valuecol, C_PROMPT_LO, buf);
switch(i) {
case 0: /* enter */
done = 13;
break;
case -1: /* escape */
case F2:
case F3:
case F4:
case F5:
case F6:
case F7:
case F8:
case F9:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -