Debian Codegraph @

src/editor/tileanimator.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2011 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #include "tileanimator.hpp"
17 #include "tracktile.hpp"
18
19 #include <QTimeLine>
20
21 const int FRAMES = 30;
22
23 TileAnimator::TileAnimator(TrackTile * tile)
24 : QTimeLine(250)
25 , m_tile(tile)
26 {
27 setFrameRange(0, FRAMES);
28
29 connect(this, &TileAnimator::frameChanged, this, &TileAnimator::setTileRotation);
30 }
31
32 bool TileAnimator::rotate90CW()
33 {
34 if (state() == QTimeLine::NotRunning)
35 {
36 m_a0 = m_tile->rotation();
37 m_a1 = m_tile->rotation() + 90;
38
39 start();
40
41 return true;
42 }
43
44 return false;
45 }
46
47 bool TileAnimator::rotate90CCW()
48 {
49 if (state() == QTimeLine::NotRunning)
50 {
51 m_a0 = m_tile->rotation();
52 m_a1 = m_tile->rotation() - 90;
53
54 start();
55
56 return true;
57 }
58
59 return false;
60 }
61
62 void TileAnimator::setTileRotation(int frame)
63 {
64 m_tile->setRotation(m_a0 + frame * (m_a1 - m_a0) / FRAMES);
65 }