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