00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _SO_GLUT_RENDER_AREA_
00025 #define _SO_GLUT_RENDER_AREA_
00026
00027
00028 #define SoXt SoGlut
00029 #define SoXtRenderArea SoGlutRenderArea
00030
00031 #include <Inventor/SoSceneManager.h>
00032 #include <Inventor/SbViewportRegion.h>
00033 #include <Inventor/events/SoKeyboardEvent.h>
00034 #include <Inventor/events/SoLocation2Event.h>
00035 #include <Inventor/events/SoMouseButtonEvent.h>
00036 #include <Inventor/actions/SoGLRenderAction.h>
00037 #include <Inventor/fields/SoSFTime.h>
00038
00039
00040
00041
00042 class SoGlut;
00043 class SoGlutRenderArea;
00044
00045
00046 #define Widget int
00047
00048
00049
00050 class SoGlut
00051 {
00052 friend SoGlutRenderArea;
00053 protected:
00054
00055 static SoGlutRenderArea *windowsList;
00056 static bool widgetShowed;
00057
00058 static void addWindow(SoGlutRenderArea *window);
00059 static void removeWindow(SoGlutRenderArea *window);
00060
00061 public:
00062
00063 static Widget init(const char *appName, const char *className = "Inventor");
00064 static Widget init(int argc, char ** argv);
00065 static void mainLoop();
00066
00067 static void show(Widget widget);
00068 static void hide(Widget widget);
00069
00070
00071
00072 static SoGlutRenderArea* getWindowFromChildW(int id);
00073 static SoGlutRenderArea* getWindowFromMainW(int id);
00074
00075 };
00076
00077
00078
00079 class SoGlutRenderArea
00080 {
00081 friend SoGlut;
00082
00083 public:
00084
00085 SoGlutRenderArea(Widget parent = NULL,
00086 const char *name = NULL,
00087 SbBool buildInsideParent = TRUE,
00088 SbBool getMouseInput = TRUE,
00089 SbBool getKeyboardInput = TRUE);
00090 ~SoGlutRenderArea();
00091
00092
00093 virtual void setSceneGraph(SoNode *newScene) { sceneManager.setSceneGraph(newScene); };
00094 virtual SoNode* getSceneGraph() { return sceneManager.getSceneGraph(); };
00095
00096 void setBackgroundColor(const SbColor &c) { sceneManager.setBackgroundColor(c); };
00097 const SbColor& getBackgroundColor() const { sceneManager.getBackgroundColor(); };
00098
00099 void setViewportRegion(const SbViewportRegion &newRegion);
00100 const SbViewportRegion& getViewportRegion() const;
00101
00102 void setTransparencyType(SoGLRenderAction::TransparencyType type);
00103 SoGLRenderAction::TransparencyType getTransparencyType() const;
00104
00105 void setAntialiasing(SbBool smoothing, int numPasses) { sceneManager.setAntialiasing(smoothing, numPasses); };
00106 void getAntialiasing(SbBool &smoothing, int &numPasses) const { sceneManager.getAntialiasing(smoothing, numPasses); };
00107
00108 void setClearBeforeRender(SbBool trueOrFalse, SbBool zbTrueOrFalse=TRUE)
00109 { clearColorBuffer = trueOrFalse; clearZBuffer = zbTrueOrFalse; };
00110 SbBool isClearBeforeRender() const { return clearColorBuffer; };
00111 SbBool isClearZBufferBeforeRender() const { return clearZBuffer; };
00112
00113 void setAutoRedraw(SbBool trueOrFalse) { trueOrFalse ? autoRedraw = true : autoRedraw = false; };
00114 SbBool isAutoRedraw() const { return autoRedraw && sceneManager.isAutoRedraw(); };
00115 void setRedrawPriority(unsigned long priority) { sceneManager.setRedrawPriority(priority); };
00116 unsigned long getRedrawPriority() const { return sceneManager.getRedrawPriority(); };
00117 static unsigned long getDefaultRedrawPriority() { return SoSceneManager::getDefaultRedrawPriority(); };
00118
00119 void render() { sceneManager.render(true, true); };
00120 void scheduleRedraw() { sceneManager.scheduleRedraw(); };
00121
00122
00123 void setGLRenderAction(SoGLRenderAction *ra) { sceneManager.setGLRenderAction(ra); };
00124 SoGLRenderAction* getGLRenderAction() const { return sceneManager.getGLRenderAction(); };
00125
00126
00127
00128 SoSceneManager* getSceneManager() { return &sceneManager; };
00129
00130
00131
00132
00133
00134 void setDoubleBuffer(SbBool onOrOff);
00135 SbBool isDoubleBuffer();
00136
00137 Widget getNormalWindow() { return childW; };
00138 Widget getNormalWidget() { return childW; };
00139
00140
00141 virtual void show();
00142 virtual void hide();
00143 SbBool isVisible() { return showStatus && SoGlut::widgetShowed; };
00144
00145 Widget getWidget() const { return mainW; };
00146
00147 void setSize(const SbVec2s &size);
00148 SbVec2s getSize() { return viewport.getWindowSize(); };
00149
00150 void setTitle(const char *newTitle);
00151 const char* getTitle() const { return title; };
00152
00153
00154
00155
00156
00157
00158 static SoGlutRenderArea* getComponent(Widget w);
00159
00160
00161 public:
00162
00163
00164 void redraw_cb();
00165 void reshape_cb(int w, int h);
00166 void keyboard_cb(int key, bool down, bool spec, int x, int y);
00167 void mouse_motion_cb(int x, int y);
00168 void mouse_button_cb(SoMouseButtonEvent::Button b, bool down, int x, int y);
00169 void makeCurrent();
00170
00171 protected:
00172
00173 int mainW;
00174 int childW;
00175
00176 SoGlutRenderArea *windowsList;
00177
00178 SoSceneManager sceneManager;
00179
00180 bool showStatus;
00181 char* title;
00182 bool defaultTitle;
00183 unsigned int mode;
00184 SbViewportRegion viewport;
00185 SbBool clearColorBuffer;
00186 SbBool clearZBuffer;
00187 bool autoRedraw;
00188 SbBool getMouseInput;
00189 SbBool getKeyboardInput;
00190
00191
00192 virtual void doShow();
00193 virtual void doHide();
00194
00195 void makeEvent(SoEvent *event, int x, int y, int modifiers);
00196
00197 void createMainW();
00198 void createChildW();
00199 void destroyMainW();
00200 void destroyChildW();
00201
00202 private:
00203
00204 SoKeyboardEvent keyEvent;
00205 SoLocation2Event mouseMotionEvent;
00206 SoMouseButtonEvent mouseButtonEvent;
00207
00208 };
00209
00210 #endif