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

draw_widget.H

Go to the documentation of this file.
00001 #ifndef DRAW_WIDGET_H_IS_INCLUDED
00002 #define DRAW_WIDGET_H_IS_INCLUDED
00003 
00004 /*!
00005  *  \file draw_widget.H
00006  *  \brief Contains the definition of the DrawWidget class.
00007  *
00008  *  \sa draw_widget.C
00009  *
00010  */
00011 
00012 #include "geom/geom.H"          // for GEOM baseclass
00013 #include "manip/manip.H"        // for Interactor base class
00014 #include "mesh/lmesh.H"         // for BMESHobs and LMESH
00015 #include "std/stop_watch.H"     // for timing
00016 
00017 #include "gest/gest_guards.H"   // GESTURE FSA
00018 
00019 MAKE_PTR_SUBC(DrawWidget,GEOM);
00020 typedef const DrawWidget    CDrawWidget;
00021 typedef const DrawWidgetptr CDrawWidgetptr;
00022 
00023 /*!
00024  *  \brief Base class for gesture recognizing widgets that can display
00025  *  interactive controls.
00026  *
00027  *  They can draw. They are interactive in the sense of GEOMs
00028  *  (i.e., can process mouse/tablet Events). They can also act
00029  *  as an FSA that processes GESTUREs as high-level events. Only
00030  *  one DrawWidget is activated at any time.
00031  *
00032  *  Uses a timer to fade away after a specified period of
00033  *  inactivity.
00034  *
00035  *  Derives from GEOM to be interactive, and for draw() and
00036  *  intersect().
00037  *
00038  *  Derives from DISPobs to observe when it is displayed or
00039  *  undisplayed (to deactivate in the latter case).
00040  *
00041  *  Derives from CAMobs to observe when the camera is changing
00042  *  so it can reset its timer (and not fade away early).
00043  *
00044  */
00045 class DrawWidget : public GEOM,
00046                    public DISPobs,
00047                    public CAMobs, 
00048                    public BMESHobs,
00049                    public Interactor<DrawWidget,Event,State> {
00050    public:
00051    
00052       //******** RUN-TIME TYPE ID ********
00053    
00054       DEFINE_RTTI_METHODS3("DrawWidget", DrawWidget*, GEOM, CDATA_ITEM*);
00055    
00056       //******** STATICS ********
00057    
00058       //! \brief Anyone can get their hands on the current active widget.
00059       static DrawWidgetptr get_active_instance() { return _active; }
00060    
00061       //******** ACTIVATION *******
00062    
00063       //! \brief Toggles on or off.
00064       virtual void toggle_active();
00065    
00066       bool is_active()     const   { return _active == this; }
00067       void activate();
00068       void deactivate();
00069    
00070       //! \brief Default duration in seconds for widgets to last before
00071       //! fading away.
00072       static double default_timeout() { return 1e6; }
00073    
00074       void set_timeout  (double dur)                   { _timer.reset(dur); }
00075       void reset_timeout(double dur=default_timeout()) { set_timeout(dur); }
00076    
00077       //******** VIRTUAL METHODS ********
00078    
00079       // If derived classes operate on a particular mesh, they should
00080       // return a pointer to the mesh here. This is used in the virtual
00081       // method DISPobs::notify() to check whether the mesh has been
00082       // undisplayed (and if so, deactivate the widget).
00083       virtual BMESHptr bmesh() const { return 0; }
00084       virtual LMESH* lmesh()   const { return LMESH::upcast(bmesh()); }
00085    
00086       //******** MODE NAME ********
00087    
00088       // displayed in jot window
00089       virtual str_ptr      mode_name()     const { return NULL_STR; }
00090       bool                 has_mode_name() const { return mode_name() != NULL_STR; }
00091    
00092       //******** GESTURE PROCESSING ********
00093    
00094       bool handle_gesture(CGESTUREptr& gest) { return _fsa.handle_event(gest); }
00095    
00096       //******** CONVENIENCE ********
00097    
00098       // DrawWidget::null is used in ray_geom() to get a DrawWidget
00099       // from a RAYhit after doing intersection, e.g.:
00100       //   DrawWidgetptr widget = ray_geom(ray, DrawWidget::null);
00101       static DrawWidget *null; 
00102    
00103       //******** GEL METHODS ********
00104    
00105       virtual bool needs_blend() const { return alpha() < 1; }
00106    
00107       //******** DISPobs METHODS ********
00108    
00109       // Nofification that this widget was displayed or undisplayed:
00110       virtual void notify(CGELptr &g, int);
00111    
00112       //******** CAMobs Method *************
00113    
00114       // Notification that the camera just changed:
00115       virtual void notify(CCAMdataptr &data);
00116 
00117    protected:
00118    
00119       DrawFSA      _fsa;           // FSA for processing GESTUREs
00120       DrawState    _draw_start;    // the start state of the FSA
00121       egg_timer    _timer;         // used for timing out (to be undrawn)
00122    
00123       static DrawWidgetptr _active;  // the lone active one
00124    
00125       //******** MANAGERS ********
00126    
00127       // 'dur' parameter tells how long until the fadeout:
00128       DrawWidget(double dur=default_timeout());
00129    
00130       virtual ~DrawWidget();
00131    
00132       //******** PROTECTED METHODS ********
00133    
00134       // Shortly before the timer expires, start fading away.
00135       // this computes the alpha to use for fading.
00136       double alpha() const {
00137          const double FADE_TIME = 0.5; // fade for half a second
00138          return min(_timer.remaining() / FADE_TIME, 1.0);
00139       }
00140    
00141       // Called when deactivated, for subclasses that want to do
00142       // something at that time:
00143       virtual void reset() {}
00144 
00145 };
00146 
00147 #endif // DRAW_WIDGET_H_IS_INCLUDED
00148 
00149 /* end of file draw_widget.H */

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