core/vgui/impl/glut/vgui_glut_window.cxx
Go to the documentation of this file.
00001 // \author fsm
00002 #include "vgui_glut_window.h"
00003 #include "vgui_glut_adaptor.h"
00004 #include <vgui/vgui_glut.h>
00005 
00006 vgui_glut_window::vgui_glut_window(char const *title,
00007                                    unsigned w, unsigned h,
00008                                    int posx, int posy)
00009   : vgui_window()
00010   , glutwin(0)
00011   , pending_reshape(false)
00012   , pending_reposition(false)
00013 {
00014   // We have to be careful to remember what the current
00015   // window is before creating a new one because we might
00016   // be inside the event handler of another window and
00017   // when we return we will still expect that GL context
00018   // to be the active one.
00019   int old = glutGetWindow();
00020 
00021   // create new window:
00022   glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
00023   glutInitWindowSize (w,h);
00024   glutInitWindowPosition(posx, posy);
00025   int window = glutCreateWindow( title ? title : __FILE__ );
00026   glutwin = new vgui_glut_adaptor(this, window);
00027   //glutHideWindow();
00028 
00029   // if another window was already current when the new one
00030   // was created, switch back to the old one now:
00031   if (old != 0)
00032     glutSetWindow(old);
00033 }
00034 
00035 vgui_glut_window::~vgui_glut_window()
00036 {
00037   delete glutwin;
00038   glutwin = 0;
00039 }
00040 
00041 void vgui_glut_window::show()
00042 {
00043   int old = glutGetWindow();
00044   glutSetWindow( static_cast<vgui_glut_adaptor*>(glutwin)->get_id() );
00045   glutShowWindow();
00046   glutSetWindow( old );
00047 }
00048 
00049 void vgui_glut_window::hide()
00050 {
00051   int old = glutGetWindow();
00052   glutSetWindow( static_cast<vgui_glut_adaptor*>(glutwin)->get_id() );
00053   glutHideWindow();
00054   glutSetWindow( old );
00055 }
00056 
00057 void vgui_glut_window::iconify()
00058 {
00059   int old = glutGetWindow();
00060   glutSetWindow( static_cast<vgui_glut_adaptor*>(glutwin)->get_id() );
00061   glutIconifyWindow();
00062   glutSetWindow( old );
00063 }
00064 
00065 void vgui_glut_window::reshape(unsigned w, unsigned h)
00066 {
00067   int old = glutGetWindow();
00068   glutSetWindow( static_cast<vgui_glut_adaptor*>(glutwin)->get_id() );
00069   glutReshapeWindow(w,h);
00070   glutSetWindow( old );
00071 }
00072 
00073 void vgui_glut_window::reposition(int x,int y)
00074 {
00075   int old = glutGetWindow();
00076   glutSetWindow( static_cast<vgui_glut_adaptor*>(glutwin)->get_id() );
00077   glutPositionWindow(x,y);
00078   glutSetWindow( old );
00079 }
00080 
00081 void vgui_glut_window::set_title(vcl_string const &s)
00082 {
00083   glutSetWindowTitle(s.c_str());
00084   glutSetIconTitle(s.c_str());
00085 }
00086 
00087 void vgui_glut_window::hello_from_adaptor()
00088 {
00089 }