2 Copyright 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
5 Kmahjongg is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "TileSprite.h"
24 TileSprite::TileSprite( KGameCanvasAbstract
* canvas
, QPixmap
& backunselected
, QPixmap
& backselected
, QPixmap
& face
, TileViewAngle angle
, bool selected
)
25 : QObject(), KGameCanvasItem(canvas
)
29 m_backselected
= backselected
;
30 m_backunselected
= backunselected
;
32 m_selected
= selected
;
34 m_woffset
= m_backselected
.width() - m_face
.width();
35 m_hoffset
= m_backselected
.height() - m_face
.height();
39 TileSprite::~TileSprite()
43 void TileSprite::setAngle(TileViewAngle angle
, QPixmap
& backunselected
, QPixmap
& backselected
) {
45 m_backselected
= backselected
;
46 m_backunselected
= backunselected
;
48 //changed(); We need to call updateSpriteMap to relayer anyway
51 void TileSprite::updateOffset() {
55 m_faceoffset
= QPoint(m_woffset
,0);
58 m_faceoffset
= QPoint(0,0);
61 m_faceoffset
= QPoint(0,m_hoffset
);
64 m_faceoffset
= QPoint(m_woffset
,m_hoffset
);
69 void TileSprite::paintInternal(QPainter
* p
, const QRect
& /*prect*/,
70 const QRegion
& /*preg*/, const QPoint
& /*delta*/, double cumulative_opacity
) {
71 int op
= int(cumulative_opacity
*opacity() + 0.5);
77 p
->setOpacity( op
/255.0 );
83 void TileSprite::paint(QPainter
* p
) {
85 p
->drawPixmap(pos(), m_backselected
);
86 p
->drawPixmap(pos()+m_faceoffset
, m_face
);
88 p
->drawPixmap(pos(), m_backunselected
);
89 p
->drawPixmap(pos()+m_faceoffset
, m_face
);
93 void TileSprite::fadeOut() {
95 setOpacity(opacity()-25);
97 //cancel fade and schedule our destruction!
102 QTimer::singleShot(40, this, SLOT(fadeOut()));
105 void TileSprite::fadeIn() {
107 setOpacity(opacity()+25);
108 if ((opacity() == 255)||(m_dying
)) {
113 QTimer::singleShot(40, this, SLOT(fadeIn()));
116 QRect
TileSprite::rect() const {
117 return QRect(pos(), m_backselected
.size());
120 #include "TileSprite.moc"