📄 _msdos.c
字号:
int panel_x;
int panel_x1;
int mes_x;
int mes_width;
int y1;
mes_width = text_width(message);
y1 = y0 + text_height("H") + 2*yspace - 1;
panel_width = xskip;
for(i=0;i<n;i++)
{ L[i] = panel_width;
panel_width += 2*xspace+text_width(labels[i]);
R[i] = panel_width;
panel_width += xskip;
}
mes_x = (panel_width-mes_width)/2;
if (mes_x < xskip)
{ int d = xskip - mes_x;
for(i=0;i<n;i++)
{ L[i] += d;
R[i] += d;
}
panel_width += 2*d;
mes_x = xskip;
}
panel_x = (max_xcoord()-panel_width)/2;
if (xpos > 0 && xpos+panel_width < max_xcoord()) panel_x = xpos;
if (panel_x<0) panel_x=0;
panel_y = (ypos>0) ? ypos : (max_ycoord()-panel_height)/2;
panel_x1=panel_x+panel_width+1;
panel_y1=panel_y+panel_height+1;
/* save picture */
buffer = save_box(panel_x,panel_y,panel_x1,panel_y1);
save_mode = x_draw_set_mode(0);
set_line_style(0,1);
save_color = get_color();
set_color(PANEL_BG_COLOR);
box(panel_x,panel_y,panel_x1,panel_y1);
set_color(PANEL_FG_COLOR);
rectangle(panel_x+1,panel_y+1,panel_x1-1,panel_y1-1);
put_text(panel_x+mes_x,panel_y+mes_y,message,0);
for (i=0;i<n;i++) /* draw buttons */
{ rectangle(panel_x+L[i],panel_y+y0,panel_x+R[i],panel_y+y1);
put_text(panel_x+L[i]+xspace,panel_y+y0+yspace,labels[i],0);
}
while (answer == -1)
{
double x,y;
int xpix,ypix;
x_read_mouse(0,0.0,0.0,&x,&y);
xpix = XPIX(x) - panel_x;
ypix = YPIX(y) - panel_y;
if ( y0 < ypix && ypix < y1)
{ int i = 0;
while (i < n && R[i] < xpix) i++;
if (i < n && L[i] < xpix) answer = i;
}
}
/* highlight pressed button */
set_color(PANEL_FG_COLOR);
box(panel_x+L[answer],panel_y+y0,panel_x+R[answer],panel_y+y1);
set_color(PANEL_BG_COLOR);
for(i=0;i<50;i++)
put_text(panel_x+L[answer]+xspace,panel_y+y0+yspace,labels[answer],0);
restore_box(buffer);
free((char*)buffer);
set_color(save_color);
x_draw_set_mode(save_mode);
set_line_style(x_draw_line_style,x_draw_line_width);
return answer;
}
int x_draw_read_panel(message,n,labels,vertical)
char *message;
int n;
char **labels;
int vertical;
{
return read_panel(message,n,labels,-1,-1);
}
int confirm(header,x,y)
char *header;
int x,y;
{ char* s[2];
s[0] = "NO";
s[1] = "YES";
return read_panel(header,2,s,x,y);
}
int x_draw_confirm(header)
char *header;
{ char* s[2];
s[0] = "NO";
s[1] = "YES";
return x_draw_read_panel(header,2,s,0);
}
int x_draw_acknowledge(header)
char *header;
{ /* ask for ok */
char* s[1];
s[0] = "OK";
mouse_last_xpix = mouse_xpix = max_xcoord()/2;
mouse_last_ypix = mouse_ypix = max_ycoord()/2 + 10;
return x_draw_read_panel(header,1,s,0);
}
void x_draw_message_panel(argc,argv)
int argc;
char** argv;
{ }
void x_draw_notice()
{ }
void x_draw_cursor()
{ }
/*---------------------------------------------------------------------------*/
/* panels */
/*---------------------------------------------------------------------------*/
typedef struct {
char* header;
int but_count;
char* buttons[16];
int text_count;
char* text[16];
int string_count;
char* string_label[8];
char* string_ref[8];
int int_count;
char* int_label[8];
int* int_ref[8];
int float_count;
char* float_label[8];
double* float_ref[8];
int choice_count;
int choice_size[8];
int choice_step[8];
int choice_offset[8];
char* choice_label[8];
char* choices[8][8];
int* choice_ref[8];
} LEDA_PANEL;
typedef LEDA_PANEL* leda_panel;
leda_panel x_draw_panel_create()
{ leda_panel p = (leda_panel) malloc(sizeof(LEDA_PANEL));
p->header = "";
p->but_count = 0;
p->text_count = 0;
p->int_count = 0;
p->float_count = 0;
p->string_count = 0;
p->choice_count = 0;
return p;
}
void x_draw_panel_destroy(p)
leda_panel p;
{ free((char*)p); }
void x_draw_panel_label(p,s)
leda_panel p;
char* s;
{ p->header = s; }
void x_draw_panel_text_item(p,s)
leda_panel p;
char* s;
{ p->text[p->text_count++] = s; }
void x_draw_panel_string_item(p,s,x)
leda_panel p;
char* s;
char* x;
{ p->string_label[p->string_count] = s;
p->string_ref[p->string_count] = x;
p->string_count++;
}
void x_draw_panel_string_menu_item(p,s,x,argc,argv)
leda_panel p;
char* s;
char* x;
int argc;
char** argv;
{ x_draw_panel_string_item(p,s,x); }
void x_draw_panel_int_item(p,s,x)
leda_panel p;
char* s;
int* x;
{ p->int_label[p->int_count] = s;
p->int_ref[p->int_count] = x;
p->int_count++;
}
void x_draw_panel_slider_item(p,s,x,Min,Max)
leda_panel p;
char* s;
int* x;
int Min;
int Max;
{ x_draw_panel_int_item(p,s,x); }
void x_draw_panel_float_item(p,s,x)
leda_panel p;
char* s;
double* x;
{ p->float_label[p->float_count] = s;
p->float_ref[p->float_count] = x;
p->float_count++;
}
void x_draw_panel_choice_item(p,text,address,argc,argv,step,offset)
leda_panel p;
char* text;
int* address;
int argc;
char** argv;
int step;
int offset;
{ int i;
p->choice_label[p->choice_count] = text;
p->choice_ref[p->choice_count] = address;
p->choice_step[p->choice_count] = step;
p->choice_offset[p->choice_count] = offset;
for(i = 0; i < argc; i++) p->choices[p->choice_count][i] = argv[i];
p->choice_size[p->choice_count] = argc;
p->choice_count++;
}
void x_draw_panel_button(p,s)
leda_panel p;
char* s;
{ p->buttons[p->but_count++] = s; }
void x_draw_panel_button_line(p,n,b)
leda_panel p;
int n;
char** b;
{ int i;
for(i=0; i<n; i++) x_draw_panel_button(p,b[i]);
}
int x_draw_panel_open(p)
leda_panel p;
{ int i,j,x,y,ymax;
int n=0;
int xoff = 100;
int yoff = 10;
int but;
float f;
double xc,yc;
char text[80];
int save_mode = x_draw_set_mode(0);
int save_lw = x_draw_set_line_width(1);
int save_col = get_color();
set_color(FG_COLOR);
save_screen();
clear_screen();
y = yoff;
put_text(xoff,y,p->header,1);
for(i=0;i<p->text_count; i++) put_text(xoff,y+=20,p->text[i],1);
y+=20;
for(i=0;i<p->int_count; i++)
{ sprintf(text,"%-15s = %8d",p->int_label[i],*p->int_ref[i]);
y+=20;
rectangle(xoff,y+1,xoff+20,y+19);
put_text(xoff+30,y+4,text,1);
}
for(i=0;i<p->float_count; i++)
{ sprintf(text,"%-15s = %8.2f",p->float_label[i],*p->float_ref[i]);
y+=20;
rectangle(xoff,y+1,xoff+20,y+19);
put_text(xoff+30,y+4,text,1);
}
for(i=0;i<p->string_count; i++)
{ sprintf(text,"%-15s = %8s",p->string_label[i],p->string_ref[i]);
y+=20;
rectangle(xoff,y+1,xoff+20,y+19);
put_text(xoff+30,y+4,text,1);
}
for(i=0;i<p->choice_count; i++)
{ int x = (*p->choice_ref[i]-p->choice_offset[i])/p->choice_step[i];
sprintf(text,"%-15s = %8s",p->choice_label[i], p->choices[i][x]);
y+=20;
rectangle(xoff,y+1,xoff+20,y+19);
put_text(xoff+30,y+4,text,1);
}
n = p->int_count +
p->float_count +
p->string_count+
p->choice_count;
ymax = y + 25;
if (n>0 || p->but_count==0)
{ y += 20;
rectangle(xoff,y+1,xoff+20,y+19);
put_text(xoff+30,y+4,"OK",1);
y += 20;
rectangle(xoff,y+1,xoff+20,y+19);
put_text(xoff+30,y+4,"QUIT",1);
ymax = y + 25;
for(;;)
{ i = -1;
while (i < 0 || i > n+1)
{ but = x_read_mouse(0,0.0,0.0,&xc,&yc);
x = XPIX(xc);
y = YPIX(yc);
if (xoff <= x && x <= xoff+20 )
i = (y-yoff)/20 - p->text_count - 2;
}
y = 20*(p->text_count+i+2)+yoff;
set_color(FG_COLOR);
box(xoff+1,y+2,xoff+19,y+18);
if (i == n) break; /* OK */
if (i == n+1) /* QUIT */
{ exit_graphics();
exit(0);
}
j = i;
if (i < p->int_count)
{ if (but==3)
*p->int_ref[i] = atoi(read_text_panel(p->int_label[i],xoff,ymax));
if (but==1) (*p->int_ref[i])++;
if (but==2) (*p->int_ref[i])--;
sprintf(text,"%-15s = %8d",p->int_label[i],*p->int_ref[i]);
i = n;
}
else i -= p->int_count;
if (i < p->float_count)
{ f = atof(read_text_panel(p->float_label[i],xoff,ymax));
*p->float_ref[i] = (double)f;
sprintf(text,"%-15s = %8.2f",p->float_label[i],f);
i = n;
}
else i -= p->float_count;
if (i < p->string_count)
{ strcpy(p->string_ref[i],read_text_panel(p->string_label[i],xoff,ymax));
sprintf(text,"%-15s = %8s",p->string_label[i],p->string_ref[i]);
i = n;
}
else i -= p->string_count;
if (i < p->choice_count)
{ /*
int c = read_panel(p->choice_label[i],p->choice_size[i],
p->choices[i],xoff,ymax);
*/
int c = 1 + (*(p->choice_ref[i])-p->choice_offset[i])/p->choice_step[i];
if (c >= p->choice_size[i]) c=0;
*(p->choice_ref[i]) = p->choice_offset[i] + c * p->choice_step[i];
sprintf(text,"%-15s = %8s",p->choice_label[i], p->choices[i][c]);
}
set_color(BG_COLOR);
box(xoff+1,y+2,xoff+19,y+18);
set_color(FG_COLOR);
put_text(xoff+30,20*(p->text_count+j+2)+yoff+4,text,1);
}
}
if (p->but_count!=0)
i = read_panel(p->header,p->but_count,p->buttons,xoff,ymax);
x_draw_set_mode(save_mode);
x_draw_set_line_width(save_lw);
set_color(save_col);
restore_screen();
return i;
}
#ifdef MAIN
void main()
{ double x,y;
double x1,y1;
double px[20], py[20];
char s[256];
int i;
char* p;
x_draw_init_window(0,0,0,0,"LEDA und der Schwan");
x_draw_init(0.0,100.0,0.0,0);
for(i= 0; i< 16; i++) x_draw_line(0.0,0.0,95.0,20.0*i,i);
while(x_read_mouse(0,0.0,0.0,&x,&y) != 3)
{ x_read_mouse(3,x,y,&x1,&y1);
x_draw_filled_circle(x,y,hypot(x1-x,y1-y),1);
// x_draw_arc(x,y,hypot(x1-x,y1-y),0.0,1.6,1);
}
x_draw_set_mode(1);
for(;;)
{ i = 0;
if (x_read_mouse(0,0.0,0.0,&px[0],&py[0])==3) break;
while (x_read_mouse(1,px[i],py[i],&(px[i+1]),&(py[i+1])) !=3)
{ x_draw_line(px[i],py[i],px[i+1],py[i+1],1);
i++;
}
x_draw_filled_polygon(i+1,px,py,1);
}
x_draw_set_mode(0);
for(;;)
{ i = 0;
if (x_read_mouse(0,0.0,0.0,&px[0],&py[0])==3) break;
while (x_read_mouse(1,px[i],py[i],&(px[i+1]),&(py[i+1])) !=3)
{ x_draw_line(px[i],py[i],px[i+1],py[i+1],1);
i++;
}
x_draw_filled_polygon(i+1,px,py,0);
}
x_draw_read_text_panel("string = ",0,0,0);
x_draw_end();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -