• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kmahjongg

  • sources
  • kde-4.14
  • kdegames
  • kmahjongg
TileSprite.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
3  begin : Oct 31 2006
4 
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.
9 
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.
14 
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.
18 */
19 
20 #include "TileSprite.h"
21 #include <QPixmap>
22 #include <QTimer>
23 
24 TileSprite::TileSprite( KGameCanvasAbstract* canvas, QPixmap & backunselected, QPixmap & backselected, QPixmap & face, TileViewAngle angle, bool selected )
25  : QObject(), KGameCanvasItem(canvas)
26 {
27  m_dying = false;
28  setOpacity(255);
29  m_backselected = backselected;
30  m_backunselected = backunselected;
31  m_face = face;
32  m_selected = selected;
33  m_angle = angle;
34  m_woffset = m_backselected.width() - m_face.width();
35  m_hoffset = m_backselected.height() - m_face.height();
36  updateOffset();
37 }
38 
39 TileSprite::~TileSprite()
40 {
41 }
42 
43 void TileSprite::setAngle(TileViewAngle angle, QPixmap & backunselected, QPixmap & backselected) {
44  m_angle = angle;
45  m_backselected = backselected;
46  m_backunselected = backunselected;
47  updateOffset();
48  //changed(); We need to call updateSpriteMap to relayer anyway
49 }
50 
51 void TileSprite::updateOffset() {
52  switch( m_angle )
53  {
54  case NW:
55  m_faceoffset = QPoint(m_woffset,0);
56  break;
57  case NE:
58  m_faceoffset = QPoint(0,0);
59  break;
60  case SE:
61  m_faceoffset = QPoint(0,m_hoffset);
62  break;
63  case SW:
64  m_faceoffset = QPoint(m_woffset,m_hoffset);
65  break;
66  }
67 }
68 
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);
72 
73  if(op <= 0)
74  return;
75 
76  if(op < 255)
77  p->setOpacity( op/255.0 );
78  paint(p);
79  if(op < 255)
80  p->setOpacity(1.0);
81 }
82 
83 void TileSprite::paint(QPainter* p) {
84  if (m_selected) {
85  p->drawPixmap(pos(), m_backselected);
86  p->drawPixmap(pos()+m_faceoffset, m_face);
87  } else {
88  p->drawPixmap(pos(), m_backunselected);
89  p->drawPixmap(pos()+m_faceoffset, m_face);
90  }
91 }
92 
93 void TileSprite::fadeOut() {
94  m_dying = true;
95  setOpacity(opacity()-25);
96  if (opacity() <= 0) {
97  //cancel fade and schedule our destruction!
98  deleteLater();
99  return;
100  }
101  //keep fading
102  QTimer::singleShot(40, this, SLOT(fadeOut()));
103 }
104 
105 void TileSprite::fadeIn() {
106  if (m_dying) return;
107  setOpacity(opacity()+25);
108  if ((opacity() == 255)||(m_dying)) {
109  //cancel fade in
110  return;
111  }
112  //keep fading
113  QTimer::singleShot(40, this, SLOT(fadeIn()));
114 }
115 
116 QRect TileSprite::rect() const {
117  return QRect(pos(), m_backselected.size());
118 }
119 
120 #include "TileSprite.moc"
TileSprite::fadeOut
void fadeOut()
Slot Description.
Definition: TileSprite.cpp:93
QPainter::setOpacity
void setOpacity(qreal opacity)
QPixmap::size
QSize size() const
KGameCanvasItem
QPixmap::width
int width() const
QPoint
NE
North East.
Definition: KmTypes.h:59
TileSprite::~TileSprite
~TileSprite()
Deafault destructor.
Definition: TileSprite.cpp:39
TileSprite::fadeIn
void fadeIn()
Slot Description.
Definition: TileSprite.cpp:105
TileSprite::setAngle
void setAngle(TileViewAngle angle, QPixmap &backunselected, QPixmap &backselected)
Method Description.
Definition: TileSprite.cpp:43
TileSprite.h
TileViewAngle
TileViewAngle
Tile angles for face composition.
Definition: KmTypes.h:57
QRect
TileSprite::TileSprite
TileSprite(KGameCanvasAbstract *canvas, QPixmap &backunselected, QPixmap &backselected, QPixmap &face, TileViewAngle angle, bool selected)
Constructor.
Definition: TileSprite.cpp:24
QObject
TileSprite::paintInternal
virtual void paintInternal(QPainter *p, const QRect &prect, const QRegion &preg, const QPoint &delta, double cumulative_opacity)
Method Description.
Definition: TileSprite.cpp:69
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
SW
South West.
Definition: KmTypes.h:61
QObject::deleteLater
void deleteLater()
QPixmap
QPixmap::height
int height() const
pos
struct pos POSITION
Definition: KmTypes.h:34
TileSprite::selected
double selected()
Method Description.
Definition: TileSprite.h:97
TileSprite::paint
virtual void paint(QPainter *p)
Method Description.
Definition: TileSprite.cpp:83
TileSprite::rect
virtual QRect rect() const
Method Description.
Definition: TileSprite.cpp:116
NW
North West.
Definition: KmTypes.h:58
QRegion
SE
South East.
Definition: KmTypes.h:60
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmahjongg

Skip menu "kmahjongg"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal