home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / QT MovieToolBox / RollPicture.c < prev   
Encoding:
C/C++ Source or Header  |  1994-01-19  |  6.7 KB  |  242 lines  |  [TEXT/KAHL]

  1. #include "gGlobals.h"
  2.  
  3. /*********************************************
  4. File:    RollPicture.c
  5.         By R. Mark Fleming.
  6.     
  7.     Roll a picture from left ot right, right to left,
  8.     up to down, down to up.
  9.     
  10.     History...
  11.     Dec. 1993    RMF    Modified for use with QuickTime code from other Pysc Animation projects.
  12.     
  13.     Options:
  14.     
  15.     fill = 0 if roll image around instead of sliding the image into the picture frame.
  16.     direction = four possible direction of movement supported.
  17.     stageNum = the stage image to be producted
  18.     totalStages = number of stage the image is to be used to create full transition.
  19. *********************************************/
  20.  
  21. void DoRoll(long stageNum,long totalStages, int direction, int fill)
  22. {
  23.     GWorldPtr    saveWorld;
  24.     GDHandle    saveGD;
  25.     RGBColor     opColor;
  26.     
  27.     register int i, steps;
  28.     Rect rTemp, rLeft, rRight, r, r2;
  29.     
  30.     if (totalStages == 0) { SysBeep(0); return; }
  31.     
  32.     rTemp = gWorld->portRect;
  33.     
  34.     if (direction == 1 || direction == 2)    i = rTemp.right - rTemp.left;
  35.     else     i = rTemp.bottom - rTemp.top;                /* Get Width or Height */
  36.     
  37.     if (totalStages >= i) {                                /* Get step size */
  38.         steps = 1;
  39.     } else steps = (i / ((long)totalStages)) + 1L;
  40.         
  41.     switch (direction) {                                /* Set starting pos. */
  42.         case 1:    /* Left to Right */
  43.             i = rTemp.left;    
  44.             break;
  45.         
  46.         case 2:    /* Right to Left */    
  47.             i = rTemp.right;    
  48.             break;
  49.             
  50.         case 3:    /* Roll Up */
  51.             i = rTemp.top;
  52.             break;
  53.         
  54.         case 4:    /* Roll Down */
  55.             i = rTemp.bottom;    
  56.             break;
  57.             }
  58.     
  59.         
  60.     do {
  61.     
  62.     r2 = r = rRight = rLeft = rTemp;                /* Use min. area of image */
  63.     if (stageNum) {
  64. #if 0
  65.     switch (direction) {
  66.         case 1:    /* Left to Right */
  67.             i += steps;
  68.             if (i >= rTemp.right) i = rTemp.left + steps;    
  69.             break;
  70.         
  71.         case 2:    /* Right to Left */    
  72.             i -= steps;
  73.             if (i < rTemp.left) i = rTemp.right - steps;    
  74.             break;
  75.             
  76.         case 3:    /* Roll Up */
  77.             i += steps;
  78.             if (i > rTemp.bottom) i = rTemp.top + steps;
  79.             break;
  80.         
  81.         case 4:    /* Roll Down */
  82.             i -= steps;
  83.             if (i < rTemp.top) i = rTemp.bottom - steps;    
  84.             break;
  85.             }
  86. #else
  87.     switch (direction) {
  88.         case 1:    /* Left to Right */
  89.             i += steps;
  90.             if (i >= rTemp.right) i = rTemp.right;    
  91.             break;
  92.         
  93.         case 2:    /* Right to Left */    
  94.             i -= steps;
  95.             if (i < rTemp.left) i = rTemp.left;    
  96.             break;
  97.             
  98.         case 3:    /* Roll Up */
  99.             i += steps;
  100.             if (i > rTemp.bottom) i = rTemp.bottom;
  101.             break;
  102.         
  103.         case 4:    /* Roll Down */
  104.             i -= steps;
  105.             if (i < rTemp.top) i = rTemp.top;    
  106.             break;
  107.             }
  108. #endif    
  109.         }
  110.         
  111.         if (direction == 1 || direction == 2) {        /* Left-Right scroll ! */
  112.             /*    Destinations...
  113.              *    +------------------------+--------------------+
  114.              *      L.left -- L.right      i  R.left -- R.right     */
  115.             rLeft.right = i;     /* Left Rect (dest of right over hang) */
  116.             rRight.left = i;    /* Right Rect (dest of left part of image)  */
  117.             /* Source... 
  118.              * +-----------------------+--------------------+
  119.              *  r2.left --- r2.right  L.left  r.left --- r.right */
  120.             r.left = r.right - (rLeft.right - rLeft.left);        /* Left Edge */
  121.             r2.right = r2.left + (rRight.right - rRight.left);    /* Right Edge */
  122.         } else {                                    /* up - down scroll ! */
  123.             /*    Destinations...
  124.              *    +------------------------+--------------------+
  125.              *      L.left -- L.right      i  R.left -- R.right     */
  126.             rLeft.bottom = i;     /* Top Rect (dest of right over hang) */
  127.             rRight.top = i;        /* Bottom Rect (dest of left part of image)  */
  128.             /* Source... 
  129.              * +-----------------------+--------------------+
  130.              *  r2.left --- r2.right  L.left  r.left --- r.right */
  131.             r.top = r.bottom - (rLeft.bottom - rLeft.top);        /* bottom Edge */
  132.             r2.bottom = r2.top + (rRight.bottom - rRight.top);    /* top Edge */
  133.             }
  134.             
  135.         } while (stageNum-- > 0);
  136.     
  137.     
  138.     GetGWorld(&saveWorld,&saveGD);
  139.  
  140.     SetGWorld(gDstWorld,nil);
  141.     
  142.         /*  Use offscreen buffer... setup image... */        
  143.     CopyBits( (BitMap*)*gWorld->portPixMap, (BitMap*)*gDstWorld->portPixMap, 
  144.                 &r, &rLeft, srcCopy, 0L);
  145.                 
  146.     if (fill == 0) 
  147.         CopyBits( (BitMap*)*gWorld->portPixMap, (BitMap*)*gDstWorld->portPixMap, 
  148.                     &r2, &rRight, srcCopy, 0l);    
  149.     else
  150.         EraseRect(&rRight);    
  151.  
  152.     SetGWorld(saveWorld,saveGD);
  153.     
  154. }
  155.  
  156.  
  157. void DoFlipIn(long stageNum,long totalStages, int direction)
  158. {
  159.     GWorldPtr    saveWorld;
  160.     GDHandle    saveGD;
  161.     RGBColor     opColor;
  162.     
  163.     register int i, steps;
  164.     Rect rLeft, rRight, r, r2;
  165.     
  166.     rLeft = gWorld->portRect;
  167.     i = rLeft.right - rLeft.left;
  168.     if (totalStages == 0) { SysBeep(0); return; }
  169.     if (totalStages > i) totalStages = i;
  170.     steps = (i / ((long)totalStages)) + 1L;
  171.     
  172.     if (direction == 1 || direction == 2)    i = gWorld->portRect.left + steps;
  173.     else     i = gWorld->portRect.top + steps;
  174.     
  175.     r2 = r = rRight = rLeft = gWorld->portRect;                /* Use min. area of image */
  176.     
  177.     do {
  178.     r2 = r = rRight = rLeft = gWorld->portRect;                /* Use min. area of image */
  179.     switch (direction) {
  180.         
  181.         case 1:    /* Left to Right */
  182.             i += steps;
  183.             if (i >= gWorld->portRect.right) i = gWorld->portRect.left + steps;    
  184.             break;
  185.         
  186.         case 2:    /* Right to Left */    
  187.             i -= steps;
  188.             if (i < gWorld->portRect.left) i = gWorld->portRect.right - steps;    
  189.             break;
  190.             
  191.         case 3:    /* Roll Up */
  192.             i += steps;
  193.             if (i > gWorld->portRect.bottom) i = gWorld->portRect.top + steps;
  194.             break;
  195.         
  196.         case 4:    /* Roll Down */
  197.             i -= steps;
  198.             if (i < gWorld->portRect.top) i = gWorld->portRect.bottom - steps;    
  199.             break;
  200.             }
  201.             
  202.         if (direction == 1 || direction == 2) {        /* Left-Right scroll ! */
  203.             /*    Destinations...
  204.              *    +------------------------+--------------------+
  205.              *      L.left -- L.right      i  R.left -- R.right     */
  206.             rLeft.right = i;     /* Left Rect (dest of right over hang) */
  207.             rRight.left = i;    /* Right Rect (dest of left part of image)  */
  208.             /* Source... 
  209.              * +-----------------------+--------------------+
  210.              *  r2.left --- r2.right  L.left  r.left --- r.right */
  211.             r.left = r.right - (rLeft.right - rLeft.left);        /* Left Edge */
  212.             r2.right = r2.left + (rRight.right - rRight.left);    /* Right Edge */
  213.         } else {                                    /* up - down scroll ! */
  214.             /*    Destinations...
  215.              *    +------------------------+--------------------+
  216.              *      L.left -- L.right      i  R.left -- R.right     */
  217.             rLeft.bottom = i;     /* Top Rect (dest of right over hang) */
  218.             rRight.top = i;        /* Bottom Rect (dest of left part of image)  */
  219.             /* Source... 
  220.              * +-----------------------+--------------------+
  221.              *  r2.left --- r2.right  L.left  r.left --- r.right */
  222.             r.top = r.bottom - (rLeft.bottom - rLeft.top);        /* bottom Edge */
  223.             r2.bottom = r2.top + (rRight.bottom - rRight.top);    /* top Edge */
  224.             }
  225.             
  226.         } while (stageNum-- > 0);
  227.     
  228.     
  229.     GetGWorld(&saveWorld,&saveGD);
  230.  
  231.     SetGWorld(gDstWorld,nil);
  232.     
  233.         /*  Use offscreen buffer... setup image... */        
  234.     CopyBits( (BitMap*)*gWorld->portPixMap, (BitMap*)*gDstWorld->portPixMap, 
  235.                 &r, &rLeft, srcCopy, 0L);
  236.                     
  237.     CopyBits( (BitMap*)*gAltWorld->portPixMap, (BitMap*)*gDstWorld->portPixMap, 
  238.                 &r2, &rRight, srcCopy, 0l);
  239.  
  240.     SetGWorld(saveWorld,saveGD);
  241.     
  242. }    /* End of () */