/***************************************************************************
                          board_2d.h  -  description
                             -------------------
    begin                : Fri Feb 28 2003
    copyright            : (C) 2003 by The Knights Project
    email                : knights-general@lists.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef BOARD_2D_H
#define BOARD_2D_H

#include <board_base.h>
#include <tqpixmap.h>
#include <tqptrlist.h>

/**
  *@author The Knights Team
  */

struct sprite
{
	bool Restore;
	int Steps;
	int POSITION_Origin;
	int POSITION_Destination;
	int POSITION_TargetTaken;
	TQPoint POINT_Origin;
	TQPoint POINT_Current;
	TQPoint POINT_LastUpdate;
	TQPoint POINT_Destination;
	TQPixmap PIXMAP_Sprite;
	TQPixmap PIXMAP_FlipFrame;
};

typedef TQPtrList<sprite> SpriteList;
class KnightsPixCache;

class board_2d : public board_base
{
	Q_OBJECT
  
	public: 
											board_2d(TQWidget *parent=0, const char *name=0, resource *Rsrc=0, logic *Lgc=0);
											~board_2d();
		virtual void			drawMove( const ChessMove &chessMove, const bool &reverse=FALSE );
		virtual void			setPremovePositions( const int&, const int& );
		virtual void			redrawLights( void );
		void							paintEvent( TQPaintEvent *event );
		void							mouseReleaseEvent( TQMouseEvent *event );
		void							mousePressEvent( TQMouseEvent *event );
		void							mouseMoveEvent( TQMouseEvent *event );

	public slots:
		virtual void			resizeBoard( void );
		virtual void			redrawAll( void );
		virtual void			drawPosition( const int& );
		virtual void			commit( void );

	protected:
		void							drawCoords( TQPixmap *pic, const int &pos );
		TQPoint						coords( const int&, const int&);
		int								position( const TQPoint& );
		void							drawSprites( void );
		TQPixmap						getChessman( const int &pos );
		bool							isSprite( const int &pos );
		void							myBlit( const TQPoint &dp, const TQPaintDevice *src, const TQRect &sr );

	protected slots:
		void							updateSprites( void );

	private:
		SpriteList				sprites;
		sprite						*DragSprite;
		KnightsPixCache		*cache;
		TQPixmap						myself;
		TQPoint						pressPoint;
		bool							orientation;
		bool							lastMoveWasDrag;
		bool							init;

		int								updateX1;
		int								updateY1;
		int								updateX2;
		int								updateY2;

		/* Premove Positions */
		int								premoveFrom;
		int								premoveTo;
};

#endif
