Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GLUT_GLUT_EVENT_HANDLERS_H
00002 #define OPENTISSUE_UTILITY_GLUT_GLUT_EVENT_HANDLERS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl.h>
00013
00014 #include <OpenTissue/utility/glut/glut_application.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace glut
00019 {
00020
00021
00022 instance_pointer application;
00023
00024 void set_application_instance( OpenTissue::glut::instance_pointer const & ptr) { application = ptr; }
00025
00026 void mouse( int Button, int State, int cur_x, int cur_y )
00027 {
00028 int MODIFIERS = glutGetModifiers();
00029 bool shift = ( MODIFIERS & GLUT_ACTIVE_SHIFT ) == GLUT_ACTIVE_SHIFT;
00030 bool alt = ( MODIFIERS & GLUT_ACTIVE_ALT ) == GLUT_ACTIVE_ALT;
00031 bool ctrl = ( MODIFIERS & GLUT_ACTIVE_CTRL ) == GLUT_ACTIVE_CTRL;
00032 bool left = (Button == GLUT_LEFT_BUTTON);
00033 bool middle = (Button == GLUT_MIDDLE_BUTTON);
00034 bool right = (Button == GLUT_RIGHT_BUTTON);
00035 bool down = (State == GLUT_DOWN);
00036 if(down)
00037 application->mouse_down(cur_x,cur_y,shift,ctrl,alt,left,middle,right);
00038 else
00039 application->mouse_up(cur_x,cur_y,shift,ctrl,alt,left,middle,right);
00040 glutPostRedisplay();
00041 }
00042
00043 void motion( int cur_x, int cur_y )
00044 {
00045 application->mouse_move(cur_x,cur_y);
00046 glutPostRedisplay();
00047 }
00048
00049 void reshape( int cur_width, int cur_height )
00050 {
00051 application->width() = cur_width;
00052 application->height() = cur_height;
00053
00054 glViewport( 0, 0, application->width(), application->height() );
00055
00056 application->setup_model_view_projection();
00057 application->setup_lights();
00058
00059 glutPostRedisplay();
00060 }
00061
00062 void idle()
00063 {
00064 application->run();
00065 glutPostRedisplay();
00066 }
00067
00068 void key( unsigned char k, int , int )
00069 {
00070 switch (k)
00071 {
00072 case 27:
00073 case 'q':
00074 application->shutdown();
00075 #if defined(WIN32)
00076 Sleep(2*1000);
00077 #else
00078 sleep (2);
00079 #endif
00080 exit(k);
00081 break;
00082 case ' ':
00083 application->idle() = !application->idle();
00084 if(application->idle())
00085 glutIdleFunc( &idle );
00086 else
00087 glutIdleFunc(0);
00088
00089 default:
00090 application->action(k);
00091 break;
00092 };
00093 glutPostRedisplay();
00094 }
00095
00096 void specialkey(int k, int , int )
00097 {
00098 switch (k){
00099 case -1 :
00100 break;
00101 default:
00102 application->special_action(k);
00103 break;
00104 };
00105 glutPostRedisplay();
00106 return;
00107 }
00108
00109 void display()
00110 {
00111 application->display();
00112 }
00113
00114 void menu( int entry )
00115 {
00116 key( entry, 0, 0 );
00117 }
00118
00119 }
00120 }
00121
00122
00123 #endif