File: gnashpython.h

package info (click to toggle)
gnash 0.8.4-3~lenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 20,356 kB
  • ctags: 17,677
  • sloc: cpp: 115,589; ansic: 25,104; xml: 12,898; sh: 10,150; makefile: 5,588; lisp: 2,750; python: 549; exp: 73
file content (189 lines) | stat: -rw-r--r-- 4,886 bytes parent folder | download
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// gnashpython.h: headers for the python bindings to Gnash
// 
//   Copyright (C) 2008 Free Software Foundation, Inc.
// 
// This program 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 3 of the License, or
// (at your option) any later version.
// 
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//

#ifndef GNASHPYTHON_H
#define GNASHPYTHON_H

#ifdef HAVE_CONFIG_H
# include "gnashconfig.h"
#endif

#include "Range2d.h"
#include "gnash.h"
#include "ManualClock.h"
#include "movie_root.h"
#include "movie_definition.h"
#include "render_handler.h"
#include "character.h"
#include "log.h"

#include <string>
#include <memory>
#include <deque>
#include <boost/python.hpp>

// Because the Python bindings are there to allow flexible access
// to Gnash in an interpreted language, there need to be many
// checks on initialization order to avoid memory errors.

// Boost 1.33 seems to dislike auto_ptrs in the class
// declaration. Perhaps I'm not handling them correctly, perhaps
// it's better in 1.34.

// Forward declarations
namespace gnash {
namespace pythonwrapper {
        class GnashCharacter;
        class GnashPlayer;
}
}

namespace gnash {

namespace pythonwrapper {

class GnashPlayer
{

public:

    GnashPlayer();
    ~GnashPlayer();

    // For exiting
    void close();

    /// Movie creation
    
    /// Takes a python file object
    bool loadMovie(PyObject& pf);
    bool initVM();

    // Renderer
    bool setRenderer(const std::string& r);

    // Movie information
    float getSWFFrameRate() const;
    int getSWFFrameCount() const;
    int getSWFVersion() const;
    float getSWFWidth() const;
    float getSWFHeight() const;
    int getSWFBytesTotal() const;
    int getSWFBytesLoaded() const;
    std::string getSWFURL() const;

    // Player state
    int getCurrentFrame() const;
    
    // Sprites
    GnashCharacter* getCharacterById(int id);    
    GnashCharacter* getTopmostMouseEntity();

    // Interaction
    void advanceClock(unsigned long ms);
    void advance();
    void render(bool forceRedraw);
    void restart();
    void setVerbosity(unsigned verbosity);
    
    geometry::SnappingRanges2d<int> getInvalidatedRanges() const;
    
    // Move the pointer to position x, y.
    // @ return whether the move triggered an event needing a redraw. Use this
    // to decide whether to rerender.
    bool movePointer(int x, int y);
    
    // Send a mouse click event at the current position of the pointer.
    // @ return whether the move triggered an event needing a redraw. Use this
    // to decide whether to rerender.
    bool mouseClick();

    // @ return whether the keypress triggered an event needing a redraw. Use this
    // to decide whether to rerender.
    bool pressKey(int code);

    static std::string getLogMessage();
    static size_t logSize();
    
private:
    void init();
    void setBaseURL(std::string url);
    bool addRenderer(gnash::render_handler* handler);

    gnash::movie_definition* _movieDef;
    gnash::movie_root* _movieRoot;
    gnash::ManualClock _manualClock;
    gnash::render_handler* _renderer;

    gnash::InvalidatedRanges _invalidatedBounds;
 
    gnash::LogFile& _logFile;
    
    // The position of our pointer
    int _xpos, _ypos;

    // The base URL of the movie;
    std::string _url;

    static std::deque<std::string> _logMessages;

    static void receiveLogMessages(const std::string& s);

};

class GnashCharacter
{
public:
    GnashCharacter();
    GnashCharacter(gnash::character* c);
    ~GnashCharacter();

    // The only constant aspect of a character?
    const int id() { return _character->get_id(); }

    std::string name() { return _character->get_name(); }

    const char* textName() { return _character->get_text_name(); }

    std::string target() { return _character->getTarget(); }

    float ratio() { return _character->get_ratio(); }

    int depth() { return _character->get_depth(); }
    
    int clipDepth() { return _character->get_clip_depth(); }
    
    float height() { return _character->get_height(); }
    
    float width() { return _character->get_width(); }

    bool visible() { return _character->get_visible(); }
    
    void advance() { _character->advance(); }
    
    GnashCharacter* getParent();
    
private:
    gnash::character*  _character;
};

}
}
// end namespace pythonwrapper
#endif