Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

glutm/window.h

Go to the documentation of this file.
00001 #ifndef GLUTM_WINDOW_H
00002 #define GLUTM_WINDOW_H
00003 
00004 /*
00005 
00006   GLT OpenGL C++ Toolkit (LGPL)
00007   Copyright (C) 2000-2002 Nigel Stewart  
00008 
00009   Email: nigels.com@gmail.com   
00010   WWW:   http://www.nigels.com/glt/
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 */
00027 
00033 #include <glutm/config.h>
00034 #include <glutm/glut.h>
00035 #include <glutm/menu.h>
00036 
00037 #include <glt/viewport.h>
00038 
00039 #include <string>
00040 
00041 class GlutMaster;
00042 
00043 // These are here for the benefit of derived classes that
00044 // want to use the same default arguments for constructors
00045 
00046 const std::string  titleDefault("GlutMaster");
00047 const int          widthDefault       = 400;
00048 const int          heightDefault      = 400;
00049 const int          xDefault           = 10;
00050 const int          yDefault           = 10;
00051 const unsigned int displayModeDefault = GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL;
00052 
00054 
00061 class GlutWindow
00062 {
00063     friend class GlutMaster;
00064 
00065     #ifdef GLUTM_SAVER
00066     friend LRESULT WINAPI ScreenSaverProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
00067     #endif
00068 
00069 public:
00093     GlutWindow
00094     (
00095         const std::string &title       = titleDefault,
00096         const int          width       = widthDefault, 
00097         const int          height      = heightDefault,
00098         const int          x           = xDefault, 
00099         const int          y           = yDefault,
00100         const unsigned int displayMode = displayModeDefault
00101     );
00102 
00104     virtual ~GlutWindow();
00105 
00106     //
00107     // Callback Functions
00108     // (Derived classes should implement some of these)
00109     //
00110 
00115     virtual void OnOpen();
00120     virtual void OnClose();
00125     virtual void OnDisplay();
00130     virtual void OnTick();
00135     virtual void OnIdle();
00140     virtual void OnTimer(unsigned char val);
00142     virtual void OnKeyboard(unsigned char key, int x, int y);
00144     virtual void OnKeyboardUp(unsigned char key, int x, int y);
00146     virtual void OnSpecial(int key, int x, int y);   
00148     virtual void OnSpecialUp(int key, int x, int y);   
00150     virtual void OnMouse(int button, int state, int x, int y);
00152     virtual void OnMotion(int x, int y);
00154     virtual void OnPassiveMotion(int x, int y);
00155 
00165     virtual void OnEntry(int state);
00166 
00168     virtual void OnMenu(int value);
00170     virtual void OnReshape(int w, int h);
00172     virtual void OnVisibility(int visible);
00173 
00174     //
00175     // Window manipulation
00176     //
00177 
00183     void open();
00189     void grab(const GlutWindow &window);
00194     void close();
00199     void position(int x,int y);
00204     void reshape(int width,int height);
00205     
00246     void setCursor(int cursor);
00247 
00252     void enterGameMode();
00257     void leaveGameMode();
00262     void toggleGameMode();
00267     void postRedisplay();
00272     void setTimer(unsigned int msecs,unsigned char val);
00278     void setTick(unsigned int msec);
00283     void setIdle(bool idle);
00288     void setSwapBuffers(const bool swap);
00289 
00290     //
00291     // OpenGL Frame Buffer Capture
00292     //
00293 
00295     bool captureRGB    (const std::string &filename);
00297     bool captureZBuffer(const std::string &filename);
00299     bool captureStencil(const std::string &filename);
00300 
00301     //
00302     // Window state
00303     //
00304 
00306              bool getOpen() const;
00308              bool getIdle() const;
00310      unsigned int getTick() const;
00312              bool getSwapBuffers() const;
00313 
00315               int getX()              const;
00317               int getY()              const;
00319               int getWidth()          const;
00321               int getHeight()         const; 
00322 
00324               int getBufferSize()     const;
00326               int getStencilSize()    const;
00328               int getDepthSize()      const;
00330               int getRedSize()        const;
00332               int getGreenSize()      const;
00334               int getBlueSize()       const;
00336               int getAlphaSize()      const;
00337 
00339               int getAccumRedSize()   const;
00341               int getAccumGreenSize() const;
00343               int getAccumBlueSize()  const;
00345               int getAccumAlphaSize() const;
00346 
00348              bool getDoubleBuffer()   const;
00350              bool getRGBA()           const;
00352              bool getStereo()         const;
00353                                         
00355              bool getTopLevel()       const;
00357               int getNumChildren()    const;
00358 
00360               int getColormapSize()   const;
00362               int getNumSamples()     const;
00364               int getCursor()         const;
00365                                         
00367              bool getShiftModifier()  const;
00369              bool getCtrlModifier()   const;
00371              bool getAltModifier()    const;
00372 
00373     //
00374     //
00375     //
00376 
00382     typedef enum
00383     {
00384         MENU_CLOSE = 0xff00,
00385 
00386         // Capture OpenGL frame buffer
00387 
00388         MENU_CAPTURE_RGB,       
00389         MENU_CAPTURE_STENCIL,       
00390         MENU_CAPTURE_ZBUFFER,       
00392     } MenuCallbacks;
00393 
00394 protected:  
00395 
00397     virtual void OnPreDisplay();
00399     virtual void OnPostDisplay();
00401     virtual void OnPreTimer(unsigned char val);
00402 
00404          int &windowID();        
00406    const int &windowID() const;     
00407 
00409     GltViewport _viewport;
00410 
00412     GlutMenu    _leftButtonMenu;
00414     GlutMenu    _rightButtonMenu;
00415 
00417     bool _swapBuffers;
00418 
00420     static const unsigned char _tickVal;
00421 
00423     std::string nextFilename();
00425     int _fileIndex;
00426 
00427 private:
00428 
00430     void swapBuffers();
00431 
00433             bool _idle;
00435     unsigned int _tick;         
00437     bool         _tickPending;
00438     
00440     int _windowID;
00441 
00443     bool _shiftModifier;
00445     bool _ctrlModifier;
00447     bool _altModifier;
00448 
00449     // These are used each time open() is called
00450 
00451     int          _x,_y;
00452     int          _width,_height;
00453     unsigned int _displayMode;
00454     bool         _gameMode;
00455     std::string  _title;
00456 
00457     // In tick-driven mode, mouse events are only
00458     // handled at the maximum refresh rate
00459 
00460     bool _mouseEvents;
00461     int  _mouseX,_mouseY;
00462 
00463     // Save the dimensions for switching 
00464     // between window and game mode
00465 
00466     bool _windowSaved;
00467     int  _windowX,_windowY,_windowWidth,_windowHeight;
00468 };
00469 
00470 #endif

Generated on Tue Nov 5 11:11:04 2002 for GLT by doxygen1.2.18