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

tablet.H

Go to the documentation of this file.
00001 #ifndef TABLET_H
00002 #define TABLET_H
00003 
00004 #include "std/support.H"
00005 #include "dev/tty.H"
00006 #include "dev/dev.H"
00007 
00008 class TabletDesc {
00009  public :
00010    enum TabletType {
00011          TINY,
00012          SMALL, 
00013          LARGE, 
00014          MULTI_MODE, 
00015          LCD,
00016          INTUOS,
00017          CROSS
00018    };
00019 
00020    int        _baud;
00021    int        _rec_len;
00022    str_ptr    _init_str;
00023    int        _yres;
00024    TabletType _type;
00025 
00026    TabletDesc()  { }
00027    TabletDesc(TabletType t);
00028    TabletDesc(int baud, int rec_len, Cstr_ptr &s, int yres):
00029               _baud(baud), _rec_len(rec_len), _init_str(s), _yres(yres) { }
00030 };
00031 
00032 // 
00033 // The "TabletEvent" and "TabletQueue" classes are used in tablet
00034 // DEVmultimode_tablet (but could also probably be used for DEVtablet, too, to
00035 // reduce the tablet lag effects).
00036 // 
00037 
00038 // This class representes a single Wacom tablet event.
00039 class TabletQueue;
00040 class TabletEvent
00041 {
00042  friend class TabletQueue;
00043  public:
00044    TabletEvent(char *buf, TabletDesc *d);
00045    TabletEvent() : _desc(0) {}
00046    virtual ~TabletEvent() {}
00047 
00048    int          get_device()    const { return _device;  }
00049 
00050    double      *get_pos()             { return _pos;     }
00051    char         get_buttons()         { return _buttons; }
00052 
00053    int          touching_tablet()     { return _touching_tablet; }
00054    double       stylus_pressure()     { return _stylus_pressure; }
00055 
00056    int          is_valid() { return _is_valid; }
00057    int          is_eraser() { return _is_eraser;}/* only valid for intuos */
00058 
00059    enum { STYLUS, PUCK };
00060    enum { BUTTON_DOWN, MOTION, BUTTON_UP };
00061 
00062  protected:
00063    int          _device;
00064    TabletDesc  *_desc;
00065 
00066    double       _pos[2];
00067    char         _buttons;
00068    int          _touching_tablet;
00069    double       _stylus_pressure;
00070    int          _is_valid;
00071    int          _is_eraser;
00072 };
00073 
00074 // This class accepts & filters tablet button and motion events such that
00075 // only "critical" events are saved. Basically, extra motion events (ones
00076 // that will be out of date because there exists a more recent motion
00077 // event) are thrown away.
00078 // 
00079 class TabletQueue
00080 {
00081  protected:
00082    int          _length;
00083    TabletEvent *_queue;
00084    int          _head,_tail;
00085 
00086    void         do_enqueue( TabletEvent &event );
00087  public:
00088    TabletQueue() : _length(256), _queue(0), _head(0), _tail(0)
00089                           { _queue = new TabletEvent[_length]; assert(_queue); }
00090    virtual ~TabletQueue() { delete _queue; }
00091 
00092    int          empty()   { return (_head == _tail); }
00093    void         reset()   { _tail = _head = 0; }
00094 
00095    void         enqueue( TabletEvent &event );
00096    TabletEvent  dequeue();
00097 };
00098 
00099 class Tablet : public TTYfd
00100 {
00101   protected:
00102 
00103    double            _yres;
00104    DEVice_2d         _stylus;
00105    DEVice_buttons    _styl_buttons;
00106    TabletDesc        _desc;
00107 
00108   public:
00109                      Tablet(FD_MANAGER *, TabletDesc::TabletType t,
00110                             const char *tty = NULL,
00111                             const char *name = "DEV_TABLET");
00112    virtual int       activate();
00113 
00114    DEVice_2d        &stylus()                   { return _stylus; }
00115    DEVice_buttons   &stylus_buttons()           { return _styl_buttons; }
00116 
00117    void              mod_setting_bit(int bit_num, int val);
00118 
00119    void              add_handler(DEVhandler *h) { _stylus.add_handler(h); 
00120                                                   _styl_buttons.add_handler(h);}
00121 };
00122 
00123 /* Button bits as generated by the TabletMultimode:
00124    0: pressing with tip (NOT eraser)
00125    1,2 switch on side of pen while in range
00126    3 pressing with eraser
00127    7 eraser in range ("touching")
00128    8 stylus in range ("touching")
00129 */
00130 
00131 class TabletMultimode : public Tablet
00132 {
00133   protected:
00134    DEVice_2d_absrel  _puck;
00135    DEVice_buttons    _puck_buttons;
00136 
00137    int               _device_to_report;
00138    int               _num_bytes_left_from_last_read;
00139    char              _tablet_data_buffer[4096];
00140 
00141    TabletQueue       _stylus_queue;
00142    TabletQueue       _puck_queue;
00143 
00144    int               _using_stylus_eraser;
00145    double            _stylus_pressure;
00146 
00147   public:
00148 
00149    enum { 
00150       STYLUS = 0,
00151       PUCK   = 1 
00152    };
00153 
00154            TabletMultimode(FD_MANAGER *, 
00155                            TabletDesc::TabletType type = TabletDesc::LARGE, 
00156                            const char *tty  = NULL,
00157                            const char *name = "DEV_TABLET");
00158 
00159            void     enqueue_available_tablet_events();
00160    virtual void     sample();
00161 
00162    DEVice_2d_absrel &puck()                     { return _puck; }
00163    DEVice_buttons   &puck_buttons()             { return _puck_buttons; }
00164 
00165    double            stylus_pressure()          { return _stylus_pressure; }
00166 
00167    void              add_handler(DEVhandler *h) { _puck.add_handler(h); 
00168                                                   _puck_buttons.add_handler(h);
00169                                                   Tablet::add_handler(h); }
00170 
00171    void              reset() {
00172       _stylus_queue.reset();
00173       _puck_queue  .reset();
00174    }
00175 
00176 };
00177 
00178 #endif
00179 

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