#include "circle.h"
#include "fstream.h"


Circle::Circle( Screen* newScreen, int x0, int y0, int r )
  : GObject( newScreen, x0, y0 )
{
  radius = r;
  bBuffer = NULL;
  savedBackground = 0;
}
/*
Circle::Circle( Circle& c )
 : GObject( c.screen, c.getX(), c.getY() )
{
  savedBackground =  c.savedBackground;
  if( savedBackground )
  {

  }
}

Circle::operator=( Circle& c )
{
}
*/

void Circle::draw( void )
{
  saveBackground();
  screen->drawCircle( x, y, radius, color );
}

void Circle::saveBackground( void )
{
  int x1, y1, w1, h1;
  x1 = x - radius;
  y1 = y - radius;
  w1 = radius + radius+1;
  h1 = radius + radius+1;

  bBuffer = screen->getArea( x1, y1, w1, h1 );
  savedBackground = 1;
}

void Circle::restoreBackground()
{
  if( savedBackground )
  {
    int x1, y1, w1, h1;
    x1 = x - radius;
    y1 = y - radius;
    w1 = radius + radius+1;
    h1 = radius + radius+1;
    screen->putArea( x1, y1, bBuffer );
    screen->freeArea( bBuffer );
    bBuffer = NULL;
    savedBackground = 0;
  }
}

Bool Circle::isOver( int x2, int y2 )
{
  int x1, y1, w1, h1;
  x1 = x + radius;
  y1 = y + radius;
  w1 = radius + radius;
  h1 = radius + radius;
  if( ((y2 - y1)<radius )  && ((x2 - x) < radius ) )
    return 1;
  return 0;

}

int Circle::North( void )
{
  return y - radius;
}

int Circle::South( void )
{
  return y + radius;
}

int Circle::East( void )
{
  return x + radius;
}

int Circle::West( void )
{
  return x - radius;
}


void Circle::setRadius( int r )
{
  radius = r ;
}
