• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrrenderer.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright 2012 Ian Wadham <iandw.au@gmail.com> *
3  * Copyright 2012 Roney Gomes <roney477@gmail.com> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ****************************************************************************/
18 
19 #ifndef KGRRENDERER_H
20 #define KGRRENDERER_H
21 
22 #include <QObject>
23 #include <QString>
24 #include <KGameRenderer>
25 
26 #include "kgrsprite.h"
27 
28 class KGrScene;
29 class KgThemeProvider;
30 class KgThemeSelector;
31 class KGameRenderedItem;
32 
33 /* @short A class to assist theme-handling and rendering in KGoldrunner.
34  *
35  * KGoldrunner has two SVG files for each theme: one to hold the Actors (hero
36  * and enemies) and one to hold the Set (bricks, ladders, background, etc.).
37  *
38  * The files are marked with the keywords "Actors" and "Set" in each theme's
39  * .desktop file, rather than the usual "Filename" keyword. There are two
40  * KgThemeProvider objects and two KGameRenderer objects, each with its own
41  * set of SVG files and KgTheme objects.
42  *
43  * There is one KgThemeSelector object, which selects the "Set" theme and uses
44  * the "Set" KgThemeProvider. Its currentThemeChanged signal is connected to a
45  * currentThemeChanged slot in KGrRenderer, which finds the KgTheme for the
46  * corresponding "Actors" theme and SVG file.
47  *
48  * KGoldrunner also has several different usages of the KGameRenderer concepts
49  * of "frameSuffix" and "frameBaseIndex". For animation frames (hero, enemies
50  * and dug bricks), it always has frameSuffix = "_%1" and frameBaseIndex = 1, so
51  * animation will be handled normally by KGameRenderer.
52  *
53  * Depending on the theme and the artist's choices, backgrounds and tiles can
54  * have one or more variants, to add variety to the look of brick walls, etc.
55  * The suffixes used can be "-%1" or just "%1" and the frameBaseIndex = 0, or
56  * there can be just one variant, with no suffix. The keyTable structure and the
57  * getPixmapKey() and getBackgroundKey() methods of KGrRenderer provide ways to
58  * go from KGoldrunner's internal tile-types to SVG element names that can be
59  * used as pixmap keys in KGameRenderer.
60  */
61 class KGrRenderer : public QObject
62 {
63  Q_OBJECT
64 public:
65  KGrRenderer (KGrScene * scene);
66  virtual ~KGrRenderer();
67 
68  /*
69  * Get a pointer to the KGameRenderer for "Set" graphics (bricks, etc.).
70  */
71  KGameRenderer * getSetRenderer() { return m_setRenderer; }
72 
73  /*
74  * Get a pointer to the KGameRenderer for "Actors" graphics (hero, etc.).
75  */
76  KGameRenderer * getActorsRenderer() { return m_actorsRenderer; }
77 
78  /*
79  * Create the QGraphicsScene item for a tile of a particular type (e.g. bar,
80  * gold, concrete, etc.) at a place in the on-screen KGoldrunner grid.
81  *
82  * @param picType The internal KGoldrunner type of the required tile. If
83  * FREE, just delete the previous tile (if any).
84  * @param currentTile The pre-existing tile that is to be replaced or
85  * deleted, or zero if the place is empty.
86  */
87  KGameRenderedItem * getTileItem (const char picType,
88  KGameRenderedItem * currentTile);
89 
90  /*
91  * Create the QGraphicsScene item for the background corresponding to the
92  * current level.
93  *
94  * @param level The current level in a KGoldrunner game.
95  * @param currentBackground The pre-existing background that is to be
96  * replaced, or zero if theres'no background yet.
97  */
98  KGameRenderedItem * getBackground (const int level,
99  KGameRenderedItem * currentBackground);
100 
101  /*
102  * Create the QGraphicsScene item for a border tile.
103  *
104  * @param spriteKey The name of the sprite which will be rendered.
105  * @param currentItem The pre-existing item that is to be replaced, or
106  * zero if the previous theme had no border.
107  */
108  KGameRenderedItem * getBorderItem (QString spriteKey,
109  KGameRenderedItem * currentItem);
110 
111  /*
112  * TODO - Document this.
113  */
114  KGrSprite * getSpriteItem (const char picType, const int tickTime);
115 
116  /*
117  * Returns true case the current theme has a border around its background
118  * and false otherwise.
119  */
120  bool hasBorder () const;
121 
122  /*
123  * Get the color of the scene's background brush requested for the current
124  * theme.
125  */
126  QColor borderColor () const;
127 
128  /*
129  * Get the color of the on-screen text which appears in certain game stages
130  * (the demo stage for instance) and in the score box.
131  */
132  QColor textColor () const;
133 
134  /*
135  * Get a pixmap of a particular tile type (e.g. brick, ladder, gold etc.)
136  *
137  * @param picType The internal KGoldRunner type of the required tile.
138  */
139  QPixmap getPixmap (const char picType);
140 
141  /*
142  * Show the theme-selector dialog. When the theme changes, KGrRenderer uses
143  * a signal and slot to keep the "Set" and "Actors" parts of the theme and
144  * SVG files in synch.
145  */
146  void selectTheme();
147 
148 private slots:
149  // Keep the "Set" and "Actors" parts of a KGoldrunner theme in synch as
150  // the theme-selection changes.
151  void currentThemeChanged(const KgTheme * currentSetTheme);
152 
153 private:
154  enum PicSrc {Actors, Set};
155 
156  // Structure of table-row to specify a tile or pixmap type in a theme.
157  struct PixmapSpec {
158  const char picType; // KGoldrunner's internal type.
159  const PicSrc picSource; // Actors or Set?
160  const char * picKey; // Prefix of SVG element name.
161  const char * frameSuffix; // Format of suffix or "" if none.
162  const int frameBaseIndex; // Lowest value of suffix or -1 if none.
163  int frameCount; // Number of variants available.
164  // -2 = not yet counted, -1 = element
165  // not found, 0 = only one variant with
166  // no suffix, >0 = number of variants.
167  };
168 
169  KGrScene * m_scene; // The scene to be rendered.
170 
171  KgThemeProvider * m_setProvider; // Provider for Set themes.
172  KgThemeProvider * m_actorsProvider; // Provider for Actors themes.
173 
174  KgThemeSelector * m_themeSelector; // Selector (dialog) for themes.
175 
176  KGameRenderer * m_setRenderer; // Renderer for Set SVG files.
177  KGameRenderer * m_actorsRenderer; // Renderer for Actors SVG files.
178 
179  static PixmapSpec keyTable []; // Table of tile/background specs.
180 
181  // Set the frame counts to -2 at startup and when the theme changes.
182  void initPixmapKeys();
183 
184  // Make the Actors theme (hero, etc.) match the Set theme (bricks, etc.).
185  void matchThemes (const KgTheme * currentSetTheme);
186 
187  // Find a tile type or background in the table of tiles and backgrounds.
188  int findKeyTableIndex (const char picType);
189 
190  // Count the number of variants of a tile or background.
191  int countFrames (const int index);
192 
193  /*
194  * Get the SVG element name for a KGoldrunner tile type. If the theme has
195  * more than one tile of that type (e.g. BRICK), make a random selection.
196  *
197  * @param picType The internal KGoldrunner type of a tile or background.
198  */
199  QString getPixmapKey (const char picType, const int index);
200 
201  /*
202  * Get the SVG element name for a KGoldrunner background. If the theme has
203  * more than one background, cycle though the choices as the KGoldrunner
204  * game's level changes.
205  *
206  * @param level The current level in a KGoldrunner game.
207  */
208  QString getBackgroundKey (const int level);
209 };
210 
211 #endif // KGRRENDERER_H
KGrRenderer::getPixmap
QPixmap getPixmap(const char picType)
Definition: kgrrenderer.cpp:234
KGrRenderer::getSetRenderer
KGameRenderer * getSetRenderer()
Definition: kgrrenderer.h:71
KGrRenderer::textColor
QColor textColor() const
Definition: kgrrenderer.cpp:228
KGrRenderer::KGrRenderer
KGrRenderer(KGrScene *scene)
Definition: kgrrenderer.cpp:37
KGrRenderer::getTileItem
KGameRenderedItem * getTileItem(const char picType, KGameRenderedItem *currentTile)
Definition: kgrrenderer.cpp:139
KGrRenderer::borderColor
QColor borderColor() const
Definition: kgrrenderer.cpp:222
kgrsprite.h
QObject
KGrRenderer::getActorsRenderer
KGameRenderer * getActorsRenderer()
Definition: kgrrenderer.h:76
QString
QColor
KGrRenderer
Definition: kgrrenderer.h:61
QPixmap
KGrSprite
Definition: kgrsprite.h:29
KGameRenderedItem
KgTheme
KGrScene
The QGraphicsScene that represents KGoldrunner on the screen.
Definition: kgrscene.h:75
KGrRenderer::getBorderItem
KGameRenderedItem * getBorderItem(QString spriteKey, KGameRenderedItem *currentItem)
Definition: kgrrenderer.cpp:195
KGrRenderer::getSpriteItem
KGrSprite * getSpriteItem(const char picType, const int tickTime)
Definition: kgrrenderer.cpp:162
KGrRenderer::getBackground
KGameRenderedItem * getBackground(const int level, KGameRenderedItem *currentBackground)
Definition: kgrrenderer.cpp:179
KGrRenderer::selectTheme
void selectTheme()
Definition: kgrrenderer.cpp:108
KGrRenderer::~KGrRenderer
virtual ~KGrRenderer()
Definition: kgrrenderer.cpp:81
KGrRenderer::hasBorder
bool hasBorder() const
Definition: kgrrenderer.cpp:212
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal