home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / systempatch / sysi2 / gfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-11  |  2.3 KB  |  123 lines

  1. #include "sysi2.h"
  2.  
  3. /* these are setup in main.c */
  4. extern struct SignalSemaphore TRBMSem;  /* To protect and share TmpRasBM */
  5. extern struct BitMap *TmpRasBM;
  6.  
  7. /* Vanilla Gadget Background */
  8. void DrawBack(struct RastPort *RP, 
  9.               UBYTE TopEdgePen,
  10.               UBYTE BottomEdgePen,
  11.               UBYTE FillPen,
  12.               WORD X1,
  13.               WORD Y1,
  14.               WORD X2,
  15.               WORD Y2)
  16. {
  17.   SetAPen(RP,FillPen);
  18.   MyRectFill(RP,X1,Y1,X2,Y2);
  19.  
  20.   SetAPen(RP,BottomEdgePen);
  21.   Move(RP,X2,Y1);
  22.   Draw(RP,X2,Y2);
  23.   Draw(RP,X1,Y2);
  24.   
  25.   SetAPen(RP,TopEdgePen);  
  26.   Draw(RP,X1,Y1);
  27.   Draw(RP,X2,Y1);
  28. }
  29.  
  30.  
  31. /* This is the maximum number of points FillPoly will handle.
  32.    increase it if nessecary                                   */
  33. #define MAX_FILLPOLYPOINTS 20
  34.  
  35.   struct Point32
  36.   {
  37.     LONG X,Y;
  38.   };
  39.  
  40.  
  41. void FillPoly(struct RastPort *RP,ULONG Points, ...)
  42. {
  43.  
  44.   struct AreaInfo ai={0},*oldai;
  45.   __aligned UBYTE ab[5*MAX_FILLPOLYPOINTS];
  46.  
  47.   struct TmpRas tr,*oldtr;
  48.  
  49.   WORD minx,maxx,miny,maxy,sx,sy;
  50.   LONG l,points,*pntr;
  51.   struct Point32 *p;
  52.  
  53.   pntr  = &Points;
  54.   points= *pntr;
  55.  
  56.   if(points>MAX_FILLPOLYPOINTS)
  57.     return;
  58.     
  59.   pntr++;
  60.   p=(struct Point32 *)pntr;
  61.   
  62.   minx=miny= 32000;
  63.   maxx=maxy=-32000;
  64.  
  65.   for(l=0;l<points;l++)
  66.   {
  67.     minx=min(minx,p[l].X);
  68.     miny=min(miny,p[l].Y);
  69.     maxx=max(maxx,p[l].X);
  70.     maxy=max(maxy,p[l].Y);
  71.   }
  72.   sx=maxx-minx;
  73.   sy=maxy-miny;
  74.   
  75.   if( sx<100 && sy<100 )
  76.   {
  77.     ObtainSemaphore(&TRBMSem);
  78.     tr.RasPtr=TmpRasBM->Planes[0];
  79.     tr.Size=TmpRasBM->BytesPerRow * TmpRasBM->Rows;
  80.     oldtr=RP->TmpRas;
  81.     oldai=RP->AreaInfo;
  82.     RP->TmpRas=&tr;
  83.     RP->AreaInfo=&ai;
  84.     InitArea(&ai,ab,MAX_FILLPOLYPOINTS);
  85.     AreaMove(RP,p[0].X,p[0].Y);
  86.     for(l=1;l<points;l++)
  87.     {
  88.       AreaDraw(RP,p[l].X,p[l].Y);
  89.     }
  90.     AreaEnd(RP);
  91.     RP->TmpRas=oldtr;
  92.     RP->AreaInfo=oldai;
  93.     WaitBlit();
  94.     ReleaseSemaphore(&TRBMSem);
  95.   }
  96. }
  97.  
  98. void DrawPoly(struct RastPort *RP,LONG Count, ...)
  99. {
  100.   LONG count,*points;
  101.   LONG l;
  102.  
  103.   points = &Count;
  104.   count  = *points;
  105.  
  106.   points++;
  107.  
  108.   Move(RP,*points,*(points+1));
  109.   for(l=1;l<count;l++)
  110.   {
  111.     points+=2;
  112.     Draw(RP,*points,*(points+1));
  113.   }
  114. }
  115.  
  116. void MyRectFill(struct RastPort *RP,
  117.                  WORD X1, WORD Y1,
  118.                  WORD X2, WORD Y2)
  119. {
  120.   if(X2>=X1 && Y2>=Y1 && X1>=0 && Y1>=0)
  121.     RectFill(RP,X1,Y1,X2,Y2);
  122. }
  123.