Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SoGlutRenderArea.h

Go to the documentation of this file.
00001 //
00002 // SoGlutRenderArea
00003 //
00004 // simple window component for Inventor
00005 //
00006 // Copyright (C) 2001  PC John (email: xpeciv00@dcse.fee.vutbr.cz)
00007 //
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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   // internal functions, 
00071   // use SoGlutRenderArea::getComponent() instead
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   // from SoXtRenderArea
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   //void  setEventCallback(SoXtRenderAreaEventCB *fcn, void *userData = NULL)
00123   void setGLRenderAction(SoGLRenderAction *ra)  { sceneManager.setGLRenderAction(ra); };
00124   SoGLRenderAction* getGLRenderAction() const  { return sceneManager.getGLRenderAction(); };
00125 
00126   //void setSceneManager(SoSceneManager *sm)
00127   //SoSceneManager* getSceneManager() const;
00128   SoSceneManager* getSceneManager()  { return &sceneManager; };
00129 
00130   // from SoXtGLWidget
00131   //void setBorder(SbBool onOrOff);
00132   //SbBool isBorder() const;
00133 
00134   void setDoubleBuffer(SbBool onOrOff);
00135   SbBool isDoubleBuffer();
00136 
00137   Widget getNormalWindow()  { return childW; };
00138   Widget getNormalWidget()  { return childW; };
00139 
00140   // from SoXtComponent
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   //void setIconTitle(const char *newIconTitle);
00154   //const char* getIconTitle() const;
00155 
00156   //void setWindowCloseCallback(SoXtComponentCB *func, void *data = NULL);
00157   
00158   static SoGlutRenderArea* getComponent(Widget w);
00159 
00160 
00161 public:
00162 
00163   // internal functions
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 /* _SO_GLUT_RENDER_AREA_ */

Generated on Sun Feb 17 21:42:34 2002 for Sector 5 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001