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

mmenu.H

Go to the documentation of this file.
00001 
00002 #ifndef MMENU_H
00003 #define MMENU_H
00004 
00005 #include "disp/gel.H"
00006 #include "disp/view.H"
00007 #include "geom/geom.H"
00008 #include "geom/text2d.H"
00009 #include "manip/manip.H"
00010 
00011 
00012 //------------------------------------------------------
00013 //
00014 //  MenuCb_t - 
00015 //     is a generic callback Interface for testing a
00016 //  guard condition for an FSA arc.
00017 //
00018 //------------------------------------------------------
00019 class MenuCb_t {
00020   public: 
00021                MenuCb_t()       { }
00022       virtual ~MenuCb_t()       { }
00023    virtual void exec()           = 0;
00024 };
00025 
00026 //------------------------------------------------------
00027 //
00028 //  MenuCbFunc_t - 
00029 //
00030 //     test EVENTs with a given function
00031 //
00032 //------------------------------------------------------
00033 class MenuCbFunc_t: public MenuCb_t {
00034  public:
00035    typedef void (*func_t)();
00036 
00037  protected:
00038    func_t  _func;
00039 
00040  public: 
00041        MenuCbFunc_t(func_t f):_func(f) {}
00042    virtual void exec()      { (*_func)(); }
00043 };
00044 
00045 //------------------------------------------------------
00046 //
00047 //  MenuCbMeth_t - 
00048 //     
00049 //  test EVENTs with a given method on an object
00050 //
00051 //------------------------------------------------------
00052 template <class T>
00053 class MenuCbMeth_t: public MenuCb_t {
00054   public:
00055     typedef void (T::*_method)();
00056 
00057   protected:
00058     T      *_obj;
00059     _method _meth;
00060 
00061   public: 
00062    MenuCbMeth_t(T *o, _method m) : _obj(o),_meth(m) {}
00063    virtual void exec()      { (_obj->*_meth)(); }
00064 };
00065 
00066 
00067 
00068 MAKE_PTR_SUBC(MMENU, FRAMEobs);
00069 class MMENU : public FRAMEobs, public Simple_int
00070 {
00071  public:
00072   enum DIR { N=0,NE,E,SE,S,SW,W,NW,NUM_DIRS };
00073 
00074  protected:
00075      struct MMENUMenuItem {
00076          MenuCb_t *_f;
00077          GEOMptr _g;
00078          MMENUMenuItem(){
00079              _g = NULL; _f = NULL;
00080          }
00081          MMENUMenuItem(CGEOMptr g, MenuCb_t *f){
00082              _g = g; _f = f;
00083          }
00084 
00085          bool operator==(const MMENUMenuItem &m) const {
00086              return _f==m._f && _g==m._g;
00087          }
00088      };
00089 
00090   ARRAY<MMENUMenuItem> _items;
00091  public:
00092   void add(CGEOMptr &g, MenuCb_t *o=0) {
00093       _items.add(MMENUMenuItem(g, o));
00094   }
00095   void add(Cstr_ptr &n, MenuCb_t *o=0){
00096       add(new TEXT2D("",n), o);
00097   }
00098   void clear(){
00099      _items.clear();
00100   }
00101 
00102  protected:
00103   int _sel;
00104 
00105 /* cardinal direction implementation
00106   MenuCb_t        *_funcs[NUM_DIRS];
00107   GEOMptr          _geoms[NUM_DIRS];
00108   DIR              _sel;
00109 */
00110 
00111   VIEWptr          _view;
00112   double           _t0;
00113   mlib::XYpt       _d;
00114   int              _disp;
00115 
00116   CCOLOR           _nhighlight_col;
00117   CCOLOR           _highlight_col;
00118 
00119  public:
00120    virtual ~MMENU() {}
00121    MMENU(CEvent &d, CEvent  &m, CEvent  &u) :
00122       Simple_int(d,m,u),
00123       _sel(-1),
00124       _t0(0),
00125       _disp(0),
00126       _nhighlight_col(.2,.2,0.7), 
00127       _highlight_col(1,0,0) {}
00128 
00129    virtual void  call(int sel);
00130    virtual int   invoke ( CEvent &, State *&);
00131    virtual int   down   ( CEvent &, State *&);
00132    virtual int   move   ( CEvent &, State *&);
00133    virtual int   up     ( CEvent &, State *&);
00134    virtual int   tick   ();
00135 };
00136 
00137 #endif

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