Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gfxGLWindowGLUI.cpp

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #include <freecloth/gfx/gfxGLWindowGLUI.h>
00020 #include <freecloth/geom/geMatrix4.h>
00021 #include <freecloth/resmgt/rcProxyShdPtr.h>
00022 #include <freecloth/base/vector>
00023 #include <freecloth/base/map>
00024 #include <freecloth/base/GL_glut.h>
00025 #include <freecloth/base/glui.h>
00026 
00027 ////////////////////////////////////////////////////////////////////////////////
00028 // LOCAL DECLARATIONS
00029 
00030 #if COMPILER_MSVC
00031 // MSVC6 has bugs in its dynamic_cast<> implementation, causing crashes.
00032 // The reinterpret_cast<> implementation doesn't have this bug.
00033 #define DYNAMIC_CAST_REF(type,obj) \
00034     reinterpret_cast<type&>( obj )
00035 #else
00036 #define DYNAMIC_CAST_REF(type,obj) \
00037     dynamic_cast<type&>( obj )
00038 #endif
00039 
00040 ////////////////////////////////////////////////////////////////////////////////
00041 // CLASS GfxGLWindowGLUI::Imp
00042 
00043 class GfxGLWindowGLUI::Imp {
00044 public:
00045     //----- types and enumerations -----
00046     typedef GfxGLWindowGLUI::ControlID ControlID;
00047     typedef GfxGLWindowGLUI::PanelID PanelID;
00048     typedef UInt32 FullControlID;
00049     typedef RCProxyShdPtr< GLUI_Control > ControlPtr;
00050     typedef RCProxyShdPtr< GLUI_Panel > PanelPtr;
00051     typedef std::list< ControlPtr > ControlList;
00052     typedef std::map< ControlID, ControlPtr > ControlMap;
00053     typedef std::map< PanelID, PanelPtr > PanelMap;
00054 
00055     //----- member functions -----
00056     FullControlID makeFullControlID( const GfxGLWindowGLUI&, ControlID );
00057     ControlID getControlID( FullControlID );
00058 
00059     void addControl( GLUI_Control*, ControlID );
00060     void addPanel( GLUI_Panel*, PanelID );
00061 
00062     GLUI_Control& getControl( GfxGLWindowGLUI::ControlID );
00063     const GLUI_Control& getControl( GfxGLWindowGLUI::ControlID ) const;
00064     GLUI_Panel& getPanel( GfxGLWindowGLUI::PanelID );
00065     
00066     //----- data members -----
00067     
00068     GLUI* _glui;
00069 
00070 private:
00071 
00072     //----- data members -----
00073     
00074     ControlMap _controlMap;
00075     PanelMap _panelMap;
00076 
00077     // to hold pointers to id-less controls
00078     ControlList _controlList;
00079 };
00080 
00081 //------------------------------------------------------------------------------
00082 
00083 GfxGLWindowGLUI::Imp::FullControlID GfxGLWindowGLUI::Imp::makeFullControlID(
00084     const GfxGLWindowGLUI&,
00085     ControlID id
00086 ) {
00087     // Eventually, when we support multiple GLUIs, this should combine window
00088     // and id
00089     return id;
00090 }
00091 
00092 //------------------------------------------------------------------------------
00093 
00094 GfxGLWindowGLUI::Imp::ControlID GfxGLWindowGLUI::Imp::getControlID(
00095     FullControlID fid
00096 ) {
00097     return fid;
00098 }
00099 
00100 //------------------------------------------------------------------------------
00101 
00102 void GfxGLWindowGLUI::Imp::addControl( GLUI_Control* control, ControlID id )
00103 {
00104     DGFX_ASSERT( control != 0 );
00105     if ( id != GfxGLWindowGLUI::CTRL_NONE ) {
00106         DGFX_ASSERT( _controlMap.find( id ) == _controlMap.end() );
00107         _controlMap[ id ] = ControlPtr( control );
00108     }
00109     else {
00110         _controlList.push_back( ControlPtr( control ) );
00111     }
00112 }
00113 
00114 //------------------------------------------------------------------------------
00115 
00116 void GfxGLWindowGLUI::Imp::addPanel( GLUI_Panel* panel, PanelID id ) {
00117     DGFX_ASSERT( panel != 0 && id != GfxGLWindowGLUI::PANEL_NONE );
00118     DGFX_ASSERT( _panelMap.find( id ) == _panelMap.end() );
00119     _panelMap[ id ] = PanelPtr( panel );
00120 }
00121 
00122 //------------------------------------------------------------------------------
00123 
00124 GLUI_Control& GfxGLWindowGLUI::Imp::getControl( ControlID id ) {
00125     ControlMap::iterator i = _controlMap.find( id );
00126     DGFX_ASSERT( i != _controlMap.end() );
00127     return *i->second;
00128 }
00129 
00130 //------------------------------------------------------------------------------
00131 
00132 const GLUI_Control& GfxGLWindowGLUI::Imp::getControl( ControlID id ) const {
00133     ControlMap::const_iterator i = _controlMap.find( id );
00134     DGFX_ASSERT( i != _controlMap.end() );
00135     return *i->second;
00136 }
00137 
00138 //------------------------------------------------------------------------------
00139 
00140 GLUI_Panel& GfxGLWindowGLUI::Imp::getPanel( PanelID id ) {
00141     PanelMap::iterator i = _panelMap.find( id );
00142     DGFX_ASSERT( i != _panelMap.end() );
00143     return *i->second;
00144 }
00145 
00146 
00147 ////////////////////////////////////////////////////////////////////////////////
00148 // CLASS GfxGLWindowGLUI
00149 
00150 //------------------------------------------------------------------------------
00151 
00152 GfxGLWindowGLUI::GfxGLWindowGLUI(
00153     const GfxConfig& config,
00154     const String& title
00155 ) : GfxGLWindowGLUT( config, title ),
00156     _imp( new Imp )
00157 {
00158     _imp->_glui = GLUI_Master.create_glui_subwindow(
00159         _windowId, GLUI_SUBWINDOW_RIGHT
00160     );
00161     _imp->_glui->set_main_gfx_window( _windowId );
00162 }
00163 
00164 //------------------------------------------------------------------------------
00165 
00166 GfxGLWindowGLUI::~GfxGLWindowGLUI()
00167 {
00168     delete _imp;
00169 }
00170 
00171 //------------------------------------------------------------------------------
00172 
00173 void GfxGLWindowGLUI::addGroup(
00174     BorderType borderType,
00175     PanelID pid,
00176     PanelID parent
00177 ) {
00178     UInt32 gtypes[] = {
00179         GLUI_PANEL_NONE, GLUI_PANEL_RAISED, GLUI_PANEL_EMBOSSED
00180     };
00181     DGFX_ASSERT( pid != PANEL_NONE );
00182     GLUI_Panel* panel;
00183     if ( parent != PANEL_NONE ) {
00184         panel = _imp->_glui->add_panel_to_panel(
00185             &_imp->getPanel( parent ),
00186             "",
00187             gtypes[ static_cast<UInt32>( borderType ) ]
00188         );
00189     }
00190     else {
00191         panel = _imp->_glui->add_panel(
00192             "",
00193             gtypes[ static_cast<UInt32>( borderType ) ]
00194         );
00195     }
00196     _imp->addPanel( panel, pid );
00197 }
00198 
00199 //------------------------------------------------------------------------------
00200 
00201 void GfxGLWindowGLUI::addPanel(
00202     const String& name,
00203     PanelID pid,
00204     PanelID parent
00205 ) {
00206     DGFX_ASSERT( pid != PANEL_NONE );
00207     GLUI_Panel* panel;
00208     if ( parent != PANEL_NONE ) {
00209         panel = _imp->_glui->add_panel_to_panel(
00210             &_imp->getPanel( parent ),
00211             const_cast<char*>( name.c_str() ),  // FIXME: stupid GLUI!
00212             GLUI_PANEL_EMBOSSED
00213         );
00214     }
00215     else {
00216         panel = _imp->_glui->add_panel(
00217             const_cast<char*>( name.c_str() ),  // FIXME: stupid GLUI!
00218             GLUI_PANEL_EMBOSSED
00219         );
00220     }
00221     _imp->addPanel( panel, pid );
00222 }
00223 
00224 //------------------------------------------------------------------------------
00225 
00226 void GfxGLWindowGLUI::addRollout(
00227     const String& name,
00228     PanelID pid,
00229     bool open,
00230     PanelID parent
00231 ) {
00232     DGFX_ASSERT( pid != PANEL_NONE );
00233     GLUI_Panel* panel;
00234     if ( parent != PANEL_NONE ) {
00235         panel = _imp->_glui->add_rollout_to_panel(
00236             &_imp->getPanel( parent ),
00237             const_cast<char*>( name.c_str() ),  // FIXME: stupid GLUI!
00238             open
00239         );
00240     }
00241     else {
00242         panel = _imp->_glui->add_rollout(
00243             const_cast<char*>( name.c_str() ),  // FIXME: stupid GLUI!
00244             open
00245         );
00246     }
00247     _imp->addPanel( panel, pid );
00248 }
00249 
00250 //------------------------------------------------------------------------------
00251 
00252 void GfxGLWindowGLUI::addColumn( bool showDivider, PanelID pid )
00253 {
00254     if ( pid != PANEL_NONE ) {
00255         _imp->_glui->add_column_to_panel(
00256             &_imp->getPanel( pid ),
00257             showDivider
00258         );
00259     }
00260     else {
00261         _imp->_glui->add_column( showDivider );
00262     }
00263 }
00264 
00265 //------------------------------------------------------------------------------
00266 
00267 void GfxGLWindowGLUI::addButton( const String& name, ControlID id, PanelID pid )
00268 {
00269     Imp::FullControlID fid = _imp->makeFullControlID( *this, id );
00270     GLUI_Control* ctrl;
00271     if ( pid != PANEL_NONE ) {
00272         ctrl = _imp->_glui->add_button_to_panel(
00273             &_imp->getPanel( pid ),
00274             const_cast<char*>( name.c_str() ), // FIXME: stupid GLUI!
00275             fid,
00276             controlCB
00277         );
00278     }
00279     else {
00280         ctrl = _imp->_glui->add_button(
00281             const_cast<char*>( name.c_str() ), // FIXME: stupid GLUI!
00282             fid,
00283             controlCB
00284         );
00285     }
00286     _imp->addControl( ctrl, id );
00287 }
00288 
00289 //------------------------------------------------------------------------------
00290 
00291 void GfxGLWindowGLUI::addRotate( const String& name, ControlID id, PanelID pid )
00292 {
00293     Imp::FullControlID fid = _imp->makeFullControlID( *this, id );
00294     GLUI_Rotation* rot;
00295     if ( pid != PANEL_NONE ) {
00296         rot = _imp->_glui->add_rotation_to_panel(
00297             &_imp->getPanel( pid ),
00298             const_cast<char*>( name.c_str() ), // FIXME: stupid GLUI!
00299             NULL,
00300             fid,
00301             controlCB
00302         );
00303     }
00304     else {
00305         rot = _imp->_glui->add_rotation(
00306             const_cast<char*>( name.c_str() ), // FIXME: stupid GLUI!
00307             NULL,
00308             fid,
00309             controlCB
00310         );
00311     }
00312     rot->reset();
00313     _imp->addControl( rot, id );
00314 }
00315 
00316 //------------------------------------------------------------------------------
00317 
00318 void GfxGLWindowGLUI::addTranslate(
00319     const String& name,
00320     TranslateType type,
00321     ControlID id,
00322     PanelID pid
00323 ) {
00324     UInt32 gtypes[] = {
00325         GLUI_TRANSLATION_XY,
00326         GLUI_TRANSLATION_X,
00327         GLUI_TRANSLATION_Y,
00328         GLUI_TRANSLATION_Z
00329     };
00330     Imp::FullControlID fid = _imp->makeFullControlID( *this, id );
00331     GLUI_Control* ctrl;
00332     if ( pid != PANEL_NONE ) {
00333         ctrl = _imp->_glui->add_translation_to_panel(
00334             &_imp->getPanel( pid ),
00335             const_cast<char*>( name.c_str() ), // FIXME: stupid GLUI!
00336             gtypes[ static_cast<UInt32>( type ) ],
00337             NULL,
00338             fid,
00339             controlCB
00340         );
00341     }
00342     else {
00343         ctrl = _imp->_glui->add_translation(
00344             const_cast<char*>( name.c_str() ), // FIXME: stupid GLUI!
00345             gtypes[ static_cast<UInt32>( type ) ],
00346             NULL,
00347             fid,
00348             controlCB
00349         );
00350     }
00351     _imp->addControl( ctrl, id );
00352 }
00353 
00354 //------------------------------------------------------------------------------
00355 
00356 void GfxGLWindowGLUI::addText( const String& label, ControlID id, PanelID pid )
00357 {
00358     GLUI_Control* ctrl;
00359     if ( pid != PANEL_NONE ) {
00360         ctrl = _imp->_glui->add_statictext_to_panel(
00361             &_imp->getPanel( pid ),
00362             const_cast<char*>( label.c_str() ) // FIXME: stupid GLUI!
00363         );
00364     }
00365     else {
00366         ctrl = _imp->_glui->add_statictext(
00367             const_cast<char*>( label.c_str() ) // FIXME: stupid GLUI!
00368         );
00369     }
00370     _imp->addControl( ctrl, id );
00371 }
00372 
00373 //------------------------------------------------------------------------------
00374 
00375 void GfxGLWindowGLUI::addEditText(
00376     const String& label,
00377     ControlID id,
00378     PanelID pid
00379 ) {
00380     addEditBox( label, EDIT_TEXT, id, pid );
00381 }
00382 
00383 //------------------------------------------------------------------------------
00384 
00385 void GfxGLWindowGLUI::addEditInt(
00386     const String& label,
00387     ControlID id,
00388     PanelID pid
00389 ) {
00390     addEditBox( label, EDIT_INT, id, pid );
00391 }
00392 
00393 //------------------------------------------------------------------------------
00394 
00395 void GfxGLWindowGLUI::addEditFloat(
00396     const String& label,
00397     ControlID id,
00398     PanelID pid
00399 ) {
00400     addEditBox( label, EDIT_FLOAT, id, pid );
00401 }
00402 
00403 //------------------------------------------------------------------------------
00404 
00405 void GfxGLWindowGLUI::addEditBox(
00406     const String& label,
00407     EditType type,
00408     ControlID id,
00409     PanelID pid
00410 ) {
00411     Imp::FullControlID fid = _imp->makeFullControlID( *this, id );
00412     UInt32 gtypes[] = {
00413         GLUI_EDITTEXT_TEXT,
00414         GLUI_EDITTEXT_INT,
00415         GLUI_EDITTEXT_FLOAT
00416     };
00417     GLUI_Control* ctrl;
00418     if ( pid != PANEL_NONE ) {
00419         ctrl = _imp->_glui->add_edittext_to_panel(
00420             &_imp->getPanel( pid ),
00421             const_cast<char*>( label.c_str() ), // FIXME: stupid GLUI!
00422             gtypes[ static_cast<UInt32>( type ) ],
00423             NULL,
00424             fid,
00425             controlCB
00426         );
00427     }
00428     else {
00429         ctrl = _imp->_glui->add_edittext(
00430             const_cast<char*>( label.c_str() ), // FIXME: stupid GLUI!
00431             gtypes[ static_cast<UInt32>( type ) ],
00432             NULL,
00433             fid,
00434             controlCB
00435         );
00436     }
00437     _imp->addControl( ctrl, id );
00438 }
00439 
00440 //------------------------------------------------------------------------------
00441 
00442 void GfxGLWindowGLUI::addCheckbox(
00443     const String& label,
00444     ControlID id,
00445     PanelID pid
00446 ) {
00447     Imp::FullControlID fid = _imp->makeFullControlID( *this, id );
00448     GLUI_Control* ctrl;
00449     if ( pid != PANEL_NONE ) {
00450         ctrl = _imp->_glui->add_checkbox_to_panel(
00451             &_imp->getPanel( pid ),
00452             const_cast<char*>( label.c_str() ), // FIXME: stupid GLUI!
00453             NULL,
00454             fid,
00455             controlCB
00456         );
00457     }
00458     else {
00459         ctrl = _imp->_glui->add_checkbox(
00460             const_cast<char*>( label.c_str() ), // FIXME: stupid GLUI!
00461             NULL,
00462             fid,
00463             controlCB
00464         );
00465     }
00466     _imp->addControl( ctrl, id );
00467 }
00468 
00469 //------------------------------------------------------------------------------
00470 
00471 void GfxGLWindowGLUI::addRadioGroup( ControlID id, PanelID pid )
00472 {
00473     Imp::FullControlID fid = _imp->makeFullControlID( *this, id );
00474     GLUI_Control* ctrl;
00475     if ( pid != PANEL_NONE ) {
00476         ctrl = _imp->_glui->add_radiogroup_to_panel(
00477             &_imp->getPanel( pid ),
00478             NULL,
00479             fid,
00480             controlCB
00481         );
00482     }
00483     else {
00484         ctrl = _imp->_glui->add_radiogroup( NULL, fid, controlCB );
00485     }
00486     _imp->addControl( ctrl, id );
00487 }
00488 
00489 //------------------------------------------------------------------------------
00490 
00491 void GfxGLWindowGLUI::addRadioButton( ControlID groupid, const String& label )
00492 {
00493     GLUI_Control& ctrl = _imp->getControl( groupid );
00494     GLUI_RadioGroup& group = DYNAMIC_CAST_REF( GLUI_RadioGroup, ctrl );
00495     GLUI_Control* newctrl = _imp->_glui->add_radiobutton_to_group(
00496         &group, 
00497         const_cast<char*>( label.c_str() )  // stupid GLUI!
00498     );
00499     _imp->addControl( newctrl, CTRL_NONE );
00500 }
00501 
00502 //------------------------------------------------------------------------------
00503 
00504 void GfxGLWindowGLUI::setRotate( ControlID id, const GeMatrix4& val )
00505 {
00506     GLUI_Control& ctrl = _imp->getControl( id );
00507     GLUI_Rotation& rot = DYNAMIC_CAST_REF( GLUI_Rotation, ctrl );
00508     // Stupid GLUI!
00509     rot.set_float_array_val( const_cast<Float*>( val.asColMajor() ) );
00510 }
00511 
00512 //------------------------------------------------------------------------------
00513 
00514 void GfxGLWindowGLUI::setTranslateX( ControlID id, Float val )
00515 {
00516     GLUI_Control& ctrl = _imp->getControl( id );
00517     GLUI_Translation& tr = DYNAMIC_CAST_REF( GLUI_Translation, ctrl );
00518     tr.set_x( val );
00519 }
00520 
00521 //------------------------------------------------------------------------------
00522 
00523 void GfxGLWindowGLUI::setTranslateY( ControlID id, Float val )
00524 {
00525     GLUI_Control& ctrl = _imp->getControl( id );
00526     GLUI_Translation& tr = DYNAMIC_CAST_REF( GLUI_Translation, ctrl );
00527     tr.set_y( val );
00528 }
00529 
00530 //------------------------------------------------------------------------------
00531 
00532 void GfxGLWindowGLUI::setTranslateZ( ControlID id, Float val )
00533 {
00534     GLUI_Control& ctrl = _imp->getControl( id );
00535     GLUI_Translation& tr = DYNAMIC_CAST_REF( GLUI_Translation, ctrl );
00536     tr.set_z( val );
00537 }
00538 
00539 //------------------------------------------------------------------------------
00540 
00541 void GfxGLWindowGLUI::setText( ControlID id, const String& label )
00542 {
00543     GLUI_Control& ctrl = _imp->getControl( id );
00544     GLUI_StaticText& text = DYNAMIC_CAST_REF( GLUI_StaticText, ctrl );
00545     // FIXME: stupid constless GLUI!
00546     text.set_text( const_cast<char*>( label.c_str() ) );
00547 }
00548 
00549 //------------------------------------------------------------------------------
00550 
00551 void GfxGLWindowGLUI::setEditText( ControlID id, const String& text )
00552 {
00553     GLUI_Control& ctrl = _imp->getControl( id );
00554     GLUI_EditText& textbox = DYNAMIC_CAST_REF( GLUI_EditText, ctrl );
00555     // FIXME: stupid constless GLUI!
00556     textbox.set_text( const_cast<char*>( text.c_str() ) );
00557 }
00558 
00559 //------------------------------------------------------------------------------
00560 
00561 void GfxGLWindowGLUI::setEditInt( ControlID id, Int32 val )
00562 {
00563     GLUI_Control& ctrl = _imp->getControl( id );
00564     GLUI_EditText& text = DYNAMIC_CAST_REF( GLUI_EditText, ctrl );
00565     text.set_int_val( val );
00566 }
00567 
00568 //------------------------------------------------------------------------------
00569 
00570 void GfxGLWindowGLUI::setEditFloat( ControlID id, Float val )
00571 {
00572     GLUI_Control& ctrl = _imp->getControl( id );
00573     GLUI_EditText& text = DYNAMIC_CAST_REF( GLUI_EditText, ctrl );
00574     text.set_float_val( val );
00575 }
00576 
00577 //------------------------------------------------------------------------------
00578 
00579 void GfxGLWindowGLUI::setEditIntLimits(
00580     ControlID id,
00581     Int32 low,
00582     Int32 high,
00583     bool wrap
00584 ) {
00585     GLUI_Control& ctrl = _imp->getControl( id );
00586     GLUI_EditText& text = DYNAMIC_CAST_REF( GLUI_EditText, ctrl );
00587     text.set_int_limits( low, high, wrap ? GLUI_LIMIT_WRAP : GLUI_LIMIT_CLAMP );
00588 }
00589 
00590 //------------------------------------------------------------------------------
00591 
00592 void GfxGLWindowGLUI::setEditFloatLimits(
00593     ControlID id,
00594     Float low,
00595     Float high,
00596     bool wrap
00597 ) {
00598     GLUI_Control& ctrl = _imp->getControl( id );
00599     GLUI_EditText& text = DYNAMIC_CAST_REF( GLUI_EditText, ctrl );
00600     text.set_float_limits( low, high, wrap ? GLUI_LIMIT_WRAP:GLUI_LIMIT_CLAMP );
00601 }
00602 
00603 //------------------------------------------------------------------------------
00604 
00605 void GfxGLWindowGLUI::setCheckbox( ControlID id, bool value )
00606 {
00607     GLUI_Control& ctrl = _imp->getControl( id );
00608     GLUI_Checkbox& cb = DYNAMIC_CAST_REF( GLUI_Checkbox, ctrl );
00609     cb.set_int_val( value ? 1 : 0 );
00610 }
00611 
00612 //------------------------------------------------------------------------------
00613 
00614 void GfxGLWindowGLUI::setRadioGroup( ControlID id, UInt32 value )
00615 {
00616     GLUI_Control& ctrl = _imp->getControl( id );
00617     GLUI_RadioGroup& rg = DYNAMIC_CAST_REF( GLUI_RadioGroup, ctrl );
00618     rg.set_int_val( value );
00619 }
00620 
00621 //------------------------------------------------------------------------------
00622 
00623 GeMatrix4 GfxGLWindowGLUI::getRotate( ControlID id ) const
00624 {
00625     const GLUI_Control& ctrl = _imp->getControl( id );
00626     const GLUI_Rotation& rot = DYNAMIC_CAST_REF( const GLUI_Rotation, ctrl );
00627     Float data[ 16 ];
00628     // FIXME: stupid constless GLUI!
00629     const_cast<GLUI_Rotation&>( rot ).
00630         get_float_array_val( data );
00631     return GeMatrix4::colMajor( data );
00632 }
00633 
00634 //------------------------------------------------------------------------------
00635 
00636 Float GfxGLWindowGLUI::getTranslateX( ControlID id ) const
00637 {
00638     const GLUI_Control& ctrl = _imp->getControl( id );
00639     const GLUI_Translation& trans =
00640         DYNAMIC_CAST_REF( const GLUI_Translation, ctrl );
00641     // FIXME: stupid constless GLUI!
00642     return const_cast<GLUI_Translation&>( trans ).
00643         get_x();
00644 }
00645 
00646 //------------------------------------------------------------------------------
00647 
00648 Float GfxGLWindowGLUI::getTranslateY( ControlID id ) const
00649 {
00650     const GLUI_Control& ctrl = _imp->getControl( id );
00651     const GLUI_Translation& trans =
00652         DYNAMIC_CAST_REF( const GLUI_Translation, ctrl );
00653     // FIXME: stupid constless GLUI!
00654     return const_cast<GLUI_Translation&>( trans ).
00655         get_y();
00656 }
00657 
00658 //------------------------------------------------------------------------------
00659 
00660 Float GfxGLWindowGLUI::getTranslateZ( ControlID id ) const
00661 {
00662     const GLUI_Control& ctrl = _imp->getControl( id );
00663     const GLUI_Translation& trans =
00664         DYNAMIC_CAST_REF( const GLUI_Translation, ctrl );
00665     // FIXME: stupid constless GLUI!
00666     return const_cast<GLUI_Translation&>( trans ).
00667         get_z();
00668 }
00669 
00670 //------------------------------------------------------------------------------
00671 
00672 bool GfxGLWindowGLUI::getCheckbox( ControlID id ) const
00673 {
00674     const GLUI_Control& ctrl = _imp->getControl( id );
00675     const GLUI_Checkbox& cb = DYNAMIC_CAST_REF( const GLUI_Checkbox, ctrl );
00676     // FIXME: stupid constless GLUI!
00677     return const_cast<GLUI_Checkbox&>( cb ).
00678         get_int_val() != 0;
00679 }
00680 
00681 //------------------------------------------------------------------------------
00682 
00683 UInt32 GfxGLWindowGLUI::getRadioGroup( ControlID id ) const
00684 {
00685     const GLUI_Control& ctrl = _imp->getControl( id );
00686     const GLUI_RadioGroup& rg = DYNAMIC_CAST_REF( const GLUI_RadioGroup, ctrl );
00687     // FIXME: stupid constless GLUI!
00688     return const_cast<GLUI_RadioGroup&>( rg ).
00689         get_int_val();
00690 }
00691 
00692 //------------------------------------------------------------------------------
00693 
00694 String GfxGLWindowGLUI::getEditText( ControlID id ) const
00695 {
00696     const GLUI_Control& ctrl = _imp->getControl( id );
00697     const GLUI_EditText& text = DYNAMIC_CAST_REF( const GLUI_EditText, ctrl );
00698     // FIXME: stupid constless GLUI!
00699     return const_cast<GLUI_EditText&>( text ).
00700         get_text();
00701 }
00702 
00703 //------------------------------------------------------------------------------
00704 
00705 Int32 GfxGLWindowGLUI::getEditInt( ControlID id ) const
00706 {
00707     const GLUI_Control& ctrl = _imp->getControl( id );
00708     const GLUI_EditText& text = DYNAMIC_CAST_REF( const GLUI_EditText, ctrl );
00709     // FIXME: stupid constless GLUI!
00710     return const_cast<GLUI_EditText&>( text ).
00711         get_int_val();
00712 }
00713 
00714 //------------------------------------------------------------------------------
00715 
00716 Float GfxGLWindowGLUI::getEditFloat( ControlID id ) const
00717 {
00718     const GLUI_Control& ctrl = _imp->getControl( id );
00719     const GLUI_EditText& text = DYNAMIC_CAST_REF( const GLUI_EditText, ctrl );
00720     // FIXME: stupid constless GLUI!
00721     return const_cast<GLUI_EditText&>( text ).
00722         get_float_val();
00723 }
00724 
00725 //------------------------------------------------------------------------------
00726 
00727 void GfxGLWindowGLUI::registerIdleCB()
00728 {
00729     GLUI_Master.set_glutIdleFunc( idleCB );
00730 }
00731 
00732 //------------------------------------------------------------------------------
00733 
00734 void GfxGLWindowGLUI::registerCBs()
00735 {
00736     ::glutDisplayFunc( displayCB );
00737     ::glutMotionFunc( motionCB );
00738     ::glutPassiveMotionFunc( passiveMotionCB );
00739     GLUI_Master.set_glutKeyboardFunc( keyboardCB );
00740     GLUI_Master.set_glutMouseFunc( mouseCB );
00741     GLUI_Master.set_glutSpecialFunc( specialCB );
00742     GLUI_Master.set_glutReshapeFunc( reshapeCB );
00743 }
00744 
00745 //------------------------------------------------------------------------------
00746 
00747 void GfxGLWindowGLUI::reshapeCB( int, int )
00748 {
00749     int tx,ty,tw,th;
00750     GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
00751     GfxGLWindowGLUI& window = DYNAMIC_CAST_REF( GfxGLWindowGLUI, getWindow() );
00752     ::glViewport( tx, ty, tw, th );
00753     window.windowResized( tx, ty, tw, th );
00754     window.handleMiscEvents();
00755 }
00756 
00757 //------------------------------------------------------------------------------
00758 
00759 void GfxGLWindowGLUI::controlCB( int uid )
00760 {
00761     // FIXME: need contravariant getWindow method...
00762     GfxGLWindowGLUI& window = DYNAMIC_CAST_REF( GfxGLWindowGLUI, getWindow() );
00763 
00764     window.uiReceived( window._imp->getControlID( uid ) );
00765     window.handleMiscEvents();
00766 }

Generated on Fri May 2 16:51:13 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002