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
00021
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
00047
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
00064
00065
00066
00067
00068 void
00069 GLUT_KBD::update_mods(CXYpt &) {
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
00088 _kbds += (GLUT_KBD *) 0;
00089 }
00090 _kbds[winsys->id()] = this;
00091 glutKeyboardFunc(normal_keydown_callback);
00092 glutKeyboardUpFunc(normal_keyup_callback);
00093
00094
00095 }
00096
00097 GLUT_KBD *
00098 GLUT_KBD::kbd()
00099 {
00100 return _kbds[glutGetWindow()];
00101 }