Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

glut_winsys.C

Go to the documentation of this file.
00001 #ifdef macosx
00002 #include <unistd.h>
00003 #endif
00004 
00005 #include "glew/glew.H" // must come first
00006 
00007 #include "std/config.H"
00008 #include "glut_winsys.H"
00009 #include "tty_glut.H"
00010 #include "mouse.H" 
00011 #include "kbd.H"
00012 #include "glui/glui.h"
00013 #include "glui_menu.H"
00014 #include "glui_dialogs.H"
00015 
00016 #ifdef USE_GLUT_WACOM
00017 #include "glutwacom/glutwacom.h"
00018 #endif
00019 
00020 using namespace mlib;
00021 
00022 /*****************************************************************
00023  * GLUT_WINSYS
00024  *****************************************************************/
00025 
00026 //////////////////////////////////////////////////////
00027 // Static Variables Initialization
00028 //////////////////////////////////////////////////////
00029 
00030 ARRAY<GLUT_WINSYS*>  GLUT_WINSYS::_windows(1);
00031 
00032 //////////////////////////////////////////////////////
00033 // WINSYS Factory
00034 //////////////////////////////////////////////////////
00035 WINSYS *
00036 WINSYS::create(int &argc, char **argv)
00037 {
00038    if (!GLUT_WINSYS::instance()) 
00039       return new GLUT_WINSYS(argc, argv);
00040 
00041    return GLUT_WINSYS::instance()->copy();
00042 }
00043 
00044 /////////////////////////////////////
00045 // Constructor
00046 /////////////////////////////////////
00047 GLUT_WINSYS::GLUT_WINSYS(int &argc, char **argv) :
00048    _id(-1),
00049    _width (Config::get_var_int("JOT_WINDOW_WIDTH",  640,true)),
00050    _height(Config::get_var_int("JOT_WINDOW_HEIGHT", 480,true)),
00051    _init_x(Config::get_var_int("JOT_WINDOW_X",  4,true)),
00052    _init_y(Config::get_var_int("JOT_WINDOW_Y", 28,true)),
00053    _map_pending(false),
00054    _show_special_cursor(false),
00055    _mouse(0),
00056    _curpush(0),
00057    _file_select(0),
00058    _alert_box(0)
00059 {
00060   _double_buffered = 1;
00061 
00062 #ifdef WIN32
00063    // Start up the socket library...
00064    WSADATA wsaData;
00065    if (WSAStartup(0x0101, &wsaData))
00066    {
00067       err_ret("GLUT_WINSYS::GLUT_WINSYS() - Error while initializing sockets.");
00068    }
00069    SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ENABLE_PROCESSED_INPUT);
00070 #endif
00071 
00072 #ifdef macosx
00073    //apple's GLUT framework trashes current dir..
00074    //so get current directory
00075    char * cwd = getcwd(NULL, 0);
00076 #endif
00077 
00078    glutInit(&argc, argv);
00079 
00080 #ifdef macosx
00081    //and restore directory afterwards
00082    chdir (cwd);
00083    free(cwd);
00084 #endif
00085 
00086    FD_MANAGER::set_mgr(new GLUT_MANAGER);
00087 }
00088 
00089 /////////////////////////////////////
00090 // Destructor
00091 /////////////////////////////////////
00092 GLUT_WINSYS::~GLUT_WINSYS() 
00093 {
00094 #ifdef WIN32
00095    if (WSACleanup())
00096       err_ret("GLUT_WINSYS::~GLUT_WINSYS() - **Error** closing sockets");
00097 #endif
00098 }
00099 
00100 /////////////////////////////////////
00101 // setup()
00102 /////////////////////////////////////
00103 void
00104 GLUT_WINSYS::setup(CVIEWptr &v)
00105 {
00106    WINSYS::setup(v);
00107 
00108    //Initial window parameters
00109    glutInitWindowSize(_width, _height);
00110    glutInitWindowPosition(_init_x, _init_y);
00111 
00112    glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH|GLUT_STENCIL|GLUT_ACCUM);
00113    
00114    //Create the windows (it becomes 'current')
00115    _name = Config::get_var_str("JOT_WINDOW_NAME", "Jot",true);
00116    _id = glutCreateWindow(**_name);
00117 
00118    while (_windows.num() <= _id)
00119       _windows += (GLUT_WINSYS*) 0; // XXX - Must cast or += ARRAY is used
00120    _windows[_id] = this;
00121 
00122    //Set callbacks for 'current' window
00123    glutVisibilityFunc(visibility_cb);
00124    glutReshapeFunc(reshape_cb);
00125 
00126    //Frankly, these should be set only for
00127    //the root window... but we only ever have
00128    //one window these days.
00129    glutDisplayFunc(display_cb);
00130    GLUI_Master.set_glutIdleFunc(idle_cb);
00131       
00132    //Sets the keyboard cbs
00133    new GLUT_KBD(this);
00134 
00135    //Sets the mouse/tablet cbs
00136    _mouse = new GLUT_MOUSE(this); 
00137 
00138    //Allocate the dialogs
00139    _file_select = new GLUIFileSelect(this);  assert(_file_select);
00140    _alert_box = new GLUIAlertBox(this);  assert(_alert_box);
00141 
00142    GLenum err = glewInit();
00143    if (err == GLEW_OK) {
00144       if (Config::get_var_bool("JOT_PRINT_GLEW_INFO", false)) {
00145          cerr << "\nGLUT_WINSYS::setup: using GLEW "
00146               << glewGetString(GLEW_VERSION) << endl;
00147          if (GLEW_VERSION_2_0)
00148             cerr << "OpenGL 2.0 is supported" << endl;
00149          else if (GLEW_VERSION_1_5)
00150             cerr << "OpenGL 1.5 is supported" << endl;
00151          else if (GLEW_VERSION_1_4)
00152             cerr << "OpenGL 1.4 is supported" << endl;
00153          else if (GLEW_VERSION_1_3)
00154             cerr << "OpenGL 1.3 is supported" << endl;
00155          else if (GLEW_VERSION_1_2)
00156             cerr << "OpenGL 1.2 is supported" << endl;
00157          else if (GLEW_VERSION_1_1)
00158             cerr << "OpenGL 1.1 is supported" << endl;
00159          else 
00160             cerr << "Error: unknown version of OpenGL" << endl;
00161       }
00162    } else {
00163      // Problem: glewInit failed, something is seriously wrong.
00164      cerr << "GLUT_WINSYS::setup: error calling glewInit: "
00165      << glewGetErrorString(err) << endl;
00166    }
00167 }
00168 
00169 /////////////////////////////////////
00170 // mouse()
00171 /////////////////////////////////////
00172 Mouse*
00173 GLUT_WINSYS::mouse()
00174 {
00175    assert(_mouse);
00176    return _mouse;
00177 }
00178 
00179 /////////////////////////////////////
00180 // curspush()
00181 /////////////////////////////////////
00182 DEVhandler*
00183 GLUT_WINSYS::curspush() 
00184 { 
00185    if (!_curpush) {_curpush = new GLUT_CURSpush(this); assert(_curpush); }
00186 
00187    return _curpush;
00188 }
00189 
00190 /////////////////////////////////////
00191 // idle_cb()
00192 /////////////////////////////////////
00193 void    
00194 GLUT_WINSYS::idle_cb()      
00195 { 
00196    GLUT_MANAGER::idle_cb(); 
00197 }
00198 
00199 /////////////////////////////////////
00200 // display_cb()
00201 /////////////////////////////////////
00202 void    
00203 GLUT_WINSYS::display_cb()   
00204 { 
00205    GLUT_MANAGER::display_cb(); 
00206 }
00207 
00208 /////////////////////////////////////
00209 // visibility_cb()
00210 /////////////////////////////////////
00211 void
00212 GLUT_WINSYS::visibility_cb(int state)
00213 {
00214    GLUT_MANAGER *mgr = (GLUT_MANAGER *)FD_MANAGER::mgr(); assert(mgr);
00215    // XXX - Just block events to the blocking window, or all windows?
00216    //       Right now, we only use one window, so this is academic...
00217    // XXX - Process these callbacks even when blocking. It only does
00218    //       add/remove on the window in the timeouts list of GLUT_WINSYS.
00219    //if (mgr->get_blocker() == GLUT_WINSYS::window()) return;
00220 
00221    GLUT_WINSYS *win= _windows[glutGetWindow()];     assert(win->_map_cb);
00222 
00223    // Only do mapped callback if we have height and width for the window
00224    if (state == GLUT_VISIBLE && win->_width == 0 && win->_height == 0) 
00225    {
00226       win->_map_pending = true;
00227       return;
00228    }
00229 
00230    switch (state) 
00231    {
00232      case      GLUT_VISIBLE:     win->_map_cb->mapped();  break;
00233      case      GLUT_NOT_VISIBLE: win->_map_cb->icon();    break;
00234      assert(0);
00235    }
00236 } 
00237 
00238 /////////////////////////////////////
00239 // reshape_cb()
00240 /////////////////////////////////////
00241 void
00242 GLUT_WINSYS::reshape_cb(int width, int height)
00243 {
00244    GLUT_MANAGER *mgr = (GLUT_MANAGER *)FD_MANAGER::mgr(); assert(mgr);
00245    // XXX - Just block events to the blocking window, or all windows?
00246    //       Right now, we only use one window, so this is academic...
00247    // XXX - Store the new window size, but don't tell the view. 
00248    //       This will be called by unblock() to handle any pending work...
00249 
00250    GLUT_WINSYS *win = _windows[glutGetWindow()];
00251    assert(win && win->_view != NULL);
00252 
00253    win->_width = width;
00254    win->_height = height;
00255 
00256    if (win->_map_pending) 
00257    {
00258       win->_map_pending = false;
00259       visibility_cb(GLUT_VISIBLE);
00260    }
00261 
00262    if (mgr->get_blocker() == GLUT_WINSYS::window()) return;
00263 
00264    win->_view->set_size(width, height, 0, 0);   
00265 }
00266 
00267 /////////////////////////////////////
00268 // block()
00269 /////////////////////////////////////
00270 void
00271 GLUT_WINSYS::block()
00272 { 
00273    //Do pre-blocking work...
00274 
00275    //XXX - Just block this window's gluis?!
00276    GLUI_Master.block_gluis_by_gfx_window_id(_id);
00277 }
00278 
00279 /////////////////////////////////////
00280 // unblock()
00281 /////////////////////////////////////
00282 void
00283 GLUT_WINSYS::unblock()
00284 { 
00285    //Do post-blocking work...
00286 
00287    //XXX - Just unblock this window's gluis?!
00288    GLUI_Master.unblock_gluis_by_gfx_window_id(_id);
00289 
00290    //Now complete reshape callback if req'd...
00291 
00292    int width, height;
00293 
00294    _view->get_size(width, height);   
00295 
00296    if ((width != _width) || (height != _height))
00297    {
00298       int old_id = glutGetWindow();
00299       glutSetWindow(_id);
00300       reshape_cb(_width,_height);
00301       glutSetWindow(old_id);
00302    }
00303 }
00304 
00305 /////////////////////////////////////
00306 // size()
00307 /////////////////////////////////////
00308 void
00309 GLUT_WINSYS::size(int& w, int& h)
00310 { 
00311    w = _width; 
00312    h = _height;
00313 }
00314 
00315 /////////////////////////////////////
00316 // position()
00317 /////////////////////////////////////
00318 void
00319 GLUT_WINSYS::position(int& x, int& y)
00320 { 
00321    if (_id == -1) 
00322    {
00323       x = _init_x;
00324       y = _init_y;
00325    } 
00326    else {
00327       int old_id = glutGetWindow();
00328       glutSetWindow(_id);
00329       x = glutGet(GLUT_WINDOW_X);
00330       y = glutGet(GLUT_WINDOW_Y);
00331       glutSetWindow(old_id);
00332    }
00333 }
00334 
00335 /////////////////////////////////////
00336 // position_manually()
00337 /////////////////////////////////////
00338 void
00339 GLUT_WINSYS::position_manually(int x, int y) 
00340 {
00341    int old_id = glutGetWindow();
00342    if (_id == -1) {
00343       _init_x = x;
00344       _init_y = y;
00345    } 
00346    else 
00347    {
00348       glutSetWindow(_id);
00349       glutPositionWindow(x,y);
00350       glutSetWindow(old_id);
00351    }
00352 }
00353 
00354 /////////////////////////////////////
00355 // size_manually()
00356 /////////////////////////////////////
00357 void
00358 GLUT_WINSYS::size_manually(int w, int h) 
00359 {
00360    int old_id = glutGetWindow();
00361    if (_id == -1) 
00362    {
00363       _width = w;
00364       _height = h;
00365    } 
00366    else 
00367    {
00368       glutSetWindow(_id);
00369       glutReshapeWindow(w,h);
00370       glutSetWindow(old_id);
00371    }
00372 }
00373 
00374 /////////////////////////////////////
00375 // file_select()
00376 /////////////////////////////////////
00377 FileSelect*
00378 GLUT_WINSYS::file_select()
00379 { 
00380    //Shouldn't ask for this
00381    //before it's initialized 
00382    //in setup()
00383    assert(_file_select);
00384    return _file_select; 
00385 }
00386 
00387 /////////////////////////////////////
00388 // alert_box()
00389 /////////////////////////////////////
00390 AlertBox*
00391 GLUT_WINSYS::alert_box()
00392 { 
00393    //Shouldn't ask for this
00394    //before it's initialized 
00395    //in setup()
00396    assert(_alert_box);
00397    return _alert_box; 
00398 }
00399 
00400 /////////////////////////////////////
00401 // menu()
00402 /////////////////////////////////////
00403 MoveMenu*
00404 GLUT_WINSYS::menu(Cstr_ptr &name)
00405 {
00406    assert(_id != -1);  // menu() shouldn't be called before setup()
00407    return new GLUIMoveMenu(name, _id);
00408 }
00409 
00410 /////////////////////////////////////
00411 // swap_buffers()
00412 /////////////////////////////////////
00413 void
00414 GLUT_WINSYS::swap_buffers()
00415 {
00416    glutSwapBuffers(); 
00417 }
00418 
00419 #if 0 //linux
00420 
00421 // this is quite a hack, but finding a window by title is even worse in X-alexni
00422 #include <X11/Xlib.h>
00423 // we may be stuck with having to do this
00424 #undef MIN
00425 
00426 #include "glut_jot/glutint.h"
00427 // include glutint.h would do this properly, but it's in the GLUT source code...
00428 // do we want that or just have this hack? either way will work.
00429 #if 0
00430 extern Display *__glutDisplay;
00431 typedef struct _GLUTwindow {
00432   int num;              /* Small integer window id (0-based). */
00433  
00434   /* Window system related state. */
00435 #if defined(_WIN32)
00436   int pf;               /* Pixel format. */
00437   HDC hdc;              /* Window's Win32 device context. */
00438 #endif
00439   Window win;           /* X window for GLUT window */
00440   // more stuff
00441 } GLUTwindow;
00442 extern GLUTwindow *__glutCurrentWindow;
00443 #endif // 0
00444 #endif //linux
00445 
00446 /////////////////////////////////////
00447 // set_focus()
00448 /////////////////////////////////////
00449 void
00450 GLUT_WINSYS::set_focus()
00451 {
00452    err_mesg(ERR_LEV_SPAM, "GLUT_WINSYS::set_focus() - Setting focus...");
00453 
00454 #ifdef WIN32
00455    HWND hwnd;
00456 
00457    hwnd = FindWindow("GLUT", **_name);
00458    if(hwnd != NULL)
00459    {
00460       //SetFocus(hwnd);
00461       SetActiveWindow(hwnd);
00462    }
00463    else
00464    {
00465       err_msg("GLUT_WINSYS::set_focus() - Error! Failed getting handle to window: '%s'!!", **_name);
00466    }
00467 #elif linux
00468    // __glutDisplay and __glutCurrentWindow are not defined in all
00469    // versions of glut, so we're trying the code from the macosx
00470    // section instead:
00471    int old_window=glutGetWindow();
00472    glutSetWindow(_id);
00473    glutPopWindow();
00474    glutSetWindow(old_window);
00475 /*
00476    int old_window=glutGetWindow();
00477    glutSetWindow(_id);
00478    glutPopWindow();
00479    if(__glutCurrentWindow->win)
00480      XSetInputFocus( __glutDisplay,  __glutCurrentWindow->win, RevertToParent, CurrentTime);
00481    glutSetWindow(old_window);
00482 */
00483 #elif macosx
00484    int old_window=glutGetWindow();
00485    glutSetWindow(_id);
00486    glutPopWindow();
00487    glutSetWindow(old_window);
00488 #else
00489    err_mesg(ERR_LEV_WARN, "GLUT_WINSYS::set_focus() - NOTE: Need to implement this on this platform!");
00490 #endif
00491 }
00492 
00493 /////////////////////////////////////
00494 // get_cursor()
00495 /////////////////////////////////////
00496 int
00497 GLUT_WINSYS::get_cursor()
00498 {
00499    int winsys_cursor, glut_cursor, old_window;
00500 
00501    old_window = glutGetWindow();
00502    glutSetWindow(_id); 
00503    glut_cursor = glutGet(GLUT_WINDOW_CURSOR);
00504    glutSetWindow(old_window);
00505 
00506    switch(glut_cursor)
00507    {  
00508       case GLUT_CURSOR_RIGHT_ARROW:         winsys_cursor = CURSOR_RIGHT_ARROW;          break;
00509       case GLUT_CURSOR_LEFT_ARROW:          winsys_cursor = CURSOR_LEFT_ARROW;           break;
00510       case GLUT_CURSOR_INFO:                winsys_cursor = CURSOR_INFO;                 break;
00511       case GLUT_CURSOR_DESTROY:             winsys_cursor = CURSOR_DESTROY;              break;            
00512       case GLUT_CURSOR_HELP:                winsys_cursor = CURSOR_HELP;                 break;                
00513       case GLUT_CURSOR_CYCLE:               winsys_cursor = CURSOR_CYCLE;                break;               
00514       case GLUT_CURSOR_SPRAY:               winsys_cursor = CURSOR_SPRAY;                break;               
00515       case GLUT_CURSOR_WAIT:                winsys_cursor = CURSOR_WAIT;                 break;                
00516       case GLUT_CURSOR_TEXT:                winsys_cursor = CURSOR_TEXT;                 break;                
00517       case GLUT_CURSOR_CROSSHAIR:           winsys_cursor = CURSOR_CROSSHAIR;            break;           
00518       case GLUT_CURSOR_UP_DOWN:             winsys_cursor = CURSOR_UP_DOWN;              break;             
00519       case GLUT_CURSOR_LEFT_RIGHT:          winsys_cursor = CURSOR_LEFT_RIGHT;           break;          
00520       case GLUT_CURSOR_TOP_SIDE:            winsys_cursor = CURSOR_TOP_SIDE;             break;            
00521       case GLUT_CURSOR_BOTTOM_SIDE:         winsys_cursor = CURSOR_BOTTOM_SIDE;          break;         
00522       case GLUT_CURSOR_LEFT_SIDE:           winsys_cursor = CURSOR_LEFT_SIDE;            break;           
00523       case GLUT_CURSOR_RIGHT_SIDE:          winsys_cursor = CURSOR_RIGHT_SIDE;           break;          
00524       case GLUT_CURSOR_TOP_LEFT_CORNER:     winsys_cursor = CURSOR_TOP_LEFT_CORNER;      break;     
00525       case GLUT_CURSOR_TOP_RIGHT_CORNER:    winsys_cursor = CURSOR_TOP_RIGHT_CORNER;     break;    
00526       case GLUT_CURSOR_BOTTOM_RIGHT_CORNER: winsys_cursor = CURSOR_BOTTOM_RIGHT_CORNER;  break; 
00527       case GLUT_CURSOR_BOTTOM_LEFT_CORNER:  winsys_cursor = CURSOR_BOTTOM_LEFT_CORNER;   break; 
00528       case GLUT_CURSOR_FULL_CROSSHAIR:      winsys_cursor = CURSOR_FULL_CROSSHAIR;       break;      
00529       case GLUT_CURSOR_NONE:                winsys_cursor = CURSOR_NONE;                 break;                
00530       case GLUT_CURSOR_INHERIT:             winsys_cursor = CURSOR_INHERIT;              break;             
00531       default:                              winsys_cursor = CURSOR_NONE;                 break;                
00532    }
00533    return winsys_cursor;
00534 }
00535 
00536 /////////////////////////////////////
00537 // set_cursor()
00538 /////////////////////////////////////
00539 void
00540 GLUT_WINSYS::set_cursor(int winsys_cursor)
00541 {
00542    int glut_cursor;
00543 
00544    switch(winsys_cursor)
00545    {  
00546       case CURSOR_RIGHT_ARROW:         glut_cursor = GLUT_CURSOR_RIGHT_ARROW;          break;
00547       case CURSOR_LEFT_ARROW:          glut_cursor = GLUT_CURSOR_LEFT_ARROW;           break;
00548       case CURSOR_INFO:                glut_cursor = GLUT_CURSOR_INFO;                 break;
00549       case CURSOR_DESTROY:             glut_cursor = GLUT_CURSOR_DESTROY;              break;            
00550       case CURSOR_HELP:                glut_cursor = GLUT_CURSOR_HELP;                 break;                
00551       case CURSOR_CYCLE:               glut_cursor = GLUT_CURSOR_CYCLE;                break;               
00552       case CURSOR_SPRAY:               glut_cursor = GLUT_CURSOR_SPRAY;                break;               
00553       case CURSOR_WAIT:                glut_cursor = GLUT_CURSOR_WAIT;                 break;                
00554       case CURSOR_TEXT:                glut_cursor = GLUT_CURSOR_TEXT;                 break;                
00555       case CURSOR_CROSSHAIR:           glut_cursor = GLUT_CURSOR_CROSSHAIR;            break;           
00556       case CURSOR_UP_DOWN:             glut_cursor = GLUT_CURSOR_UP_DOWN;              break;             
00557       case CURSOR_LEFT_RIGHT:          glut_cursor = GLUT_CURSOR_LEFT_RIGHT;           break;          
00558       case CURSOR_TOP_SIDE:            glut_cursor = GLUT_CURSOR_TOP_SIDE;             break;            
00559       case CURSOR_BOTTOM_SIDE:         glut_cursor = GLUT_CURSOR_BOTTOM_SIDE;          break;         
00560       case CURSOR_LEFT_SIDE:           glut_cursor = GLUT_CURSOR_LEFT_SIDE;            break;           
00561       case CURSOR_RIGHT_SIDE:          glut_cursor = GLUT_CURSOR_RIGHT_SIDE;           break;          
00562       case CURSOR_TOP_LEFT_CORNER:     glut_cursor = GLUT_CURSOR_TOP_LEFT_CORNER;      break;     
00563       case CURSOR_TOP_RIGHT_CORNER:    glut_cursor = GLUT_CURSOR_TOP_RIGHT_CORNER;     break;    
00564       case CURSOR_BOTTOM_RIGHT_CORNER: glut_cursor = GLUT_CURSOR_BOTTOM_RIGHT_CORNER;  break; 
00565       case CURSOR_BOTTOM_LEFT_CORNER:  glut_cursor = GLUT_CURSOR_BOTTOM_LEFT_CORNER;   break; 
00566       case CURSOR_FULL_CROSSHAIR:      glut_cursor = GLUT_CURSOR_FULL_CROSSHAIR;       break;      
00567       case CURSOR_NONE:                glut_cursor = GLUT_CURSOR_NONE;                 break;                
00568       case CURSOR_INHERIT:             glut_cursor = GLUT_CURSOR_INHERIT;              break;             
00569       default:                         glut_cursor = GLUT_CURSOR_NONE;                 break;                
00570    }
00571 
00572    int old_window = glutGetWindow();
00573    
00574    glutSetWindow(_id); 
00575 
00576    glutSetCursor(glut_cursor);
00577    
00578    glutSetWindow(old_window);
00579 
00580 }
00581 
00582 /////////////////////////////////////
00583 // draw()
00584 /////////////////////////////////////
00585 int
00586 GLUT_WINSYS::draw()
00587 {
00588    if (!_show_special_cursor) return 0;
00589 
00590    // compute pixel coordinates of cursor
00591    int x = int(((_cursor_pt[0] + 1.0)/2.0) * (double)_width);
00592    int y = int(((_cursor_pt[1] + 1.0)/2.0) * (double)_height);
00593 
00594    // render the 'cross-hairs' cursor
00595    glPushMatrix();
00596 
00597    glViewport(0, 0, (GLsizei)_width, (GLsizei)_height);
00598 
00599    glMatrixMode(GL_PROJECTION);
00600    glLoadIdentity();
00601    gluOrtho2D(0, (GLdouble)_width, 0, (GLdouble)_height);
00602 
00603    glMatrixMode(GL_MODELVIEW);
00604    glLoadIdentity();
00605 
00606    glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT);
00607 
00608    glDisable(GL_LIGHTING);          // GL_ENABLE_BIT
00609    glColor3dv(COLOR::red.data());   // GL_CURRENT_BIT
00610 
00611    glBegin(GL_LINES);
00612 
00613    // draw 20-pixel-long cross hairs
00614 
00615    glVertex2i(x, y+10);
00616    glVertex2i(x, y-10);
00617 
00618    glVertex2i(x+10, y);
00619    glVertex2i(x-10, y);
00620 
00621    glEnd();
00622 
00623    glPopAttrib();
00624    glPopMatrix();
00625 
00626    return 0;
00627 }
00628 
00629 /////////////////////////////////////
00630 // push_cursor()
00631 /////////////////////////////////////
00632 void
00633 GLUT_WINSYS::push_cursor(CXYpt & pt) 
00634 { 
00635    _cursor_pt = pt; 
00636    _show_special_cursor = true;
00637 
00638    const int xpos = (int)( pt[0] /2* _width  + _width /2.);
00639    const int ypos = (int)(-pt[1] /2* _height + _height/2.);
00640 
00641    int old_window = glutGetWindow();
00642    
00643    glutSetWindow(_id); 
00644    //XXX - If _show_special_cursor is true, we draw a GL cursor
00645    //      So why do we warp the OS's system cursor, too?
00646    glutWarpPointer(xpos, ypos);
00647    //XXX - Only really needed for the GL cursor, not if the system
00648    //      cursor we're sufficient...
00649    //glutPostRedisplay();
00650    glutSetWindow(old_window);
00651 }
00652 
00653 /////////////////////////////////////
00654 // display()
00655 /////////////////////////////////////
00656 void 
00657 GLUT_WINSYS::display() 
00658 {
00659    //Nothing needed... window is already built and showing...
00660 }
00661  
00662 
00663 /////////////////////////////////////
00664 // operator>>()
00665 /////////////////////////////////////
00666 STDdstream& 
00667 GLUT_WINSYS::operator>>(STDdstream &ds) 
00668 {
00669    int x,y;
00670    position(x,y);
00671 
00672    return ds << x << y << _width << _height; 
00673 }
00674 
00675 /////////////////////////////////////
00676 // operator<<()
00677 /////////////////////////////////////
00678 STDdstream&
00679 GLUT_WINSYS::operator<<(STDdstream &ds) 
00680 {
00681    int x, y, w, h;
00682 
00683    ds >> x >> y >> w >> h;
00684 /*
00685    if (_id == -1) 
00686    {
00687       _width = w;
00688       _height = h;
00689       _init_x = x;
00690       _init_y = y;
00691    } 
00692    else 
00693    {
00694       position_manually(x,y);
00695       size_manually(_width,_height);
00696    }
00697 */
00698    position_manually(x,y);
00699    size_manually(w,h);
00700 
00701    return ds;
00702 }
00703 
00704 /* end of file glut_winsys.C */

Generated on Mon Sep 18 11:39:31 2006 for jot by  doxygen 1.4.4