GLUTCallbackFunctions.h File Reference

This file contains the declarations of all important callback functions for the GLUT and GLUI events. More...

#include "../src/main.h"
#include "../src/Graph.h"
#include "../src/RadialLayout.h"

Include dependency graph for GLUTCallbackFunctions.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

void createGLUTWindow (Graph *graph, RadialLayout *radial_layout, GLuint screen_width, GLuint screen_height)
void createGLUI ()
void myGLUTIdleFunc ()
void myGLUTReshapeFunc (GLint screen_width, GLint screen_height)
void renderScene ()
void updateRenderMode ()
void startDemoMode ()
void myGLUTKeyboardEventFunc (unsigned char key, int x_pos, int y_pos)
void myGLUTMouseEventFunc (int button, int state, int x_pos, int y_pos)
int retrieveObjectID (int x_coord, int y_coord)
void myGlutMotion (int x_pos, int y_pos)
void resetSceneRotation ()
void toggleCaptionEnabling ()


Detailed Description

This file contains the declarations of all important callback functions for the GLUT and GLUI events.

Definition in file GLUTCallbackFunctions.h.


Function Documentation

void createGLUI  ) 
 

This creates the GLUI for the application.

Definition at line 98 of file GLUTCallbackFunctions.cpp.

References is_caption_enabled_, main_window, myGLUTIdleFunc(), resetSceneRotation(), selected_animation_speed_, selected_render_mode_, startDemoMode(), toggleCaptionEnabling(), and updateRenderMode().

Referenced by createGLUTWindow().

00099 { 00100 //exit(3434); 00101 GLUI *glui_window = GLUI_Master.create_glui("Menu"); 00102 // for he animation speed 00103 00104 GLUI_Spinner *animation_speed_spinner = 00105 glui_window->add_spinner("Speed:", GLUI_SPINNER_INT, 00106 &selected_animation_speed_); 00107 00108 animation_speed_spinner->set_int_limits(100, 2000); 00109 00110 // for he render mode 00111 GLUI_Panel *radio_group_panel = glui_window->add_panel("Render Mode"); 00112 GLUI_RadioGroup *render_mode_radio_group = 00113 glui_window->add_radiogroup_to_panel(radio_group_panel, 00114 &selected_render_mode_, 1, 00115 (GLUI_Update_CB)updateRenderMode); 00116 00117 // put on the GLUI 00118 glui_window->add_checkbox("Enable Caption", &is_caption_enabled_, 2, 00119 (GLUI_Update_CB)toggleCaptionEnabling); 00120 glui_window->add_radiobutton_to_group(render_mode_radio_group, 00121 "Ivan's Version"); 00122 glui_window->add_radiobutton_to_group(render_mode_radio_group, 00123 "Laura's Version"); 00124 glui_window->add_button("Demo", 0, (GLUI_Update_CB)startDemoMode); 00125 glui_window->add_button("Reset Rotation", 0, 00126 (GLUI_Update_CB)resetSceneRotation); 00127 glui_window->add_separator(); 00128 glui_window->add_button("Quit", 0, (GLUI_Update_CB)exit); 00129 00130 glui_window->set_main_gfx_window(main_window); 00131 00132 // register the idle callback with GLUI (not with GLUT!) 00133 GLUI_Master.set_glutIdleFunc(myGLUTIdleFunc); 00134 }

Here is the call graph for this function:

void createGLUTWindow Graph graph,
RadialLayout radial_layout,
GLuint  screen_width,
GLuint  screen_height
 

This is the callback function for the GLUT initializations.

Parameters:
graph The graph to draw.
radial_layout The radiallayout to draw.
screen_width The screen width.
screen_height The screen height.

Definition at line 54 of file GLUTCallbackFunctions.cpp.

References createGLUI(), Graph::createGraph(), graph_, main_window, myGLUTKeyboardEventFunc(), myGlutMotion(), myGLUTMouseEventFunc(), myGLUTReshapeFunc(), radial_layout_, renderScene(), screen_height_, and screen_width_.

Referenced by main().

00056 { 00057 screen_width_ = screen_width <= 0 ? 100 : screen_width; 00058 screen_height_ = screen_height <= 0 ? 100 : screen_height; 00059 if (graph == NULL) 00060 { 00061 cerr << "Graph is NULL." << endl; 00062 exit(0); 00063 } 00064 graph_ = graph; 00065 00066 if (radial_layout == NULL) 00067 { 00068 cerr << "Radial Layout is NULL." << endl; 00069 exit(0); 00070 } 00071 radial_layout_ = radial_layout; 00072 00073 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 00074 glutInitWindowPosition(50, 50); 00075 glutInitWindowSize(800, 600); 00076 main_window = glutCreateWindow("InfoViz: Animated Radial Tree Exploration"); 00077 00078 // assign the GLUT callback functions 00079 glutDisplayFunc(renderScene); 00080 00081 glutReshapeFunc(myGLUTReshapeFunc); 00082 glutKeyboardFunc(myGLUTKeyboardEventFunc); 00083 glutMouseFunc(myGLUTMouseEventFunc); 00084 glutMotionFunc(myGlutMotion); 00085 00086 // create graph 00087 graph_->createGraph("Hallo"); 00088 // create the GLUI 00089 createGLUI(); 00090 // run the GLUT main moop and wait for events 00091 glutMainLoop(); 00092 }

Here is the call graph for this function:

void myGLUTIdleFunc  ) 
 

This creates the GLUI for the application.

Definition at line 226 of file GLUTCallbackFunctions.cpp.

References main_window.

Referenced by createGLUI().

00227 { 00228 // the current window is undefined during an idle callback; therefore we 00229 // need to explicitly change it if necessary 00230 if (glutGetWindow() != main_window) 00231 { 00232 glutSetWindow(main_window); 00233 } 00234 glutPostRedisplay(); 00235 }

void myGLUTKeyboardEventFunc unsigned char  key,
int  x_pos,
int  y_pos
 

This handles the key board events.

Parameters:
key The user-typed key.
x_pos The keyboard's x position.
y_pos The keyboard's y position.

Definition at line 289 of file GLUTCallbackFunctions.cpp.

References graph_, is_fullscreen_mode_on_, startDemoMode(), and Graph::toggleRenderMode().

Referenced by createGLUTWindow().

00290 { 00291 switch(key) 00292 { 00293 case 27 : 00294 case 'q' : 00295 exit(0); 00296 case GLUT_KEY_F1 : 00297 if (!is_fullscreen_mode_on_) 00298 { 00299 glutFullScreen(); 00300 is_fullscreen_mode_on_ = true; 00301 } 00302 else 00303 { 00304 glutReshapeWindow(800, 600); 00305 is_fullscreen_mode_on_ = false; 00306 } 00307 break; 00308 case 'a' : 00309 startDemoMode(); 00310 break; 00311 case 'm' : 00312 graph_->toggleRenderMode(); 00313 break; 00314 default : 00315 break; 00316 }; 00317 }

Here is the call graph for this function:

void myGlutMotion int  x_pos,
int  y_pos
 

This is the callback function for the motions in the scene.

Parameters:
x_pos The x position of the viewport.
y_pos The y position of the viewport.

Definition at line 407 of file GLUTCallbackFunctions.cpp.

References is_left_mouse_button_down_, last_x_pos_, last_y_pos_, screen_height_, screen_width_, x_rotation_, y_rotation_, and z_rotation_.

Referenced by createGLUTWindow(), and renderScene().

00408 { 00409 if (!is_left_mouse_button_down_) 00410 { 00411 x_rotation_ += (GLfloat) (y_pos - last_y_pos_); 00412 y_rotation_ += (GLfloat) (x_pos - last_x_pos_); 00413 00414 last_x_pos_ = x_pos; 00415 last_y_pos_ = y_pos; 00416 00417 if ((last_x_pos_ == screen_width_ / 2) || 00418 (last_y_pos_ == screen_height_ / 2)) 00419 { 00420 } 00421 else 00422 { 00423 if (((x_pos - screen_width_ / 2) * (last_y_pos_ - screen_height_ / 2) 00424 - (last_x_pos_ - screen_width_ / 2) * (y_pos - screen_height_ / 2)) 00425 > 0) 00426 { 00427 z_rotation_ += (GLfloat) ((abs(x_pos - last_x_pos_) 00428 + abs(y_pos - last_y_pos_))); 00429 } 00430 else 00431 { 00432 z_rotation_ += (GLfloat) (-1*(abs(x_pos - last_x_pos_) 00433 + abs(y_pos - last_y_pos_))); 00434 } 00435 } 00436 00437 glutPostRedisplay(); 00438 } 00439 }

void myGLUTMouseEventFunc int  button,
int  state,
int  x_pos,
int  y_pos
 

This handles the mouse events.

Parameters:
button Holds the flag which mouse button has been clicked.
state Indicates whether the mouse button is up or down.
x_pos The mouse cursor's x position.
y_pos The mouse cursor's y position.

Definition at line 327 of file GLUTCallbackFunctions.cpp.

References clicked_object_id_, graph_, Graph::highlightNodeIfSelected(), is_animation_running_, is_left_mouse_button_down_, Graph::isANodeClicked(), num_iterations_, retrieveObjectID(), and Graph::setCenterNode().

Referenced by createGLUTWindow().

00328 { 00329 if (button == GLUT_LEFT_BUTTON) 00330 { 00331 cout << x_pos << " " << y_pos << endl; 00332 // Here we pass in the cursors X and Y co-ordinates to test 00333 // an object under the mouse. 00334 clicked_object_id_ = retrieveObjectID(x_pos, y_pos); 00335 graph_->highlightNodeIfSelected(clicked_object_id_); 00336 00337 if ((graph_->isANodeClicked(clicked_object_id_)) 00338 && (is_animation_running_ == false)) 00339 { 00340 num_iterations_ = 1; 00341 is_animation_running_ = true; 00342 graph_->setCenterNode(clicked_object_id_); 00343 } 00344 } 00345 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) 00346 { 00347 is_left_mouse_button_down_ = true; 00348 } 00349 else// (button == GLUT_LEFT_BUTTON && state == GLUT_UP) 00350 { 00351 is_left_mouse_button_down_ = false; 00352 } 00353 }

Here is the call graph for this function:

void myGLUTReshapeFunc GLint  screen_width,
GLint  screen_height
 

This reshapes the OpenGL window to specified resolution.

Definition at line 241 of file GLUTCallbackFunctions.cpp.

Referenced by createGLUTWindow().

00242 { 00243 GLfloat width_height_aspect = 00244 (GLfloat)screen_width / (GLfloat)screen_height; 00245 00246 glViewport(0, 0, screen_width, screen_height); 00247 00248 glMatrixMode(GL_PROJECTION); 00249 glLoadIdentity(); 00250 00251 glutPostRedisplay(); 00252 }

void renderScene  ) 
 

This renders the entire scene into OpenGL.

Definition at line 140 of file GLUTCallbackFunctions.cpp.

References Graph::drawGraph(), graph_, is_animation_mode_active_, is_animation_running_, is_reset_rotation_, last_x_pos_, last_y_pos_, myGlutMotion(), num_iterations_, radial_layout_, screen_height_, screen_width_, selected_animation_speed_, Graph::setAnimationMode(), Graph::setAnimationSpeed(), Graph::setSceneRotation(), x_rotation_, y_rotation_, and z_rotation_.

Referenced by createGLUTWindow(), and retrieveObjectID().

00141 { 00142 if ((is_animation_running_ == false) 00143 && (is_animation_mode_active_ == true)) 00144 { 00145 num_iterations_ = 1; 00146 is_animation_running_ = true; 00147 graph_->setAnimationMode(true); 00148 } 00149 if (num_iterations_ <= selected_animation_speed_) 00150 { 00151 ++num_iterations_; 00152 } 00153 00154 graph_->setAnimationSpeed(&selected_animation_speed_); 00155 00156 GLfloat width_height_aspect = 00157 (GLfloat)screen_width_ / (GLfloat)screen_height_; 00158 00159 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 00160 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00161 00162 //glMatrixMode(GL_PROJECTION); 00163 //glLoadIdentity(); 00164 glFrustum(-width_height_aspect * 0.04, width_height_aspect * 0.04, -0.04, 00165 0.04, 0.1, 15.0); 00166 00167 glMatrixMode( GL_MODELVIEW ); 00168 glLoadIdentity(); // reset the view 00169 00170 // position view up vector 00171 gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0); 00172 00173 // number of circles 00174 GLint num_circles = 10; 00175 00176 // radius of the starting circle 00177 GLfloat radius = -0.1f; 00178 GLUquadricObj *qobj; 00179 qobj = gluNewQuadric(); 00180 00182 if (is_reset_rotation_ == true) 00183 { 00184 glRotatef(0.0f, 0.0f, 1.0f, 0.0f); 00185 glRotatef(0.0f, 1.0f, 0.0f, 0.0f); 00186 glRotatef(0.0f, 0.0f, 0.0f, 1.0f); 00187 is_reset_rotation_ = false; 00188 y_rotation_ = 0.0f; 00189 x_rotation_ = 0.0f; 00190 last_y_pos_ = 0.0f; 00191 last_x_pos_ = 0.0f; 00192 myGlutMotion(last_x_pos_, last_y_pos_); 00193 } 00194 else 00195 { 00196 glRotatef(y_rotation_, 0.0f, 1.0f, 0.0f); 00197 glRotatef(x_rotation_, 1.0f, 0.0f, 0.0f); 00198 glRotatef(0.0f, 0.0f, 0.0f, 1.0f); 00199 } 00201 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); 00202 glEnable(GL_LINE_SMOOTH); 00204 gluQuadricNormals(qobj, GLU_SMOOTH); 00205 glDisable(GL_BLEND); 00206 radial_layout_ -> setNumberDisplayedRings(num_circles); 00207 radial_layout_ -> setRadiusOfRing(1, radius); 00208 radial_layout_ -> renderRadialLayout(qobj); 00209 00210 glInitNames(); 00211 glPushName(0); 00212 graph_->setSceneRotation(x_rotation_, y_rotation_, z_rotation_); 00213 graph_->drawGraph(qobj); 00214 glColor3f(1.0f, 1.0f, 1.0f); 00215 glDisable(GL_LINE_SMOOTH); 00216 00217 // swap buffers 00218 glutSwapBuffers(); 00219 gluDeleteQuadric(qobj); 00220 }

Here is the call graph for this function:

void resetSceneRotation  ) 
 

This resets the rotation of the entire scene.

Definition at line 445 of file GLUTCallbackFunctions.cpp.

References is_reset_rotation_.

Referenced by createGLUI().

00446 { 00447 is_reset_rotation_ = true; 00448 }

int retrieveObjectID int  x_coord,
int  y_coord
 

This finds the object which was clicked by the user given the x, y coordinates.

Parameters:
x_coord The x coordinate of the viewport.
y_coord The y coordinate of the viewport.

Definition at line 362 of file GLUTCallbackFunctions.cpp.

References renderScene(), screen_height_, and screen_width_.

Referenced by myGLUTMouseEventFunc().

00363 { 00364 int objectsFound = 0; 00365 int viewportCoords[4] = {0}; 00366 00367 unsigned int selectBuffer[1024] = {0}; 00368 00369 glSelectBuffer(1024, selectBuffer); 00370 glGetIntegerv(GL_VIEWPORT, viewportCoords); 00371 00372 glMatrixMode(GL_PROJECTION); 00373 glPushMatrix(); 00374 glRenderMode(GL_SELECT); 00375 glLoadIdentity(); 00376 gluPickMatrix(x_coord, viewportCoords[3] - y_coord, 2, 2, viewportCoords); 00377 00378 gluPerspective(45.0f,(float)screen_width_/(float)screen_height_,0.1f,150.0f); 00379 glMatrixMode(GL_MODELVIEW); 00380 00381 renderScene(); 00382 00383 objectsFound = glRenderMode(GL_RENDER); 00384 glMatrixMode(GL_PROJECTION); 00385 glPopMatrix(); 00386 00387 glMatrixMode(GL_MODELVIEW); 00388 00389 if (objectsFound > 0) 00390 { 00391 unsigned int lowestDepth = selectBuffer[1]; 00392 00393 int selectedObject = selectBuffer[3]; 00394 00395 // Return the selected object 00396 return selectedObject; 00397 } 00398 return 0; 00399 }

Here is the call graph for this function:

void startDemoMode  ) 
 

This starts the demo mode.

Definition at line 267 of file GLUTCallbackFunctions.cpp.

References graph_, is_animation_mode_active_, is_animation_running_, num_iterations_, and Graph::setAnimationMode().

Referenced by createGLUI(), and myGLUTKeyboardEventFunc().

00268 { 00269 if (is_animation_mode_active_ == false) 00270 { 00271 num_iterations_ = 1; 00272 is_animation_mode_active_ = true; 00273 is_animation_running_ = true; 00274 graph_->setAnimationMode(true); 00275 } 00276 else 00277 { 00278 is_animation_mode_active_ = false; 00279 } 00280 }

Here is the call graph for this function:

void toggleCaptionEnabling  ) 
 

This toggles the caption of the nodes. If enablen the caption's will be displayed.

Definition at line 455 of file GLUTCallbackFunctions.cpp.

References graph_, and Graph::toggleCaptionMode().

Referenced by createGLUI().

00456 { 00457 graph_->toggleCaptionMode(); 00458 }

Here is the call graph for this function:

void updateRenderMode  ) 
 

This updates the rendermode.

Definition at line 258 of file GLUTCallbackFunctions.cpp.

References graph_, and Graph::toggleRenderMode().

Referenced by createGLUI().

00259 { 00260 graph_->toggleRenderMode(); 00261 }

Here is the call graph for this function:


Generated on Mon Jun 14 12:49:01 2004 for InfoVis by doxygen 1.3.7