~ubuntu-branches/ubuntu/trusty/klines/trusty-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*******************************************************************
 *
 * Copyright 2006-2007 Dmitry Suzdalev <dimsuz@gmail.com>
 *
 * This file is part of the KDE project "KLines"
 *
 * KLines is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * KLines is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KLines; see the file COPYING.  If not, write to
 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 ********************************************************************/
#ifndef KL_RENDERER_H
#define KL_RENDERER_H

#include <QPixmap>

#include "commondefs.h"

class KGameRenderer;

/**
 * This class is responsible for rendering all the game graphics.
 * Graphics is rendered from svg file specified by current theme.
 * Only one instance of this class exists during a program run.
 * It can be accessed with static function KLinesRenderer::self().
 */
class KLinesRenderer
{
public:
    enum AnimationType { BornAnim, SelectedAnim, DieAnim, MoveAnim };

    static void Init();
    static void UnInit();

    static inline KGameRenderer * renderer()
    {
        return m_renderer;
    }
    
    /**
     * Loads theme specified in preferences or a default one if none specified.
     */
    static bool loadTheme();

    /**
     * @return pixmap of the ball of color c in steady state
     */
    static QString ballPixmapId(BallColor c);
    static QPixmap ballPixmap(BallColor c);
    /**
     * @param type type of animation sequence
     * @param c color of the ball
     * @param frame frame number (must be between 0..numFrames(type)-1)
     * @return string containing elementId
     */
    static QString animationFrameId(AnimationType type, BallColor c, int frame);
    /**
     * @return pixmap for background painting.
     */
    static QPixmap backgroundPixmap(const QSize& size);
    /**
     * @return pixmap for border surrounding the play field.
     * Will return an invalid QPixmap if no such element exists
     * in theme's svg file.
     * @see hasBorderElement
     */
    static QPixmap backgroundBorderPixmap(const QSize& size);
    /**
     * @return pixmap of background tile (cell)
     */
    static QPixmap backgroundTilePixmap();
    /**
     * @return pixmap for PreviewItem
     */
    static QPixmap previewPixmap();
    /**
     * Sets render sizes for cells
     */
    static void setCellSize(int cellSize);
    /**
     * @return current cell size
     */
    static inline int cellSize()
    {
        return m_cellSize;
    }

    static inline QSize cellExtent()
    {
        return QSize(m_cellSize, m_cellSize);
    }

    static bool hasBorderElement();

    /**
     * @return number of frames in animation sequence of type t
     */
    static inline int frameCount(AnimationType t)
    {
        switch(t)
        {
        case BornAnim:
            return m_numBornFrames;
        case SelectedAnim:
            return m_numSelFrames;
        case DieAnim:
            return m_numDieFrames;
        default: // e.g. Move - not handled here
            return 0;
        }
    }
    /**
     * @return duration of animation sequence of type t
     */
    static inline int animDuration(AnimationType t)
    {
        switch(t)
        {
        case BornAnim:
            return m_bornDuration;
        case SelectedAnim:
            return m_selDuration;
        case DieAnim:
            return m_dieDuration;
        case MoveAnim:
            return m_moveDuration;
        default:
            return 0;
        }
    }
private:
    // disable copy - it's singleton
    KLinesRenderer();
    KLinesRenderer(const KLinesRenderer&);
    KLinesRenderer& operator=(const KLinesRenderer&);
    ~KLinesRenderer();

    /**
     * Pixmap is rendered according to current cellSize
     * If customSize is not passed, pixmap will be of (m_cellSize,m_cellSize) size
     *
     * @return rendered pixmap
     */
    static QPixmap getPixmap(const QString& svgName, const QSize& customSize = QSize());

    /**
     *  This is the size of the scene's cell.
     *  All rendered pixmaps (except background) will have this size
     */
    static int m_cellSize;

    static KGameRenderer *m_renderer;

    static int m_numBornFrames;
    static int m_numSelFrames;
    static int m_numDieFrames;

    static int m_bornDuration;
    static int m_selDuration;
    static int m_dieDuration;
    static int m_moveDuration; // one cell
};

#endif