#ifndef __LINE_H
#define __LINE_H

#include "graphic.h"
#include "list/list.h"

static const MAXLINE=1000;

// prototyping
class Function;

//
// class Line
//
class Line : public GObject
{
  public:
    friend class SaveFunction;
    friend class RestoreFunction;
    friend class SplitLineFunction;
    friend class MLine;

    Line( Screen* screen, int x1=0, int y1=0, int x2=0, int y2=0 );
    Line( Line& line ); // Copyconstructor
    virtual Line& operator= ( Line& line );
    virtual ~Line( void );

    virtual void draw( void );
    virtual void draw( int x1, int y1, int x2, int y2 );
    virtual void restoreBackground( void );
    virtual void saveBackground( void );
    virtual ZeigerListe<Line>* split( void );

    virtual void set( int x1, int y1, int x2=-1, int y2=-1 );

    virtual Bool isOver( int x, int y );
    //virtual void doFunction( Function& );
    virtual int getX1( void ) { return x+cDx; }
    virtual int getY1( void ) { return y+cDy; }
    virtual void mirror( void );
    virtual int isMarked( void ) { return marked; };
    virtual void mark( void ) { marked = 1; };
    virtual void unmark( void ) { marked = 0; };
    //virtual void highlight();
    virtual int North( void );
    virtual int South( void );
    virtual int East( void );
    virtual int West( void );
  protected:
    void bresenham( Function& func, int x1 = -1, int y1 = -1 , int x2 = -1, int y2 = -1 );

    Color buffer[MAXLINE];
    int iLX1, iLY1, iLX2, iLY2; // fuer bresenham benoetigt
    int cDx, cDy;               // Position des Endpunktes relativ zum Startpunkt
    int marked;
};

typedef ZeigerListe<Line> LineList;

//
// Class MLine, Marked Line
//
class MLine: public Line
{
  public:
    MLine( Screen* screen, int x1=0, int y1=0, int x2=0, int y2=0 )
      : Line( screen, x1, y1, x2, y2 ){};
    MLine( Line& line) : Line( line.screen, line.getX(), line.getY() )
    {
      Line::operator=(line);
    };
    virtual ~MLine( void ) {};
    virtual void draw( void );
};

typedef ZeigerListe<MLine> MLineList;

//
// Klasse Funktor fuer Line::bresenham()
//
class Function
{
  public:
    virtual void function( int, int ) = 0;
};

class DrawFunction: public Function
{
  public:
    DrawFunction( Line* nLine ) { line = nLine; }
    void function( int x, int y );
  protected:
    Line* line;
};

class SaveFunction: public Function
{
  public:
    SaveFunction( Line* nLine ) { line = nLine; i = 0; }
    void function( int x, int y );
  protected:
    Line* line;
    int i;
};

class RestoreFunction: public Function
{
  public:
    RestoreFunction( Line* nLine ) { line = nLine; i = 0; }
    void function( int x, int y );
  protected:
    Line* line;
    int i;
};

class IsOverFunction: public Function
{
  public:
    IsOverFunction( int x, int y ) { fx = x; fy = y ; over = 0; }
    void function( int x, int y );

    Bool over;

  protected:
    int fx, fy;
};

class SplitLineFunction: public Function
{
  public:
    friend class Line;
    SplitLineFunction( Line* line );

    void function( int x, int y );

  protected:
    int startX, startY;
    int oldX, oldY;
    ZeigerListe<Line>* list;
};
#endif // __LINE_H
