SVN_SILENT made messages (.desktop file)
[kdegames.git] / klines / renderer.h
blobc2d8f4aaf6196b117f10c44ea6b7a818793902e7
1 /*******************************************************************
3 * Copyright 2006-2007 Dmitry Suzdalev <dimsuz@gmail.com>
5 * This file is part of the KDE project "KLines"
7 * KLines is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * KLines is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with KLines; see the file COPYING. If not, write to
19 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
22 ********************************************************************/
23 #ifndef KL_RENDERER_H
24 #define KL_RENDERER_H
26 #include <QPixmap>
28 #include "commondefs.h"
30 class KSvgRenderer;
31 class KPixmapCache;
33 /**
34 * This class is responsible for rendering all the game graphics.
35 * Graphics is rendered from svg file specified by current theme.
36 * QPixmaps which are returned are cached until setCellSize()
37 * doesn't get called.
38 * Only one instance of this class exists during a program run.
39 * It can be accessed with static function KLinesRenderer::self().
41 class KLinesRenderer
43 public:
44 enum AnimationType { BornAnim, SelectedAnim, DieAnim, MoveAnim };
45 /**
46 * Returns one and the only instance of KLinesRenderer
48 static KLinesRenderer* self();
49 /**
50 * Loads new theme. Resets cache and puts new flashy rerendered
51 * pixmaps there
52 * @param themeName specifies theme name which is the part of the
53 * theme's file path relative to $KDEDIR/share/apps/klines, for example
54 * it might be "themes/default.desktop"
56 bool loadTheme( const QString& themeName );
57 /**
58 * @return pixmap of the ball of color c in steady state
60 QPixmap ballPixmap( BallColor c ) const;
61 /**
62 * @param type type of animation sequence
63 * @param c color of the ball
64 * @param frame frame number (must be between 0..numFrames(type)-1)
65 * @return pixmap containing animation frame
67 QPixmap animationFrame( AnimationType type, BallColor c, int frame ) const;
68 /**
69 * @return pixmap for background painting.
71 QPixmap backgroundPixmap(const QSize& size) const;
72 /**
73 * @return pixmap for border surrounding the play field.
74 * Will return an invalid QPixmap if no such element exists
75 * in theme's svg file.
76 * @see hasBorderElement
78 QPixmap backgroundBorderPixmap( const QSize& size ) const;
79 /**
80 * @return pixmap of background tile (cell)
82 QPixmap backgroundTilePixmap() const;
83 /**
84 * @return pixmap for PreviewItem
86 QPixmap previewPixmap() const;
87 /**
88 * Sets render sizes for cells
90 void setCellSize(int cellSize);
91 /**
92 * @return current cell size
94 int cellSize() const { return m_cellSize; }
96 bool hasBorderElement() const;
98 /**
99 * @return number of frames in animation sequence of type t
101 inline int frameCount( AnimationType t ) const
103 switch(t)
105 case BornAnim:
106 return m_numBornFrames;
107 case SelectedAnim:
108 return m_numSelFrames;
109 case DieAnim:
110 return m_numDieFrames;
111 default: // e.g. Move - not handled here
112 return 0;
116 * @return duration of animation sequence of type t
118 inline int animDuration(AnimationType t) const
120 switch(t)
122 case BornAnim:
123 return m_bornDuration;
124 case SelectedAnim:
125 return m_selDuration;
126 case DieAnim:
127 return m_dieDuration;
128 case MoveAnim:
129 return m_moveDuration;
130 default:
131 return 0;
134 private:
135 // disable copy - it's singleton
136 KLinesRenderer();
137 KLinesRenderer( const KLinesRenderer& );
138 KLinesRenderer& operator=( const KLinesRenderer& );
139 ~KLinesRenderer();
142 * Tries to find pixmap with cacheName in cache.
143 * If pixmap is not found in cache, this function will put it there
144 * Pixmap is rendered according to current cellSize
145 * If customSize is not passed, pixmap will be of (m_cellSize,m_cellSize) size
147 * @return rendered pixmap
149 QPixmap pixmapFromCache(const QString& svgName, const QSize& customSize = QSize()) const;
151 * This is the size of the scene's cell.
152 * All rendered pixmaps (except background) will have this size
154 int m_cellSize;
156 * Name of currently loaded theme
158 QString m_currentTheme;
160 KSvgRenderer *m_renderer;
161 KPixmapCache *m_cache;
163 int m_numBornFrames;
164 int m_numSelFrames;
165 int m_numDieFrames;
167 int m_bornDuration;
168 int m_selDuration;
169 int m_dieDuration;
170 int m_moveDuration; // one cell
173 #endif