KDEGames

kgamerendererclient.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Stefan Majewsky <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-only
5 */
6 
7 #include "kgamerendererclient.h"
8 
9 // own
10 #include "kgamerenderer.h"
11 #include "kgamerenderer_p.h"
12 // Qt
13 #include <QTimer>
14 
15 KGameRendererClientPrivate::KGameRendererClientPrivate(KGameRenderer* renderer, const QString& spriteKey, KGameRendererClient* parent)
16  : m_parent(parent)
17  , m_renderer(renderer)
18  , m_spec(spriteKey, -1, QSize())
19 {
20 }
21 
23  : d(new KGameRendererClientPrivate(renderer, spriteKey, this))
24 {
25  renderer->d->m_clients.insert(this, QString());
26  //The following may not be triggered directly because it may call receivePixmap() which is a pure virtual method at this point.
27  QTimer::singleShot(0, d.get(), &KGameRendererClientPrivate::fetchPixmap);
28 }
29 
30 KGameRendererClient::~KGameRendererClient()
31 {
32  d->m_renderer->d->m_clients.remove(this);
33 }
34 
36 {
37  return d->m_renderer;
38 }
39 
41 {
42  return d->m_spec.spriteKey;
43 }
44 
46 {
47  if (d->m_spec.spriteKey != spriteKey)
48  {
49  d->m_spec.spriteKey = spriteKey;
50  d->fetchPixmap();
51  }
52 }
53 
55 {
56  return d->m_renderer->frameCount(d->m_spec.spriteKey);
57 }
58 
60 {
61  return d->m_spec.frame;
62 }
63 
65 {
66  if (d->m_spec.frame != frame)
67  {
68  //do some normalization ourselves
69  const int frameCount = this->frameCount();
70  if (frameCount <= 0 || frame < 0)
71  {
72  frame = -1;
73  }
74  else
75  {
76  const int frameBaseIndex = d->m_renderer->frameBaseIndex();
77  frame = (frame - frameBaseIndex) % frameCount + frameBaseIndex;
78  }
79  if (d->m_spec.frame != frame)
80  {
81  d->m_spec.frame = frame;
82  d->fetchPixmap();
83  }
84  }
85 }
86 
88 {
89  return d->m_spec.size;
90 }
91 
93 {
94  if (d->m_spec.size != renderSize)
95  {
96  d->m_spec.size = renderSize;
97  d->fetchPixmap();
98  }
99 }
100 
102 {
103  return d->m_spec.customColors;
104 }
105 
107 {
108  if (d->m_spec.customColors != customColors)
109  {
110  d->m_spec.customColors = customColors;
111  d->fetchPixmap();
112  }
113 }
114 
115 void KGameRendererClientPrivate::fetchPixmap()
116 {
117  m_renderer->d->requestPixmap(m_spec, m_parent);
118 }
void setCustomColors(const QHash< QColor, QColor > &customColors)
Defines the custom color replacements for this client.
Cache-enabled rendering of SVG themes.
Definition: kgamerenderer.h:86
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-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:34:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.