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

recorder_ui.C

Go to the documentation of this file.
00001 #include "geom/winsys.H"
00002 
00003 
00004 #include "recorder_ui.H"
00005 
00006 Recorder*         RecorderUI::_rec = 0;
00007 RecorderUI*             RecorderUI::_instance = 0;
00008 
00009 GLUI_Listbox*        RecorderUI::_path_listbox  = 0;
00010 GLUI_EditText*       RecorderUI::_name_edittext    = 0;
00011 GLUI_EditText*       RecorderUI::_fnum_edittext    = 0;
00012 GLUI_Spinner*        RecorderUI::_fps_spin      = 0;
00013 
00014 GLUI_Checkbox*          RecorderUI::_check_rec     = 0;
00015 GLUI_Checkbox*          RecorderUI::_check_play    = 0;
00016 GLUI_Checkbox*          RecorderUI::_check_pause   = 0;
00017 GLUI_Checkbox*          RecorderUI::_check_sync         = 0;
00018 GLUI_RadioGroup*        RecorderUI::_radio_render  = 0;
00019 GLUI_RadioGroup*        RecorderUI::_radio_frames  = 0;
00020 
00021 
00022 RecorderUI::RecorderUI(Recorder* rec) :
00023    _glui(0)
00024 {
00025    assert(rec);
00026 
00027    assert(_rec == 0);  // As per the note in the header file, there should
00028    // be only one UI and one rec in existence, so _rec should
00029    // still be null.
00030 
00031    _rec = rec;
00032    _instance = this;
00033 
00034    init();
00035 }
00036 
00037 void
00038 RecorderUI::init()
00039 {
00040    //cerr << "peeks\n";
00041    // Get the glut main window ID from the winsys
00042 
00043    int main_win_id = VIEW::peek()->win()->id();
00044 
00045    //cerr << "windows\n";
00046    // Create the glui widget that will contain the rec controls
00047    _glui = GLUI_Master.create_glui("Recorder Control", 0);
00048    _glui->set_main_gfx_window(main_win_id);
00049 
00050    //cerr << "buttons\n";
00051 
00052   //recording controls 
00053 
00054 
00055   
00056 
00057   //RECORD
00058    GLUI_Panel* _rec_panel = _glui->add_panel ( "rec", GLUI_PANEL_NONE );
00059 
00060    _check_rec = _glui->add_checkbox_to_panel(_rec_panel, "", NULL, -1, 
00061                                              RecorderUI::button_cb );
00062    _check_rec->disable();
00063    _glui->add_column_to_panel( _rec_panel, false );
00064    _glui->add_button_to_panel( _rec_panel, "Record", RECORD_BUTTON_ID, 
00065                                RecorderUI::button_cb);
00066 
00067    //PLAY
00068    GLUI_Panel* _play_panel = _glui->add_panel ( "play", GLUI_PANEL_NONE );
00069 
00070    _check_play = _glui->add_checkbox_to_panel (_play_panel, "" , NULL, -1,
00071                                                RecorderUI::button_cb );  
00072    _check_play->disable();
00073    _glui->add_column_to_panel( _play_panel, false );
00074    _glui->add_button_to_panel( _play_panel, "Play", PLAY_BUTTON_ID, 
00075                                RecorderUI::button_cb); 
00076 
00077 
00078    //PAUSE
00079    GLUI_Panel* _pause_panel = _glui->add_panel ( "pause", GLUI_PANEL_NONE );
00080 
00081    _check_pause = _glui->add_checkbox_to_panel ( _pause_panel, "", NULL, -1,
00082                                                  RecorderUI::button_cb );
00083    _check_pause->disable();
00084    _glui->add_column_to_panel( _pause_panel, false );  
00085    _glui->add_button_to_panel( _pause_panel, "Pause", PAUSE_BUTTON_ID, 
00086                                RecorderUI::button_cb);
00087 
00088 
00089 
00090    GLUI_Panel* _frame_panel = _glui->add_panel ( "frame", GLUI_PANEL_NONE );
00091 
00092 
00093    _fnum_edittext = _glui->add_edittext_to_panel ( _frame_panel,
00094                                                    "Frame " , 
00095                                                    GLUI_EDITTEXT_INT, 
00096                                                    NULL, 
00097                                                    -1,
00098                                                    RecorderUI::set_framenum_cb);
00099   
00100    _check_sync  =  _glui->add_checkbox_to_panel(    _frame_panel, 
00101                                                     "synchronize", 
00102                                                     NULL, 
00103                                                     -1, 
00104                                                     RecorderUI::resync_cb );
00105 
00106    _glui->add_separator();
00107 
00108    GLUI_Panel* _step_panel = _glui->add_panel ( "step", GLUI_PANEL_NONE );
00109 
00110    _glui->add_button_to_panel( _step_panel, "Stop", STOP_BUTTON_ID, 
00111                                RecorderUI::button_cb);
00112    _glui->add_button_to_panel( _step_panel, "Step Rev", REV_BUTTON_ID, 
00113                                RecorderUI::button_cb);
00114    _glui->add_button_to_panel( _step_panel, "Step Fwd", FWD_BUTTON_ID, 
00115                                RecorderUI::button_cb);
00116 
00117    _glui->add_separator();
00118  
00119    GLUI_Panel* _renderpane = _glui->add_panel ( "render to disk" );
00120 
00121    _radio_render = _glui->add_radiogroup_to_panel ( _renderpane,  NULL, RENDER_ON_BUTTON_ID, RecorderUI::button_cb );
00122    assert(_radio_render);
00123    _glui->add_radiobutton_to_group ( _radio_render , "off" );
00124    _glui->add_column_to_panel      ( _renderpane, false ) ;
00125    _glui->add_radiobutton_to_group ( _radio_render, "on" );
00126    
00127 
00128    _glui->add_separator();
00129 
00130    GLUI_Panel* _framepane = _glui->add_panel ( "play all frames" );
00131    _radio_frames = _glui->add_radiogroup_to_panel ( _framepane,  NULL, PLAY_FRAMES_BUTTON_ID, RecorderUI::button_cb );
00132    _glui->add_radiobutton_to_group ( _radio_frames , "off" );
00133    _glui->add_column_to_panel      ( _framepane, false ) ;
00134    _glui->add_radiobutton_to_group ( _radio_frames, "on" );
00135    
00136    _glui->add_separator();
00137 
00138    _glui->add_button("Save Path", SAVE_PATH_BUTTON_ID, 
00139                      RecorderUI::button_cb);
00140    _glui->add_button("Open Path", OPEN_PATH_BUTTON_ID, 
00141                      RecorderUI::button_cb);
00142    _glui->add_button("Delete Path", DEL_PATH_BUTTON_ID, 
00143                      RecorderUI::button_cb);
00144    _glui->add_button("New Path", NEW_PATH_BUTTON_ID, 
00145                      RecorderUI::button_cb);
00146 
00147    //cerr << "edittext\n";
00148    _name_edittext = _glui->add_edittext ("filename",
00149                                          GLUI_EDITTEXT_TEXT,
00150                                          NULL, -1,
00151                                          RecorderUI::name_edittext_cb
00152       );
00153 
00154    _name_edittext->set_text("default");
00155 
00156    _glui->add_separator();
00157    // Another separator
00158 
00159 
00160   //cerr << "add path\n";
00161   //default path value
00162    _path_listbox = _glui->add_listbox ( "Path", 
00163                                         _rec->get_path(),
00164                                         -1, RecorderUI::path_listbox_cb);
00165   
00166    _path_listbox->add_item( -1, "no path");
00167 
00168 
00169    _glui->add_separator();
00170 
00171    //cerr << "add fps\n";
00172 
00173 
00174    _fps_spin = _glui->add_spinner("fps",
00175                                   GLUI_SPINNER_INT, 
00176                                   (void*) _rec->get_fps(), 
00177                                   -1, RecorderUI::set_fps_cb
00178       );
00179    assert(_fps_spin);
00180 
00181   // Set allowable width limits
00182    _fps_spin->set_int_limits(1, 128, GLUI_LIMIT_CLAMP);
00183 
00184  
00185     
00186    //cerr << "zingzang\n";
00187    _glui->hide();
00188 }
00189 
00190 void
00191 RecorderUI::update()
00192 {
00193 
00194    if(!_glui) 
00195       {
00196          cerr << "NPRPenUI::update() - Error! "
00197               << " No GLUI object to update (not showing)!" << endl;
00198       }
00199    else 
00200       {
00201          _glui->sync_live();
00202       }
00203 }
00204 
00205 
00206 int 
00207 RecorderUI::add_path_entry (int id, char* text )
00208 { 
00209    return _path_listbox->add_item( id, text);
00210   
00211 }
00212 
00213 int 
00214 RecorderUI::del_path_entry (int id) 
00215 {
00216    //names are associated with a fixed id
00217    //so we leave a null link in the path array
00218    //and delete from the UI list!
00219    if ( id == -1 ) return 0;
00220    return _path_listbox->delete_item ( id );
00221 
00222 }
00223 
00224 
00225 
00226 
00227 void
00228 RecorderUI::show()
00229 {
00230    if(_glui) 
00231       _glui->show();
00232 }
00233 
00234 
00235 void
00236 RecorderUI::hide()
00237 {
00238    if(_glui) 
00239       _glui->hide();
00240 }
00241 
00242 
00243 
00244 void
00245 RecorderUI::button_cb(int id)
00246 {
00247    if(_rec == NULL) return;
00248 
00249    switch(id) {
00250     case(RECORD_BUTTON_ID):
00251       _rec->rec_record();
00252       break;
00253     case(PLAY_BUTTON_ID):
00254       _rec->rec_play();
00255       break;
00256 
00257     case(PAUSE_BUTTON_ID):
00258       _rec->rec_pause();
00259       break;
00260 
00261     case(STOP_BUTTON_ID):
00262       _rec->rec_stop();
00263       break;
00264 
00265     case(FWD_BUTTON_ID):
00266       _rec->step_fwd();
00267       break;
00268 
00269     case(REV_BUTTON_ID):
00270       _rec->step_rev();
00271       break;
00272 
00273     case(RENDER_ON_BUTTON_ID):
00274       set_render_state();
00275       break;
00276 
00277     case(PLAY_FRAMES_BUTTON_ID):
00278       if (_instance)
00279          _instance->set_play_all_frames();
00280       break;
00281 
00282     case(NEW_PATH_BUTTON_ID):
00283       _rec->new_path();
00284       break;
00285 
00286     case(SAVE_PATH_BUTTON_ID):
00287       _rec->save_path(*_rec->get_path());
00288       break;
00289 
00290     case(OPEN_PATH_BUTTON_ID):
00291       _rec->open_path( _name_edittext->get_text() );
00292       break;
00293 
00294     case(DEL_PATH_BUTTON_ID):
00295       _rec->del_path(*_rec->get_path());
00296       break;
00297 
00298     default: 
00299       break;
00300    }
00301 }
00302 
00303 
00304 
00305 
00306 
00307 void 
00308 RecorderUI::path_listbox_cb(int /* id */) 
00309 { 
00310    if(_rec == NULL) return;
00311    int pathnum = _path_listbox->get_int_val();
00312    _rec->set_path(pathnum);
00313 }
00314 
00315 void 
00316 RecorderUI::set_fps_cb(int /* id */) 
00317 { 
00318    if(_rec == NULL) return;
00319    _rec->set_fps(_fps_spin->get_int_val());
00320 }
00321 
00322 void 
00323 RecorderUI::name_edittext_cb(int /* id */)
00324 { 
00325    if(_rec == NULL) return;
00326    _rec->_name_buf = str_ptr ( _name_edittext->get_text() );
00327 }
00328 
00329 void
00330 RecorderUI::resync_cb( int /*id*/)
00331 {
00332    _rec->set_sync( _check_sync->get_int_val()==1 );
00333    
00334 }
00335 
00336 void 
00337 RecorderUI::set_framenum_cb(int /* id */)
00338 { 
00339    if(_rec == NULL) return;
00340 
00341    _rec->set_pos ( atoi(  _fnum_edittext->get_text() ) );
00342    _instance->set_frame_num(_rec->path_pos());
00343      
00344 }
00345 
00346 void
00347 RecorderUI::set_sync() { 
00348    _check_sync->set_int_val( _rec->sync() );
00349 }
00350 
00351 void 
00352 RecorderUI::update_checks() { 
00353    if ( _check_rec )   _check_rec->set_int_val    ( _rec->rec_on()           );
00354    if ( _check_play )  _check_play->set_int_val   ( _rec->play_on()          );
00355    if ( _check_pause ) _check_pause->set_int_val  ( _rec->pause_on()         );
00356    if ( _radio_frames ) _radio_frames->set_int_val( (int) _rec->play_all_frames()  );
00357 }  
00358 
00359 void 
00360 RecorderUI::set_render_state() 
00361 { 
00362 
00363    if ( !_radio_render ) return;
00364    if ( _radio_render->get_int_val() ) _rec->render_on();
00365    else _rec->render_off();
00366 }
00367 
00368 void 
00369 RecorderUI::set_play_all_frames() { 
00370    if ( _radio_frames ) _rec->play_all_frames() = ( _radio_frames->get_int_val()==1 );
00371 }

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