home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 13 / boot-disc-1997-09.iso / HyprWire / DATA.Z / UpperLeftTransition.java < prev    next >
Text File  |  1997-01-21  |  5KB  |  106 lines

  1. package kinetix.hyperc1.transitions;
  2.  
  3. import java.awt.Image;
  4. import java.awt.Rectangle;
  5. import java.awt.Point;
  6.  
  7. /* This sample TransitionPlugIn will slide the module     */
  8. /* to/from the upper left corner of the parent container. */
  9.  
  10. public class UpperLeftTransition extends UserTransition
  11.     {
  12.     Image m_image;
  13.     boolean m_show;
  14.  
  15.     Point m_offpos = new Point(0, 0);
  16.     Point m_offset = new Point(0, 0);
  17.  
  18.  
  19.     /* Constructor */
  20.     
  21.     public UpperLeftTransition()
  22.         {
  23.         }
  24.  
  25.     /* void init(Image image, Rectangle drawRect, Rectangle parentRect,    */
  26.     /*   Rectangle clipRect, int nFrames, int nMilliseconds, boolean show) */
  27.     /*                                                                     */
  28.     /*   Will be called at the start of each transition.                   */
  29.     /*     image = an image of the module (the background is transparent). */
  30.     /*     drawRect = the position of the image on the applet.             */
  31.     /*     parentRect = the position of the parent container.              */
  32.     /*     clipRect = the clipping rectangle for the transition, is equal  */
  33.     /*                to the entire window on entry.                       */
  34.     /*     nFrames = the number of frames to be drawn.                     */
  35.     /*     nMilliseconds = the duration of the transition.                 */
  36.     /*     show = true for show, false for hide.                           */
  37.     /*                                                                     */
  38.     /*   drawRect and clipRect may be modified by changing the members.    */
  39.     /*   drawRect may also be modified in the calls to getFrame(...).      */
  40.     /*                                                                     */
  41.     /*   You cannot call getGraphics() on the image passed in because it   */
  42.     /*   is created with java.awt.image.MemoryImageSource and has a        */
  43.     /*   transparent background.                                           */
  44.  
  45.     public void init(Image image, Rectangle drawRect, Rectangle parentRect,
  46.         Rectangle clipRect, int nFrames, int nMilliseconds, boolean show)
  47.         {
  48.         m_image = image;
  49.         m_show = show;
  50.  
  51.         /* Set the clipRect for the transition to the parent container */
  52.         clipRect.x = parentRect.x;
  53.         clipRect.y = parentRect.y;
  54.         clipRect.width  = parentRect.width;
  55.         clipRect.height = parentRect.height;
  56.  
  57.         /* Calculate the position of the module when outside the container */
  58.         m_offpos.x = parentRect.x - drawRect.width;
  59.         m_offpos.y = parentRect.y - drawRect.height;
  60.  
  61.         /* Calculate the offset between successive frames */
  62.         m_offset.x = (m_offpos.x - drawRect.x) / (nFrames + 1);
  63.         m_offset.y = (m_offpos.y - drawRect.y) / (nFrames + 1);
  64.         }
  65.  
  66.     /* Image getFrame(int iframe, Rectangle srcRect, Rectangle drawRect) */
  67.     /*                                                                   */
  68.     /*   Will be called once for each frame to be drawn.                 */
  69.     /*   A modified image may be returned on each call.                  */
  70.     /*                                                                   */
  71.     /*   srcRect = The portion of the returned image to be drawn.        */
  72.     /*   drawRect = The location for this frame on the applet window.    */
  73.     /*              The source image will be stretched to fit drawRect.  */
  74.     /*                                                                   */
  75.     /*   srcRect will be the size of the original image on the first     */
  76.     /*   frame (iframe = 0).                                             */
  77.     /*   Both of the rectangles may be modified by changing the members. */
  78.     /*   Any changes to the rectangles will be retained on successive    */
  79.     /*   calls to getFrame().                                            */
  80.  
  81.     public Image getFrame(int iframe, Rectangle srcRect, Rectangle drawRect)
  82.         {
  83.         if (iframe == 0)        /* First frame */
  84.             {
  85.             if (m_show)         /* if showing, start outside the container */
  86.                 {
  87.                 drawRect.x = m_offpos.x;
  88.                 drawRect.y = m_offpos.y;
  89.  
  90.                 m_offset.x = -m_offset.x;
  91.                 m_offset.y = -m_offset.y;
  92.                 }
  93.             }
  94.  
  95.         drawRect.x += m_offset.x;  /* Move the image on each frame */
  96.         drawRect.y += m_offset.y;
  97.  
  98.         return m_image;
  99.         }
  100.  
  101.     public void reset()         /* Release images, memory, etc. */
  102.         {
  103.         m_image = null;
  104.         }
  105.     }
  106.