#ifndef Tmp1_TabletReader_H
#define Tmp1_TabletReader_H
#include <Glasses/ZNode.h>
#include <Gled/GMutex.h>
#include <Gled/GThread.h>
#include <Gled/GTime.h>
class TabletStroke;
class TabletStrokeList;
class TabletReader : public ZNode
{
  MAC_RNR_FRIENDS(TabletReader);
public:
  enum ButtonBits_e
  {
    BB_Touch    = 1 << 5,
    BB_Stylus_1 = 1 << 6,
    BB_Stylus_2 = 1 << 7,
    BB_Button_0 = 1 << 8,
    BB_Button_1 = 1 << 9,
    BB_Pad_Buttons = BB_Touch | BB_Stylus_1 | BB_Stylus_2
  };
  enum Tool_e
  {
    T_None   = 0,
    T_Pen    = 1,
    T_Eraser = 4,
    T_Pad    = 8
  };
  enum StrokeType_e
  {
    SS_None, SS_Absolute, SS_Relative, SS_Continuous
  };
private:
  void _init();
protected:
  StrokeType_e  mStrokeType; 
  Bool_t        bInvertY;    
  Bool_t        bKeepStrokeInProximity; 
  Float_t       mPosScale;   
  Float_t       mPrsScale;   
  Int_t         mOffX;       
  Int_t         mOffY;       
  Int_t         mButtons;
  
  Bool_t        bButton0;         
  Bool_t        bButton1;         
  Bool_t        bStylus1;         
  Bool_t        bStylus2;         
  Bool_t        bInProximity;     
  Bool_t        bInTouch;         
  Bool_t        bInStroke;        
  
  Float_t       mPenXOff;
  Float_t       mPenYOff;
  Float_t       mPenTOff;
  Float_t       mPenX, mPenY, mPenP, mPenT; 
  Int_t         mRawX, mRawY, mRawP; 
  GTime         mEventTime;        
  GTime         mFirstStrokeStart; 
  GTime         mStrokeStart;      
  Bool_t        bPrintButtEvs;    
  Bool_t        bPrintButtState;  
  Bool_t        bPrintPositions;  
  Bool_t        bPrintOther;      
  ZLink<TabletStrokeList> mStrokeList;  
  ZLink<TabletStroke>     mStroke;      
  GMutex    mTabletMutex;  
  GThread  *mTabletThread; 
  Bool_t    bReqStop;      
  Bool_t      get_button(Int_t bb) { return bb & mButtons; }
  const char* get_button_name(Int_t bb);
  Bool_t      flip_report_button(Int_t bb);
  Bool_t      check_pen_buttons(Int_t buttons_delta);
  void        clear_pen_buttons();
  Bool_t      check_pad_buttons(Int_t buttons_delta);
  void begin_stroke_list();
  void end_stroke_list();
  void begin_stroke();
  void end_stroke();
public:
  TabletReader(const Text_t* n="TabletReader", const Text_t* t=0);
  virtual ~TabletReader();
  void StartRead(); 
  void StopRead();  
#include "TabletReader.h7"
  ClassDef(TabletReader, 1);
}; 
#endif