home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / d_vt100.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  10KB  |  457 lines

  1. /*--------------------------------------------------------------*/
  2. /*    VT100 Driver 1.0 , for GLE V3.0        */
  3. /*---------------------------------------------------------------------------*/
  4. #include "all.h"
  5. #include <math.h>
  6. #include "core.h"
  7. #include "mygraph.h"
  8. #include "mydev.h"
  9. #define GS 29
  10. #define FF 12
  11. #define MAXX (130)
  12. #define MAXY (23)
  13. int screenbit[MAXX+4][MAXY+4];
  14. int ingraphmode;
  15. extern struct gmodel g;
  16. /*---------------------------------------------------------------------------*/
  17. #define pi 3.141592653
  18. #define true (!false)
  19. #define BLACKANDWHITE 1
  20. #define ESC 27
  21. #define false 0
  22. #define dbg if ((gle_debug & 64)>0)
  23. #define stop if ((gle_debug & 128)>0) return
  24. extern int gle_debug;
  25. int incap=true;
  26. int getch(void);
  27. /*---------------------------------------------------------------------------*/
  28. /* The global variables for the PC screen driver */
  29. /*-----------------------------------------------*/
  30.  
  31. int i,l,j,ix,iy;
  32. double f;
  33. double devxcm=23,devycm=15.5;
  34. FILE *hpfile;
  35.  
  36. #define gerr() i = graphresult(); if (i!=0) printf("Graph error: %s \n",grapherrormsg(i));
  37. #define sx(v) ( ((v) * d_xscale))
  38. #define sy(v) ( (((v) * d_yscale)))
  39. #define rx(v) ( ((v) * d_xscale))
  40. #define ry(v) ( (((v) * d_yscale)))
  41.  
  42. double d_scale, d_xscale, d_yscale;
  43. int d_graphmode;
  44. int d_fillstyle=1,d_fillcolor;
  45. int d_lstyle,d_lwidth;
  46. char outstr[400];
  47.  
  48. d_devcmd(char *s)
  49. {}
  50. /*---------------------------------------------------------------------------*/
  51. d_dfont(char *c)
  52. {
  53.     /* only used for the DFONT driver which builds fonts */
  54. }
  55. /*---------------------------------------------------------------------------*/
  56. static char lastline[80];
  57. d_message(char *s)
  58. {
  59.     static int single_step;
  60.     int oldcolor,oldx,oldy;
  61.     w_message(s);
  62. }
  63. /*---------------------------------------------------------------------------*/
  64. d_source(char *s)
  65. {
  66.     s=s;
  67. }
  68. /*---------------------------------------------------------------------------*/
  69. d_get_type(char *t)
  70. {
  71.     strcpy(t,"INTERACTIVE, VT100, VAX");
  72. }
  73. /*---------------------------------------------------------------------------*/
  74. d_set_path(int onoff)
  75. {}
  76. /*---------------------------------------------------------------------------*/
  77. d_newpath()
  78. {
  79. }
  80. /*---------------------------------------------------------------------------*/
  81. extern char output_file[];
  82. d_open(double width, double height)
  83. {
  84.     /* Get largest rectangle we can fit on the screen */
  85.     d_scale = devxcm / width;
  86.     f = devycm / height;
  87.     if (f<d_scale) d_scale = f;
  88.     d_xscale = d_scale * MAXX / devxcm; /* Device Scale X, Device Scale y */
  89.     d_yscale = d_scale * MAXY / devycm;
  90. }
  91. /*---------------------------------------------------------------------------*/
  92. d_tidyup()
  93. {
  94. }
  95. d_close()
  96. {
  97.     int x,y;
  98.     char oneline[200];
  99.     int lastinv=false;
  100.     g_flush();
  101.  
  102.     scr_refresh();
  103.     printf("%c[?3h",27);
  104.     for (y = MAXY-1;y>= 0;y--) {
  105.       oneline[0] = 0;
  106.       for (x=0;x<=MAXX;x++) {
  107.         if (screenbit[x][y]==0) strcat(oneline," ");
  108.         else strcat(oneline,"#");
  109. /*        if (screenbit[x][y]==0) {
  110.             if (lastinv) strcat(oneline,"\x1b[0m ");
  111.             else strcat(oneline," ");
  112.             lastinv = false;
  113.         } else {
  114.             if (!lastinv) strcat(oneline,"\x1b[7m ");
  115.             else strcat(oneline," ");
  116.             lastinv = true;
  117.         }*/
  118.       }
  119.       printf("%s\n",oneline);
  120.     }
  121.     printf("\x1b[7m");
  122.     text_inkey();
  123.     printf("\x1b[0m");
  124.     printf("%c[?3l",27);
  125. }
  126. /*---------------------------------------------------------------------------*/
  127. d_set_line_cap(int i)
  128. {
  129.     i++;
  130. }
  131. /*---------------------------------------------------------------------------*/
  132. d_set_line_join(int i)
  133. {
  134.     i++;
  135. }
  136. /*---------------------------------------------------------------------------*/
  137. d_set_line_miterlimit(double d)
  138. {
  139.     i++;
  140. }
  141. /*---------------------------------------------------------------------------*/
  142. d_set_line_width(double w)
  143. {
  144. }
  145. /*---------------------------------------------------------------------------*/
  146. d_set_line_styled(double dd)
  147. {}
  148. d_set_line_style(char *s)
  149. {
  150.     d_lstyle = 2;
  151.     if (strcmp(s,"")==0) d_lstyle = 1;
  152.     if (strcmp(s,"1")==0) d_lstyle = 1;
  153. }
  154. /*---------------------------------------------------------------------------*/
  155. d_fill()
  156. {
  157. }
  158. /*---------------------------------------------------------------------------*/
  159. d_fill_ary(int nwk,double (*wkx)[],double (*wky)[])
  160. {
  161.     int i;
  162. /*    fprintf(psfile,"%g %g moveto \n",(*wkx)[0],(*wky)[0]);
  163.     for (i=1;i<nwk;i++)
  164.         fprintf(psfile,"%g %g l \n",(*wkx)[i],(*wky)[i]);
  165. */
  166. }
  167. d_line_ary(int nwk,double (*wkx)[],double (*wky)[])
  168. {
  169.     int i;
  170. /*
  171.     g_dev( (*wkx)[0], (*wky)[0], &ix, &iy);
  172.     moveto(ix,iy);
  173.     for (i=1;i<nwk;i++) {
  174.         g_dev( (*wkx)[i], (*wky)[i], &ix, &iy);
  175.         lineto(ix,iy);
  176.     }
  177. */
  178. }
  179. /*---------------------------------------------------------------------------*/
  180. d_stroke()
  181. {
  182. }
  183. /*---------------------------------------------------------------------------*/
  184. d_clip()
  185. {
  186. }
  187. /*---------------------------------------------------------------------------*/
  188. d_set_matrix(double newmat[3][3])
  189. {
  190. }
  191. /*---------------------------------------------------------------------------*/
  192. d_move(double zx,double zy)
  193. {
  194. }
  195. /*---------------------------------------------------------------------------*/
  196. d_reverse()     /* reverse the order of stuff in the current path */
  197. {
  198. }
  199. /*---------------------------------------------------------------------------*/
  200. d_closepath()
  201. {
  202.     g_line(g.closex,g.closey);
  203. }
  204. /*---------------------------------------------------------------------------*/
  205. int vt100line(int  x1, int  y1, int  x2, int  y2);
  206. int hpglxy(double xx, double yy);
  207. d_line(double zx,double zy)
  208. {
  209.     static double ix,iy,ux,uy;
  210.     g_dev(g.curx,g.cury,&ux,&uy);
  211.     g_dev(zx,zy,&ix,&iy);
  212.     vt100line(sx(ux),sy(uy),sx(ix),sy(iy));
  213. }
  214. /*---------------------------------------------------------------------------*/
  215. /* int screenbit[MAXX+1][MAXY+1]; */
  216. xxvt100line(int  x1, int  y1, int  x2, int  y2)
  217. {
  218. #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  219.     int dx,dy,dxabs,dyabs,i,px,py,sdx,sdy,x,y;
  220.     if (x1<0) x1 = 0;
  221.     if (x1>MAXX) x1 = MAXX;
  222.     if (y1<0) y1 = 0;
  223.     if (y1>MAXY) y1 = MAXY;
  224.     if (x2<0) x2 = 0;
  225.     if (x2>MAXX) x2 = MAXX;
  226.     if (y2<0) y2 = 0;
  227.     if (y2>MAXY) y2 = MAXY;
  228.  
  229.     /* line algorithym begins */
  230.  
  231.     dx = x2 - x1;
  232.     dy = y2 - y1;
  233.     sdx = sign(dx);
  234.     sdy = sign(dy);
  235.     dxabs = abs(dx);
  236.     dyabs = abs(dy);
  237.     x = 0;
  238.     y = 0;
  239.     px = x1;
  240.     py = y1;
  241.     if (dxabs >= dyabs) {
  242.         for (i=0; i<=dxabs; i++) {
  243.             y += dyabs;
  244.             if (y>=dxabs) {
  245.                 y -= dxabs;
  246.                 py += sdy;
  247.             }
  248.             screenbit[px][py] = '#';
  249.             px += sdx;
  250.         }
  251.     } else {
  252.         for (i=0; i<=dyabs; i++) {
  253.             x += dxabs;
  254.             if (x>=dyabs) {
  255.                 x -= dyabs;
  256.                 px += sdx;
  257.             }
  258.             screenbit[px][py] = '#';
  259.             py += sdy;
  260.         }
  261.     }
  262. }
  263.  
  264. unsigned long int PATTERN = 0xFFFFFFFF;
  265. int LINEWIDTH=1;
  266.  
  267. vt100line(int  x1, int  y1, int  x2, int  y2)
  268. {
  269. #define sign(x) ((x) > 0 ? 1:  ((x) == 0 ? 0:  (-1)))
  270.     int dx, dy, dxabs, dyabs, i, j, px, py, sdx, sdy, x, y;
  271.     unsigned long int mask=0x80000000;
  272.  
  273.     if (x1<0) x1 = 0;
  274.     if (x1>MAXX) x1 = MAXX;
  275.     if (y1<0) y1 = 0;
  276.     if (y1>MAXY) y1 = MAXY;
  277.     if (x2<0) x2 = 0;
  278.     if (x2>MAXX) x2 = MAXX;
  279.     if (y2<0) y2 = 0;
  280.     if (y2>MAXY) y2 = MAXY;
  281.  
  282.     dx = x2 - x1;
  283.     dy = y2 - y1;
  284.     sdx = sign(dx);
  285.     sdy = sign(dy);
  286.     dxabs = abs(dx);
  287.     dyabs = abs(dy);
  288.     x = 0;
  289.     y = 0;
  290.     px = x1;
  291.     py = y1;
  292.  
  293.  
  294.             mask = mask ? mask : 0x80000000;
  295.             if (PATTERN & mask)
  296.                 {
  297.                 for (j= -LINEWIDTH/2; j<=LINEWIDTH/2; j++)
  298.                     screenbit[px][py+j] = '#';
  299.  
  300.             }
  301.             mask >>= 1;
  302.  
  303.  
  304.     if (dxabs >= dyabs)
  305.     {
  306.         for (i=0; i<dxabs; i++)
  307.         {
  308.             mask = mask ? mask : 0x80000000;
  309.             y += dyabs;
  310.             if (y>=dxabs)
  311.             {
  312.                 y -= dxabs;
  313.                 py += sdy;
  314.             }
  315.             px += sdx;
  316.             if (PATTERN & mask)
  317.                 {
  318.                 for (j= -LINEWIDTH/2; j<=LINEWIDTH/2; j++)
  319.                     screenbit[px][py+j] = '#';
  320.  
  321.             }
  322.             mask >>= 1;
  323.         }
  324.     }
  325.     else
  326.     {
  327.         for (i=0; i<dyabs; i++)
  328.         {
  329.             mask = mask ? mask : 0x80000000;
  330.             x += dxabs;
  331.             if (x>=dyabs)
  332.             {
  333.                 x -= dyabs;
  334.                 px += sdx;
  335.                 }
  336.             py += sdy;
  337.             if (PATTERN & mask)
  338.             {
  339.                 for (j= -LINEWIDTH/2; j<=LINEWIDTH/2; j++)
  340.                     screenbit[px+j][py] = '#';
  341.             }
  342.                 mask >>= 1;
  343.         }
  344.     }
  345. }
  346. /*---------------------------------------------------------------------------*/
  347. d_clear()
  348. {
  349.     int x,y;
  350.     for (y=0;y<=MAXY;y++) {
  351.       for (x=0;x<=MAXX;x++) {
  352.         screenbit[x][y] = 0;
  353.       }
  354.     }
  355. }
  356. /*---------------------------------------------------------------------------*/
  357. d_flush()
  358. {
  359. }
  360. /*---------------------------------------------------------------------------*/
  361. d_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  362. {
  363.     df_arcto(x1,y1,x2,y2,rrr);
  364. }
  365. /*---------------------------------------------------------------------------*/
  366. d_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  367. {
  368.     df_arc(r,t1,t2,cx,cy);
  369. }
  370. /*---------------------------------------------------------------------------*/
  371. d_narc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  372. {
  373.     df_arc(r,t1,t2,cx,cy);
  374. }
  375. /*---------------------------------------------------------------------------*/
  376. d_box_fill(dbl x1, dbl y1, dbl x2, dbl y2)
  377. {
  378.     df_box_fill(x1,y1,x2,y2);
  379. }
  380. d_box_stroke(dbl x1, dbl y1, dbl x2, dbl y2)
  381. {
  382.     df_box_stroke(x1,y1,x2,y2);
  383. }
  384. /*---------------------------------------------------------------------------*/
  385. d_circle_stroke(double zr)
  386. {
  387.     df_circle_stroke(zr);
  388. }
  389. d_circle_fill(double zr)
  390. {
  391.     df_circle_fill(zr);
  392. }
  393. /*---------------------------------------------------------------------------*/
  394. d_bezier(dbl x1,dbl y1,dbl x2,dbl y2,dbl x3,dbl y3)
  395. {
  396.     double ax,bx,cx,ay,by,cy,dist;
  397.     double xxx,yyy,i,t,nstep,x0,y0;
  398.     g_get_xy(&x0,&y0);
  399.     dist = fabs(x3-x0) + fabs(y3-y0);
  400.     nstep = 10;
  401.     if (dist>3) nstep = 20;
  402.     if (dist<.5) nstep = 5;
  403.     if (dist<.3) nstep = 3;
  404.      if (dist<.1) {
  405.         g_line(x3,y3);
  406.         return;
  407.     }
  408.     cx = (x1-x0)*3;
  409.     bx = (x2-x1)*3-cx;
  410.     ax = x3-x0-cx-bx;
  411.     cy = (y1-y0)*3;
  412.     by = (y2-y1)*3-cy;
  413.     ay = y3-y0-cy-by;
  414.     for (i=0;i<=nstep;i++) {
  415.         t = i/nstep;
  416.         xxx = ax*pow(t,3.0) + bx*t*t + cx*t + x0;
  417.         yyy = ay*pow(t,3.0) + by*t*t + cy*t + y0;
  418.         g_line(xxx,yyy);
  419.     }
  420. }
  421. /*---------------------------------------------------------------------------*/
  422. d_set_color(long f)
  423. {
  424. }
  425. d_set_fill(long f)
  426. {
  427. }
  428. /*---------------------------------------------------------------------------*/
  429. d_beginclip()
  430. {
  431. }
  432. d_endclip()
  433. {
  434. }
  435. struct char_data {float wx,wy,x1,y1,x2,y2; };
  436. int font_get_chardata(struct char_data **cd, int ff, int cc);
  437. /*---------------------------------------------------------------------------*/
  438. d_char(int font, int cc)
  439. {
  440.     static struct char_data cd;
  441.     static int ix,iy,ix1,ix2,iy1,iy2,fz,fzx;
  442.     static int ux,uy;
  443.     static int safnt;
  444.     char ss[2];
  445.  
  446.     ss[0] = cc;
  447.     ss[1] = 0;
  448.     if (safnt==0) safnt = pass_font("PLSR");
  449.     if (font>=2) {
  450.         my_char(font,cc);
  451.         return;
  452.     }
  453.     my_char(safnt,cc);
  454. }
  455.  
  456.  
  457.