// (c) MIT 2003.  All rights reserved.

package rec.house;

import java.util.*;
import java.awt.*;
import rec.util.*;
import rec.geo.*;
import rec.sys.*;
import rec.core.*;

public class MoveContainRecognizer extends MoveRecognizer
{
  public MoveContainRecognizer()
  {
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
   * This is called with every point added to the stroke.  If the 
   * rec returns WANT it gets full control of all added points,
   * UNSURE makes no comment, and DONT_WANT stops all calls.
   * 
   * DONT_WANT is not absolutely needed.  UNSURE works as well.
   */
  public int want( Surface s, rec.sys.Squiggle st, boolean ending )
  {
    if( movie == null ) {

      GPoint p = st.getFirstPoint();
	
      VisibleWidget vw = SelectPolyRecognizer.selectPoly( s, p );
      if ( vw == null )
	{
	  System.err.println( "normal selecting" );
	  GeometryCalculator calc = new GeometryCalculator( s );
	  vw = calc.findSelectedWidgets( p );
	}

      movie = vw;
      if( vw == null ) {
	Console.writeln( "nothing selected." );
	return( DONT_WANT );
      }
      else {
	Console.writeln( vw + " selected-- going to take it" );
	m_Offset_X = st.getFirstPoint().x -
	  movie.getLocation().getCenter().x;
	m_Offset_Y = st.getFirstPoint().y -
	  movie.getLocation().getCenter().y;
      }
    }
    
    if( st.getNumberOfPoints() > 5 )
      return( WANT );
    else
      return( UNSURE );
  }

}

////////////////////////////////////////////////////////////////////////////////
