home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + _turbo.c
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
- /* TC graphic routines */
-
- #include <graphics.h>
- #include <dos.h>
- #include <conio.h>
-
- #include <math.h>
- #include <string.h>
- #include <stdio.h>
- #include <values.h>
-
- #define KEY_UP 72
- #define KEY_DO 80
- #define KEY_LE 75
- #define KEY_RI 77
-
-
- #define XPIX(coord) (int)(xorigin + (coord)*x_draw_scale)
- #define YPIX(coord) (int)(yorigin - (coord)*y_draw_scale)
-
- #define XREAL(pix) ((double)(pix-xorigin)/x_draw_scale)
- #define YREAL(pix) ((double)(yorigin-pix)/y_draw_scale)
-
-
- static char default_frame_label[128];
-
- static char frame_label[80];
-
- static char read_frame_format[] = "%8.2f %8.2f %s";
-
- typedef void (*PRD)();
- typedef void (*PMA)();
-
- static void x_draw_mouse_default_action(x,y)
- double x,y;
- { /* do nothing */}
-
- PRD x_draw_redraw = 0;
- PMA x_draw_mouse_action = x_draw_mouse_default_action;
-
- static int x_draw_have_mouse;
-
- static int xpix_mode_op;
-
- static int xdots,ydots, xorigin,yorigin; /* pixels */
-
- static int mouse_key,mouse_xpix, mouse_ypix;
- static int mouse_last_xpix, mouse_last_ypix;
- static int mouse_start_xpix, mouse_start_ypix; /* start for segments ... */
- static int mouse_read_kind;
-
-
- static double mouse_xreal,mouse_yreal;
- static double mouse_last_xreal,mouse_last_yreal;
- static double mouse_start_xreal,mouse_start_yreal;
-
- static double x_draw_aspect_ratio;
- static double y_draw_scale;
-
- /* external variables */
-
- int SCREEN_WIDTH = 740;
- int SCREEN_HEIGHT = 360;
-
- double x_draw_xmax,x_draw_xmin,x_draw_ymax,x_draw_ymin, x_draw_scale;
-
- int x_draw_grid_mode;
- int x_draw_depth;
-
- int x_draw_line_width, x_draw_node_width, x_draw_line_style, x_draw_color,
- x_draw_text_mode, x_draw_drawing_mode, x_draw_screen_flush;
-
-
-
- /* some forward declarations */
-
- void x_draw_circle();
- void x_draw_rectangle();
- void x_draw_clear();
- void x_draw_ctext();
- void x_draw_text();
- void x_draw_cursor();
-
-
- void x_draw_flush() { }
-
- void x_draw_set_redraw(f)
- PRD f;
- { x_draw_redraw = f;
- }
-
- void x_draw_set_frame_label(message)
- char* message;
- { strcpy(frame_label,message);
- }
-
- void x_draw_reset_frame_label()
- { x_draw_set_frame_label(default_frame_label);
- }
-
-
- void x_draw_mouse_segment_action(x,y)
- double x,y;
- { setcolor(WHITE);
- line(mouse_start_xpix,mouse_start_ypix,XPIX(x),YPIX(y));
- }
-
- void x_draw_mouse_rect_action(x,y)
- double x,y;
- {
- x_draw_rectangle(mouse_start_xreal,mouse_start_yreal,x,y,WHITE);
- }
-
-
- void x_draw_mouse_circle_action(x,y)
- double x,y;
- { double r = hypot(x - mouse_start_xreal, y - mouse_start_yreal);
- setcolor(WHITE);
- line(mouse_start_xpix,mouse_start_ypix-(int)(r*y_draw_scale),
- mouse_start_xpix,mouse_start_ypix+(int)(r*y_draw_scale));
- line(mouse_start_xpix+(int)(r*x_draw_scale),mouse_start_ypix,
- mouse_start_xpix-(int)(r*x_draw_scale),mouse_start_ypix);
- }
-
-
- void x_draw_set_font(fname)
- char* fname;
- { }
-
-
-
-
- static void x_draw_set_color(col)
- int col;
- { switch(col)
- { case 1 : col = WHITE;
- break;
- case 0 : col = BLACK;
- break;
- case 2 : col = LIGHTRED;
- break;
- case 3 : col = LIGHTGREEN;
- break;
- case 4 : col = LIGHTBLUE;
- break;
- case 5 : col = YELLOW;
- break;
- case 6 : col = LIGHTCYAN;
- break;
- case 7 : col = BROWN;
- break;
- }
- setcolor(col);
- setfillstyle(SOLID_FILL,col);
- }
-
- int x_draw_set_line_width(w)
- int w;
- { int save = x_draw_line_width;
- x_draw_line_width = w;
- setlinestyle(x_draw_line_style,0,w);
- return save;
- }
-
-
- int x_draw_set_line_style(s)
- int s;
- { int old = x_draw_line_style;
- x_draw_line_style = s;
- setlinestyle(s,0,x_draw_line_width);
- return old;
- }
-
-
- int x_draw_set_mode(m)
- int m;
- { int old=x_draw_drawing_mode;
- x_draw_drawing_mode=m;
- setwritemode(m);
- return old;
- }
-
-
- int x_draw_set_node_width(w)
- int w;
- { int save = x_draw_node_width;
- x_draw_node_width = w;
- return save;
- }
-
- int x_draw_set_text_mode(m)
- int m;
- { int save = x_draw_text_mode;
- x_draw_text_mode = m;
- return save;
- }
-
- static void draw_cursor(x,y)
- int x,y;
- { int save = getcolor();
- int dx = 8;
- int dy = 8*x_draw_aspect_ratio;
- setcolor(WHITE);
- setlinestyle(SOLID_LINE,0,THICK_WIDTH);
- line(x-dx,y,x+dx,y);
- line(x,y-dy,x,y+dy);
- setlinestyle(x_draw_line_style,0,x_draw_line_width);
- setcolor(save);
- }
-
-
- int x_read_mouse_action(action, xstart,ystart,x,y)
- PMA action;
- double xstart;
- double ystart;
- double *x;
- double *y;
- {
- int taste=0;
-
- union REGS regs;
-
- if (action==0)
- action = x_draw_mouse_default_action;
-
- setwritemode(XOR_PUT);
-
- mouse_start_xreal = xstart;
- mouse_start_yreal = ystart;
- mouse_start_xpix = XPIX(xstart);
- mouse_start_ypix = YPIX(ystart);
-
- if (x_draw_grid_mode) x_draw_cursor();
-
- action(mouse_last_xreal,mouse_last_yreal);
-
- draw_cursor(mouse_last_xpix, mouse_last_ypix);
-
-
- while (taste == 0)
- {
- if (x_draw_have_mouse)
- { regs.x.ax=03;
- int86(0x33,®s,®s);
- taste=regs.x.bx;
- mouse_xpix=regs.x.cx;
- mouse_ypix=regs.x.dx;
- }
- else
- { char c;
- c = getch();
- switch(c) {
- case KEY_LE: mouse_xpix -= 8; break;
- case KEY_RI: mouse_xpix += 8; break;
- case KEY_UP: mouse_ypix -= 8*x_draw_aspect_ratio; break;
- case KEY_DO: mouse_ypix += 8*x_draw_aspect_ratio; break;
- case 'j': mouse_ypix +=1; break;
- case 'k': mouse_ypix -=1; break;
- case 'l': mouse_xpix +=1; break;
- case 'h': mouse_xpix -=1; break;
- case '1': taste = 1; break;
- case '2': taste = 4; break;
- case '3': taste = 2; break;
- case 3 : closegraph(); exit(0); break; /* ctrl-C */
- case 13 : taste = 1; break; /* return */
- }
- }
-
- if (x_draw_grid_mode) x_draw_cursor();
-
- mouse_xreal = XREAL(mouse_xpix);
- mouse_yreal = YREAL(mouse_ypix);
-
- if (x_draw_grid_mode)
- { mouse_xreal = x_draw_grid_mode * (int)(mouse_xreal/x_draw_grid_mode + ((mouse_xreal > 0) ? 0.5 : -0.5));
-
- mouse_yreal = x_draw_grid_mode * (int)(mouse_yreal/x_draw_grid_mode + ((mouse_yreal > 0) ? 0.5 : -0.5));
-
- mouse_xpix = XPIX(mouse_xreal);
- mouse_ypix = YPIX(mouse_yreal);
- x_draw_cursor();
- }
-
- if (mouse_last_xpix != mouse_xpix || mouse_last_ypix != mouse_ypix)
- { action(mouse_last_xreal,mouse_last_yreal);
- action(mouse_xreal,mouse_yreal);
- draw_cursor(mouse_last_xpix,mouse_last_ypix);
- draw_cursor(mouse_xpix,mouse_ypix);
- }
- /*
- if (x_draw_mouse_action)
- { x_draw_mouse_action(mouse_last_xreal,mouse_last_yreal);
- x_draw_mouse_action(mouse_xreal,mouse_yreal);
- }
- */
-
- mouse_last_xpix = mouse_xpix;
- mouse_last_ypix = mouse_ypix;
-
- mouse_last_xreal = mouse_xreal;
- mouse_last_yreal = mouse_yreal;
-
- }
-
- if (x_draw_have_mouse)
- while (regs.x.bx != 0)
- { regs.x.ax=03;
- int86(0x33,®s,®s);
- }
-
- /* if (!x_draw_have_mouse) */
-
- draw_cursor(mouse_xpix,mouse_ypix);
- action(mouse_xreal,mouse_yreal);
-
- /*
- if (x_draw_mouse_action)
- x_draw_mouse_action(mouse_xreal,mouse_yreal);
- */
-
- if (x_draw_grid_mode) x_draw_cursor();
-
-
- *x = mouse_xreal;
- *y = mouse_yreal;
-
- setwritemode(COPY_PUT);
-
- switch (taste) {
- case 1: return 1;
- case 4: return 2;
- case 2: return 3;
- default: return taste;
- }
-
- }
-
-
- int x_read_mouse(kind, xstart,ystart,x,y)
- int kind; /* 0: point, 1: segment, 2:rectangle, 3: circle */
- double xstart;
- double ystart;
- double *x;
- double *y;
- {
- PMA f;
- int key;
-
- switch(kind) {
-
- case 0 : f = 0; /* x_draw_mouse_default_action; */
- break;
-
- case 1: f = x_draw_mouse_segment_action;
- break;
-
- case 2: f = x_draw_mouse_rect_action;
- break;
-
- case 3: f = x_draw_mouse_circle_action;
- break;
-
- default: f = x_draw_mouse_default_action;
- break;
-
- }
-
- key = x_read_mouse_action(f,xstart,ystart,x,y);
-
- return key;
-
- }
-
-
- void x_draw_init_window(w_width,w_height,w_xpos,w_ypos,frame_label)
- int w_width;
- int w_height;
- int w_xpos;
- int w_ypos;
- char* frame_label;
- {
- int i;
- union REGS regs;
- int fehler;
- int xasp, yasp;
-
-
- // ***** Initialisierung des Grafikfensters
-
- int gdriver=DETECT, gmode, errorcode;
- //initgraph(&gdriver,&gmode,"\\TC\\BGI\\");
-
- initgraph(&gdriver,&gmode,"\\BORLANDC\\BGI\\");
- errorcode=graphresult();
-
- if(errorcode != grOk)
- { printf(grapherrormsg(errorcode));
- exit(1);
- }
-
- // ***** Initialisierung des Mousetreibers
- regs.x.ax=0;
- int86(0x33,®s,®s);
- fehler=regs.x.ax;
- if (fehler != 0x0ffff)
- x_draw_have_mouse = 0;
- else
- x_draw_have_mouse = 1;
-
-
- strcpy(default_frame_label,frame_label);
-
- x_draw_depth = 1;
-
- x_draw_set_line_style(0);
- x_draw_set_line_width(1);
- x_draw_set_mode(0);
- x_draw_set_node_width(12);
- x_draw_set_text_mode(0);
-
- x_draw_color = WHITE;
-
- x_draw_xmin = 0;
- x_draw_ymin = 0;
- x_draw_xmax = 0;
- x_draw_ymax = 0;
- x_draw_scale = 1;
- y_draw_scale = 1;
-
- mouse_xpix = 0;
- mouse_ypix = 0;
- mouse_last_xpix = 0;
- mouse_last_ypix = 0;
-
- getaspectratio(&xasp,&yasp);
- x_draw_aspect_ratio = (float)xasp/(float)yasp;
-
- setfillstyle(SOLID_FILL,WHITE);
-
- if (! x_draw_have_mouse)
- x_draw_acknowledge("NO MOUSE ! (use cursor keys)");
- }
-
- void x_draw_init(x0,x1,y0,g_mode)
- double x0,x1,y0;
- int g_mode;
- {
- if (x0>=x1)
- {fprintf(stderr,"Illegal arguments in draw_init: x0 (%f) >= x1 (%f)\n",x0,x1);
- abort();
- }
-
- x_draw_grid_mode = g_mode;
-
- x_draw_reset_frame_label();
-
- xdots = getmaxx();
- ydots = getmaxy();
-
-
- x_draw_scale = ((double)xdots)/(x1-x0);
- y_draw_scale = x_draw_scale * x_draw_aspect_ratio;
-
- /* at least grid distance of 2 pixels */
- if ((x_draw_grid_mode) && (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;
- }
-
- 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 = getmaxx()/2;
- mouse_ypix = mouse_last_ypix = getmaxy()/2;
-
- mouse_xreal = XREAL(mouse_xpix);
- mouse_yreal = YREAL(mouse_ypix);
-
- x_draw_clear(0);
-
- if (x_draw_grid_mode) x_draw_cursor();
-
- if (x_draw_redraw) (*x_draw_redraw)();
-
- }
-
-
- void x_show_window()
- { }
-
- void x_draw_end() { closegraph(); }
-
- void x_draw_line(x1, y1, x2, y2, col)
- double x1,y1,x2,y2;
- int col;
- { x_draw_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);
- x_draw_set_color(col);
- setlinestyle(x_draw_line_style,0,1);
- line(X-2,Y-2,X+2,Y+2);
- line(X-2,Y+2,X+2,Y-2);
- setlinestyle(x_draw_line_style,0,x_draw_line_width);
- }
-
- void x_draw_arc(x0,y0,a,b,col)
- double x0,y0;
- int a,b,col;
- { x_draw_set_color(col);
- ellipse(XPIX(x0)-a,YPIX(y0)-b,0,360,2*a,2*b);
- }
-
- void x_draw_filled_arc(x0,y0,a,b,col)
- double x0,y0;
- int a,b,col;
- { x_draw_set_color(col);
- fillellipse(XPIX(x0)-a,YPIX(y0)-b,2*a,2*b);
- }
-
- void x_draw_node(x0,y0,col)
- double x0,y0;
- int col;
- { int save = x_draw_set_line_width(1);
- x_draw_set_color(col);
- circle(XPIX(x0),YPIX(y0),2*x_draw_node_width);
- x_draw_set_line_width(save);
- }
-
- void x_draw_filled_node(x0,y0,col)
- double x0,y0;
- int col;
- { x_draw_set_color(col);
- fillellipse(XPIX(x0),YPIX(y0),2*x_draw_node_width,
- 2*x_draw_node_width*x_draw_aspect_ratio);
- }
-
-
- 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);
- }
-
- void x_draw_ellipse(x0,y0,a,b,col)
- double x0,y0,a,b;
- int col;
- { int A = (int)(a*x_draw_scale);
- int B = (int)(b*y_draw_scale);
- x_draw_arc(x0,y0,A,B,col); }
-
- void x_draw_filled_ellipse(x0,y0,a,b,col)
- double x0,y0,a,b;
- int col;
- { int A = (int)(a*x_draw_scale);
- int B = (int)(b*y_draw_scale);
- x_draw_filled_arc(x0,y0,A,B,col); }
-
-
- void x_draw_circle(x0,y0,r,col)
- double x0,y0,r;
- int col;
- { int R = (int)(r*x_draw_scale);
- x_draw_set_color(col);
- circle(XPIX(x0),YPIX(y0),R);
- }
-
-
- void x_draw_filled_circle(x0,y0,r,col)
- double x0,y0,r;
- int col;
- { int A = (int)(r*x_draw_scale);
- int B = (int)(r*y_draw_scale);
- x_draw_set_color(col);
- fillellipse(XPIX(x0),YPIX(y0),A,B);
- }
-
-
- int x_draw_xpix(x)
- double x;
- { return XPIX(x); }
-
- int x_draw_ypix(x)
- double x;
- { return YPIX(x); }
-
- void x_draw_pix(x,y,col)
- double x,y;
- int col;
- {
- putpixel(XPIX(x),YPIX(y),col);
- }
-
-
- 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_filled_polygon(n,xcoord,ycoord,col)
- int col, n;
- double *xcoord, *ycoord;
- {
- int* points;
- int i;
-
- points = (int *) malloc(2*n*sizeof(int));
-
- for (i=0; i<n; i++)
- { points[2*i] = XPIX(xcoord[i]);
- points[2*i+1] = YPIX(ycoord[i]);
- }
-
- x_draw_set_color(col);
-
- fillpoly(n,points);
-
- free((char*)points);
-
- }
-
- void x_draw_polygon(n,xcoord,ycoord,col)
- int col, n;
- double *xcoord, *ycoord;
- {
- int* points;
- int i;
-
- points = (int *) malloc(2*(n+1)*sizeof(int));
-
- for (i=0; i<n; i++)
- { points[2*i] = XPIX(xcoord[i]);
- points[2*i+1] = YPIX(ycoord[i]);
- }
-
- points[2*n] = points[0];
- points[2*n+1] = points[1];
-
- x_draw_set_color(col);
-
- drawpoly(n+1,points);
-
- free((char*)points);
-
- }
-
- void x_draw_rectangle(x1,y1,x2,y2,col)
- double x1,y1,x2,y2;
- int col;
- {
- x_draw_line(x1,y1,x1,y2,col);
- x_draw_line(x1,y2,x2,y2,col);
- x_draw_line(x2,y2,x2,y1,col);
- x_draw_line(x2,y1,x1,y1,col);
-
- }
-
-
- void x_draw_filled_rectangle(x1,y1,x2,y2,col)
- double x1,y1,x2,y2;
- int col;
- { double xcoord[4], ycoord[4];
-
- xcoord[0] = x1;
- ycoord[0] = y1;
- xcoord[1] = x1;
- ycoord[1] = y2;
- xcoord[2] = x2;
- ycoord[2] = y2;
- xcoord[3] = x2;
- ycoord[3] = y1;
-
- x_draw_filled_polygon(4,xcoord,ycoord,col);
-
- }
-
-
- void x_draw_copy_rect(x1,y1,x2,y2,x,y)
- double x1,y1,x2,y2,x,y;
- { int X1 = XPIX(x1);
- int Y1 = XPIX(y1);
- int X2 = XPIX(x2);
- int Y2 = XPIX(y2);
- int p[16000];
- if (X1 > X2 || Y1 > Y2) return;
- if ((X2-X1+1)*(Y2-Y1+1)/8 > 16000) return;
- getimage(X1,Y1,X2,Y2,p);
- putimage(XPIX(x),YPIX(y),p,COPY_PUT);
- }
-
-
- /*
- void x_draw_move_rect(x1,y1,x2,y2,x,y)
- double x1,y1,x2,y2,x,y;
- {}
- */
-
-
-
- void x_draw_clear(col)
- int col;
- { clearviewport();
- setcolor(WHITE);
- outtextxy(30,1,frame_label);
- }
-
-
- /* TEXT */
-
- static void x_draw_clear_text(x,y,s,center)
- int x,y;
- char * s;
- int center;
- { int width = textwidth(s);
- int height = textheight(s);
- int frame[10];
- if (center != 0)
- { frame[0] = x-width/2;
- frame[1] = y-height/2;
- }
- else
- { frame[0]=x;
- frame[1]=y;
- }
- frame[2]=frame[0]+width;
- frame[3]=frame[1];
- frame[4]=frame[0]+width;
- frame[5]=frame[1]+height;
- frame[6]=frame[0];
- frame[7]=frame[1]+height;
- frame[8]=frame[0];
- frame[9]=frame[1];
-
- setcolor(BLACK);
- setfillstyle(SOLID_FILL,BLACK);
- fillpoly(5,frame);
- }
-
-
- void x_draw_message(line,s,col)
- int line;
- char * s;
- int col;
- { int x = 5*textwidth("H");
- int y = (int)(1.25*textheight("H")*(line+1));
- settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
- settextjustify(LEFT_TEXT,TOP_TEXT);
- setcolor(WHITE);
- outtextxy(x,y,s);
- }
-
- void x_draw_ctext(x,y,s,col)
- double x,y;
- char * s;
- int col;
- { if (x_draw_text_mode != 0) x_draw_clear_text(x,y,s,1);
- settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
- settextjustify(CENTER_TEXT,CENTER_TEXT);
- x_draw_set_color(col);
- outtextxy(x,y,s);
- }
-
- void x_draw_text(x,y,s,col)
- double x,y;
- char * s;
- int col;
- { if (x_draw_text_mode != 0) x_draw_clear_text(x,y,s,0);
- settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
- settextjustify(LEFT_TEXT,TOP_TEXT);
- x_draw_set_color(col);
- outtextxy(XPIX(x),YPIX(y),s);
- }
-
- 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_cursor()
- {
- int X,Y;
-
- X = XPIX(mouse_xreal);
- Y = YPIX(mouse_yreal);
-
- line(X,Y,X+10,Y);
- line(X,Y,X-10,Y);
- line(X,Y,X,Y+10);
- line(X,Y,X,Y-10);
-
- }
-
-
-
- int x_draw_confirm(header)
- char *header;
- { /* ask for yes or no */
- 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 = getmaxx()/2;
- mouse_last_ypix = mouse_ypix = getmaxy()/2 + 10;
-
- return x_draw_read_panel(header,1,s,0);
- }
-
- int x_draw_screen_width() { return(getmaxx()); }
-
-
- int x_draw_screen_height() { return(getmaxx()); }
-
- 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;
- setcolor(col);
- outtextxy(x,y,out);
- }
-
- char* x_draw_read_text_panel(message,menu_label,n,items)
- char *message;
- char *menu_label;
- int n;
- char **items;
- { union REGS regs;
-
- int i;
- int tw,mw;
- int x1,x2,y1,y2;
- int p[5000];
- char c;
-
- int cw = textwidth("H");
-
- int loop=0;
- char* result = (char*)malloc(32);
- int maxx=getmaxx();
- int maxy=getmaxy();
- int save_color=getcolor();
- int poly[10];
-
- n = 0;
- menu_label = "";
- items = 0;
-
- if (strlen(message) == 0) message = "STRING INPUT";
- if (strlen(message) > 31) message[31] = 0;
-
- mw = textwidth(message);
- tw = 24*cw;
-
- setcolor(BLACK);
-
- settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
- settextjustify(LEFT_TEXT,TOP_TEXT);
- setwritemode(COPY_PUT);
-
- x1 = (maxx-tw-mw-30)/2;
- x2 = x1+tw+mw+30;
- y1 = maxy/2-15;
- y2 = maxy/2+15;
-
- getimage(x1,y1,x2,y2,p);
- poly[0]=x1; poly[1]=y1;
- poly[2]=x2; poly[3]=y1;
- poly[4]=x2; poly[5]=y2;
- poly[6]=x1; poly[7]=y2;
- poly[8]=x1; poly[9]=y1;
- setfillstyle(SOLID_FILL,LIGHTBLUE);
- fillpoly(5,poly);
- outtextxy(x1+10,y1+12,message);
-
- line(x1+10,y1+20,x2-10,y1+20);
-
- x2 = x1 + mw + 20;
- y2 = y1+12;
-
-
- x_draw_putch(x2,y2,'|',BLACK);
-
- c=getch();
-
- while(c != 13)
- { int x = x2+loop*cw;
- if (loop < 23 && isprint(c))
- { result[loop]=c;
- x_draw_putch(x,y2,'|',LIGHTBLUE);
- x_draw_putch(x,y2,c,BLACK);
- loop++;
- x_draw_putch(x+cw,y2,'|',BLACK);
- }
- if(c==8 && loop>0)
- { loop--;
- x_draw_putch(x,y2,'|',LIGHTBLUE);
- x_draw_putch(x-cw,y2,result[loop],LIGHTBLUE);
- x_draw_putch(x-cw,y2,'|',BLACK);
- }
- c=getch();
- }
-
- result[loop]='\0';
-
- putimage(x1,y1,p,COPY_PUT);
-
- setcolor(save_color);
-
- return result;
- }
-
- int x_draw_read_panel(message,n,labels,vertical)
- char *message;
- int n;
- char **labels;
- int vertical;
- {
- union REGS regs;
- unsigned int size;
- int answer= -1;
- int save_color;
- int i;
- int panel_width;
- int frame[10],but[10];
- int buffer[6000];
-
- int L[16];
- int R[16];
-
- int panel_height = 54;
- int mes_y = 10;
- int y0 = 30;
- int xskip = 30;
- int xspace = 5;
- int yspace = 3;
- int panel_y = (getmaxy()-panel_height)/2;
- int panel_x;
- int mes_x;
- int mes_width = textwidth(message);
-
- int y1 = y0 + textheight("H") + 2*yspace;
-
- if (vertical !=0 ) vertical = 0;
-
- panel_width = xskip;
-
- for(i=0;i<n;i++)
- { L[i] = panel_width;
- panel_width += 2*xspace+textwidth(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 = (getmaxx()-panel_width)/2;
-
- frame[0]=panel_x;
- frame[1]=panel_y;
- frame[2]=panel_x+panel_width;
- frame[3]=panel_y;
- frame[4]=panel_x+panel_width;
- frame[5]=panel_y+panel_height;
- frame[6]=panel_x;
- frame[7]=panel_y+panel_height;
- frame[8]=panel_x;
- frame[9]=panel_y;
-
- /* save picture */
-
- getimage(frame[0],frame[1],frame[4],frame[5],buffer);
-
-
- settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
- settextjustify(LEFT_TEXT,TOP_TEXT);
- setwritemode(COPY_PUT);
- setlinestyle(SOLID_LINE,0,2);
-
- save_color = getcolor();
- setcolor(LIGHTBLUE);
- setfillstyle(SOLID_FILL,LIGHTBLUE);
-
- fillpoly(5,frame);
-
- setcolor(BLACK);
- for (i=0;i<n;i++)
- { rectangle(panel_x+L[i],panel_y+y0,panel_x+R[i],panel_y+y1);
- outtextxy(panel_x+L[i]+xspace,panel_y+y0+yspace,labels[i]);
- }
-
- outtextxy(panel_x+mes_x,panel_y+mes_y,message);
-
- setcolor(save_color);
-
- 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 */
-
- but[0] = panel_x+L[answer];
- but[1] = panel_y+y0;
- but[2] = panel_x+R[answer];
- but[3] = panel_y+y0;
- but[4] = panel_x+R[answer];
- but[5] = panel_y+y1;
- but[6] = panel_x+L[answer];
- but[7] = panel_y+y1;
- but[8] = panel_x+L[answer];
- but[9] = panel_y+y0;
-
- setfillstyle(SOLID_FILL,BLACK);
- fillpoly(5,but);
- outtextxy(panel_x+L[answer]+xspace,panel_y+y0+yspace,labels[answer]);
- setfillstyle(SOLID_FILL,LIGHTBLUE);
- delay(200);
-
- putimage(frame[0],frame[1],buffer,COPY_PUT);
-
- return answer;
- }
-
- void x_draw_message_panel(argc,argv)
- int argc;
- char** argv;
- { }
-
- void x_draw_notice()
- { }
-