Per-frame Sprites patch one
[profile/ivi/qtdeclarative.git] / src / quick / items / qquicksprite.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the Declarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qquicksprite_p.h"
43 #include <QDebug>
44
45 QT_BEGIN_NAMESPACE
46
47 /*!
48     \qmlclass Sprite QQuickSprite
49     \inqmlmodule QtQuick 2
50     \brief The Sprite element represents a sprite animation
51
52 */
53 /*!
54     \qmlproperty int QtQuick2::Sprite::duration
55
56     Time between frames. Use -1 to indicate one sprite frame per rendered frame.
57 */
58 /*!
59     \qmlproperty int QtQuick2::Sprite::durationVariation
60
61     The time between frames can vary by up to this amount. Variation will never decrease the time
62     between frames to less than 0.
63
64     Default is 0.
65 */
66
67 /*!
68     \qmlproperty string QtQuick2::Sprite::name
69
70     The name of this sprite, for use in the to property of other sprites.
71 */
72 /*!
73     \qmlproperty QVariantMap QtQuick2::Sprite::to
74
75     A list of other sprites and weighted transitions to them,
76     for example {"a":1, "b":2, "c":0} would specify that one-third should
77     transition to sprite "a" when this sprite is done, and two-thirds should
78     transition to sprite "b" when this sprite is done. As the transitions are
79     chosen randomly, these proportions will not be exact. With "c":0 in the list,
80     no sprites will randomly transition to "c", but it wll be a valid path if a sprite
81     goal is set.
82
83     If no list is specified, or the sum of weights in the list is zero, then the sprite
84     will repeat itself after completing.
85 */
86 /*!
87     \qmlproperty int QtQuick2::Sprite::frames
88
89     Number of frames in this sprite.
90 */
91 /*!
92     \qmlproperty int QtQuick2::Sprite::frameHeight
93
94     Height of a single frame in this sprite.
95 */
96 /*!
97     \qmlproperty int QtQuick2::Sprite::frameWidth
98
99     Width of a single frame in this sprite.
100 */
101 /*!
102     \qmlproperty url QtQuick2::Sprite::source
103
104     The image source for the animation.
105
106     If frameHeight and frameWidth are not specified, it is assumed to be a single long row of square frames.
107     Otherwise, it can be multiple contiguous rows or rectangluar frames, when one row runs out the next will be used.
108 */
109
110 QQuickSprite::QQuickSprite(QObject *parent) :
111     QQuickStochasticState(parent)
112     , m_generatedCount(0)
113     , m_framesPerRow(0)
114     , m_frameHeight(0)
115     , m_frameWidth(0)
116     , m_rowY(0)
117 {
118 }
119
120 QT_END_NAMESPACE