~ubuntu-branches/ubuntu/utopic/libavg/utopic

« back to all changes in this revision

Viewing changes to src/anim/Anim.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2010-05-02 23:50:04 UTC
  • mfrom: (1.1.4 upstream) (2.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100502235004-i6u38zelbi2k12ii
Tags: 1.0.1-1
* new upstream release (Closes: #565512)
* Remove patches that have been merged upstream.
* Add a patch that avoids building tests by default.
* Remove .py extension from two more scripts in /usr/bin .
* Add 2 example files to /usr/share/doc/python-libavg/examples/ .
* Describe a workaround for bug #579937 in README.Debian.
* Install debian/libavg.pth into /usr/share/pyshared/ .
  (Closes: #575551)
* Add get-orig-source target to debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  libavg - Media Playback Engine. 
 
3
//  Copyright (C) 2003-2008 Ulrich von Zadow
 
4
//
 
5
//  This library is free software; you can redistribute it and/or
 
6
//  modify it under the terms of the GNU Lesser General Public
 
7
//  License as published by the Free Software Foundation; either
 
8
//  version 2 of the License, or (at your option) any later version.
 
9
//
 
10
//  This library is distributed in the hope that it will be useful,
 
11
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
//  Lesser General Public License for more details.
 
14
//
 
15
//  You should have received a copy of the GNU Lesser General Public
 
16
//  License along with this library; if not, write to the Free Software
 
17
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
//
 
19
//  Current versions can be found at www.libavg.de
 
20
 
 
21
#include "Anim.h"
 
22
 
 
23
#include "../base/Exception.h"
 
24
#include "../base/ObjectCounter.h"
 
25
 
 
26
#include "../player/Player.h"
 
27
 
 
28
using namespace boost::python;
 
29
using namespace std;
 
30
 
 
31
namespace avg {
 
32
   
 
33
Anim::Anim(const object& startCallback, const object& stopCallback)
 
34
    : m_StartCallback(startCallback),
 
35
      m_StopCallback(stopCallback),
 
36
      m_bRunning(false),
 
37
      m_bIsRoot(true)
 
38
{
 
39
    ObjectCounter::get()->incRef(&typeid(*this));
 
40
}
 
41
 
 
42
Anim::~Anim()
 
43
{
 
44
    ObjectCounter::get()->decRef(&typeid(*this));
 
45
}
 
46
 
 
47
void Anim::setStartCallback(const object& startCallback)
 
48
{
 
49
    m_StartCallback = startCallback;
 
50
}
 
51
 
 
52
void Anim::setStopCallback(const object& stopCallback)
 
53
{
 
54
    m_StopCallback = stopCallback;
 
55
}
 
56
 
 
57
void Anim::start(bool)
 
58
{
 
59
    if (m_bRunning) {
 
60
        throw(Exception(AVG_ERR_UNSUPPORTED, 
 
61
                "Anim.start(): animation already running."));
 
62
    }
 
63
    if (!(Player::get()->isPlaying())) {
 
64
        throw(Exception(AVG_ERR_UNSUPPORTED, 
 
65
                "Animation playback can only be started when the player is running."));
 
66
    }
 
67
    m_bRunning = true;
 
68
    if (m_bIsRoot) {
 
69
        Player::get()->registerPreRenderListener(this);
 
70
    }
 
71
    if (m_StartCallback != object()) {
 
72
        call<void>(m_StartCallback.ptr());
 
73
    }
 
74
}
 
75
 
 
76
bool Anim::isRunning() const
 
77
{
 
78
    return m_bRunning;
 
79
}
 
80
 
 
81
void Anim::setHasParent()
 
82
{
 
83
    assert(!m_bRunning);
 
84
    m_bIsRoot = false;
 
85
}
 
86
 
 
87
void Anim::onPreRender()
 
88
{
 
89
    step();
 
90
}
 
91
    
 
92
void Anim::setStopped()
 
93
{
 
94
    if (m_bIsRoot) {
 
95
        Player::get()->unregisterPreRenderListener(this);
 
96
    }
 
97
    m_bRunning = false;
 
98
    if (m_StopCallback != object()) {
 
99
        call<void>(m_StopCallback.ptr());
 
100
    }
 
101
}
 
102
 
 
103
}