📄 _msdos.c
字号:
/* TEXT */
void x_draw_del_messages()
{ int x,y;
int save_mode;
int i;
set_color(FG_COLOR);
save_mode = x_draw_set_mode(1);
while (mesg_count > 0)
{ x = 4*text_width("H");
y = (int)(1.25*text_height("H")*mesg_count);
put_text(x,y,mesg_list[mesg_count-1],0);
free(mesg_list[mesg_count-1]);
mesg_count--;
}
x_draw_set_mode(save_mode);
}
void x_draw_message(s)
char * s;
{ int x,y;
int save_mode;
x = 4*text_width("H");
y = (int)(1.25*text_height("H")*(mesg_count+1));
set_color(FG_COLOR);
save_mode = x_draw_set_mode(1);
mesg_list[mesg_count] = (char*)malloc(strlen(s)+1);
strcpy(mesg_list[mesg_count],s);
put_text(x,y,s,0);
mesg_count++;
x_draw_set_mode(save_mode);
}
void x_draw_ctext(x,y,s,col)
double x,y;
char * s;
int col;
{ int X = XPIX(x) - text_width(s)/2 + 1;
int Y = YPIX(y) - text_height(s)/2 + 1;
set_color(col);
put_text(X,Y,s,x_draw_text_mode);
}
void x_draw_text(x,y,s,col)
double x,y;
char * s;
int col;
{ set_color(col);
put_text(XPIX(x),YPIX(y),s,x_draw_text_mode);
}
void x_draw_int(x0,y0,i,col)
double x0,y0;
int i,col;
{ char buf[16];
sprintf(buf,"%d",i);
x_draw_ctext(x0,y0,buf,col);
}
void x_draw_clear(col)
int col;
{ int x,y;
int save_mode;
x_draw_del_messages();
clear_screen();
save_mode = x_draw_set_mode(1);
put_text(20,1,frame_label,0);
x_draw_set_mode(save_mode);
set_color(FG_COLOR);
if (x_draw_grid_mode) /* draw grid */
{ for(x = (int)(x_draw_xmin/x_draw_grid_mode)*x_draw_grid_mode; x<=x_draw_xmax; x+=x_draw_grid_mode)
for(y = (int)(x_draw_ymin/x_draw_grid_mode)*x_draw_grid_mode; y<=x_draw_ymax; y+=x_draw_grid_mode)
{ if (x*y == 0) fill_circle(XPIX(x),YPIX(y),1);
else pixel(XPIX(x),YPIX(y));
}
}
}
void x_draw_init(x0,x1,y0,g_mode)
double x0,x1,y0;
int g_mode;
{
if (x0>=x1)
{ exit_graphics();
printf("Illegal arguments in draw_init: x0 (%f) >= x1 (%f)\n",x0,x1);
abort();
}
mesg_count = 0;
x_draw_grid_mode = g_mode;
x_draw_reset_frame_label();
xdots = max_xcoord();
ydots = max_ycoord();
x_draw_scale = ((double)xdots)/(x1-x0);
if (x_draw_grid_mode*x_draw_scale < 2) x_draw_grid_mode=0;
if (x_draw_grid_mode)
{ if (x_draw_scale < 1) x_draw_scale = 1;
else x_draw_scale = (int)x_draw_scale;
}
y_draw_scale = x_draw_scale * x_draw_aspect_ratio;
x_draw_xmin = x0;
x_draw_ymin = y0;
x_draw_xmax = x0+xdots/x_draw_scale;
x_draw_ymax = y0+ydots/y_draw_scale;
xorigin = -x0*x_draw_scale;
yorigin = ydots+y0*y_draw_scale;
mouse_xpix = mouse_last_xpix = max_xcoord()/2;
mouse_ypix = mouse_last_ypix = max_ycoord()/2;
mouse_xreal = XREAL(mouse_xpix);
mouse_yreal = YREAL(mouse_ypix);
x_draw_clear(BG_COLOR);
if (x_draw_redraw) (*x_draw_redraw)();
}
void x_show_window() {}
void x_draw_end() { exit_graphics(); }
void x_draw_pix(x,y,col)
double x,y;
int col;
{ set_color(col);
pixel(XPIX(x),YPIX(y));
}
void x_draw_line(x1, y1, x2, y2, col)
double x1,y1,x2,y2;
int col;
{ set_color(col);
line(XPIX(x1), YPIX(y1), XPIX(x2), YPIX(y2));
}
void x_draw_point(x,y,col)
double x,y;
int col;
{ int X = XPIX(x);
int Y = YPIX(y);
set_color(col);
pixel(X-2,Y-2);
pixel(X-2,Y+2);
pixel(X-1,Y-1);
pixel(X-1,Y+1);
pixel(X,Y);
pixel(X+1,Y-1);
pixel(X+1,Y+1);
pixel(X+2,Y-2);
pixel(X+2,Y+2);
}
void x_draw_node(x0,y0,col)
double x0,y0;
int col;
{ int save = x_draw_set_line_width(1);
set_color(col);
circle(XPIX(x0),YPIX(y0),x_draw_node_width);
x_draw_set_line_width(save);
}
void x_draw_filled_node(x0,y0,col)
double x0,y0;
int col;
{ set_color(col);
fill_circle(XPIX(x0),YPIX(y0),x_draw_node_width);
}
void x_draw_text_node(x0,y0,s,col)
double x0,y0;
int col;
char* s;
{
int save = x_draw_text_mode;
x_draw_text_mode = 0; /* transparent */
if (x_draw_depth==1 || col == 1)
x_draw_node(x0,y0,1);
else
x_draw_filled_node(x0,y0,col);
x_draw_ctext(x0,y0,s,1);
x_draw_text_mode = save;
}
void x_draw_int_node(x0,y0,i,col)
double x0,y0;
int i,col;
{ char buf[16];
sprintf(buf,"%d",i);
x_draw_text_node(x0,y0,buf,col);
}
x_draw_ellipse()
{ fprintf(stderr,"sorry, draw ellipse not implemented\n"); }
x_draw_filled_ellipse()
{ fprintf(stderr,"sorry, draw ellipse not implemented\n"); }
void x_draw_circle(x0,y0,r,col)
double x0,y0,r;
int col;
{ int R = (int)(r*x_draw_scale);
int i;
set_color(col);
circle(XPIX(x0),YPIX(y0),R);
for (i=1;i<=x_draw_line_width/2;i++)
{ circle(XPIX(x0),YPIX(y0),R-i);
circle(XPIX(x0),YPIX(y0),R+i);
}
}
x_draw_arc()
{ fprintf(stderr,"sorry, draw arc not implemented\n"); }
x_draw_filled_arc()
{ fprintf(stderr,"sorry, draw arc not implemented\n"); }
/*
void x_draw_arc(x0,y0,r,a,b,col)
double x0,y0,r,a,b;
int col;
{ int R = (int)(r*x_draw_scale);
int i;
set_color(col);
if (a<0) a += 2*M_PI;
if (b<0) b += 2*M_PI;
if (a<=b)
{ arc(XPIX(x0),YPIX(y0),R,a,b);
for (i=1;i<=x_draw_line_width/2;i++)
{ arc(XPIX(x0),YPIX(y0),R-i,a,b);
arc(XPIX(x0),YPIX(y0),R+i,a,b);
}
}
else
{ arc(XPIX(x0),YPIX(y0),R,0,b);
arc(XPIX(x0),YPIX(y0),R,a,2*M_PI);
for (i=1;i<=x_draw_line_width/2;i++)
{ arc(XPIX(x0),YPIX(y0),R-i,0,b);
arc(XPIX(x0),YPIX(y0),R+i,0,b);
arc(XPIX(x0),YPIX(y0),R-i,a,2*M_PI);
arc(XPIX(x0),YPIX(y0),R+i,a,2*M_PI);
}
}
}
*/
void x_draw_filled_circle(x0,y0,r,col)
double x0,y0,r;
int col;
{ int R = (int)(r*x_draw_scale);
set_color(col);
fill_circle(XPIX(x0),YPIX(y0),R);
}
int x_draw_xpix(x)
double x;
{ return XPIX(x); }
int x_draw_ypix(x)
double x;
{ return YPIX(x); }
void x_draw_plot_xy(x0,x1,f,col)
double x0,x1;
double (*f)();
int col;
{ }
void x_draw_plot_yx(y0,y1,f,col)
double y0,y1;
double (*f)();
int col;
{ }
void x_draw_polygon(n,xcoord,ycoord,col)
int col, n;
double *xcoord, *ycoord;
{ int i;
set_color(col);
for (i=0; i<n-1; i++)
line(XPIX(xcoord[i]),YPIX(ycoord[i]),XPIX(xcoord[i+1]),YPIX(ycoord[i+1]));
line(XPIX(xcoord[0]),YPIX(ycoord[0]),XPIX(xcoord[n-1]),YPIX(ycoord[n-1]));
}
void x_draw_filled_polygon(n,xcoord,ycoord,col)
int col, n;
double *xcoord, *ycoord;
{ int* X = (int*)malloc(n*sizeof(int));
int* Y = (int*)malloc(n*sizeof(int));
int i;
for(i=0;i<n;i++)
{ X[i] = XPIX(xcoord[i]);
Y[i] = YPIX(ycoord[i]);
}
set_color(col);
fill_polygon(n,X,Y);
free(X);
free(Y);
}
void x_draw_rectangle(x1,y1,x2,y2,col)
double x1,y1,x2,y2;
int col;
{ set_color(col);
rectangle(XPIX(x1),YPIX(y1),XPIX(x2),YPIX(y2));
}
void x_draw_filled_rectangle(x1,y1,x2,y2,col)
double x1,y1,x2,y2;
int col;
{ set_color(col);
box(XPIX(x1),YPIX(y1),XPIX(x2),YPIX(y2));
}
void x_draw_fill(x,y,col)
double x,y;
int col;
{ set_color(col);
flood_fill(XPIX(x),YPIX(y));
}
void x_draw_copy_rect() { }
int x_draw_screen_width() { return(max_xcoord()); }
int x_draw_screen_height() { return(max_xcoord()); }
static void x_draw_putch(x,y,ch,col)
int x;
int y;
char ch;
int col;
{ char out[2];
out[0] = ch;
out[1] = 0;
set_color(col);
put_text(x,y,out,0);
}
static char* read_text_panel(message,x1,y1)
char *message;
int x1,y1;
{
int i;
int tw,mw;
int x2,y2;
unsigned char* p;
char c;
int cw = text_width("H");
int loop=0;
char* result = (char*)malloc(32);
int maxx=max_xcoord();
int maxy=max_ycoord();
int save_color=get_color();
int save_mode = x_draw_set_mode(0);
if (strlen(message) == 0) message = "STRING INPUT";
if (strlen(message) > 31) message[31] = 0;
mw = text_width(message);
tw = 24*cw;
if (x1<0)
{ x1 = (maxx-tw-mw-30)/2;
y1 = maxy/2-15;
}
x2 = x1+tw+mw+30;
y2 = y1 + 30;
p = save_box(x1,y1,x2,y2);
set_color(PANEL_BG_COLOR);
box(x1,y1,x2,y2);
set_color(PANEL_FG_COLOR);
rectangle(x1+1,y1+1,x2-1,y2-1);
put_text(x1+10,y1+8,message,0);
x2 = x1 + mw + 20;
y2 = y1+8;
x_draw_putch(x2,y2,'|',PANEL_FG_COLOR);
c=getch();
while(c != 13)
{ int x = x2+loop*cw;
if (loop < 23 && isprint(c))
{ result[loop]=c;
x_draw_putch(x,y2,'|',PANEL_BG_COLOR);
x_draw_putch(x,y2,c,PANEL_FG_COLOR);
x_draw_putch(x+cw,y2,'|',PANEL_FG_COLOR);
loop++;
}
if(c==8 && loop>0)
{ loop--;
x_draw_putch(x,y2,'|',PANEL_BG_COLOR);
x_draw_putch(x-cw,y2,result[loop],PANEL_BG_COLOR);
x_draw_putch(x-cw,y2,'|',PANEL_FG_COLOR);
}
c=getch();
}
result[loop]='\0';
restore_box(p);
free((char*)p);
set_color(save_color);
x_draw_set_mode(save_mode);
return result;
}
char* x_draw_read_text_panel(message,menu_label,n,items)
char *message;
char *menu_label;
int n;
char **items;
{
return read_text_panel(message,-1,-1);
}
static int read_panel(message,n,labels,xpos,ypos)
char *message;
int n;
char **labels;
int xpos, ypos;
{
unsigned int size;
int answer= -1;
int save_color;
int save_mode;
int i;
int panel_width;
unsigned char* buffer;
int L[16];
int R[16];
int panel_height = 58;
int mes_y = 7;
int y0 = 30;
int xskip = 30;
int xspace = 5;
int yspace = 3;
int panel_y;
int panel_y1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -