//****************************************************************************
//Copyright (C) 2005-2006 Beijing BlueDJ Technology Co.,Ltd. All rights reserved.

//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 (in the file LICENSE.GPL); if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

//Please visit http://www.bluedj.com for more infomation about us.
//Contact us at ggwizard@gmail.com or darkdong@gmail.com.
//****************************************************************************/

#ifndef __DJGAME_GAMEPANEL_IMAGEITEM_H__
#define __DJGAME_GAMEPANEL_IMAGEITEM_H__

#include<QtGui>
#include <Qt3Support>
#include "DJBaseGlobal.h"
#include "DJGamePanel.h"
#include "DJGameUser.h"

#define DJGAME_DESKTOP_TID_AVATAR					0x1
#define DJGAME_DESKTOP_TID_USERNAME					0x2
#define DJGAME_DESKTOP_TID_TIMER					0x3

#define DJGAME_DESKTOP_TID_RULE_BASETEXT				0x04
#define DJGAME_DESKTOP_TID_RULE_BASETIME				0x14
#define DJGAME_DESKTOP_TID_RULE_FASTTEXT				0x05
#define DJGAME_DESKTOP_TID_RULE_FASTTIME				0x15
#define DJGAME_DESKTOP_TID_RULE_TIMEOUTTEXT				0x06
#define DJGAME_DESKTOP_TID_RULE_TIMEOUTTIME				0x16

#define DJGAME_DESKTOP_TYPE_PLAYER					0x01
#define DJGAME_DESKTOP_TYPE_TIMER					0x3
#define DJGAME_DESKTOP_TYPE_RULE					0x04

#define DJGAME_DESKTOP_TID_GAMEDEFINE				0x100
#define DJGAME_DESKTOP_TYPE_GAMEDEFINE				0x100


static const int djgame_imageRTTI = 984576;
static const int djgame_lineRTTI = 9889576;
static const int djgame_textRTTI = 9009576;
static const int djgame_spriteRTTI = 90097432;
class DJ_BASE_EXPORT DJGameImageItem: public Q3CanvasRectangle
{
public:
    DJGameImageItem( QImage img, Q3Canvas *canvas,QMatrix &m,unsigned short tid,unsigned short sid,unsigned short type,bool bMovable);
    int 	rtti () const { return djgame_imageRTTI; }
    bool	hit( const QPoint&) const;
    void	setMark( bool flag );
    bool	isMarked();
    QPen	pen() const;
    void	setPen( const QPen& pen );
	unsigned short type();
	unsigned short tid();
	unsigned short sid();
	bool movable();
	void setMovable(bool b);
	void setMatrix(QMatrix &);
	void setStaticMatrix(QMatrix &);
	void move(double x, double y);
	double	x();
	double 	y();
	int width ();
	int height ();
	
	void setVAlignment(quint16 align);
	void setHAlignment(quint16 align);
	
	void changeImage( QImage &img);
	QPixmap getPixmap() const;
protected:
    virtual void drawShape( QPainter &p );
private:
	unsigned short c_tid,c_sid,c_type;
    QImage image;
    QPixmap pixmap;
    QPen 	m_pen;
    bool	c_bMark;
	bool 	c_bMovable;
	QMatrix c_matrix,c_staticMatrix;
	qreal c_x,c_y;

	quint16   c_vAlignment,c_hAlignment;
};

class DJ_BASE_EXPORT DJGameLineItem:public Q3CanvasLine
{
	public :
		DJGameLineItem(Q3Canvas * canvas,QMatrix &m,unsigned short tid,unsigned short sid,unsigned short type,bool bMovable=false);
		~DJGameLineItem();
		int 	rtti () const { return djgame_lineRTTI; }
		unsigned short type();
		unsigned short tid();
		unsigned short sid();
		bool movable();
		void setMovable(bool b);
		void setPoints ( int xa, int ya, int xb, int yb );
		void setMatrix(QMatrix &);
	private :
		bool c_bMovable;
		unsigned short c_tid,c_sid,c_type;
		QMatrix c_matrix;
		qreal c_x,c_y;
		int c_xa,c_ya,c_xb,c_yb;
};

class DJ_BASE_EXPORT DJGameTextItem:public Q3CanvasText
{
	public :
		DJGameTextItem(const QString &t,Q3Canvas * canvas,QMatrix &m,unsigned short tid,unsigned short sid,unsigned short type,bool bMovable=false);
		~DJGameTextItem();
		int 	rtti () const { return djgame_textRTTI; }
		bool movable();
		void setMovable(bool b);
		unsigned short type();
		unsigned short tid();
		unsigned short sid();
		
		double x();
		double y();
		void move(double x, double y);
		void setMatrix(QMatrix &m);
		void setStaticMatrix(QMatrix &);
		QFont font();
		void setFont( const QFont & f );
		
		void setVAlignment(quint16 align);
		void setHAlignment(quint16 align);

	private :
		bool c_bMovable;
		unsigned short c_tid,c_sid,c_type;
		QMatrix c_matrix,c_staticMatrix;
		quint16   c_vAlignment,c_hAlignment;
		qreal c_x,c_y;
	
	QFont c_font;
};

class DJ_BASE_EXPORT DJGameDesktopSpriteItem : public Q3CanvasSprite
{
	public :
		DJGameDesktopSpriteItem( QMatrix &m,Q3CanvasPixmapArray * a, Q3Canvas * cv );
		~DJGameDesktopSpriteItem();
		int 	rtti () const { return djgame_spriteRTTI; }
	
		double x();
		double y();
		void move(double x, double y);
		void setMatrix(QMatrix &m);
		void setStaticMatrix(QMatrix &);
		void setVAlignment(quint16 align);
		void setHAlignment(quint16 align);
		
	private :
		QMatrix c_matrix,c_staticMatrix;
		qreal c_x,c_y;
		quint16   c_vAlignment,c_hAlignment;
};

#endif
