KDEGames

kgamerendererclient.h
1/*
2 SPDX-FileCopyrightText: 2010 Stefan Majewsky <majewsky@gmx.net>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#ifndef KGAMERENDERERCLIENT_H
8#define KGAMERENDERERCLIENT_H
9
10// own
11#include "kdegames_export.h"
12// Qt
13#include <QPixmap>
14// Std
15#include <memory>
16
17class KGameRendererClientPrivate;
18class KGameRenderer;
19class KGameRendererPrivate;
20
21#ifndef KDEGAMES_QCOLOR_QHASH
22#define KDEGAMES_QCOLOR_QHASH
23inline uint qHash(const QColor &color)
24{
25 return color.rgba();
26}
27#endif // KDEGAMES_QCOLOR_QHASH
28
29/**
30 * @class KGameRendererClient kgamerendererclient.h <KGameRendererClient>
31 * @short An object that receives pixmaps from a KGameRenderer.
32 *
33 * This class abstracts a sprite rendered by KGameRenderer. Given a sprite key,
34 * render size and possibly a frame index, it returns the QPixmap for this
35 * sprite (frame) once it becomes available. See the KGameRenderer class
36 * documentation for details.
37 *
38 * Subclasses have to reimplement the receivePixmap() method.
39 * @since 4.6
40 */
41class KDEGAMES_EXPORT KGameRendererClient
42{
43public:
44 /// Creates a new client which receives pixmaps for the sprite with the
45 /// given @a spriteKey as provided by the given @a renderer.
46 KGameRendererClient(KGameRenderer *renderer, const QString &spriteKey);
47 virtual ~KGameRendererClient();
48
49 /// @return the renderer used by this client
50 KGameRenderer *renderer() const;
51 /// @return the frame count, or 0 for non-animated sprites, or -1 if the
52 /// sprite does not exist at all
53 /// @see KGameRenderer::frameCount()
54 int frameCount() const;
55
56 /// @return the key of the sprite currently rendered by this client
57 QString spriteKey() const;
58 /// Defines the key of the sprite which is rendered by this client.
59 void setSpriteKey(const QString &spriteKey);
60 /// @return the current frame number, or -1 for non-animated sprites
61 int frame() const;
62 /// For animated sprites, render another frame. The given frame number is
63 /// normalized by taking the modulo of the frame count, so the following
64 /// code works fine:
65 /// @code
66 /// class MyClient : public KGameRendererClient { ... }
67 /// MyClient client;
68 /// client.setFrame(client.frame() + 1); //cycle to next frame
69 /// client.setFrame(KRandom::random()); //choose a random frame
70 /// @endcode
71 void setFrame(int frame);
72 /// @return the size of the pixmap requested from KGameRenderer
73 QSize renderSize() const;
74 /// Defines the size of the pixmap that will be requested from
75 /// KGameRenderer. For pixmaps rendered on the screen, you usually want
76 /// to set this size such that the pixmap does not have to be scaled when
77 /// it is rendered onto your primary view (for speed reasons).
78 ///
79 /// The default render size is very small (width = height = 3 pixels), so
80 /// that you notice when you forget to set this. ;-)
81 void setRenderSize(QSize renderSize);
82 /// @return the custom color replacements for this client
83 QHash<QColor, QColor> customColors() const;
84 /// Defines the custom color replacements for this client. That is, for
85 /// each entry in this has, the key color will be replaced by its value
86 /// if it is encountered in the sprite.
87 ///
88 /// @note Custom colors increase the rendering time considerably, so use
89 /// this feature only if you really need its flexibility.
90 void setCustomColors(const QHash<QColor, QColor> &customColors);
91
92protected:
93 /// This method is called when the KGameRenderer has provided a new
94 /// pixmap for this client (esp. after theme changes and after calls to
95 /// setFrame(), setRenderSize() and setSpriteKey()).
96 virtual void receivePixmap(const QPixmap &pixmap) = 0;
97
98private:
99 friend class KGameRendererClientPrivate;
100 friend class KGameRenderer;
101 friend class KGameRendererPrivate;
102 std::unique_ptr<KGameRendererClientPrivate> const d_ptr;
103 Q_DECLARE_PRIVATE(KGameRendererClient)
104};
105
106#endif // KGAMERENDERERCLIENT_H
An object that receives pixmaps from a KGameRenderer.
virtual void receivePixmap(const QPixmap &pixmap)=0
This method is called when the KGameRenderer has provided a new pixmap for this client (esp.
Cache-enabled rendering of SVG themes.
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
QRgb rgba() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:50:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.