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

kbd.C

Go to the documentation of this file.
00001 #include "std/support.H"
00002 #include "glew/glew.H"
00003 
00004 #include "glut_winsys.H"
00005 #include "tty_glut.H"
00006 #include "glui/glui.h"
00007 #include "kbd.H"
00008 #include "geom/fsa.H"
00009 #include "std/config.H"
00010 
00011 using mlib::PIXEL;
00012 using mlib::CXYpt;
00013 
00014 ARRAY<GLUT_KBD *> GLUT_KBD::_kbds(1);
00015 
00016 extern "C" void
00017 normal_keydown_callback(unsigned char k, int x, int y)
00018 {
00019    GLUT_MANAGER *mgr = (GLUT_MANAGER *)FD_MANAGER::mgr(); assert(mgr);
00020    // XXX - Just block events to the blocking window, or all windows?
00021    //       Rightnow, we only use one window, so this is academic...
00022    if (mgr->get_blocker() == GLUT_WINSYS::window()) return;
00023 
00024    static bool debug = Config::get_var_bool("JOT_DEBUG_KEY_CALLBACKS",false,true);
00025    if (debug)
00026       err_msg("key pressed: %d", int(k));
00027 
00028    GLUT_KBD *kbd = GLUT_KBD::kbd();
00029 
00030    int w, h;
00031    kbd->winsys()->size(w, h);
00032 
00033    VIEWptr view = GLUT_WINSYS::window()->view();
00034 
00035    VIEWint_list::get(view)->handle_event(Evd(k));
00036    
00037    CXYpt curs(PIXEL(x, (double) h - y));
00038 
00039    kbd->update_mods(curs);
00040 }
00041 
00042 extern "C" void
00043 normal_keyup_callback(unsigned char k, int x, int y)
00044 {
00045    GLUT_MANAGER *mgr = (GLUT_MANAGER *)FD_MANAGER::mgr(); assert(mgr);
00046    // XXX - Just block events to the blocking window, or all windows?
00047    //       Rightnow, we only use one window, so this is academic...
00048    if (mgr->get_blocker() == GLUT_WINSYS::window()) return;
00049 
00050    GLUT_KBD *kbd = GLUT_KBD::kbd();
00051    VIEWptr view = GLUT_WINSYS::window()->view();
00052 
00053    VIEWint_list::get(view)->handle_event(Evd(k,KEYU));
00054 
00055    int w, h;
00056    kbd->winsys()->size(w, h);
00057    CXYpt curs(PIXEL(x, (double) h - y));
00058 
00059    kbd->update_mods(curs);
00060 }
00061 
00062 //
00063 // GLUT can't send shift/ctrl up/down as an event, so before
00064 // every event is sent we have to check to see if the modifier
00065 // status has changed, and if it has we have to send the change
00066 // event
00067 //
00068 void
00069 GLUT_KBD::update_mods(CXYpt &/*cur*/) {
00070 
00071    const int mods = glutGetModifiers();
00072    const bool new_shift = (mods & GLUT_ACTIVE_SHIFT) ? 1 : 0;
00073    const bool new_ctrl  = (mods & GLUT_ACTIVE_CTRL)  ? 1 : 0;
00074 
00075    if (new_shift != _shift) {
00076       _shift = new_shift;
00077    }
00078    if (new_ctrl != _ctrl) {
00079       _ctrl = new_ctrl;
00080    }
00081 }
00082 
00083 GLUT_KBD::GLUT_KBD(GLUT_WINSYS *winsys)
00084    : _winsys(winsys), _shift(false), _ctrl(false)
00085 {
00086    while (_kbds.num() <= winsys->id()) {
00087       // XXX - Must cast or += ARRAY is used, which makes this an infinite loop
00088       _kbds += (GLUT_KBD *) 0;
00089    }
00090    _kbds[winsys->id()] = this;
00091    glutKeyboardFunc(normal_keydown_callback);
00092    glutKeyboardUpFunc(normal_keyup_callback);
00093    //For imbedded GLUI windows that must 'share' the callbacks...
00094    //GLUI_Master.set_glutKeyboardFunc(normal_keydown_callback);
00095 }
00096 
00097 GLUT_KBD *
00098 GLUT_KBD::kbd()
00099 {
00100    return _kbds[glutGetWindow()];
00101 }

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