00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VRS_SG_CANVAS_H
00021 #define VRS_SG_CANVAS_H
00022
00023 #include <vrs/contextdata.h>
00024 #include <vrs/sharedobj.h>
00025 #include <vrs/viewport.h>
00026 #include <vrs/time.h>
00027 #include <vrs/sg/behaviornode.h>
00028 #include <vrs/sg/inputevent.h>
00029 #include <vrs/sg/manager.h>
00030 #include <vrs/scenenode.h>
00031 #include <vrs/sg/scenething.h>
00032 #include <vrs/sg/cursor.h>
00033
00034 namespace VRS {
00035
00036 class Clock;
00037 class Engine;
00038 class Filter;
00039 class IntersectionInfo;
00040 class MultiSceneRenderer;
00041 class TechniqueProcessor;
00042 class ButtonEvent;
00043 class ConfigureEvent;
00044 class KeyEvent;
00045 class MotionEvent;
00046 class PointerEvent;
00047 class ResizeEvent;
00048 class WheelEvent;
00049 class TimeManager;
00050 template <typename T> class Array;
00051 template <typename T> class Iterator;
00052 template <typename T> class NonPersistentArray;
00053 template <typename T> class Stack;
00054
00056 class VRS_CORE_API Canvas : public Manager {
00057
00058 public:
00059 Canvas(
00060 Clock* canvasClock = NULL,
00061 double pixelRatio = 1.0,
00062 double resolutionDPI = 96.0
00063 );
00064 virtual ~Canvas();
00071 void append(SceneNode* sceneGraph);
00072 void prepend(SceneNode* sceneGraph);
00073 void insert(int atPosition, SceneNode* sceneGraph);
00074 void remove(SceneNode* sceneGraph);
00075 bool contains(SceneNode* sceneGraph) const;
00076
00077 void switchOn(SceneNode* sceneGraph);
00078 void switchOff(SceneNode* sceneGraph);
00079 bool isSwitchedOn(SceneNode* sceneGraph) const;
00080
00081 int sceneGraphs() const;
00082 SceneNode* sceneGraph(int atPosition) const;
00083
00084
00085 void append(BehaviorNode* behaviorGraph);
00086 void prepend(BehaviorNode* behaviorGraph);
00087 void insert(int atPosition, BehaviorNode* behaviorGraph);
00088 void remove(BehaviorNode* behaviorGraph);
00089 bool contains(BehaviorNode* behaviorGraph) const;
00090
00091 void reset(BehaviorNode* behaviorGraph);
00092 void switchOn(BehaviorNode* behaviorGraph, Clock* clock = NULL);
00093 void switchOff(BehaviorNode* behaviorGraph);
00094 bool isSwitchedOn(BehaviorNode* behaviorGraph) const;
00095
00096 int behaviorGraphs() const;
00097 BehaviorNode* behaviorGraph(int atPosition) const;
00098
00099
00100 virtual void enableRedisplay();
00102 virtual void disableRedisplay();
00104 virtual bool isRedisplayEnabled() const;
00106
00107 void redisplay();
00109
00115 virtual void postForRedisplay(double delay = 0.0);
00118 virtual bool isRedisplayNeeded() const;
00120 virtual VRSTime lastRedisplay() const;
00122
00123 static Iterator<Canvas*>* canvasList();
00125 static void redisplayAll();
00127 static void postAllForRedisplay(double delay = 0.0);
00129
00130 virtual void setSize(unsigned int width, unsigned int height) = 0;
00132
00133 virtual unsigned int getWidth() const = 0;
00135
00136 virtual unsigned int getHeight() const = 0;
00138
00139 double pixelRatio() const;
00141 void setResolution(double dpi);
00143
00148 double getResolution() const;
00150
00151 virtual void setSceneRenderer(MultiSceneRenderer*);
00153 virtual MultiSceneRenderer* getSceneRenderer() const;
00155
00156 virtual Engine* engine() const = 0;
00158 virtual TechniqueProcessor* processor() const = 0;
00160
00161 Clock* clock() const;
00163
00164 void pushClock(Clock* clock);
00165 void popClock();
00166
00167 void install(Engine* externalEngine);
00168 void deinstall(Engine* externalEngine);
00169 bool isInstalled(Engine* externalEngine) const;
00170
00171
00172
00173
00174 virtual void eval(Engine* engine, TechniqueProcessor* techniqueprocessor);
00175
00176
00177
00178
00179
00180
00181
00182 virtual bool prepareRedisplay();
00184
00197 virtual void finishRedisplay();
00199
00202 virtual void makeContextCurrent();
00204
00210 virtual void releaseContext();
00212
00215 IntersectionInfo* pickingResult(
00216 ButtonEvent* buttonEvent,
00217 SO<Filter> filter=NULL
00218 ) const;
00219
00222 SO<Iterator<SO<IntersectionInfo> > > allPickingResults(
00223 ButtonEvent* buttonEvent,
00224 SO<Filter> filter=NULL
00225 ) const;
00226
00227 int handle(Event* e);
00230
00231
00232
00233
00234 void setWatching(int onOff);
00235 int getWatching() const;
00236
00237 Matrix modelviewMatrix() const;
00238 Matrix projectionMatrix() const;
00239
00241
00242 virtual void setCursor(Cursor::Shape cursor);
00243
00245
00246 virtual Cursor::Shape getCursor() const;
00247
00248 VRS_TYPEINFO(Canvas, Manager);
00249
00250 void installEngine(Engine* engine);
00251 void deinstallEngine(Engine* engine);
00252
00253 void renderContents();
00255
00260 SceneThing* sceneRootNode() const;
00262
00263 Viewport* viewport() const;
00267 ContextData<Canvas*>* canvasHint() const;
00271 enum RenderingMode { Interactive = 1, HighQuality = 2 };
00272 virtual RenderingMode getRenderingMode() const;
00273 virtual void setRenderingMode(RenderingMode mode);
00274
00275 KeyEvent* keyEvent (
00276 InputEvent::Modifier modifiers,
00277 VRSTime time,
00278 unsigned long keyCode,
00279 int pressed,
00280 bool isAutoRepeat = false
00281 );
00282 MotionEvent* motionEvent (
00283 InputEvent::Modifier modifiers,
00284 VRSTime time,
00285 int x, int y, bool sameWindow
00286 );
00287 ButtonEvent* buttonEvent (
00288 InputEvent::Modifier modifiers,
00289 VRSTime time,
00290 InputEvent::Button button,
00291 InputEvent::Change pressed,
00292 int x, int y
00293 );
00294 ResizeEvent* resizeEvent (
00295 unsigned int width, unsigned int height, double aspectRatio=1.0
00296 );
00297 ConfigureEvent* configureEvent (
00298 int reason
00299 );
00300 PointerEvent* pointerEvent (
00301 InputEvent::Modifier modifiers,
00302 VRSTime time,
00303 bool entered
00304 );
00305
00306 WheelEvent* wheelEvent (
00307 InputEvent::Modifier modifiers,
00308 VRSTime time,
00309 int delta,
00310 int x,
00311 int y
00312 );
00313
00314 protected:
00315 virtual void acceptChildren(std::vector<Visitable*>& appendChildrenHere) const;
00316
00317 private:
00318
00319 SO<SceneThing> georoot_;
00320 SO<SceneThing> scenes_;
00321 SO<Array<SO<BehaviorNode> > > interaction_;
00322 SO<TimeManager> animation_;
00323
00324 SO<KeyEvent> keyEvent_;
00325 SO<MotionEvent> motionEvent_;
00326 SO<ButtonEvent> buttonEvent_;
00327 SO<ResizeEvent> resizeEvent_;
00328 SO<ConfigureEvent> configureEvent_;
00329 SO<PointerEvent> pointerEvent_;
00330 SO<WheelEvent> wheelEvent_;
00331
00332 double pixelRatio_;
00333 double resolutionDPI_;
00334 SO<Viewport> viewport_;
00335 SO<ContextData<Canvas*> > canvasHint_;
00336 SO<NonPersistentArray<Engine*> > installedEngines_;
00337 SO<MultiSceneRenderer> multiSceneRenderer_;
00338
00339 bool rendering_;
00340 bool redisplayDisabled_;
00341 VRSTime lastUpdate_;
00342 VRSTime nextUpdate_;
00343 SO<Stack<SO<Clock> > > clocks_;
00344 Cursor::Shape cursor_;
00345
00346 RenderingMode m_renderingMode;
00347
00348 mutable SO<ButtonEvent> lastPickingEvent_;
00349 mutable SO<IntersectionInfo> lastPickingResult_;
00350
00351 mutable InputEvent::Button currentPressedButtons_;
00352 };
00353
00354 }
00355
00356 #endif // VRS_SG_CANVAS_H