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

gest_int.H

Go to the documentation of this file.
00001 /**********************************************************************
00002  * gest_int.H
00003  **********************************************************************/
00004 #ifndef GEST_INT_H_HAS_BEEN_INCLUDED
00005 #define GEST_INT_H_HAS_BEEN_INCLUDED
00006 
00007 #include "geom/fsa.H"
00008 #include "manip/manip.H"
00009 #include "std/stop_watch.H"
00010 
00011 #include "gesture.H"
00012 
00013 // forward declare gesture observer class (defined below)
00014 class GestObs;
00015 
00016 /*****************************************************************
00017  * GESTURE_list:
00018  *****************************************************************/
00019 class GESTURE_list : public LIST<GESTUREptr> {
00020  public:
00021    //******** MANAGERS ********
00022    GESTURE_list(int n=0) : LIST<GESTUREptr>(n) { begin_index(); }
00023    GESTURE_list(const GESTURE_list& list) : LIST<GESTUREptr>(list) {
00024       begin_index();
00025    }
00026 
00027    virtual ~GESTURE_list() { end_index(); }
00028 
00029    //******** ARRAY INDEXING ********
00030    virtual void set_index(CGESTUREptr& g, int i) const {
00031       // XXX -
00032       //  Should confirm g belongs to this list?
00033       //  Yes but, for now, assume GESTURE_list 
00034       //    is only used by GEST_INT.
00035       //
00036       if (g)
00037          ((GESTUREptr&)g)->set_index(i);
00038    }
00039    virtual void clear_index(CGESTUREptr& g) const { set_index(g, BAD_IND); }
00040    virtual int  get_index  (CGESTUREptr& g) const {
00041       return g ? ((GESTUREptr&)g)->index() : BAD_IND;
00042    }
00043 };
00044 
00045 /*****************************************************************
00046  * GEST_INT
00047  *
00048  *      Interactor for drawing stroke-based gestures.
00049  *
00050  *      Handles down/move/up events to record gestures, then hands off
00051  *      the gestures to "observers," i.e. Pens that trigger
00052  *      appropriate callbacks.
00053  *****************************************************************/
00054 #define CGEST_INTptr const GEST_INTptr
00055 MAKE_PTR_SUBC(GEST_INT,FRAMEobs);
00056 //permuted FRAMEobs and CAMobs because of segfault when compiled with g++ 3.3.2
00057 class GEST_INT : public FRAMEobs, public CAMobs, public Simple_int {
00058  protected:
00059    VIEWptr              _view;          // view
00060    ARRAY<GestObs*>      _obs;           // observers of gestures
00061    GESTURE_list         _stack;         // recent gestures
00062    GestureDrawer*       _drawer;        // for drawing gestures
00063    FSA                  _fsa;           // the fsa for this interactor
00064 
00065    State                _b2_pressed;
00066 
00067    // XXX - doubtful:
00068    bool                 _keep_history;  // keep gestures on the stack 
00069                                         // until history is cleared
00070    int                  _num_history;   // number of gestures in history
00071 
00072    void activate();
00073    void deactivate();
00074 
00075  public:
00076    //******** MANAGERS ********
00077    GEST_INT(CVIEWptr& view,
00078             CEvent &d, CEvent &m, CEvent &u,
00079             CEvent &d2, CEvent &u2);
00080    virtual ~GEST_INT() 
00081    { 
00082       err_mesg(ERR_LEV_SPAM, "GEST_INT destructor");
00083    }
00084 
00085    // add/remove observers
00086    // (e.g. called in Pen::activate/deactivate):
00087    void rem_obs(GestObs* g);
00088    void add_obs(GestObs* g);
00089 
00090    // restore FSA to initial state:
00091    void reset()                                 { _fsa.reset(); }
00092 
00093    // set the thing that draws Gestures:
00094    void set_drawer(GestureDrawer* drawer)     { _drawer = drawer; }
00095    GestureDrawer* drawer()                    { return _drawer; }
00096 
00097    void set_keep_history(bool b)              
00098    { 
00099       err_mesg(ERR_LEV_SPAM, "GEST_INT::set keep history() - Now is %d",(b)?(1):(0));
00100       _keep_history = b; 
00101    }
00102    bool keep_history()                        { return _keep_history; } 
00103    void start_history();
00104 
00105    // gesture accessors
00106    // (get gesture number k out of the entire gesture history):
00107    GESTUREptr gesture(int k) const {
00108       return _stack.valid_index(k) ? _stack[k] : GESTUREptr(0);
00109    }
00110    GESTUREptr last() const { return gesture(_stack.num()-1); }
00111 
00112    virtual int null_cb(CEvent&, State*&) { return 0; }
00113 
00114    //******** Simple_int methods ********
00115    virtual int down(CEvent &,State *&);
00116    virtual int move(CEvent &,State *&);
00117    virtual int up  (CEvent &,State *&);
00118 
00119    //******** CAMobs Method *************
00120    virtual void notify(CCAMdataptr &data);
00121 
00122    //******** FRAMEobs methods ********
00123    virtual int  tick();
00124 };
00125 
00126 /*****************************************************************
00127  * GestObs:
00128  *
00129  *      Abstract base class for "gesture observers" that receive
00130  *      gestures from the gesture interactor.
00131  *****************************************************************/
00132 class GestObs {
00133  public:
00134    //******** MANAGERS ********
00135    virtual ~GestObs() {}
00136 
00137    // get notification of the latest gesture
00138    virtual void notify_gesture(GEST_INT* gest_int, CGESTUREptr& gest) = 0;
00139 
00140    // take over the given down/move/up event from the GEST_INT:
00141    // can be used to invoke a menu, e.g., depending on context.
00142    virtual int handle_event(CEvent&, State* &) { return 0; }
00143 };
00144 
00145 #endif  // GEST_INT_H_HAS_BEEN_INCLUDED
00146 
00147 /* end of file gest_int.H */

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