KDEGames

kgamerendererclient.cpp
1 /***************************************************************************
2  * Copyright 2010 Stefan Majewsky <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License *
6  * version 2 as published by the Free Software Foundation *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU Library General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU Library General Public *
14  * License along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
17  ***************************************************************************/
18 
19 #include "kgamerendererclient.h"
20 #include "kgamerenderer.h"
21 #include "kgamerenderer_p.h"
22 
23 #include <QTimer>
24 
25 KGameRendererClientPrivate::KGameRendererClientPrivate(KGameRenderer* renderer, const QString& spriteKey, KGameRendererClient* parent)
26  : m_parent(parent)
27  , m_renderer(renderer)
28  , m_spec(spriteKey, -1, QSize())
29 {
30 }
31 
33  : d(new KGameRendererClientPrivate(renderer, spriteKey, this))
34 {
35  renderer->d->m_clients.insert(this, QString());
36  //The following may not be triggered directly because it may call receivePixmap() which is a pure virtual method at this point.
37  QTimer::singleShot(0, d, &KGameRendererClientPrivate::fetchPixmap);
38 }
39 
40 KGameRendererClient::~KGameRendererClient()
41 {
42  d->m_renderer->d->m_clients.remove(this);
43  delete d;
44 }
45 
47 {
48  return d->m_renderer;
49 }
50 
52 {
53  return d->m_spec.spriteKey;
54 }
55 
57 {
58  if (d->m_spec.spriteKey != spriteKey)
59  {
60  d->m_spec.spriteKey = spriteKey;
61  d->fetchPixmap();
62  }
63 }
64 
66 {
67  return d->m_renderer->frameCount(d->m_spec.spriteKey);
68 }
69 
71 {
72  return d->m_spec.frame;
73 }
74 
76 {
77  if (d->m_spec.frame != frame)
78  {
79  //do some normalization ourselves
80  const int frameCount = this->frameCount();
81  if (frameCount <= 0 || frame < 0)
82  {
83  frame = -1;
84  }
85  else
86  {
87  const int frameBaseIndex = d->m_renderer->frameBaseIndex();
88  frame = (frame - frameBaseIndex) % frameCount + frameBaseIndex;
89  }
90  if (d->m_spec.frame != frame)
91  {
92  d->m_spec.frame = frame;
93  d->fetchPixmap();
94  }
95  }
96 }
97 
99 {
100  return d->m_spec.size;
101 }
102 
104 {
105  if (d->m_spec.size != renderSize)
106  {
107  d->m_spec.size = renderSize;
108  d->fetchPixmap();
109  }
110 }
111 
113 {
114  return d->m_spec.customColors;
115 }
116 
118 {
119  if (d->m_spec.customColors != customColors)
120  {
121  d->m_spec.customColors = customColors;
122  d->fetchPixmap();
123  }
124 }
125 
126 void KGameRendererClientPrivate::fetchPixmap()
127 {
128  m_renderer->d->requestPixmap(m_spec, m_parent);
129 }
void setCustomColors(const QHash< QColor, QColor > &customColors)
Defines the custom color replacements for this client.
Cache-enabled rendering of SVG themes.
Definition: kgamerenderer.h:94
QString spriteKey() const
KGameRendererClient(KGameRenderer *renderer, const QString &spriteKey)
Creates a new client which receives pixmaps for the sprite with the given spriteKey as provided by th...
QHash< QColor, QColor > customColors() const
void setRenderSize(const QSize &renderSize)
Defines the size of the pixmap that will be requested from KGameRenderer.
An object that receives pixmaps from a KGameRenderer.
KGameRenderer * renderer() const
void setSpriteKey(const QString &spriteKey)
Defines the key of the sprite which is rendered by this client.
void setFrame(int frame)
For animated sprites, render another frame.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:36:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.