home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / BlobMgr / Library Folder / Pict.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  2.7 KB  |  98 lines  |  [TEXT/KAHL]

  1. /* -------------------------------------------------------------------- */
  2. /*                        Blob Picture Creation Routines                    */
  3. /* -------------------------------------------------------------------- */
  4.  
  5. # include    "BlobMgr.h"
  6.  
  7.  
  8. /*
  9.  * Internal picture drawing scratch variables
  10.  */
  11.  
  12. static PicHandle    picHand;
  13. static Rect            picRect = { -30000, -30000, 30000, 30000 };
  14.  
  15.  
  16. pascal void
  17. OpenBlob (void)
  18. {
  19.     picHand = OpenPicture (&picRect);
  20. }
  21.  
  22.  
  23. /*
  24.  * Close a picture blob.  The picture that was begin with OpenBlob is
  25.  * installed in the blob record and the blob type is set to picture
  26.  * (as opposed to proc) blob.  The picture is replayed with a frame
  27.  * that is the union of the bounding boxes of the static and drag regions.
  28.  * This will usually be sufficiently reasonable to avoid the problem
  29.  * of overflow that sometimes results from scaling the clipping region
  30.  * when a picture is drawn in a different size than the original.
  31.  * The dragRect and statRect fields are set to those rects bounding
  32.  * the parts of the picture corresponding to the two regions.  These
  33.  * are used to cope in the event that the blob is moved or resized.
  34.  * (See DrawBlob() and DrawBlobPic().)
  35.  *
  36.  * ClosePicBlob() does NOT set the blob's regions.  That must be done
  37.  * by the caller after calling ClosePicBlob().
  38.  */
  39.  
  40. static void
  41. ClosePicBlob (BlobHandle b, Rect *dragRect, Rect *statRect)
  42. {
  43. Rect        pRect;
  44. PicHandle    p;
  45. RgnHandle    oldClip;
  46.  
  47.     ClosePicture ();            /* stop saving picture definition */
  48.     DisposeBlobPic (b);            /* toss any pic the blob might have had */
  49.     UnionRect (dragRect, statRect, &pRect);
  50.     oldClip = NewRgn ();
  51.     GetClip (oldClip);
  52.     ClipRect (&pRect);                /* avoid clipping problem on picture */
  53.     p = OpenPicture (&pRect);        /* replay later on - this prevents */
  54.     DrawPicture (picHand, &picRect);    /* overflow if pic is scaled up */
  55.     ClosePicture ();
  56.     KillPicture (picHand);            /* don't need original picture now */
  57.     SetClip (oldClip);
  58.     DisposeRgn (oldClip);
  59.     (**b).bPicProc.bPic = p;
  60.  
  61.     (**b).dragRect = *dragRect;        /* install original drag Rect */
  62.     (**b).statRect = *statRect;        /* install original static Rect */
  63.  
  64.     SetBlobFlags (b, bPicMask);            /* set type as picture blob */
  65. }
  66.  
  67.  
  68. /*
  69.  * Close a picture blob whose regions are defined by rectangles.
  70.  */
  71.  
  72. pascal void
  73. CloseRectBlob (BlobHandle b, Rect *dragRect, Rect *statRect)
  74. {
  75.     ClosePicBlob (b, dragRect, statRect);
  76.     SetBlobRects (b, dragRect, statRect);
  77.     if (BlobEnabled (b))
  78.         DrawBlob (b, inFullBlob);
  79. }
  80.  
  81.  
  82. /*
  83.  * Close a picture blob.
  84.  */
  85.  
  86. pascal void
  87. CloseRgnBlob (BlobHandle b, RgnHandle dragRgn, RgnHandle statRgn)
  88. {
  89. Rect    dragRect, statRect;
  90.  
  91.     dragRect = (**dragRgn).rgnBBox;
  92.     statRect = (**statRgn).rgnBBox;
  93.     ClosePicBlob (b, &dragRect, &statRect);
  94.     SetBlobRgns (b, dragRgn, statRgn);
  95.     if (BlobEnabled (b))
  96.         DrawBlob (b, inFullBlob);
  97. }
  98.