#include <stdlib.h>     // abs()
#include <stdio.h>      // sprintf()

#include "graphic.h"

// Class Position //
Position::Position( void )
{
  x = 0;
  y = 0;
}

Position::Position( int x0, int y0 )
{
  x = x0;
  y = y0;
}
Position::Position( Position& p )
{
  x = p.getX();
  y = p.getY();
}

inline int  Position::getX( void )
{
  return x;
}
inline int  Position::getY()
{
  return y;
}

inline void Position::setX(int nx)
{
  x=nx;
}

inline void Position::setY(int ny)
{
  y=ny;
}

inline void Position::set(int nx, int ny)
{
  setX(nx);
  setY(ny);
};

inline Position Position::operator=  ( Position cp )
{
  set( cp.getX(), cp.getY() );
  return *this;
}

inline Bool Position::operator== ( Position& cp )
{
  return ( x==cp.x) && ( y==cp.y );
}

inline Bool Position::operator!= ( Position& cp )
{
  return ( x!=cp.x) || ( y!=cp.y );
}

inline Position Position::operator+  ( Position& cp )
{
  Position p;
  p.x = x + cp.x;
  p.y = y + cp.y;
  return p;
}

inline Position Position::operator-  ( Position& cp )
{
  Position p;
  p.x = x - cp.x;
  p.y = y - cp.y;
  return p;
}

inline Position& Position::operator+= ( Position& cp )
{
  x+=cp.x;
  y+=cp.y;
  return *this;
}

inline Position& Position::operator-= ( Position& cp )
{
  x-=cp.x;
  y-=cp.y;
  return *this;
}

// Class GObject
GObject::GObject( Screen* newScreen, int x0, int y0 )
  : Position( x0, y0 )
{
  screen = newScreen;
  color = screen->getFgc();
  cOldX = -1;
  cOldY = -1;
}

void GObject::move( int dx, int dy )
{
  restoreBackground();
  set( x+dx, y+dy );
  draw();
}

void GObject::moveTo( int newX, int newY )
{
  restoreBackground();
  set( newX, newY );
  draw();
}
void GObject::setColor( Color c )
{
  color = c;
}

void GObject::highlight()
{
   restoreBackground();
   setColor( screen->Red() );
   draw();
}

void GObject::drawPoint( int x, int y, Color c )
{
  if( c == -1 )
    c = color;
    screen->drawPoint( x, y , c );
}
