/***************************************************************************
 *   Copyright (C) 2009 by Stefan Bühler                                   *
 *   stbuehler@web.de                                                      *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef TORUSCHESSFIELD2D_H
#define TORUSCHESSFIELD2D_H

#include "toruschess.h"
#include "piecelibrary.h"

#include <QWidget>
#include <QList>

/**
	@author Stefan Bühler <stbuehler@web.de>
*/
namespace toruschess {

	class Field2D : public QWidget {
	Q_OBJECT
	public:
		Field2D(Game *game, QWidget *parent = 0);
		virtual ~Field2D();
		
		void markMoves(const QList<Move> &moves);
		
		virtual QSize sizeHint() const;
		
	protected:
		virtual void paintEvent(QPaintEvent *event);
		virtual void mousePressEvent(QMouseEvent *event);
		virtual void mouseMoveEvent(QMouseEvent *event);
		virtual void mouseReleaseEvent(QMouseEvent *event);
		virtual void wheelEvent(QWheelEvent *event);
		
		void checkSizes();
		void updateFieldBuffer();
		
		Pos findPos(int x, int y);
		
	protected slots:
		void fieldUpdated();
		
	private:
		PieceLibrary *m_lib;
		Game *m_game;
		bool m_marked[8][8];
		QList<Move> m_markedMoves;
		
		int m_fieldWidth, m_fieldHeight;
		int m_originX, m_originY;
		
		int m_mouseLastX, m_mouseLastY;
		
		QImage *m_fieldBuffer;
	};

}

#endif
