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

  1. #include <uisusrdef.h>
  2. #include <descrip.h>
  3. #include <stdio.h>
  4. /*--------------------------------------------------------------*/
  5. /*    Regis Driver 1.0 (TURBO  C) , for GLE V3.0        */
  6. /*--------------------------------------------------------------*/
  7.  
  8. /*---------------------------------------------------------------------------*/
  9. #include "all.h"
  10. #include <math.h>
  11. #include "core.h"
  12. #include "mygraph.h"
  13. #include "mydev.h"
  14. int ingraphmode;
  15. extern struct gmodel g;
  16. extern int gle_speed;
  17. extern int gle_nspeed;
  18. /*---------------------------------------------------------------------------*/
  19. #define pi 3.141592653
  20. #define true (!false)
  21. #define BLACKANDWHITE 1
  22. #define ESC 27
  23. #define false 0
  24. #define dbg if ((gle_debug & 64)>0)
  25. #define stop if ((gle_debug & 128)>0) return
  26. extern int gle_debug;
  27. int incap=true;
  28. int getch(void);
  29. /*---------------------------------------------------------------------------*/
  30. /* The global variables for the PC screen driver */
  31. /*-----------------------------------------------*/
  32.  
  33. float savexsize,saveysize;
  34. int l,j;
  35. float ix,iy;
  36. double f;
  37. float oldx,oldy;
  38. int attrib=1;
  39. int attribf=2;
  40. long vcm_id,map_size,vd_id,i,wd_id;
  41. float xsizecm, ysizecm, resolx, resoly, display_x, display_y;
  42. float zval;
  43. float windowx,windowy;
  44.  
  45. #define sx(v) ( (v) * d_xscale)
  46. #define sy(v) ( (v) * d_yscale)
  47. #define rx(v) ( (v) * d_xscale)
  48. #define ry(v) ( (v) * d_yscale)
  49.  
  50. double d_scale, d_xscale, d_yscale;
  51. int d_graphmode;
  52. int d_fillstyle=1,d_fillcolor;
  53. int d_lstyle,d_lwidth;
  54. int d_maxy;
  55.  
  56. d_devcmd(char *s)
  57. {}
  58. dxy(double x, double y, float *dx, float *dy)
  59. {
  60.     static double fx,fy;
  61.     g_dev(x,y,&fx,&fy);
  62.     *dx = sx(fx);
  63.     *dy = sy(fy);
  64. }
  65. rxy(double x, double y, float *dx, float *dy)
  66. {
  67.     static double fx,fy,zx,zy;
  68.     g_dev(x,y,&fx,&fy);
  69.     g_dev(0.0,0.0,&zx,&zy);
  70.     *dx = ( (fx-zx) * d_xscale);
  71.     *dy = ( (fy-zy) * d_yscale);
  72. }
  73. /*---------------------------------------------------------------------------*/
  74. d_dfont(char *c)
  75. {
  76.     /* only used for the DFONT driver which builds fonts */
  77. }
  78. /*---------------------------------------------------------------------------*/
  79. static char lastline[80];
  80. d_message(char *s)
  81. {
  82.     static int single_step;
  83.     int oldcolor,oldx,oldy;
  84.         w_message(s);
  85. }
  86. /*---------------------------------------------------------------------------*/
  87. d_source(char *s)
  88. {
  89.     s=s;
  90. }
  91. /*---------------------------------------------------------------------------*/
  92. d_get_type(char *t)
  93. {
  94.     strcpy(t,"INTERACTIVE, UIS, VAX");
  95.     gle_speed = 0; /* set to slow speed by default for UIS driver. */
  96. }
  97. /*---------------------------------------------------------------------------*/
  98. d_set_path(int onoff)
  99. {}
  100. /*---------------------------------------------------------------------------*/
  101. d_newpath()
  102. {
  103. }
  104. /*---------------------------------------------------------------------------*/
  105. d_open(double width, double height)
  106. {
  107.        static $DESCRIPTOR(workstation,"sys$workstation");
  108.        static $DESCRIPTOR(fillfont,"uis$fill_patterns");
  109.  
  110.     gle_nspeed = 2; /* text mode = slow and fast */
  111.      uis$get_display_size(&workstation, &xsizecm, &ysizecm, &resolx, &resoly);
  112.  
  113.     xsizecm = 20;
  114.     ysizecm = 16;
  115.     map_size = 8;
  116.     /* Get largest rectangle we can fit on the screen */
  117.     d_scale = xsizecm / width;
  118.     f = ysizecm / height;
  119.     if (f<d_scale) d_scale = f;
  120.  
  121.     d_xscale = d_scale ;
  122.     d_yscale = d_scale ;
  123.     g.userwidth = width;
  124.     g.userheight = height;
  125.  
  126.     xsizecm = width*d_scale;
  127.     ysizecm = height*d_scale;
  128.  
  129.     if (vd_id==NULL  || xsizecm != savexsize || ysizecm != saveysize) {
  130.         if (vd_id!=NULL) {
  131.             uis$delete_window(&wd_id);
  132.             uis$delete_display(&vd_id);
  133.             uis$delete_color_map(&vcm_id);
  134.         }
  135.               vcm_id = uis$create_color_map(&map_size,0,0);
  136.               vd_id = uis$create_display(&zval,&zval,&xsizecm,&ysizecm
  137.                              ,&xsizecm,&ysizecm,&vcm_id);
  138.               wd_id = uis$create_window(&vd_id,&workstation);
  139.         set_uis_colors();
  140.     }
  141.     saveysize = ysizecm;
  142.     savexsize = xsizecm;
  143.     uis$set_writing_mode(&vd_id,&0,&attrib,&UIS$C_MODE_REPL);
  144.     uis$set_writing_mode(&vd_id,&0,&attribf,&UIS$C_MODE_REPL);
  145.     uis$set_writing_index(&vd_id,&attrib,&attrib,&1);
  146.     uis$set_writing_index(&vd_id,&attribf,&attribf,&1);
  147.     uis$set_font(&vd_id,&attribf,&attribf,&fillfont);
  148.     uis$set_fill_pattern(&vd_id,&attribf,&attribf,&PATT$C_FOREGROUND);
  149. }
  150. /*---------------------------------------------------------------------------*/
  151. #define getcolor(cname) uis$get_ws_color(&vd_id,&cname,&r,&g,&b); \
  152.             uis$set_color(&vd_id,&ci,&r,&g,&b); ci++;
  153. set_uis_colors()
  154. {
  155.     int ci=0;
  156.     float r,g,b;
  157.     getcolor(UIS$C_WS_WHITE);
  158.     getcolor(UIS$C_WS_BLACK);
  159.     getcolor(UIS$C_WS_RED);
  160.     getcolor(UIS$C_WS_GREEN);
  161.     getcolor(UIS$C_WS_BLUE);
  162.     getcolor(UIS$C_WS_CYAN);
  163.     getcolor(UIS$C_WS_YELLOW);
  164.     getcolor(UIS$C_WS_MAGENTA);
  165. }
  166. /*---------------------------------------------------------------------------*/
  167. d_tidyup()
  168. {
  169. }
  170. d_close()
  171. {
  172.  
  173.     g_flush();
  174.     textmode();
  175.     fner("Picture completed, press RETURN to continue                    (Press any key)");
  176.      text_inkey();
  177.     uis$push_viewport(&wd_id);
  178. }
  179. /*---------------------------------------------------------------------------*/
  180. d_set_line_cap(int i)
  181. {
  182.     i++;
  183. }
  184. /*---------------------------------------------------------------------------*/
  185. d_set_line_join(int i)
  186. {
  187.     i++;
  188. }
  189. /*---------------------------------------------------------------------------*/
  190. d_set_line_miterlimit(double d)
  191. {
  192.     i++;
  193. }
  194. /*---------------------------------------------------------------------------*/
  195. d_set_line_width(double w)
  196. {
  197.     float wf;
  198.     wf = w;
  199.     uis$set_line_width(&vd_id,&attrib,&attrib,&wf,&UIS$C_WIDTH_WORLD);
  200. }
  201. /*---------------------------------------------------------------------------*/
  202. d_set_line_styled(double dd)
  203. {}
  204. d_set_line_style(char *s)
  205. {
  206.     unsigned long bitimg;
  207.     d_lstyle = 2;
  208.     if (strcmp(s,"")==0) d_lstyle = 1;
  209.     if (strcmp(s,"0")==0) d_lstyle = 1;
  210.     if (strcmp(s,"1")==0) d_lstyle = 1;
  211.     if (d_lstyle!=1) bitimg = 0XF00FF00F;
  212.     else bitimg = 0XFFFFFFFF;
  213.     uis$set_line_style(&vd_id,&attrib,&attrib,&bitimg);
  214. }
  215. /*---------------------------------------------------------------------------*/
  216. d_fill()
  217. {
  218. }
  219. /*---------------------------------------------------------------------------*/
  220. d_fill_ary(int nwk,double (*wkx)[],double (*wky)[])
  221. {
  222.     int i;
  223. /*    fprintf(psfile,"%g %g moveto \n",(*wkx)[0],(*wky)[0]);
  224.     for (i=1;i<nwk;i++)
  225.         fprintf(psfile,"%g %g l \n",(*wkx)[i],(*wky)[i]);
  226. */
  227. }
  228. d_line_ary(int nwk,double (*wkx)[],double (*wky)[])
  229. {
  230.     int i;
  231. /*
  232.     dxy( (*wkx)[0], (*wky)[0], &ix, &iy);
  233.     moveto(ix,iy);
  234.     for (i=1;i<nwk;i++) {
  235.         dxy( (*wkx)[i], (*wky)[i], &ix, &iy);
  236.         lineto(ix,iy);
  237.     }
  238. */
  239. }
  240. /*---------------------------------------------------------------------------*/
  241. d_stroke()
  242. {
  243. }
  244. /*---------------------------------------------------------------------------*/
  245. d_clip()
  246. {
  247. }
  248. /*---------------------------------------------------------------------------*/
  249. d_set_matrix(double newmat[3][3])
  250. {
  251. }
  252. /*---------------------------------------------------------------------------*/
  253. d_move(double zx,double zy)
  254. {
  255. }
  256. /*---------------------------------------------------------------------------*/
  257. d_reverse()     /* reverse the order of stuff in the current path */
  258. {
  259. }
  260. /*---------------------------------------------------------------------------*/
  261. d_closepath()
  262. {
  263.     g_line(g.closex,g.closey);
  264. }
  265. /*---------------------------------------------------------------------------*/
  266. d_line(double zx,double zy)
  267. {
  268.     static float ux,uy;
  269.     dxy(g.curx,g.cury,&oldx,&oldy);
  270.     dxy(zx,zy,&ux,&uy);
  271.     uis$line(&vd_id,&attrib,&oldx,&oldy,&ux,&uy);
  272. }
  273. /*---------------------------------------------------------------------------*/
  274. d_clear()
  275. {
  276.     int flag,i;
  277.     flag = (UIS$M_DL_ENHANCE_LIST | UIS$M_DL_MODIFY_LIST);
  278.     uis$erase(&vd_id);
  279.     uis$disable_display_list(&vd_id,&flag);
  280.     i = 1;
  281.     uis$set_writing_index(&vd_id,&attrib,&attrib,&i);
  282.     uis$pop_viewport(&wd_id);
  283. }
  284. /*---------------------------------------------------------------------------*/
  285. d_flush()
  286. {
  287. }
  288. /*---------------------------------------------------------------------------*/
  289. d_arcto(dbl x1,dbl y1,dbl x2,dbl y2,dbl rrr)
  290. {
  291. }
  292. /*---------------------------------------------------------------------------*/
  293. d_arc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  294. {
  295.     static float ixr,iyr,icx,icy,ixs,iys;
  296.     double ux,uy,z,xs,ys;
  297.     float ta1,ta2;
  298.  
  299.  
  300.     if (t1>t2) {z = t1; t1 = t2; t2 = z;}
  301.     ta1 = t1;
  302.     ta2 = t2;
  303.     polar_xy(r,t1,&xs,&ys);
  304.     rxy(xs,ys,&ixs,&iys);
  305.  
  306.     dxy(cx,cy,&icx,&icy);
  307.     rxy(r,r,&ixr,&iyr);
  308.     uis$circle(&vd_id,&attrib,&icx,&icy,&ixr,&ta1,&ta2);
  309.     g.xinline = false;
  310. }
  311. /*---------------------------------------------------------------------------*/
  312. d_narc(dbl r,dbl t1,dbl t2,dbl cx,dbl cy)
  313. {
  314.     static float ixr,iyr,icx,icy,ixs,iys;
  315.     double ux,uy,z,xs,ys;
  316.     float ta1,ta2;
  317.  
  318.  
  319.     if (t1>t2) {z = t1; t1 = t2; t2 = z;}
  320.     ta1 = t1;
  321.     ta2 = t2;
  322.     polar_xy(r,t1,&xs,&ys);
  323.     rxy(xs,ys,&ixs,&iys);
  324.  
  325.     dxy(cx,cy,&icx,&icy);
  326.     rxy(r,r,&ixr,&iyr);
  327.     uis$circle(&vd_id,&attrib,&icx,&icy,&ixr,&ta1,&ta2);
  328.     g.xinline = false;
  329. }
  330. /*---------------------------------------------------------------------------*/
  331. d_box_fill(dbl x1, dbl y1, dbl x2, dbl y2)
  332. {
  333.     static float ix1,iy1,ix2,iy2;
  334.     static float ii;
  335.     dxy(x1,y1,&ix1,&iy1);
  336.     dxy(x2,y2,&ix2,&iy2);
  337.     uis$plot(&vd_id,&attribf, &ix1,&iy1, &ix2,&iy1, &ix2,&iy2, &ix1,&iy2
  338.         , &ix1,&iy1);
  339.     g.xinline = false;
  340. }
  341. d_box_stroke(dbl x1, dbl y1, dbl x2, dbl y2)
  342. {
  343.     static float ix1,iy1,ix2,iy2,ix3,iy3,ix4,iy4;
  344.     static float ii;
  345.     dxy(x1,y1,&ix1,&iy1);
  346.     dxy(x2,y2,&ix2,&iy2);
  347.     uis$plot(&vd_id,&attrib, &ix1,&iy1, &ix2,&iy1, &ix2,&iy2, &ix1,&iy2
  348.         , &ix1,&iy1);
  349.     g.xinline = false;
  350. }
  351. /*---------------------------------------------------------------------------*/
  352. d_circle_stroke(double zr)
  353. {
  354.     static float ixr,iyr;
  355.     float ux,uy;
  356.     rxy(zr,zr,&ixr,&iyr);
  357.     dxy(g.curx,g.cury,&ux,&uy);
  358.     uis$circle(&vd_id,&attrib,&ux,&uy,&ixr);
  359.     g.xinline = false;
  360. }
  361. d_circle_fill(double zr)
  362. {
  363.     static float ixr,iyr;
  364.     float ux,uy;
  365.     dxy(g.curx,g.cury,&ux,&uy);
  366.     rxy(zr,zr,&ixr,&iyr);
  367.     uis$circle(&vd_id,&attribf,&ux,&uy,&ixr);
  368.     g.xinline = false;
  369. }
  370. /*---------------------------------------------------------------------------*/
  371. d_bezier(dbl x1,dbl y1,dbl x2,dbl y2,dbl x3,dbl y3)
  372. {
  373.     double ax,bx,cx,ay,by,cy,dist;
  374.     double xxx,yyy,i,t,nstep,x0,y0;
  375.     g_get_xy(&x0,&y0);
  376.     dist = fabs(x3-x0) + fabs(y3-y0);
  377.     nstep = 10;
  378.     if (dist>3) nstep = 20;
  379.     if (dist<.5) nstep = 5;
  380.     if (dist<.3) nstep = 3;
  381.      if (dist<.1) {
  382.         g_line(x3,y3);
  383.         return;
  384.     }
  385.     cx = (x1-x0)*3;
  386.     bx = (x2-x1)*3-cx;
  387.     ax = x3-x0-cx-bx;
  388.     cy = (y1-y0)*3;
  389.     by = (y2-y1)*3-cy;
  390.     ay = y3-y0-cy-by;
  391.     for (i=0;i<=nstep;i++) {
  392.         t = i/nstep;
  393.         xxx = ax*pow(t,3.0) + bx*t*t + cx*t + x0;
  394.         yyy = ay*pow(t,3.0) + by*t*t + cy*t + y0;
  395.         g_line(xxx,yyy);
  396.     }
  397. }
  398. /*---------------------------------------------------------------------------*/
  399. d_set_color(long f)
  400. {
  401.     int i;
  402.     colortyp  cc;
  403.     cc.l = f;
  404.     i = 1;
  405.     if (cc.b[B_R]>1 && cc.b[B_G]>1 && cc.b[B_B]>1) i = 4;
  406.     if (cc.b[B_R]>60 && cc.b[B_G]>60 && cc.b[B_B]>60) i = 6;
  407.     if (cc.b[B_R]>100) i = 2;
  408.     if (cc.b[B_B]>100) i = 4;
  409.     if (cc.b[B_G]>100) i = 3;
  410.     if (cc.b[B_R]>100 && cc.b[B_G]>100) i = 5;
  411.     if (cc.b[B_G]>100 && cc.b[B_B]>100) i = 7;
  412.     if (cc.b[B_R]>250 && cc.b[B_G]>250 && cc.b[B_B]>250) i = 0;
  413.     uis$set_writing_index(&vd_id,&attrib,&attrib,&i);
  414. }
  415. d_set_fill(long f)
  416. {
  417.     int i;
  418.     int p;
  419.     colortyp  cc;
  420.     cc.l = f;
  421.     i = 1;
  422.     p = PATT$C_FOREGROUND;
  423.     if (cc.b[B_R]>1 && cc.b[B_G]>1 && cc.b[B_B]>1) i = 4;
  424.     if (cc.b[B_R]>30 && cc.b[B_G]>30 && cc.b[B_B]>30)
  425.         {p = PATT$C_GREY14_16;  i = 1;}
  426.     if (cc.b[B_R]>70 && cc.b[B_G]>70 && cc.b[B_B]>70)
  427.         {p = PATT$C_GREY10_16;  i = 1;}
  428.     if (cc.b[B_R]>100) i = 2;
  429.     if (cc.b[B_B]>100) i = 4;
  430.     if (cc.b[B_G]>100) i = 3;
  431.     if (cc.b[B_R]>100 && cc.b[B_G]>100) i = 5;
  432.     if (cc.b[B_G]>100 && cc.b[B_B]>100) i = 7;
  433.     if (cc.b[B_R]>100 && cc.b[B_G]>100 && cc.b[B_B]>100)
  434.         {p = PATT$C_GREY4_16;  i = 1;}
  435.     if (cc.b[B_R]>160 && cc.b[B_G]>160 && cc.b[B_B]>160)
  436.         {p = PATT$C_GREY1_16;  i = 1;}
  437.     if (cc.b[B_R]>250 && cc.b[B_G]>250 && cc.b[B_B]>250)
  438.         {p = PATT$C_FOREGROUND; i = 0;}
  439.     uis$set_writing_index(&vd_id,&attribf,&attribf,&i);
  440.     uis$set_fill_pattern(&vd_id,&attribf,&attribf,&p);
  441. }
  442. /*---------------------------------------------------------------------------*/
  443. d_beginclip()
  444. {
  445. }
  446. d_endclip()
  447. {
  448. }
  449. struct char_data {float wx,wy,x1,y1,x2,y2; };
  450. int font_get_chardata(struct char_data **cd, int ff, int cc);
  451. /*---------------------------------------------------------------------------*/
  452. d_char(int font, int cc)
  453. {
  454.     static struct char_data cd;
  455.     static float ix,iy,ix1,ix2,iy1,iy2,fz,fzx;
  456.     static float ux,uy;
  457.     static int safnt;
  458.     char ss[2];
  459.  
  460.     ss[0] = cc;
  461.     ss[1] = 0;
  462.  
  463.     if (gle_speed==1 && isalnum(cc)) {
  464.         fast_char(font,cc);
  465.         return;
  466.     }
  467.     if (safnt==0) safnt = pass_font("PLSR");
  468.     if (font_get_encoding(font)>2) {
  469.         my_char(font,cc);
  470.         return;
  471.     }
  472.     my_char(safnt,cc);
  473. }
  474.  
  475. /*---------------------------------------------------------------------------*/
  476. fast_char(int font, int cc)
  477. {
  478.     static struct char_data cd;
  479.     static float ix,iy,ix1,ix2,iy1,iy2,fz,fzx;
  480.     static int ux,uy;
  481.        static $DESCRIPTOR(sdesc,"a");
  482.     char ss[2];
  483.  
  484.     sdesc.dsc$a_pointer = ss;
  485.     ss[0] = cc;
  486.     ss[1] = 0;
  487.     stop;
  488.  
  489.     if (font_get_encoding(font)>2) {
  490.         my_char(font,cc);
  491.         return;
  492.     }
  493.     if (g.fontsz==0) g.fontsz = 1;
  494.     dxy(g.curx, g.cury , &ix1, &iy1);
  495.     rxy(g.fontsz * .5,g.fontsz * 1.0,&fzx,&fz);
  496.     uis$set_char_size(&vd_id,&attrib,&attrib,&sdesc,&fzx,&fz);
  497.     uis$set_position(&vd_id,&ix1,&iy1);
  498.     uis$text(&vd_id,&attrib,&sdesc);
  499. }
  500. graphmode()
  501. {
  502.     ingraphmode = true;
  503. }
  504. textmode()
  505. {
  506.     ingraphmode = false;
  507. }
  508. getmaxx()
  509. {
  510.     return 799;
  511. }
  512. getmaxy()
  513. {
  514.     return 479;
  515. }
  516.  
  517.  
  518.  
  519.  
  520.