2
2
// libavg - Media Playback Engine.
3
// Copyright (C) 2003-2008 Ulrich von Zadow
3
// Copyright (C) 2003-2011 Ulrich von Zadow
5
5
// This library is free software; you can redistribute it and/or
6
6
// modify it under the terms of the GNU Lesser General Public
25
25
#include "../api.h"
26
26
#include "Timeout.h"
27
#include "DisplayEngine.h"
28
27
#include "NodeRegistry.h"
29
#include "MouseEvent.h"
30
28
#include "DisplayParams.h"
32
#include "IEventSink.h"
33
#include "EventDispatcher.h"
35
#include "MouseEvent.h"
36
29
#include "CursorState.h"
37
#include "MouseState.h"
30
#include "TestHelper.h"
31
#include "BoostPython.h"
39
33
#include "../audio/AudioParams.h"
34
#include "../graphics/GLConfig.h"
41
36
#include <libxml/parser.h>
37
#include <boost/shared_ptr.hpp>
54
49
class OffscreenCanvas;
55
class TrackerEventSource;
56
class MultitouchEventSource;
50
class TrackerInputDevice;
51
class MultitouchInputDevice;
57
52
class IFrameEndListener;
58
53
class IPlaybackEndListener;
59
54
class IPreRenderListener;
56
class EventDispatcher;
59
class SDLDisplayEngine;
61
61
typedef boost::shared_ptr<Node> NodePtr;
62
62
typedef boost::weak_ptr<Node> NodeWeakPtr;
63
typedef boost::shared_ptr<VisibleNode> VisibleNodePtr;
64
typedef boost::weak_ptr<VisibleNode> VisibleNodeWeakPtr;
65
63
typedef boost::shared_ptr<Canvas> CanvasPtr;
66
64
typedef boost::shared_ptr<MainCanvas> MainCanvasPtr;
67
65
typedef boost::shared_ptr<OffscreenCanvas> OffscreenCanvasPtr;
66
typedef boost::shared_ptr<class Contact> ContactPtr;
67
typedef boost::shared_ptr<EventDispatcher> EventDispatcherPtr;
68
typedef boost::shared_ptr<MouseEvent> MouseEventPtr;
69
typedef boost::shared_ptr<CursorEvent> CursorEventPtr;
70
typedef boost::shared_ptr<SDLDisplayEngine> SDLDisplayEnginePtr;
69
class AVG_API Player: IEventSink
77
80
void setResolution(bool bFullscreen,
78
81
int width=0, int height=0, int bpp=0);
79
83
void setWindowFrame(bool bHasWindowFrame);
80
84
void setWindowPos(int x=0, int y=0);
81
85
void setOGLOptions(bool bUsePOTTextures, bool bUseShaders,
82
86
bool bUsePixelBuffers, int multiSampleSamples);
83
87
void setMultiSampleSamples(int multiSampleSamples);
84
void enableAudio(bool bEnable);
85
88
void setAudioOptions(int samplerate, int channels);
86
89
DPoint getScreenResolution();
90
double getPixelsPerMM();
91
DPoint getPhysicalScreenDimensions();
92
void assumePixelsPerMM(double ppmm);
88
94
CanvasPtr loadFile(const std::string& sFilename);
89
95
CanvasPtr loadString(const std::string& sAVG);
91
97
OffscreenCanvasPtr loadCanvasFile(const std::string& sFilename);
92
98
OffscreenCanvasPtr loadCanvasString(const std::string& sAVG);
99
CanvasPtr createMainCanvas(const boost::python::dict& params);
100
OffscreenCanvasPtr createCanvas(const boost::python::dict& params);
93
101
void deleteCanvas(const std::string& sID);
94
102
CanvasPtr getMainCanvas() const;
95
103
OffscreenCanvasPtr getCanvas(const std::string& sID) const;
119
127
int setOnFrameHandler(PyObject * pyfunc);
120
128
bool clearInterval(int id);
122
void addEventSource(IEventSource* pSource);
130
void addInputDevice(IInputDevicePtr pSource);
123
131
MouseEventPtr getMouseState() const;
124
TrackerEventSource * addTracker();
125
TrackerEventSource * getTracker();
132
TrackerInputDevice * addTracker();
133
TrackerInputDevice * getTracker();
126
134
void enableMultitouch();
127
135
bool isMultitouchAvailable() const;
128
void setEventCapture(VisibleNodePtr pNode, int cursorID);
136
void setEventCapture(NodePtr pNode, int cursorID);
129
137
void releaseEventCapture(int cursorID);
138
bool isCaptured(int cursorID);
131
139
EventPtr getCurEvent() const;
132
140
void setMousePos(const IntPoint& pos);
133
141
int getKeyModifierState() const;
134
143
BitmapPtr screenshot();
135
144
void setCursor(const Bitmap* pBmp, IntPoint hotSpot);
136
145
void showCursor(bool bShow);
138
VisibleNodePtr getElementByID(const std::string& id);
147
NodePtr getElementByID(const std::string& id);
139
148
AVGNodePtr getRootNode();
140
149
void doFrame(bool bFirstFrame);
141
150
double getFramerate();
142
151
double getVideoRefreshRate();
143
152
bool isUsingShaders();
144
153
void setGamma(double red, double green, double blue);
145
DisplayEngine * getDisplayEngine() const;
154
SDLDisplayEngine * getDisplayEngine() const;
146
155
void setStopOnEscape(bool bStop);
147
156
bool getStopOnEscape() const;
148
157
void setVolume(double volume);
155
164
const NodeDefinition& getNodeDef(const std::string& sType);
157
166
void disablePython();
158
bool isAudioEnabled() const;
160
void loadPlugin(const std::string& name);
168
boost::python::object loadPlugin(const std::string& name);
161
169
void setPluginPath(const std::string& newPath);
162
170
std::string getPluginPath() const;
171
179
void registerPreRenderListener(IPreRenderListener* pListener);
172
180
void unregisterPreRenderListener(IPreRenderListener* pListener);
174
virtual bool handleEvent(EventPtr pEvent);
182
bool handleEvent(EventPtr pEvent);
177
185
void initConfig();
178
186
void initGraphics();
183
191
NodePtr loadMainNodeFromFile(const std::string& sFilename);
184
192
NodePtr loadMainNodeFromString(const std::string& sAVG);
185
193
NodePtr internalLoad(const std::string& sAVG);
194
SDLDisplayEnginePtr safeGetDisplayEngine();
187
196
NodePtr createNodeFromXml(const xmlDocPtr xmlDoc,
188
197
const xmlNodePtr xmlNode);
193
202
void sendFakeEvents();
194
void sendOver(CursorEventPtr pOtherEvent, Event::Type type, VisibleNodePtr pNode);
203
void sendOver(CursorEventPtr pOtherEvent, Event::Type type, NodePtr pNode);
195
204
void handleCursorEvent(CursorEventPtr pEvent, bool bOnlyCheckCursorOver=false);
197
206
void dispatchOffscreenRendering(OffscreenCanvas* pOffscreenCanvas);
201
210
MainCanvasPtr m_pMainCanvas;
203
DisplayEngine * m_pDisplayEngine;
204
AudioEngine * m_pAudioEngine;
205
TestHelper * m_pTestHelper;
212
SDLDisplayEnginePtr m_pDisplayEngine;
213
TestHelperPtr m_pTestHelper;
207
bool m_bAudioEnabled;
208
215
std::string m_CurDirName;
209
216
bool m_bStopping;
210
217
NodeRegistry m_NodeRegistry;
212
IEventSource* m_pMultitouchEventSource;
219
IInputDevicePtr m_pMultitouchInputDevice;
214
221
int addTimeout(Timeout* pTimeout);
215
222
void removeTimeout(Timeout* pTimeout);
250
257
EventDispatcherPtr m_pEventDispatcher;
251
258
struct EventCaptureInfo {
252
EventCaptureInfo(const VisibleNodeWeakPtr& pNode);
259
EventCaptureInfo(const NodeWeakPtr& pNode);
254
VisibleNodeWeakPtr m_pNode;
255
262
int m_CaptureCount;
257
264
typedef boost::shared_ptr<EventCaptureInfo> EventCaptureInfoPtr;
259
266
std::map<int, EventCaptureInfoPtr> m_EventCaptureInfoMap;
261
MouseState m_MouseState;
263
// These are maps for each cursor id.
268
MouseEventPtr m_pLastMouseEvent;
270
// The indexes of this map are cursorids.
264
271
std::map<int, CursorStatePtr> m_pLastCursorStates;
265
273
PyObject * m_EventHookPyFunc;