1/*
2 * Copyright 2007-2010 Parker Coates <coates@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#include "renderer.h"
20
21#include "settings.h"
22
23#include <KgThemeProvider>
24
25
26Renderer * Renderer::s_instance = 0;
27
28
29Renderer * Renderer::self()
30{
31 if ( s_instance == 0 )
32 s_instance = new Renderer();
33 return s_instance;
34}
35
36
37void Renderer::deleteSelf()
38{
39 delete s_instance;
40 s_instance = 0;
41}
42
43
44qreal Renderer::aspectRatioOfElement( const QString & elementId )
45{
46 const QSizeF size = boundsOnSprite( elementId ).size();
47 return size.width() / size.height();
48}
49
50
51QColor Renderer::colorOfElement( const QString & elementId )
52{
53 if ( m_cachedTheme != theme()->identifier() )
54 {
55 m_colors.clear();
56 m_cachedTheme = theme()->identifier();
57 }
58
59 QColor color;
60 QHash<QString,QColor>::const_iterator it = m_colors.constFind( elementId );
61 if ( it != m_colors.constEnd() )
62 {
63 color = it.value();
64 }
65 else
66 {
67 QPixmap pix = spritePixmap( elementId, QSize( 3, 3 ) );
68 color = pix.toImage().pixel( 1, 1 );
69 m_colors.insert( elementId, color );
70 }
71 return color;
72}
73
74static KgThemeProvider* provider()
75{
76 KgThemeProvider* prov = new KgThemeProvider;
77 prov->discoverThemes(
78 "appdata", QLatin1String("themes"), //theme file location
79 QLatin1String("greenblaze") //default theme file name
80 );
81 return prov;
82}
83
84Renderer::Renderer()
85 : KGameRenderer( provider() )
86{
87}
88
89