KDEGames

kgamerendererclient.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Stefan Majewsky <majewsky@gmx.net>
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
15KGameRendererClientPrivate::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_ptr(new KGameRendererClientPrivate(renderer, spriteKey, this))
24{
26
27 renderer->d_ptr->m_clients.insert(this, QString());
28 // The following may not be triggered directly because it may call receivePixmap() which is a pure virtual method at this point.
29 QTimer::singleShot(0, d, &KGameRendererClientPrivate::fetchPixmap);
30}
31
32KGameRendererClient::~KGameRendererClient()
33{
35
36 d->m_renderer->d_ptr->m_clients.remove(this);
37}
38
40{
42
43 return d->m_renderer;
44}
45
47{
49
50 return d->m_spec.spriteKey;
51}
52
54{
56
57 if (d->m_spec.spriteKey != spriteKey) {
58 d->m_spec.spriteKey = spriteKey;
59 d->fetchPixmap();
60 }
61}
62
64{
66
67 return d->m_renderer->frameCount(d->m_spec.spriteKey);
68}
69
71{
73
74 return d->m_spec.frame;
75}
76
78{
80
81 if (d->m_spec.frame != frame) {
82 // do some normalization ourselves
83 const int frameCount = this->frameCount();
84 if (frameCount <= 0 || frame < 0) {
85 frame = -1;
86 } else {
87 const int frameBaseIndex = d->m_renderer->frameBaseIndex();
88 frame = (frame - frameBaseIndex) % frameCount + frameBaseIndex;
89 }
90 if (d->m_spec.frame != frame) {
91 d->m_spec.frame = frame;
92 d->fetchPixmap();
93 }
94 }
95}
96
98{
100
101 return d->m_spec.size;
102}
103
105{
107
108 if (d->m_spec.size != renderSize) {
109 d->m_spec.size = renderSize;
110 d->fetchPixmap();
111 }
112}
113
115{
117
118 return d->m_spec.customColors;
119}
120
122{
124
125 if (d->m_spec.customColors != customColors) {
126 d->m_spec.customColors = customColors;
127 d->fetchPixmap();
128 }
129}
130
131void KGameRendererClientPrivate::fetchPixmap()
132{
133 m_renderer->d_ptr->requestPixmap(m_spec, m_parent);
134}
An object that receives pixmaps from a KGameRenderer.
void setCustomColors(const QHash< QColor, QColor > &customColors)
Defines the custom color replacements for this client.
void setSpriteKey(const QString &spriteKey)
Defines the key of the sprite which is rendered by this client.
KGameRenderer * renderer() const
QHash< QColor, QColor > customColors() const
void setRenderSize(QSize renderSize)
Defines the size of the pixmap that will be requested from KGameRenderer.
KGameRendererClient(KGameRenderer *renderer, const QString &spriteKey)
Creates a new client which receives pixmaps for the sprite with the given spriteKey as provided by th...
void setFrame(int frame)
For animated sprites, render another frame.
Cache-enabled rendering of SVG themes.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:12:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.