refresh 0856514572d371eb96e7cc28b455df3eae46cab0
[tagua/yd.git] / src / mainanimation.cpp
blobf5602b8c634b098a41e9478d5ebe1517c7996c05
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "mainanimation.h"
13 using namespace boost;
15 MainAnimation::MainAnimation(double speed)
16 : AnimationGroup(true)
17 , m_translate(0)
18 , m_speed(speed)
19 , m_delay(20) {
20 m_active = true;
21 connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
24 void MainAnimation::addAnimation(const shared_ptr<Animation>& a) {
25 if (!m_timer.isActive()) {
26 m_timer.start(m_delay);
27 m_time.restart();
30 AnimationGroup::addPostAnimation(a);
31 tick();
34 void MainAnimation::stop() {
35 AnimationGroup::stop();
38 void MainAnimation::tick() {
39 animationAdvance(static_cast<int>(m_time.elapsed() * m_speed) + m_translate);
40 if (empty()) {
41 // no more animations, stop the clock!
42 m_timer.stop();
46 void MainAnimation::setSpeed(double speed) {
47 int e = m_time.elapsed();
48 m_translate = int((e*m_speed + m_translate) - e*speed);
49 m_speed = speed;
52 void MainAnimation::setDelay(int delay) {
53 m_timer.setInterval(m_delay = delay);
56 MainAnimation& MainAnimation::global() {
57 static MainAnimation instance;
58 return instance;