KDEGames

kgamerenderer.h
1 /***************************************************************************
2  * Copyright 2010-2012 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 #ifndef KGAMERENDERER_H
20 #define KGAMERENDERER_H
21 
22 class QGraphicsView;
23 #include <QHash>
24 #include <QObject>
25 #include <QPixmap>
26 
27 #include <libkdegames_export.h>
28 
29 class KGameRendererPrivate;
31 class KGameRendererClientPrivate;
32 class KgTheme;
33 class KgThemeProvider;
34 
35 #ifndef KDEGAMES_QCOLOR_QHASH
36 # define KDEGAMES_QCOLOR_QHASH
37  inline uint qHash(const QColor& color)
38  {
39  return color.rgba();
40  }
41 #endif // KDEGAMES_QCOLOR_QHASH
42 
94 class KDEGAMES_EXPORT KGameRenderer : public QObject
95 {
96  Q_OBJECT
97  Q_PROPERTY(const KgTheme* theme READ theme NOTIFY themeChanged)
98  Q_PROPERTY(KgThemeProvider* themeProvider READ themeProvider NOTIFY readOnlyProperty)
99  public:
103  enum Strategy
104  {
109  UseDiskCache = 1 << 0,
113  UseRenderingThreads = 1 << 1
114  };
115  Q_DECLARE_FLAGS(Strategies, Strategy)
116 
117 
118  explicit KGameRenderer(KgThemeProvider* prov, unsigned cacheSize = 0);
126  explicit KGameRenderer(KgTheme* theme, unsigned cacheSize = 0);
128  virtual ~KGameRenderer();
129 
133  QGraphicsView* defaultPrimaryView() const;
138  void setDefaultPrimaryView(QGraphicsView* view);
140  int frameBaseIndex() const;
150  void setFrameBaseIndex(int frameBaseIndex);
152  QString frameSuffix() const;
162  void setFrameSuffix(const QString& suffix);
165  Strategies strategies() const;
174  void setStrategyEnabled(Strategy strategy, bool enabled = true);
175 
177  const KgTheme* theme() const;
180  KgThemeProvider* themeProvider() const;
181 
185  QRectF boundsOnSprite(const QString& key, int frame = -1) const;
198  int frameCount(const QString& key) const;
201  bool spriteExists(const QString& key) const;
212 
213  // The parentheses around QHash<QColor, QColor>() avoid compile
214  // errors on platforms with older gcc versions, e.g. OS X 10.6.
215  QPixmap spritePixmap(const QString& key, const QSize& size, int frame = -1, const QHash<QColor, QColor>& customColors = (QHash<QColor, QColor>())) const;
216  Q_SIGNALS:
217  void themeChanged(const KgTheme* theme);
220  void readOnlyProperty();
221  private:
222  friend class KGameRendererPrivate;
223  friend class KGameRendererClient;
224  friend class KGameRendererClientPrivate;
225  KGameRendererPrivate* const d;
226  Q_PRIVATE_SLOT(d, void _k_setTheme(const KgTheme*));
227 };
228 
229 Q_DECLARE_OPERATORS_FOR_FLAGS(KGameRenderer::Strategies)
230 
231 #endif // KGAMERENDERER_H
A theme provider manages KgTheme instances, and maintains a selection of the currentTheme().
Cache-enabled rendering of SVG themes.
Definition: kgamerenderer.h:94
Q_PROPERTY(...)
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
An object that receives pixmaps from a KGameRenderer.
Strategy
Describes the various strategies which KGameRenderer can use to speed up rendering.
A theme describes the visual appearance of a game.
Definition: kgtheme.h:72
QRgb rgba() const const
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.