package visual.dynamic.sampled;

import java.awt.*;
import java.awt.geom.*;

/**
 * A wipe that moves across the image right, left, up, or down
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class LineWipe extends RectangleWipe
{
    private int               direction;

    public static final int   DOWN  = 0;
    public static final int   LEFT  = 1;
    public static final int   RIGHT = 2;
    public static final int   UP    = 3;


    /**
     * Explicit Value Constructor
     *
     * @param direction UP, DOWN, RIGHT, or LEFT
     * @param first     The first frame
     * @param duration  The duration (in frames)
     */
    public LineWipe(int direction, int first, int duration)
    {
       super(first, duration);

       if ((direction >= DOWN) && (direction <= UP)) 
       {
          this.direction = direction;
       } 
       else 
       {
          this.direction = DOWN;
       }
    }

//[calculateClip.

    /**
     * Calculate the size of the clip rectangle
     *
     * @param width   The width  of the image
     * @param height  The height of the image
     * @param frame   The frame of the wipe
     */
    protected Rectangle2D calculateClip(float width,
					float height,
                                        int frame)
    {
       float              h, w, x, y;
       Rectangle2D        clip;


       w = width;
       h = height;
       x = 0.0f;
       y = 0.0f;
	
       if        (direction == RIGHT) 
       {
          w = scale*frame*width;
          h = height;
          x = 0.0f;
          y = 0.0f;
       } 
       else if (direction == LEFT) 
       {
          w = scale*frame*width;
          h = height;
          x = width - w;
          y = 0.0f;
       } 
       else if (direction == UP) 
       {
          w = width;
          h = scale*frame*height;
          x = 0.0f;
          y = height - h;
       } 
       else
       {
          w = width;
          h = scale*frame*height;
          x = 0.0f;
          y = 0.0f;
       }

       clip = new Rectangle2D.Float(x, y, w, h);

       return clip;
    }
//]calculateClip.
}
