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

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