00001 /***************************************************************** 00002 * draw_widget.C 00003 *****************************************************************/ 00004 00005 #include "geom/world.H" // for WORLD::create() etc. 00006 00007 #include "gest/mode_name.H" 00008 00009 #include "draw_widget.H" 00010 00011 /***************************************************************** 00012 * DrawWidget 00013 *****************************************************************/ 00014 00015 DrawWidgetptr DrawWidget::_active; 00016 DrawWidget* DrawWidget::null = 0; 00017 00018 DrawWidget::DrawWidget(double dur) : 00019 GEOM(static_name()), 00020 _fsa(&_draw_start), 00021 _timer(dur) 00022 { 00023 // Must set NO_NETWORK before calling WORLD::create() 00024 // because of observers that are called in 00025 // WORLD::create() 00026 REFlock me(this); 00027 NETWORK.set(this, 0); 00028 // XXX -- are these lines needed? 00029 // i.e., not sure if ref counted pointer gets deleted 00030 // if object is not in exist list 00031 //WORLD::create(this); 00032 //WORLD::undisplay(this, false); 00033 00034 // Turn on observations of when we are displayed/undisplayed 00035 disp_obs(this); 00036 } 00037 00038 DrawWidget::~DrawWidget() 00039 { 00040 deactivate(); 00041 unobs_display(this); 00042 } 00043 00044 void 00045 DrawWidget::activate() 00046 { 00047 if (_active && _active != this) 00048 _active->deactivate(); 00049 _active=this; 00050 00051 if (has_mode_name()) 00052 ModeName::push_name(mode_name()); 00053 00054 reset_timeout(); 00055 00056 // Sign up for CAMobs callbacks: 00057 VIEW::peek_cam()->data()->add_cb(this); 00058 00059 // If not currently displayed, get displayed: 00060 if (!DRAWN.contains(this)) 00061 WORLD::display(this, false); // XXX -- should be undoable??? 00062 } 00063 00064 void 00065 DrawWidget::deactivate() 00066 { 00067 if (_active != this) 00068 return; 00069 _active=0; 00070 00071 if (has_mode_name()) 00072 ModeName::pop_name(); 00073 00074 // Un-sign up for callbacks: 00075 // (so we don't get callbacks when we are inactive) 00076 VIEW::peek_cam()->data()->rem_cb(this); 00077 00078 // If currently displayed, stop: 00079 if (DRAWN.contains(this)) 00080 WORLD::undisplay(this, false); 00081 00082 // Let subclasses clear cached info at this time: 00083 reset(); 00084 } 00085 00086 void 00087 DrawWidget::toggle_active() 00088 { 00089 // Do it: 00090 is_active() ? deactivate() : activate(); 00091 } 00092 00093 void 00094 DrawWidget::notify(CGELptr &g, int is_displayed) 00095 { 00096 if (!g) { 00097 err_msg("DrawWidget::notify: error: GEL is NULL"); 00098 return; 00099 } 00100 00101 // The only cases we care about are when object is undisplayed: 00102 if (is_displayed) 00103 return; 00104 00105 // Deactivate in each case: 00106 // - the mesh associated with this widget was undisplayed 00107 // - the widget itself was undisplayed 00108 if ((bmesh() && bmesh()->geom() == g) || 00109 (g == this && !is_displayed)) { 00110 deactivate(); 00111 } 00112 } 00113 00114 void 00115 DrawWidget::notify(CCAMdataptr&) 00116 { 00117 // Stay hungry. 00118 // (Don't timeout while the user changes the camera). 00119 reset_timeout(); 00120 } 00121 00122 // end of file draw_widget.C