#include <stdlib.h> // abs()
#include "point.h"

Point::Point( Screen* s )
 : GObject( s, 0 , 0 )
{
  circle = new Circle( screen );
  savedBackground = 0;
}

Point::Point( Screen* s, int x0, int y0 )
 : GObject( s, x0, y0 )
{
  circle = new Circle( screen );
  savedBackground = 0;
}

Point::Point( Point& p )
 : GObject( p.screen, p.getX(), p.getY() )
{
  circle = new Circle( screen );
  savedBackground = p.savedBackground;
  if( savedBackground )
    background = p.background;
}

Point::~Point( void )
{
}

// from class GObject

void Point::saveBackground( void )
{
  background = screen->getPoint( getX(), getY() );
  circle->saveBackground();
  savedBackground = 1;
}

void Point::restoreBackground( void )
{
  if( savedBackground )
  {
    circle->restoreBackground();
    screen->drawPoint( getX(), getY(), background );
  }
}

void Point::draw( void )
{
  saveBackground();
  screen->drawPoint( getX(), getY(), color );
}

void Point::highlight( int radius )
{
  saveBackground();
  circle->set( getX(), getY() );
  circle->setRadius( radius );
  circle->setColor( screen->Red() );
  circle->draw();
  screen->drawPoint( getX(), getY(), color );
}

#define DX 3
#define DY 3
int Point::isOver( int x0, int y0 )
{
  if( ( abs(x0 - x) < DX ) && ( abs(y0 - y) < DY ) )
    return 1;
  return 0;
}
