home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d170 / surf.lha / Surf / src / scrnops.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  7KB  |  325 lines

  1. #include "scrnio.ih"
  2. #ifdef MANX
  3. #include <functions.h>
  4. #endif
  5.  
  6. #include "scrndef.h"
  7. #include "scrnio.h"
  8. #include "gadgetdef.h"
  9. #include "menudef.h"
  10.  
  11. #include "bezpt.h"
  12. #include "revolve.h"
  13. #include "control.h"
  14. #include "poly.h"
  15.  
  16.  
  17. long BackColor = DefBkPlane;
  18. short DitherMask = 7;
  19.  
  20. void SetMono( maxrval, maxgval, maxbval )
  21.     short maxrval,
  22.           maxgval,
  23.           maxbval;
  24. {
  25.     long i;
  26.     short range;
  27.     long rval, gval, bval;
  28.  
  29.     range = (NumColors -1) & 0x1f;  /* max 32 colours */
  30.     for( i = 0; i <= range; i++ ) {
  31.         rval = (maxrval * i )/range;
  32.         gval = (maxgval * i )/range;
  33.         bval = (maxbval * i )/range;
  34.  
  35.         SetRGB4( &(SurfScrn->ViewPort),  i, rval, gval, bval );
  36.     }
  37. }
  38.  
  39.  
  40. void SetRainbow()
  41. {
  42.     long i;
  43.     short range;
  44.     long rval, gval, bval;
  45.  
  46.     range = NumColors>> 1;
  47.     /*
  48.      * can't do a rainbow with only 2 colors
  49.      */
  50.     if( range < 2) {
  51.         return;
  52.     }
  53.  
  54.     for( i = 0; i < range; i++ ) {
  55.         long diff;
  56.  
  57.         diff = (0xf * i )/(range-1);
  58.         rval = 0xf - diff;
  59.         bval = diff;
  60.         gval = 0xf;
  61.         SetRGB4( &(SurfScrn->ViewPort), i, rval, gval, bval);
  62.     }
  63.     for( i = 0; i < range; i++ ) {
  64.         long diff;
  65.  
  66.         diff = (0xf * i )/(range-1);
  67.         rval = diff;
  68.         bval = 0xf;
  69.         gval = 0xf - diff;
  70.         SetRGB4( &(SurfScrn->ViewPort), i+range, rval, gval, bval);
  71.     }
  72.     SetRGB4( &(SurfScrn->ViewPort), 0L, 0L, 0L, 0L);
  73. }
  74.  
  75. /*
  76.  * set colours for hourglass pointer
  77.  */
  78. SetHourGlassCol()
  79. {
  80.     SetRGB4( &(SurfScrn->ViewPort),17L, 6L, 2L, 3L );
  81.     SetRGB4( &(SurfScrn->ViewPort),18L, 0L, 0L, 0L );
  82.     SetRGB4( &(SurfScrn->ViewPort),19L, 9L, 7L, 6L );
  83. }
  84.  
  85.  
  86.  
  87. void ClrWindow(drawaxis)
  88. bool drawaxis;
  89. {
  90.     long BkColAdj; /* background color adjusted for number of bit planes */
  91.  
  92.     BkColAdj = (BackColor * NumColors) / 32;
  93.     SetRast(rp, BackColor);  /* clear the window to colour 0 */
  94.     SetAPen(rp, WinFgCol );
  95.     /*
  96.      * Draw axis on screen
  97.      */
  98.     if( drawaxis) {
  99.         Move( rp, 0, WinVOrig);    /* x axis */
  100.         Draw( rp, (long)SurfWinDef.Width, (long)WinVOrig );
  101.  
  102.         Move( rp, WinHOrig, 0);     /* y axis */
  103.         Draw( rp, (long)WinHOrig, (long)SurfWinDef.Height );
  104.     }
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111. void DrawLine( x1, y1, x2, y2, mode )
  112. int x1, y1, x2, y2;
  113. int mode;
  114. {
  115.     SetDrMd( rp, mode );
  116.     Move( rp, (long)UCntrX(x1), (long)UCntrY(y1));
  117.     Draw(rp, (long)UCntrX(x2), (long)UCntrY(y2) );
  118. }
  119.  
  120.  
  121.  
  122. void PaintPoint(x,y,forecolor)
  123.     short x, y;
  124.     float forecolor;
  125. {
  126.     long shade;
  127.     shade = forecolor * (NumColors-1);
  128.  
  129.     if( shade >= NumColors) {
  130.         shade = NumColors-1;
  131.     }
  132.     else if ( shade < 0 ) {
  133.         shade = 0;
  134.     }
  135.  
  136.     SetAPen( rp, shade );
  137.     WritePixel( rp, (long)UCntrX(x), (long)UCntrY(y));
  138. }
  139.  
  140.  
  141.  
  142. void DrawPnt( x, y, op )
  143. int x, y, op;
  144. {
  145.     x = UCntrX(x);
  146.     y = UCntrY(y);
  147.     SetDrMd(rp, op );
  148.     RectFill( rp, (long)x, (long)y, (long)x, (long)y);
  149. }
  150.  
  151.  
  152. void DrawSqr(x, y, op )
  153. int x, y, op;
  154. {
  155.     x = UCntrX(x);
  156.     y = UCntrY(y);
  157.     SetDrMd(rp, op );
  158.     RectFill( rp, x - 2L, y -2L, x+ 2L, y+2L );
  159. }
  160.  
  161.  
  162. void DrawRhomShade( poly)
  163. Rhomboid *poly;
  164. {
  165.     int i;
  166.     int shade;
  167.     long backcolor, forecolor;
  168.  
  169.  
  170.     shade = (int)((poly->intensity) * ColorMax);
  171.     if( shade > ColorMax) {
  172.         shade = ColorMax;
  173.     }
  174.  
  175.     backcolor = shade >> 3;
  176.     forecolor = backcolor +1;
  177.     if( forecolor >= NumColors ) {
  178.         forecolor = backcolor;
  179.     }
  180.  
  181.     SetDrMd( rp, JAM2);
  182.     SetAPen( rp, forecolor );
  183.     SetBPen( rp, backcolor );
  184.     SetAfPt( rp, GrayPat[ shade & DitherMask ], 2);
  185.  
  186.     AreaMove( rp, UCntrX(poly->pt[0].x), UCntrY(poly->pt[0].y));
  187.  
  188.     for( i = 1; i < 4; i++ ) {
  189.         AreaDraw( rp, UCntrX(poly->pt[i].x), UCntrY(poly->pt[i].y) );
  190.     }
  191.     AreaEnd(rp);
  192.  
  193.     SetAfPt( rp, GrayPat[8], 2);  /* reset back to solid */
  194.  
  195. }
  196.  
  197. void DrawRhomFrame( inlist )
  198. ScrnPair inlist[];
  199. {
  200.     int i;
  201.  
  202.     SetDrMd( rp, JAM1);
  203.     SetAPen( rp, 0L );
  204.     SetOPen( rp, WinFgCol );
  205.  
  206.     AreaMove( rp, UCntrX(inlist[0].x), UCntrY(inlist[0].y));
  207.  
  208.     for( i = 1; i < 4; i++ ) {
  209.         AreaDraw( rp, UCntrX(inlist[i].x), UCntrY(inlist[i].y) );
  210.     }
  211.     AreaEnd(rp);
  212.     BNDRYOFF( rp ); /* turn off outlining */
  213. }
  214.  
  215.  
  216.  
  217.  
  218. SwitchBox()
  219. {
  220.     struct IntuiMessage mycopy,
  221.                         *orig;
  222.  
  223.     RefreshGadgets(SurfWinDef.FirstGadget, SurfWin, NULL );
  224.  
  225.     while(1) {
  226.         long wakeupmask;
  227.  
  228.         wakeupmask = Wait( SignalMask );
  229.         /*
  230.          * for now, we ignore the wakeupmask,
  231.          * just read messages from each. if I notice a performance problem,
  232.          * I'll fix it then
  233.          */
  234.  
  235.         /*
  236.          * handle messages for the control window
  237.          */
  238.         while( orig =(struct IntuiMessage *) GetMsg( CntrlWin->UserPort ) ) {
  239.  
  240.             mycopy = *orig;
  241.             ReplyMsg( orig );
  242.  
  243.             switch( mycopy.Class ) {
  244.                 case MENUPICK:
  245.                     MenuHandler( mycopy.Code );
  246.                     break;
  247.  
  248.                 case GADGETUP:
  249.                     GadgetHandler( (struct Gadget*)mycopy.IAddress );
  250.                     break;
  251.  
  252.                 case CLOSEWINDOW:
  253.                     return;
  254.  
  255.                 default:
  256.                     break;
  257.             }
  258.         }
  259.         /*
  260.          * handle the button window
  261.          */
  262.         while( orig =(struct IntuiMessage *) GetMsg( GadWin->UserPort ) ) {
  263.  
  264.             mycopy = *orig;
  265.             ReplyMsg( orig );
  266.  
  267.             switch( mycopy.Class ) {
  268.                 case GADGETUP:
  269.                     GadgetHandler( (struct Gadget*)mycopy.IAddress );
  270.                     RefreshGadgets(SurfWinDef.FirstGadget, SurfWin, NULL );
  271.                     break;
  272.  
  273.                 default:
  274.                     break;
  275.             }
  276.         }
  277.  
  278.         /*
  279.          * handle messages for the other window
  280.          */
  281.         while( orig =(struct IntuiMessage *) GetMsg( SurfWin->UserPort ) ) {
  282.  
  283.             mycopy = *orig;
  284.             ReplyMsg( orig );
  285.  
  286.             switch( mycopy.Class ) {
  287.                 case MOUSEBUTTONS:
  288.                     HandleMButtons(&mycopy);
  289.                     break;
  290.  
  291.                 case INTUITICKS:
  292.                     HandleTicks(&mycopy);
  293.                     break;
  294.  
  295.                 case MOUSEMOVE:
  296.                     break;
  297.  
  298.                 default:
  299.                     break;
  300.             }
  301.         }
  302.     }
  303. }
  304.  
  305. /*
  306.  * display error messages inside a requestor
  307.  */
  308. OutErr(errstr)
  309.     char *errstr;
  310. {
  311.     static struct IntuiText errtext =
  312.         { -1, -1, JAM1, 10, 10, NULL, NULL, NULL };
  313.     static struct IntuiText negtext =
  314.         { -1, -1, JAM1, 80, 20, NULL,(UBYTE *)"Onwards", NULL };
  315.  
  316.     errtext.IText = (UBYTE *)errstr;
  317.  
  318.     WBenchToFront();
  319.     AutoRequest(CntrlWin, &errtext, NULL, &negtext, NULL, NULL,
  320.         8*strlen(errstr)+ 40, 60 );
  321.     WindowToFront( CntrlWin );
  322.  
  323. }
  324.  
  325.