KDEGames

kgamerendererclient.h
1 /*
2  SPDX-FileCopyrightText: 2010 Stefan Majewsky <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-only
5 */
6 
7 #ifndef KGAMERENDERERCLIENT_H
8 #define KGAMERENDERERCLIENT_H
9 
10 // own
11 #include <libkdegames_export.h>
12 // Qt
13 #include <QPixmap>
14 // Std
15 #include <memory>
16 
17 class KGameRendererClientPrivate;
18 class KGameRenderer;
19 class KGameRendererPrivate;
20 
21 #ifndef KDEGAMES_QCOLOR_QHASH
22 # define KDEGAMES_QCOLOR_QHASH
23  inline 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  * @since 4.6
32  * @short An object that receives pixmaps from a KGameRenderer.
33  *
34  * This class abstracts a sprite rendered by KGameRenderer. Given a sprite key,
35  * render size and possibly a frame index, it returns the QPixmap for this
36  * sprite (frame) once it becomes available. See the KGameRenderer class
37  * documentation for details.
38  *
39  * Subclasses have to reimplement the receivePixmap() method.
40  */
41 class KDEGAMES_EXPORT KGameRendererClient
42 {
43  public:
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(const 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  protected:
92  ///This method is called when the KGameRenderer has provided a new
93  ///pixmap for this client (esp. after theme changes and after calls to
94  ///setFrame(), setRenderSize() and setSpriteKey()).
95  virtual void receivePixmap(const QPixmap& pixmap) = 0;
96  private:
97  friend class KGameRendererClientPrivate;
98  friend class KGameRenderer;
99  friend class KGameRendererPrivate;
100  std::unique_ptr<KGameRendererClientPrivate> const d;
101 };
102 
103 #endif // KGAMERENDERERCLIENT_H
Cache-enabled rendering of SVG themes.
Definition: kgamerenderer.h:86
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
An object that receives pixmaps from a KGameRenderer.
QRgb rgba() const const
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.