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)
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 ********************************************************************/
28 #include "commondefs.h"
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()
38 * Only one instance of this class exists during a program run.
39 * It can be accessed with static function KLinesRenderer::self().
44 enum AnimationType
{ BornAnim
, SelectedAnim
, DieAnim
, MoveAnim
};
46 * Returns one and the only instance of KLinesRenderer
48 static KLinesRenderer
* self();
50 * Loads new theme. Resets cache and puts new flashy rerendered
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
);
58 * @return pixmap of the ball of color c in steady state
60 QPixmap
ballPixmap( BallColor c
) const;
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;
69 * @return pixmap for background painting.
71 QPixmap
backgroundPixmap(const QSize
& size
) const;
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;
80 * @return pixmap of background tile (cell)
82 QPixmap
backgroundTilePixmap() const;
84 * @return pixmap for PreviewItem
86 QPixmap
previewPixmap() const;
88 * Sets render sizes for cells
90 void setCellSize(int cellSize
);
92 * @return current cell size
94 int cellSize() const { return m_cellSize
; }
96 bool hasBorderElement() const;
99 * @return number of frames in animation sequence of type t
101 inline int frameCount( AnimationType t
) const
106 return m_numBornFrames
;
108 return m_numSelFrames
;
110 return m_numDieFrames
;
111 default: // e.g. Move - not handled here
116 * @return duration of animation sequence of type t
118 inline int animDuration(AnimationType t
) const
123 return m_bornDuration
;
125 return m_selDuration
;
127 return m_dieDuration
;
129 return m_moveDuration
;
135 // disable copy - it's singleton
137 KLinesRenderer( const KLinesRenderer
& );
138 KLinesRenderer
& operator=( const 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
156 * Name of currently loaded theme
158 QString m_currentTheme
;
160 KSvgRenderer
*m_renderer
;
161 KPixmapCache
*m_cache
;
170 int m_moveDuration
; // one cell