home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / gbench / part02 / ops.c < prev   
Encoding:
C/C++ Source or Header  |  1988-06-12  |  10.5 KB  |  499 lines

  1. #include <gbench.h>
  2.  
  3. void StartArc(sp,cp)
  4.     State*  sp;
  5.     Cmd*    cp;
  6. {
  7.     double  adjust;
  8.     int        area = cp->p.size*cp->p.size;
  9.     int        origin;
  10.     double  theta;
  11.  
  12.     cp->size[0] = sqrt(area/cp->p.aspect);
  13.     cp->size[1] = sqrt(area*cp->p.aspect);
  14.     if (cp->p.aspect!=1.) {
  15.     theta = cp->p.angle*Pi/180;
  16.     if (theta<(Pi/2)) adjust = 0.;
  17.     else if (theta<(3*Pi/2)) adjust = Pi;
  18.     else adjust = 2*Pi;
  19.     theta = atan(tan(theta)/cp->p.aspect)+adjust;
  20.     cp->size[2] = theta*180/Pi*64;
  21.     }
  22.     else cp->size[2] = cp->p.angle*64;
  23.     origin = Border+cp->p.lwidth;
  24.     cp->x = cp->y = Border;
  25.     cp->bbx = cp->size[0]+2*cp->p.lwidth;
  26.     cp->bby = cp->size[1]+2*cp->p.lwidth;
  27.     if (cp->o.fill) {
  28.     MoveClip(
  29.         sp,cp,cp->x+cp->bbx/2-OverlapSize,cp->y+cp->bby/2-OverlapSize
  30.     );
  31.     }
  32.     else MoveClip(sp,cp,cp->x,cp->y+cp->bby/2);
  33.     Start(sp,cp);
  34. }
  35.  
  36. void DoArc(sp,cp)
  37.     State*  sp;
  38.     Cmd*    cp;
  39. {
  40.     int i;
  41.     int x = cp->x+cp->p.lwidth;
  42.     int y = cp->y+cp->p.lwidth;
  43.  
  44.     for (i=0;i<cp->p.count;i++) {
  45.     StartIteration(sp,cp);
  46. #    ifdef X11
  47.         if (cp->o.fill) {
  48.         XFillArc(
  49.             sp->d,cp->dest,cp->gc,x,y,cp->size[0],cp->size[1],0,
  50.             cp->size[2]
  51.         );
  52.         }
  53.         else {
  54.         XDrawArc(
  55.             sp->d,cp->dest,cp->gc,x,y,cp->size[0],cp->size[1],0,
  56.             cp->size[2]
  57.         );
  58.         }
  59. #    endif X11
  60.     }
  61. }
  62.  
  63. void StartBlit(sp,cp)
  64.     State*  sp;
  65.     Cmd*    cp;
  66. {
  67.     Pixel   colorfg;
  68.     int        i;
  69.  
  70.     Start(sp,cp);
  71.     cp->bbx = cp->bby = 0;
  72.     colorfg = cp->colorfg;
  73.     MoveClip(sp,cp,Border+cp->p.size/2,Border+cp->p.size/2);
  74.     for (i=0;i<2;i++) {
  75.     StartIteration(sp,cp);
  76. #    ifdef X10
  77.         XPixFill(
  78.         cp->w,Border,Border,cp->p.size,cp->p.size,colorfg,0,cp->func,
  79.         AllPlanes
  80.         );
  81. #    else
  82.         XFillRectangle(
  83.         sp->d,cp->src,sp->gc1,Border,Border,cp->p.size,cp->p.size
  84.         );
  85. #    endif
  86.     }
  87.     cp->x = cp->y = Border;
  88.     cp->size[0] = cp->p.offset*cp->p.size;
  89. }
  90.  
  91. void DoBlit(sp,cp)
  92.     State*  sp;
  93.     Cmd*    cp;
  94. {
  95.     XEvent            e;
  96.     int                i;
  97.     XGraphicsExposeEvent*   xep;
  98.  
  99. #   ifdef X10
  100.     xep = (XGraphicsExposeEvent*)&e;
  101. #   else
  102.     xep = &e.xgraphicsexpose;
  103. #   endif
  104.     for (i=0;i<cp->p.count;i++) {
  105.     StartIteration(sp,cp);
  106. #    ifdef X10
  107.         XCopyArea(
  108.         cp->w,Border,Border,cp->x+cp->size[0],cp->y+cp->size[0],
  109.         cp->p.size,cp->p.size,cp->func,AllPlanes
  110.         );
  111.         if (cp->o.overlap) do {
  112.         XMaskEvent(ExposeRegion|ExposureMask,&e);
  113.         if (e.type==ExposeRegion) {
  114.             XPixFill(
  115.             cp->w,xep->x,xep->y,xep->width,xep->height,cp->colorfg,
  116.             0,cp->func,AllPlanes
  117.             );
  118.         }
  119.         } while (e.type!=ExposureMask);
  120. #    else
  121.         XCopyArea(
  122.         sp->d,cp->src,cp->dest,cp->gc,Border,Border,cp->p.size,
  123.         cp->p.size,cp->x+cp->size[0],cp->y+cp->size[0]
  124.         );
  125.         if (cp->o.overlap) do {
  126.         XMaskEvent(sp->d,ExposureMask,&e);
  127.         if (e.type==GraphicsExpose) {
  128.             XFillRectangle(
  129.             sp->d,cp->dest,cp->gc,xep->x,xep->y,xep->width,
  130.             xep->height
  131.             );
  132.         }
  133.         } while ((e.type==GraphicsExpose)&&xep->count);
  134. #    endif
  135.     }
  136. }
  137.  
  138. void StartMap(sp,cp)
  139.     State*  sp;
  140.     Cmd*    cp;
  141. {
  142.     int        wheight;
  143.     int        i;
  144.     int        ncols = _DisplayWidth/cp->p.size;
  145. #   ifdef X11
  146.         XSetWindowAttributes swa;
  147. #   endif X11
  148.  
  149.     cp->x = cp->y = cp->bbx = cp->bby = 0;
  150.     cp->p.nwin = Limit(cp->p.nwin,1,ncols*_DisplayHeight/cp->p.size);
  151.     cp->o.altwin = false;
  152.     wheight = cp->p.size*(1+cp->p.nwin/ncols);
  153.     Start(sp,cp);
  154.     UnmapWin(sp,cp->w);
  155.     cp->w = XCreateSimpleWindow(
  156.     DARGC _RootWindow,0,0,_DisplayWidth,wheight,1,WhitePixmap,BlackPixmap
  157.     );
  158.     for (i=0;i<cp->p.nwin;i++) {
  159.     XCreateSimpleWindow(
  160.         DARGC cp->w,cp->p.size*(i%ncols),cp->p.size*(i/ncols),cp->p.size,
  161.         cp->p.size,1,WhitePixmap,BlackPixmap
  162.     );
  163.     }
  164. #   ifdef X11
  165.         swa.override_redirect = 1;
  166.         XChangeWindowAttributes(sp->d,cp->w,CWOverrideRedirect,&swa);
  167. #   endif X11
  168.     XRaiseWindow(DARGC cp->w);
  169.     XMapWindow(DARGC cp->w);
  170.     XSelectInput(DARGC cp->w,InputMask(cp));
  171. }
  172.  
  173. void DoMap(sp,cp)
  174.     State*  sp;
  175.     Cmd*    cp;
  176. {
  177.     int i;
  178.  
  179.     for (i=0;i<cp->p.count;i++) {
  180.     XMapSubwindows(DARGC cp->w);
  181.     XUnmapSubwindows(DARGC cp->w);
  182.     }
  183. }
  184.  
  185. void FinishMap(sp,cp)
  186.     State*  sp;
  187.     Cmd*    cp;
  188. {
  189.     Finish(sp,cp);
  190.     XUnmapWindow(DARGC cp->w);
  191.     XDestroyWindow(DARGC cp->w);
  192.     cp->w = sp->w1;
  193.     MapWin(sp,cp->w);
  194.     XFlush(DARG);
  195. }
  196.  
  197. void DoNop(sp,cp)
  198.     State*  sp;
  199.     Cmd*    cp;
  200. {
  201.     int    i;
  202.  
  203. #   ifdef X11
  204.     for (i=0;i<cp->p.count;i++) XNoOp(sp->d);
  205. #   endif X11
  206. }
  207.  
  208. void StartPoint(sp,cp)
  209.     State*  sp;
  210.     Cmd*    cp;
  211. {
  212.     cp->x = cp->y = Border;
  213.     cp->bbx = cp->bby = 1;
  214.     MoveClip(sp,cp,cp->x,cp->y);
  215.     Start(sp,cp);
  216. }
  217.  
  218. void DoPoint(sp,cp)
  219.     State*  sp;
  220.     Cmd*    cp;
  221. {
  222.     int i;
  223.     
  224. #   ifdef X11
  225.     for (i=0;i<cp->p.count;i++) {
  226.         StartIteration(sp,cp);
  227.         XDrawPoint(sp->d,cp->dest,cp->gc,cp->x,cp->y);
  228.     }
  229. #   endif
  230. }
  231.  
  232. void StartPoly(sp,cp)
  233.     State*  sp;
  234.     Cmd*    cp;
  235. {
  236.     int        fillrule;
  237.     int        i;
  238.     int        index;
  239.     int        origin = Border+cp->p.lwidth;
  240.     int        r = cp->p.size/2;
  241.     double  theta;
  242.  
  243.     if (cp->o.polyself) cp->p.nvert = cp->p.nvert/2*2+1;
  244.     theta = 2*Pi/cp->p.nvert;
  245.     cp->x = cp->y = Border;
  246.     cp->bbx = cp->bby = cp->p.size+2*cp->p.lwidth;
  247.     for (i=0;i<=cp->p.nvert;i++) {
  248.     index = cp->o.polyself?(i*(cp->p.nvert/2))%cp->p.nvert:i;
  249.     sp->v[i].x = origin+r*(1+cos(PolyAngle+index*theta));
  250.     sp->v[i].y = origin+r*(1-sin(PolyAngle+index*theta));
  251.     }
  252. #   ifdef X10
  253.     sp->v[0].flags = VertexStartClosed;
  254.     for (i=1;i<cp->p.nvert;i++) sp->v[i].flags = 0;
  255.     sp->v[cp->p.nvert].flags = VertexEndClosed;
  256. #   else
  257.     fillrule = cp->o.polywind?WindingRule:EvenOddRule;
  258.     XSetFillRule(sp->d,sp->gc1,fillrule);
  259.     XSetFillRule(sp->d,sp->gc2,fillrule);
  260. #   endif
  261.     if (cp->o.fill) MoveClip(sp,cp,cp->x+r,cp->x+r);
  262.     else MoveClip(sp,cp,sp->v[0].x,sp->v[0].y);
  263.     Start(sp,cp);
  264. }
  265.  
  266. void DoPoly(sp,cp)
  267.     State*  sp;
  268.     Cmd*    cp;
  269. {
  270.     int i;
  271. #   ifdef X11
  272.     int shape = cp->o.polyself?Complex:Convex;
  273. #   endif X11
  274.  
  275.     MoveVert(sp,cp,cp->p.nvert);
  276.     for (i=0;i<cp->p.count;i++) {
  277.     StartIteration(sp,cp);
  278. #    ifdef X10
  279.         X10Draw(sp,cp,cp->p.nvert+1);
  280. #    else
  281.         if (cp->o.fill) {
  282.         XFillPolygon(
  283.             sp->d,cp->dest,cp->gc,sp->v,cp->p.nvert,shape,
  284.             CoordModeOrigin
  285.         );
  286.         }
  287.         else {
  288.         XDrawLines(
  289.             sp->d,cp->dest,cp->gc,sp->v,cp->p.nvert+1,CoordModeOrigin
  290.         );
  291.         }
  292. #    endif
  293.     }
  294. }
  295.  
  296. void StartRect(sp,cp)
  297.     State*  sp;
  298.     Cmd*    cp;
  299. {
  300.     int i;
  301.     int origin = Border+cp->p.lwidth;
  302.  
  303.     cp->x = cp->y = Border;
  304.     cp->bbx = cp->bby = cp->p.size+2*cp->p.lwidth;
  305. #   ifdef X10
  306.     for (i=0;i<5;i++) {
  307.         sp->v[i].x = origin;
  308.         sp->v[i].y = origin;
  309.     }
  310.     sp->v[1].x += cp->p.size;
  311.     sp->v[2].x += cp->p.size;
  312.     sp->v[2].y += cp->p.size;
  313.     sp->v[3].y += cp->p.size;
  314.     sp->v[0].flags = VertexStartClosed;
  315.     for (i=1;i<4;i++) sp->v[i].flags = 0;
  316.     sp->v[4].flags = VertexEndClosed;
  317. #   endif X10
  318.     if (cp->o.fill) MoveClip(sp,cp,cp->x+cp->bbx/2,cp->y+cp->bby/2);
  319.     else MoveClip(sp,cp,cp->x,cp->y);
  320.     Start(sp,cp);
  321. }
  322.  
  323. void DoRect(sp,cp)
  324.     State*  sp;
  325.     Cmd*    cp;
  326. {
  327.     int    i;
  328.     int x = cp->x+cp->p.lwidth;
  329.     int y = cp->y+cp->p.lwidth;
  330.  
  331. #   ifdef X10
  332.     if (!cp->o.fill) MoveVert(sp,cp,5);
  333. #   endif X10
  334.     for (i=0;i<cp->p.count;i++) {
  335.     StartIteration(sp,cp);
  336. #    ifdef X10
  337.         if (cp->o.fill) {
  338.         if (cp->o.tile) {
  339.             XTileFill(
  340.             cp->w,x,y,cp->p.size,cp->p.size,sp->tile,0,cp->func,
  341.             AllPlanes
  342.             );
  343.         }
  344.         else {
  345.             XPixFill(
  346.             cp->w,x,y,cp->p.size,cp->p.size,cp->colorfg,0,cp->func,
  347.             AllPlanes
  348.             );
  349.         }
  350.         }
  351.         else X10Draw(sp,cp,5);
  352. #    else
  353.         if (cp->o.fill) {
  354.         XFillRectangle(
  355.             sp->d,cp->dest,cp->gc,x,y,cp->p.size,cp->p.size
  356.         );
  357.         }
  358.         else {
  359.         XDrawRectangle(
  360.             sp->d,cp->dest,cp->gc,x,y,cp->p.size,cp->p.size
  361.         );
  362.         }
  363. #    endif
  364.     }
  365. }
  366.  
  367. void StartText(sp,cp)
  368.     State*  sp;
  369.     Cmd*    cp;
  370. {
  371.     int findex = FontIndex(sp,&cp->p.ptsize);
  372.     int    i;
  373.  
  374.     cp->x = cp->y = Border;
  375.     Start(sp,cp);
  376.     if (findex<0) {
  377.     cp->p.ptsize = 0;
  378.     cp->fontid = nil;
  379.     cp->bbx = cp->bby = 0;
  380.     cp->result = NoFonts;
  381.     }
  382.     else {
  383. #    ifdef X10
  384.         cp->p.ptsize = sp->fontinfo[findex]->height;
  385.         cp->fontid = sp->fontinfo[findex]->id;
  386.         cp->bbx = cp->p.nchar*sp->fontinfo[findex]->width;
  387.         cp->bby = sp->fontinfo[findex]->height;
  388. #    else
  389.         cp->p.ptsize = sp->fontinfo[findex]->ascent;
  390.         XSetFont(sp->d,sp->gc1,sp->fontinfo[findex]->fid);
  391.         XSetFont(sp->d,sp->gc2,sp->fontinfo[findex]->fid);
  392.         cp->fontid = sp->fontinfo[findex]->fid;
  393.         cp->size[0] = sp->fontinfo[findex]->max_bounds.ascent;
  394.         cp->bbx = cp->p.nchar*sp->fontinfo[findex]->max_bounds.width;
  395.         cp->bby = cp->size[0]+sp->fontinfo[findex]->max_bounds.descent;
  396.         if (cp->o.altfont) for (i=0;i<cp->p.nchar;i++) {
  397.         sp->texts[i].font = cp->fontid;
  398.         }
  399. #    endif
  400.     }
  401.     MoveClip(sp,cp,cp->x+cp->bbx/2,cp->y+cp->bby/2);
  402. }
  403.  
  404. void DoText(sp,cp)
  405.     State*  sp;
  406.     Cmd*    cp;
  407. {
  408.     int    i;
  409.  
  410.     if (cp->result==NoFonts) return;
  411.     for (i=0;i<cp->p.count;i++) {
  412.     StartIteration(sp,cp);
  413. #    ifdef X10
  414.         if (cp->o.tile) {
  415.         XTextPad(
  416.             cp->w,cp->x,cp->y,sp->outstr,cp->p.nchar,cp->fontid,0,0,
  417.             cp->colorfg,cp->colorbg,cp->func,AllPlanes
  418.         );
  419.         }
  420.         else {
  421.         XTextMaskPad(
  422.             cp->w,cp->x,cp->y,sp->outstr,cp->p.nchar,cp->fontid,0,0,
  423.             cp->colorfg,cp->func,AllPlanes
  424.         );
  425.         }
  426. #    else
  427.         if (cp->o.altfont) {
  428.         XDrawText(
  429.             sp->d,cp->dest,cp->gc,cp->x,cp->y+cp->size[0],sp->texts,
  430.             cp->p.nchar
  431.         );
  432.         }
  433.         else if (cp->o.tile) {
  434.         XDrawImageString(
  435.             sp->d,cp->dest,cp->gc,cp->x,cp->y+cp->size[0],sp->outstr,
  436.             cp->p.nchar
  437.         );
  438.         }
  439.         else {
  440.         XDrawString(
  441.             sp->d,cp->dest,cp->gc,cp->x,cp->y+cp->size[0],sp->outstr,
  442.             cp->p.nchar
  443.         );
  444.         }
  445. #    endif
  446.     }
  447. }
  448.  
  449. void StartVec(sp,cp)
  450.     State*  sp;
  451.     Cmd*    cp;
  452. {
  453.     double  theta = cp->p.angle*Pi/180;
  454.     int        xoffset = cp->p.lwidth*Sign(cos(theta));
  455.     int        yoffset = cp->p.lwidth*Sign(-sin(theta));
  456.     int        xorigin = sp->winsize/2;
  457.     int        yorigin = sp->winsize/2;
  458.  
  459. #   ifdef X10
  460.     sp->v[0].flags = 0;
  461.     sp->v[1].flags = 0;
  462. #   endif X10
  463.     cp->x = xorigin;
  464.     cp->y = yorigin;
  465.     xorigin += xoffset;
  466.     yorigin += yoffset;
  467.     cp->bbx = cp->p.size*cos(theta);
  468.     cp->bby = cp->p.size*-sin(theta);
  469.     sp->v[0].x = xorigin;
  470.     sp->v[0].y = yorigin;
  471.     sp->v[1].x = xorigin+cp->bbx;
  472.     sp->v[1].y = yorigin+cp->bby;
  473.     cp->bbx += 2*xoffset;
  474.     cp->bby += 2*yoffset;
  475.     cp->o.fill = false;
  476.     MoveClip(sp,cp,cp->x+cp->bbx/2,cp->y+cp->bby/2);
  477.     Start(sp,cp);
  478. }
  479.  
  480. void DoVec(sp,cp)
  481.     State*  sp;
  482.     Cmd*    cp;
  483. {
  484.     int i;
  485.  
  486.     MoveVert(sp,cp,2);
  487.     for (i=0;i<cp->p.count;i++) {
  488.     StartIteration(sp,cp);
  489. #    ifdef X10
  490.         X10Draw(sp,cp,2);
  491. #    else
  492.         XDrawLine(
  493.         sp->d,cp->dest,cp->gc,sp->v[0].x,sp->v[0].y,sp->v[1].x,
  494.         sp->v[1].y
  495.         );
  496. #    endif
  497.     }
  498. }
  499.