home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 274.lha / SimGen_Src / RECTCOPY.c < prev    next >
C/C++ Source or Header  |  1989-07-26  |  8KB  |  317 lines

  1. #include <exec/types.h>
  2. #include <graphics/rastport.h>
  3. #include "picture.h"
  4. #include "sizedefs.h"
  5. #include "rectcopy.h"
  6.  
  7. int ClipLeft    = 0;
  8. int ClipTop    = 0;
  9. int ClipWidth    = WIDTH;
  10. int ClipHeight    = HEIGHT;
  11.  
  12. #define PICX        ClipLeft
  13. #define PICY        ClipTop
  14. #define FrameWidth    ClipWidth
  15. #define FrameHeight    ClipHeight
  16.  
  17. #if USE_RECTCOPY
  18. /*
  19.  * This routines copies a rectangular area from one RastPort to another.
  20.  * It is almost the same as the operating system routine ClipBlit ()
  21.  * Except this routine checks to make sure it has something to do and
  22.  * it clips to copy to the defined screen size.
  23.  *
  24.  * SYNTAX:
  25.  *  RectCopy (SrcRp, SrcX, SrcY, DestRp, DestX, DestY, width, height);
  26.  *
  27.  *    SrcRp = a pointer to the Source RastPort
  28.  *    SrcX, SrcY = top,left corner to start copying from
  29.  *    DestRp = pointer to the Destination RastPort
  30.  *    DestX, DestY = top,left corner to start copying to
  31.  *    width,height = width and height of rectangle to copy
  32.  */
  33. RectCopy (From, FLeft, FTop, To, TLeft, TTop, width, height)
  34. struct RastPort *From;
  35. int FLeft, FTop;
  36. struct RastPort *To;
  37. int TLeft, TTop;
  38. int width, height;
  39. {
  40.     if (width && height) {
  41.         ClipCopy (From, FLeft, FTop,
  42.               To  , TLeft, TTop,
  43.               width, height,
  44.                  0xC0, USECLIPBLIT);
  45.     }
  46. }
  47. #endif
  48.  
  49. /*
  50.  * This routine copies a Rectangular area from a 'Shape' to a RastPort with
  51.  * 'Transparency'  The transparent color is defined by the color that was
  52.  * transparent when the brush/shape was save from DPaint.
  53.  *
  54.  * SYNTAX:
  55.  *  ShapeCopy (Shape, SrcX, SrcY, RastPort, DestX, DestY, width, height);
  56.  *
  57.  *    Shape = a pointer to a Shape
  58.  *    SrcX, SrcY = top,left corner to start copying from
  59.  *    RastPort = Destination RastPort
  60.  *    DestX, DestY = top,left corner to start copying to
  61.  *    width,height = width and height of rectangle to copy
  62.  */
  63.  
  64. #if USE_SHAPECOPY
  65. ShapeCopy (shape, FLeft, FTop, To, TLeft, TTop, width, height)
  66. Shape *shape;
  67. int FLeft, FTop;
  68. struct RastPort *To;
  69. int TLeft, TTop;
  70. int width, height;
  71. {
  72.     if (width > 0 && height > 0) {
  73.         ClipCopy (ShapePic(shape), FLeft, FTop,
  74.               To        , TLeft, TTop,
  75.               width, height,
  76.               0xE0, USEBLTMASKBITMAPRASTPORT, NULL,
  77.               shape->MaskBm.Planes[0]);
  78.     }
  79. }
  80. #endif
  81.  
  82. /*
  83.  * ClipCopy copies a rectanglar area from the Source RastPort to the
  84.  * Destination RastPort and clips the copy to the defined area.
  85.  *
  86.  * SYNTAX:
  87.  *  ClipCopy (SrcRp, SrcX, SrcY, DestRp, DestX, DestY, width, height);
  88.  *
  89.  *    SrcRp = a pointer to the Source RastPort
  90.  *    SrcX, SrcY = top,left corner to start copying from
  91.  *    DestRp = pointer to the Destination RastPort
  92.  *    DestX, DestY = top,left corner to start copying to
  93.  *    width,height = width and height of rectangle to copy
  94.  *
  95.  *  PICX = left side of area to clip to
  96.  *  PICY = top side of area to clip to
  97.  *  FrameWidth = width of area to clip to
  98.  *  FrameHeight = height to area to clip to
  99.  */
  100.  
  101. ClipCopy (From, FLeft, FTop, To, TLeft, TTop, InWidth, InHeight, minterm,
  102.  type, planemask, bitmask)
  103. struct RastPort *From;
  104. int FLeft, FTop;
  105. struct RastPort *To;
  106. int TLeft, TTop;
  107. int InWidth, InHeight;
  108. int minterm;
  109. UBYTE type;
  110. UBYTE planemask;
  111. UWORD *bitmask;
  112. {
  113.     int width = InWidth; 
  114.     int height = InHeight;
  115.  
  116.     if (TLeft < PICX) {
  117.         width = InWidth - (PICX - TLeft);
  118.         TLeft = PICX;
  119.         FLeft += InWidth - width;
  120.     } else if (TLeft > PICX + FrameWidth - InWidth) {
  121.         width = (PICX + FrameWidth) - TLeft;
  122.     }
  123.  
  124.     if (TTop < PICY) {
  125.         height = InHeight - (PICY - TTop);
  126.         TTop = PICY;
  127.         FTop += InHeight - height;
  128.     } else  if (TTop > PICY + FrameHeight - InHeight) {
  129.         height = (PICY + FrameHeight) - TTop;
  130.     }
  131.  
  132.     if (width > 0 && height > 0) {
  133.         switch (type) {
  134.             case USECLIPBLIT:
  135.                 ClipBlit (From, FLeft, FTop,
  136.                       To  , TLeft, TTop,
  137.                       width, height,
  138.                          minterm);
  139.                 break;
  140.             case USEBLTBITMAP:
  141.                 BltBitMap (From->BitMap, FLeft, FTop,
  142.                        To->BitMap  , TLeft, TTop,
  143.                        width, height,
  144.                        minterm, planemask,
  145.                        NULL); /* May need "temp rast" */
  146.                 break;
  147.             case USEBLTBITMAPRASTPORT:
  148.                 BltBitMapRastPort (From->BitMap, FLeft, FTop,
  149.                            To          , TLeft, TTop,
  150.                            width, height,
  151.                            minterm);
  152.                 break;
  153.             case USEBLTMASKBITMAPRASTPORT:
  154.                 BltMaskBitMapRastPort (From->BitMap, FLeft, FTop,
  155.                                To          , TLeft, TTop,
  156.                                width, height,
  157.                                minterm, bitmask);
  158.                 break;
  159.                 }
  160.  
  161.     }
  162. }
  163.  
  164. #if USE_ERASESHAPE
  165. /*
  166.  * EraseShape draws a rectangle in the specified rastport the size of
  167.  * the entire shape specified in the specified color at the specified
  168.  * place.
  169.  *
  170.  * SYNTAX:
  171.  *   EraseShape (DestRp, Shape, DestX, DestY, Color)
  172.  *
  173.  *    DestRp = pointer to the Destination RastPort
  174.  *    Shape = pointer to a Shape
  175.  *    DestX, DestY = top,left corner to start drawing rectangle
  176.  *    Color = Color to draw rectangle with
  177.  */
  178.  
  179. EraseShape (rp, shape, left, top, color)
  180. struct RastPort *rp;
  181. Shape        *shape;
  182. int         left;
  183. int        top;
  184. int        color;
  185. {
  186.     SetAPen (rp, color);
  187.     ClipRectFill (rp, left, top,
  188.         ShapeWidth(shape),
  189.         ShapeHeight(shape));
  190. }
  191. #endif
  192.  
  193. #if USE_DRAWSHAPE
  194. /*
  195.  * DrawShape transparently copies an entire shape to a desired rastport
  196.  *
  197.  * SYNTAX:
  198.  *   DrawShape (DestRp, Shape, DestX, DestY);
  199.  *
  200.  *     DestRp = pointer to destination rastport
  201.  *     Shape = pointer to a shape
  202.  *     DestX, DestY = top,left corner to copy shape to
  203.  */
  204.  
  205. DrawShape (rp, shape, left, top)
  206. struct RastPort *rp;
  207. Shape        *shape;
  208. int         left;
  209. int        top;
  210. {
  211.     ShapeCopy (shape, 0, 0,
  212.         rp, left, top,
  213.         ShapeWidth(shape),
  214.         ShapeHeight(shape));
  215. }
  216. #endif
  217.  
  218. #if USE_DRAWPIC
  219. /*
  220.  * DrawPic copies an entire picture to a desired rastport
  221.  *
  222.  * SYNTAX:
  223.  *   DrawPic (DestRp, Pic, DestX, DestY);
  224.  *
  225.  *     DestRp = pointer to destination rastport
  226.  *     Pic = pointer to a picture
  227.  *     DestX, DestY = top,left corner to copy shape to
  228.  */
  229.  
  230. DrawPic (rp, pic, left, top)
  231. struct RastPort *rp;
  232. Picture        *pic;
  233. int         left;
  234. int        top;
  235. {
  236.     RectCopy (pic, 0, 0,
  237.         rp, left, top,
  238.         PicWidth(pic),
  239.         PicHeight(pic));
  240. }
  241. #endif
  242.  
  243. #if USE_CLIPRECTFILL
  244. /*
  245.  * ClipRectFill draws a solid rectangle to the specified rastport in the
  246.  * current foreground color.  It is the same as the OS routine RectFill()
  247.  * except ClipRectFill clips to the defined area.
  248.  *
  249.  * SYNTAX:
  250.  *   ClipRectFill (Rp, left, top, width, height)
  251.  *
  252.  *   Rp = pointer to rastport to draw rectangle into
  253.  *   left,top = top,left corner of rectangle
  254.  *   width,height = width and height to rectangle
  255.  */
  256.  
  257. ClipRectFill (rp, left, top, width, height)
  258. struct RastPort    *rp;
  259. int        left;
  260. int        top;
  261. int        width;
  262. int        height;
  263. {
  264.     if (left < PICX) left = PICX;
  265.     if (left >= PICX + FrameWidth) return;
  266.     if (top < PICY) top = PICY;
  267.     if (top >= PICY + FrameHeight) return;
  268.     if (left + width > PICX + FrameWidth) width = (PICX + FrameWidth) - left;
  269.     if (left + width < PICX) return;
  270.     if (top + height > PICY + FrameHeight) height = (PICY + FrameHeight) - top;
  271.     if (top + height < PICY) return;
  272.  
  273.     RectFill (rp, left, top, left + width - 1, top + height - 1);
  274. }
  275. #endif
  276.  
  277. #if USE_MATTE
  278. void Matte (shape, fleft, ftop, rp, tleft, ttop, width, height)
  279.     Shape        *shape;
  280.     int         fleft;
  281.     int        ftop;
  282.     struct RastPort *rp;
  283.     int         tleft;
  284.     int        ttop;
  285.     int        width;
  286.     int        height;
  287. {
  288.     UBYTE oldmask;
  289.  
  290.     oldmask = rp->Mask;
  291.     rp->Mask = ~rp->FgPen;
  292.     ClipCopy (shape, fleft, ftop,
  293.           rp   , tleft, ttop, width, height,
  294.           0x20, USECLIPBLIT);
  295.     rp->Mask = rp->FgPen;
  296.     ClipCopy (shape, fleft, ftop,
  297.           rp   , tleft, ttop, width, height,
  298.           0xE0, USECLIPBLIT);
  299.     rp->Mask = oldmask;
  300. }
  301. #endif
  302.  
  303. #if USE_DRAWMATTE
  304. void DrawMatte (rp, shape, left, top)
  305.  
  306.     struct RastPort *rp;
  307.     Shape        *shape;
  308.     int         left;
  309.     int        top;
  310. {
  311.     Matte (shape, 0, 0,
  312.         rp, left, top,
  313.         ShapeWidth(shape),
  314.         ShapeHeight(shape));
  315. }
  316. #endif
  317.