
// Ashok Sivakumar        6.030 Final Project 
// 12/04/99

package breakout;

import java.awt.*;
import java.awt.event.*;
import cs101.awt.*;
import cs101.io.*;				/*  Necessary import statements */
import java.io.*;
import cs101.net.*;

/* This class keeps track of the mouse position at any time on the screen
   It is the Listener for class Screen Canvas and is meant for the user
   to be able to move the paddle in an easy and convenient manner.  */
   
public class MouseTracker extends MouseMotionAdapter
{
  private ScreenCanvas sc;
  
  
  //constructor: takes a Screen Canvas and sets field
  
  public MouseTracker (ScreenCanvas screenCan)
  {
  		this.sc = screenCan;	
  }
  
  
  /******* User has option of either dragging or moving mouse  *******/
  
  
  public void mouseDragged (MouseEvent e)
  {
  	int dragx = e.getX();
  	int dragy = e.getY();
  	
  	// can only move mouse if mouse pointer is near area of paddle 
  	
  	if ( ((dragx) <= this.sc.xMax - 40)
		&& ((dragx) >= this.sc.xMin + 40)
 		&& ((dragy) >= this.sc.CanvasPaddleUL.y - 10)
		&& ((dragy) <= this.sc.CanvasPaddleLR.y + 10) )
		{
			this.sc.mouseMovePaddle(dragx, dragy); // method to move paddle to current location
		}
  }
  		
  	
  public void mouseMoved (MouseEvent e)
  {
  		this.mouseDragged(e);
  }
  
}