Use BBTablet Library to Access Wacom Tablet?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
fridlund
Posts: 24
Joined: Jun 03, 2007 15:24
Location: Southern California

Use BBTablet Library to Access Wacom Tablet?

Post by fridlund »

Hi,
Can anyone guide me how to use the BBTablet Library with FB (in Win 7 64) to access my Wacom Cintiq tablet? It's a precompiled C+ lib that's a wrapper for the WinTAB DLL supplied by Wacom. It looks like this may be the easiest way to get at the pen pressure and position data.
Here's the addr for the BBTablet stuff:
http://www.billbaxter.com/projects/bbtablet/index.html
Happy to pay someone to to this if it's not too much.
Best,
Alan
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Use BBTablet Library to Access Wacom Tablet?

Post by counting_pine »

(For convenience, here's the original bbtablet.h header):

Code: Select all

//============================================================================
// Bare-Bones Tablet Interface for C++
//
//  This header was designed to be platform-neutral for portability, 
//  but currently Win32 is the only implemented back end.
//
//  Relies on Wintab32.dll for windows operation.
//  If you have a tablet, then you should have a copy of Wintab32.dll that
//  was installed by the tablet's driver installer.
//  
//  Also necessary (for development on Windows) will be the WINTAB SDK.
//  A link can be found at http:://www.billbaxter.com/projects/bbtablet
//  It contains the necessary headers: wintab.h, pktdef.h ...
//
//  Author:        William Baxter (baxter@cs.unc.edu)
//  Last Modified: Dec 2005
//============================================================================
// (MIT License)
// Copyright (c) 2002--2009 William Baxter
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//============================================================================


#ifndef BB_TABLET_HEADER
#define BB_TABLET_HEADER

#define BBTAB_NOAUTOLINK
// autolinking causes troubles because we can't reliably detect when the
// app is linking against the DLL Runtime Libs.  The ifdef _DLL below doesn't
// do the trick.
#if defined(_WIN32) && !defined(BBTAB_NOAUTOLINK)
#ifdef _DLL
 // Decide what version of bbtablet.lib to link with and auto-link it.
 // The mnemonic is 'd' for debug, 's' for single-threaded runtime library
 // (NOTE: This convention just changed as of 2005-12!)
 #ifdef _DEBUG
 #pragma comment (lib, "bbtabletd.lib") // for /MDd apps
 #else
 #pragma comment (lib, "bbtablet.lib") // for /MD apps
 #endif
#else 
 #ifdef _DEBUG
 #pragma comment (lib, "bbtabletds.lib") // for /MTd, /MLd apps
 #else 
 #pragma comment (lib, "bbtablets.lib") // for /ML, /MT apps
 #endif
#endif
#endif


//============================================================================
/**
 * @class bbTabletEvent
 */
class bbTabletEvent
{
public:
  float x, y, z;    // Normalized [0,1] x,y,z coords
  float pressure;   // Normalized [0,1] pressure
  float tpressure;  // "Tangential pressure" like from airbrush wheel
  unsigned int id;      // Unique physical id of stylus if supported
  unsigned int buttons; // Bitmask of pressed buttons
  int type; // The type of stylus reported by WinTab
  int deviceID; // Who generated this event?

  void getOrientation(float &angle, float axis[3]) const;
  const char *getCursorName() const;
  int getCursorNumButtons() const;
  const char *getCursorButtonName(int buttonnum) const;
  
  // Routines to get the raw values reported by the driver
  int getRawX() const;
  int getRawY() const;
  int getRawZ() const;

  float getSysXf() const; // x in (virtual) desktop coords
  float getSysYf() const;
  float getWinXf() const; // x in window coords of tablet HWND
  float getWinYf() const;
  float getWinXf(void *win_handle) const; // x in coords of given window (HWND)
  float getWinYf(void *win_handle) const; 
  int getSysX() const { return int(getSysXf()+0.5f); } // These truncate to ints
  int getSysY() const { return int(getSysYf()+0.5f); } //  but the actual tablet
  int getWinX() const { return int(getWinXf()+0.5f); } //  precision is often sub-
  int getWinY() const { return int(getWinYf()+0.5f); } //  pixel.
  int getWinX(void *win_handle) const { return int(getWinXf(win_handle)+0.5f); }  
  int getWinY(void *win_handle) const { return int(getWinYf(win_handle)+0.5f); } 

  int getRawPressure() const;
  int getRawTangentialPressure() const;
  int getRawOrientAzimuth() const;
  int getRawOrientAltitude() const;
  int getRawOrientTwist() const;
  int getRawTiltX() const;
  int getRawTiltY() const;
  int getRawRoll() const; // does anything support this?
  int getRawPitch() const; // does anything support this?
  int getRawYaw() const; // does anything support this?

  bool inverted() const; // is the stylus inverted (i.e. "eraser mode")

  void *rawData;
  size_t rawDataSz;

public:
  bbTabletEvent();
  ~bbTabletEvent();
  bbTabletEvent(const bbTabletEvent &o);
  bbTabletEvent& operator=(const bbTabletEvent &o);
private:
  mutable unsigned int _flags;
  mutable float _angle;
  mutable float _axis[3];
  friend class bbTablet;
};

enum { 
  BBT_ALL_DEVICES=-1,
  BBT_INTEGRATED_DEVICES=-2,
  BBT_NONINTEGRATED_DEVICES=-3
};

class _bbTabletInternal;

//============================================================================
/* @class bbTabletObserver
 *
 *  This class defines the callback interface for using bbTablet via callbacks
 *  rather than polling.  
 */
class bbTabletObserver
{
public:
  virtual int OnTabletEvent(const bbTabletEvent &evt) = 0;
};

//============================================================================
/**
 * @class bbTablet
 *
 *   This class is a singleton. If multiple simultaneous tablets are supported
 *   by the drivers, this will be able get all their events.
 */
class bbTablet
{
private:
  // bbTablet is a singleton, so it can't be user-instantiated or copied
  // Use getInstance() instead.
  bbTablet(); 
  bbTablet(const bbTablet&);
  ~bbTablet();

public:
  enum { SYSTEM_POINTER, SEPARATE_POINTER };

  static bbTablet &getInstance();

  /** 
   * initSystem
   * @param system_window  should be an HWND on Windows, e.g.
   * @param mode 
   *      SYSTEM_POINTER if this tablet is to drive  the system cursor
   *      SEPARATE_POINTER if this tablet doesn't affect the system cursor
   * @return true if successfully initialized
   */
  bool initSystem( void *system_window, int mode = SYSTEM_POINTER );
  
  /** 
   * initTablet
   * @deprecated Call initSystem instead, which is all this method does now.
   */
  bool initTablet( void *system_window, int mode = SYSTEM_POINTER ) 
  { return initSystem(system_window, mode); }


  /** 
   * reinitTablets
   * Close and reopen all the tablet contexts in use.  May help if something
   * changes in the tablet environment.  Basically, if things go wonky, try 
   * calling this.  But generally there's no need.
   */
  bool reinitTablets();

  /**
   * setPointerMode
   * @param mode
   *      SYSTEM_POINTER if this tablet is to drive  the system cursor
   *      SEPARATE_POINTER if this tablet doesn't affect the system cursor
   * @param devID
   *      The device ID.  If BBT_ALL_DEVICES set mode for all devices
   *                      If BBT_INTEGRATED_DEVICES set mode for all devices with screens
   *                      If BBT_NONINTEGRATED_DEVICES set mode for all devices without screens
   * @return true if pointer mode successfully set
   */
  bool setPointerMode( int mode, int devID = BBT_ALL_DEVICES );
  /**
   * pointerMode
   * Returns the current pointer mode, either SYSTEM_POINTER or SEPARATE_POINTER
   */
  int pointerMode( int devID=0 ) const;

  /**
   * addObserver
   *    Adds a tablet event observer.  With this, users can get tablet events
   *    via callbacks rather than polling.  The observer's OnTabletEvent 
   *    method will be called whenever new events are ready.  Returns false
   *    if the observer couldn't be added (generally because it was already 
   *    added previously)
   */
  bool addObserver( bbTabletObserver& obs );

  /**
   * removeObserver
   *    Removes a previously added tablet event observer.  
   *    Returns false if the observer couldn't be removed (generally because
   *    it was never added.)
   */
  bool removeObserver( bbTabletObserver& obs );

  /**
   * isValid
   *    Returns true if the tablet has been successfully initialized
   */
  bool isValid( int devID = BBT_ALL_DEVICES ) const;

  /**
   * setDropOldEvents
   *    Sets whether getNextEvent will drop events if called when there is
   *    more than one event waiting in the queue.  Off by default.  Turning this on is not 
   *    recommended if you have multiple tablets or plan to use multiple 
   *    styluses simultaneously.
   */
  void setDropOldEvents(bool onOff);
  bool getDropOldEvents() const;

  /**
   * getNumDroppedEvents
   *     If setDropOldEvents() is on, then this will return the number of
   *     events that were dropped.
   */
  long getNumDroppedEvents() const;
  void resetNumDroppedEvents();
  
  bool getNextEvent(bbTabletEvent &evt, int devID = BBT_ALL_DEVICES);
  bool waitForNextEvent(bbTabletEvent &evt, unsigned int msec = 0);

  const char *getCursorName(int csrtype);
  int getCursorNumButtons(int csrtype);
  const char *getCursorButtonName(int csrtype, int buttonnum);

  int getNumActiveDevices() const;

  int getNumDevices() const;
  bool isDeviceIntegrated(int devID) const;


private:
  _bbTabletInternal *m_data;
  friend class bbTabletEvent;
  friend class _bbTabletInternal;
};

// For backwards compatibility with previous versions of bbTablet
typedef bbTablet bbTabletDevice;

#endif /* BB_TABLET_HEADER */
(EDIT: Now, the actual, pre-modified header)

Looks like there are three main classes: bbTabletEvent, bbTabletObserver and bbTablet.
bbTabletObserver just contains a single virtual function which wasn't supported in the last release of FB (but will be in the next), but could probably just be implemented with a function pointer if needed.

The other two look like they are easily translatable. There's some friend classes and mutable members which aren't supported in at this time in FB but can probably just be ignored.

I had a go at the first class:

Code: Select all

'class bbTabletEvent
type bbTabletEvent alias "bbTabletEvent"
public:
  'float x, y, z;    // Normalized [0,1] x,y,z coords
  'float pressure;   // Normalized [0,1] pressure
  'float tpressure;  // "Tangential pressure" like from airbrush wheel
  'unsigned int id;      // Unique physical id of stylus if supported
  'unsigned int buttons; // Bitmask of pressed buttons
  'int type; // The type of stylus reported by WinTab
  'int deviceID; // Who generated this event?
  as single x, y, z    '' Normalized [0,1] x,y,z coords
  as single pressure   '' Normalized [0,1] pressure
  as single tpressure  '' "Tangential pressure" like from airbrush wheel
  as uinteger id      '' Unique physical id of stylus if supported
  as uinteger buttons '' Bitmask of pressed buttons
  as integer type '' The type of stylus reported by WinTab
  as integer deviceID '' Who generated this event?

  'void getOrientation(float &angle, float axis[3]) const;
  'const char *getCursorName() const;
  'int getCursorNumButtons() const;
  'const char *getCursorButtonName(int buttonnum) const;
  declare const sub getOrientation alias "getOrientation" (byref angle as single, axis() as single)
  declare const function getCursorName alias "gtCursorName" () as const zstring ptr
  declare const function getCursorNumButtons alias "getCursorNumButtons" () as integer
  declare const function getCursorButtonName alias "getCursorButtonName" (byval buttonnum as integer) as const zstring ptr
  
  '' Routines to get the raw values reported by the driver
  'int getRawX() const;
  'int getRawY() const;
  'int getRawZ() const;
  declare const function getRawX alias "getRawX" () as integer
  declare const function getRawY alias "getRawY" () as integer
  declare const function getRawZ alias "getRawZ" () as integer

  'float getSysXf() const; '' x in (virtual) desktop coords
  'float getSysYf() const;
  'float getWinXf() const; '' x in window coords of tablet HWND
  'float getWinYf() const;
  'float getWinXf(void *win_handle) const; '' x in coords of given window (HWND)
  'float getWinYf(void *win_handle) const; 
  declare const function getSysXf alias "getSysXf"() as const single
  declare const function getSysYf alias "getSysYf"() as const single
  declare const function getWinXf alias "getWinXf"() as const single
  declare const function getWinYf alias "getWinYf"() as const single
  declare const function getWinXf alias "getWinXf"(byval win_handle as any ptr) as const single
  declare const function getWinYf alias "getWinXf"(byval win_handle as any ptr) as const single
  
  'int getSysX() const { return int(getSysXf()+0.5f); } '' These truncate to ints
  'int getSysY() const { return int(getSysYf()+0.5f); } ''  but the actual tablet
  'int getWinX() const { return int(getWinXf()+0.5f); } ''  precision is often sub-
  'int getWinY() const { return int(getWinYf()+0.5f); } ''  pixel.
  'int getWinX(void *win_handle) const { return int(getWinXf(win_handle)+0.5f); }  
  'int getWinY(void *win_handle) const { return int(getWinYf(win_handle)+0.5f); } 

  ''TODO: implement locally (can't write function bodies here)
  declare const function getSysX alias "getSysX" () as integer 
  declare const function getSysY alias "getSysY" () as integer
  declare const function getWinX alias "getWinX" () as integer 
  declare const function getWinY alias "getWinY" () as integer
  declare const function getWinX alias "getWinX" (byval win_handle as any ptr) as integer 
  declare const function getWinY alias "getWinY" (byval win_handle as any ptr) as integer

  'int getRawPressure() const;
  'int getRawTangentialPressure() const;
  'int getRawOrientAzimuth() const;
  'int getRawOrientAltitude() const;
  'int getRawOrientTwist() const;
  'int getRawTiltX() const;
  'int getRawTiltY() const;
  'int getRawRoll() const; '' does anything support this?
  'int getRawPitch() const; '' does anything support this?
  'int getRawYaw() const; '' does anything support this?
  declare const function getRawPressure alias "getRawPressure" () as integer
  declare const function getRawTangentialPressure alias "getRawTangentialPressure" () as integer
  declare const function getRawOrientAzimuth alias "getRawOrientAzimuth" () as integer
  declare const function getRawOrientAltitude alias "getRawOrientAltitude" () as integer
  declare const function getRawOrientTwist alias "getRawOrientTwist" () as integer
  declare const function getRawTiltX alias "getRawTiltX" () as integer
  declare const function getRawTiltY alias "getRawTiltY" () as integer
  declare const function getRawRoll alias "getRawRoll" () as integer
  declare const function getRawPitch alias "getRawPitch" () as integer
  declare const function getRawYaw alias "getRawYaw" () as integer

  'bool inverted() const; '' is the stylus inverted (i.e. "eraser mode")
  declare const function inverted alias "inverted" () as byte

  'void *rawData;
  'size_t rawDataSz;
  as any ptr rawData
  as size_t rawDataSz

public:
  'bbTabletEvent();
  '~bbTabletEvent();
  'bbTabletEvent(const bbTabletEvent &o);
  'bbTabletEvent& operator=(const bbTabletEvent &o);
  declare constructor ()
  declare destructor ()
  declare constructor (byref o as const bbTabletEvent)
  declare operator let(byref o as const bbTabletEvent)
private:
  'mutable unsigned int _flags;
  'mutable float _angle;
  'mutable float _axis[3];
  as /'mutable'/ uinteger _flags
  as /'mutable'/ single _angle
  as /'mutable'/ single _axis(0 to 3-1)

  'friend class bbTablet;
end type
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Use BBTablet Library to Access Wacom Tablet?

Post by counting_pine »

Here's the entire header, translated by hand, so there may be typos and there are no guarantees it will work. Especially since I can't test it.
I've left in all the C++ declarations, commented out, so typos should be easy to find and fix if a particular routine causes problems.

The bbTabletObserver class is probably quite important, but won't work without virtual functions. It might be possible to implement a sort of virtual table using function pointers, but I'm not comfortable enough to guess at a workaround. So as it suggests, you might be better off just polling for now.
Note: even when FB does support virtual functions, I'm not certain whether they will be compatible with the ones expected by the library.

Now I think about it, unless you can compile the library in the GNU C++ compiler, I have a feeling it won't work anyway since I think VC++ mangles function names differently.

Anyway, here's all I can do, but perhaps someone more knowledgeable will weigh in.

Code: Select all

''============================================================================
'' Bare-Bones Tablet Interface for C++
''
''  This header was designed to be platform-neutral for portability, 
''  but currently Win32 is the only implemented back end.
''
''  Relies on Wintab32.dll for windows operation.
''  If you have a tablet, then you should have a copy of Wintab32.dll that
''  was installed by the tablet's driver installer.
''  
''  Also necessary (for development on Windows) will be the WINTAB SDK.
''  A link can be found at http::''www.billbaxter.com/projects/bbtablet
''  It contains the necessary headers: wintab.h, pktdef.h ...
''
''  Author:        William Baxter (baxter@cs.unc.edu)
''  Last Modified: Dec 2005
''============================================================================
'' (MIT License)
'' Copyright (c) 2002--2009 William Baxter
'' 
'' Permission is hereby granted, free of charge, to any person
'' obtaining a copy of this software and associated documentation
'' files (the "Software"), to deal in the Software without
'' restriction, including without limitation the rights to use, copy,
'' modify, merge, publish, distribute, sublicense, and/or sell copies
'' of the Software, and to permit persons to whom the Software is
'' furnished to do so, subject to the following conditions:
''
'' The above copyright notice and this permission notice shall be
'' included in all copies or substantial portions of the Software.
'' 
'' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
'' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
'' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
'' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
'' BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
'' ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
'' CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
'' SOFTWARE.
''============================================================================


#ifndef BB_TABLET_HEADER
#define BB_TABLET_HEADER

#define BBTAB_NOAUTOLINK
'' autolinking causes troubles because we can't reliably detect when the
'' app is linking against the DLL Runtime Libs.  The ifdef _DLL below doesn't
'' do the trick.

'#if defined(_WIN32) && !defined(BBTAB_NOAUTOLINK)
'#ifdef _DLL
' // Decide what version of bbtablet.lib to link with and auto-link it.
' // The mnemonic is 'd' for debug, 's' for single-threaded runtime library
' // (NOTE: This convention just changed as of 2005-12!)
' #ifdef _DEBUG
' #pragma comment (lib, "bbtabletd.lib") // for /MDd apps
' #else
' #pragma comment (lib, "bbtablet.lib") // for /MD apps
' #endif
'#else 
' #ifdef _DEBUG
' #pragma comment (lib, "bbtabletds.lib") // for /MTd, /MLd apps
' #else 
' #pragma comment (lib, "bbtablets.lib") // for /ML, /MT apps
' #endif
'#endif

#if defined(__FB_WIN32__) and not defined(BBTAB_NOAUTOLINK)
#ifdef _DLL
 #if __FB_DEBUG__
 #inclib "bbtabletd.lib" '' for /MDd apps
 #else
 #inclib "bbtablet.lib" '' for /MD apps
 #endif
#else 
 #if __FB_DEBUG__
 #inclib "bbtabletds.lib" '' for /MTd, /MLd apps
 #else 
 #inclib "bbtablets.lib" '' for /ML, /MT apps
 #endif
#endif

#endif

#ifndef size_t
type size_t as uinteger
#endif

#ifndef bool
type bool as byte
#endif

extern "c++"

''============================================================================
/''
 ' @class bbTabletEvent
 '/
'class bbTabletEvent
type bbTabletEvent alias "bbTabletEvent"
public:
  'float x, y, z;    // Normalized [0,1] x,y,z coords
  'float pressure;   // Normalized [0,1] pressure
  'float tpressure;  // "Tangential pressure" like from airbrush wheel
  'unsigned int id;      // Unique physical id of stylus if supported
  'unsigned int buttons; // Bitmask of pressed buttons
  'int type; // The type of stylus reported by WinTab
  'int deviceID; // Who generated this event?
  as single x, y, z    '' Normalized [0,1] x,y,z coords
  as single pressure   '' Normalized [0,1] pressure
  as single tpressure  '' "Tangential pressure" like from airbrush wheel
  as uinteger id      '' Unique physical id of stylus if supported
  as uinteger buttons '' Bitmask of pressed buttons
  as integer type_ '' The type of stylus reported by WinTab
  as integer deviceID '' Who generated this event?

  'void getOrientation(float &angle, float axis[3]) const;
  'const char *getCursorName() const;
  'int getCursorNumButtons() const;
  'const char *getCursorButtonName(int buttonnum) const;
  declare const sub getOrientation alias "getOrientation" (byref angle as single, axis() as single)
  declare const function getCursorName alias "gtCursorName" () as const zstring ptr
  declare const function getCursorNumButtons alias "getCursorNumButtons" () as integer
  declare const function getCursorButtonName alias "getCursorButtonName" (byval buttonnum as integer) as const zstring ptr
  
  '' Routines to get the raw values reported by the driver
  'int getRawX() const;
  'int getRawY() const;
  'int getRawZ() const;
  declare const function getRawX alias "getRawX" () as integer
  declare const function getRawY alias "getRawY" () as integer
  declare const function getRawZ alias "getRawZ" () as integer

  'float getSysXf() const; '' x in (virtual) desktop coords
  'float getSysYf() const;
  'float getWinXf() const; '' x in window coords of tablet HWND
  'float getWinYf() const;
  'float getWinXf(void *win_handle) const; '' x in coords of given window (HWND)
  'float getWinYf(void *win_handle) const; 
  declare const function getSysXf alias "getSysXf"() as const single
  declare const function getSysYf alias "getSysYf"() as const single
  declare const function getWinXf alias "getWinXf"() as const single
  declare const function getWinYf alias "getWinYf"() as const single
  declare const function getWinXf alias "getWinXf"(byval win_handle as any ptr) as const single
  declare const function getWinYf alias "getWinXf"(byval win_handle as any ptr) as const single
  
  'int getSysX() const { return int(getSysXf()+0.5f); } '' These truncate to ints
  'int getSysY() const { return int(getSysYf()+0.5f); } ''  but the actual tablet
  'int getWinX() const { return int(getWinXf()+0.5f); } ''  precision is often sub-
  'int getWinY() const { return int(getWinYf()+0.5f); } ''  pixel.
  'int getWinX(void *win_handle) const { return int(getWinXf(win_handle)+0.5f); }  
  'int getWinY(void *win_handle) const { return int(getWinYf(win_handle)+0.5f); } 

  ''implemented after the type block (can't write function bodies in types in FB)
  declare const function getSysX alias "getSysX" () as integer 
  declare const function getSysY alias "getSysY" () as integer
  declare const function getWinX alias "getWinX" () as integer 
  declare const function getWinY alias "getWinY" () as integer
  declare const function getWinX alias "getWinX" (byval win_handle as any ptr) as integer 
  declare const function getWinY alias "getWinY" (byval win_handle as any ptr) as integer

  'int getRawPressure() const;
  'int getRawTangentialPressure() const;
  'int getRawOrientAzimuth() const;
  'int getRawOrientAltitude() const;
  'int getRawOrientTwist() const;
  'int getRawTiltX() const;
  'int getRawTiltY() const;
  'int getRawRoll() const; '' does anything support this?
  'int getRawPitch() const; '' does anything support this?
  'int getRawYaw() const; '' does anything support this?
  declare const function getRawPressure alias "getRawPressure" () as integer
  declare const function getRawTangentialPressure alias "getRawTangentialPressure" () as integer
  declare const function getRawOrientAzimuth alias "getRawOrientAzimuth" () as integer
  declare const function getRawOrientAltitude alias "getRawOrientAltitude" () as integer
  declare const function getRawOrientTwist alias "getRawOrientTwist" () as integer
  declare const function getRawTiltX alias "getRawTiltX" () as integer
  declare const function getRawTiltY alias "getRawTiltY" () as integer
  declare const function getRawRoll alias "getRawRoll" () as integer
  declare const function getRawPitch alias "getRawPitch" () as integer
  declare const function getRawYaw alias "getRawYaw" () as integer

  'bool inverted() const; '' is the stylus inverted (i.e. "eraser mode")
  declare const function inverted alias "inverted" () as bool

  'void *rawData;
  'size_t rawDataSz;
  as any ptr rawData
  as size_t rawDataSz

public:
  'bbTabletEvent();
  '~bbTabletEvent();
  'bbTabletEvent(const bbTabletEvent &o);
  'bbTabletEvent& operator=(const bbTabletEvent &o);
  declare constructor ()
  declare destructor ()
  declare constructor (byref o as const bbTabletEvent)
  declare operator let(byref o as const bbTabletEvent)
private:
  'mutable unsigned int _flags;
  'mutable float _angle;
  'mutable float _axis[3];
  as /'mutable'/ uinteger _flags
  as /'mutable'/ single _angle
  as /'mutable'/ single _axis(0 to 3-1)

  'friend class bbTablet;

end type
'int getSysX() const { return int(getSysXf()+0.5f); } '' These truncate to ints
'int getSysY() const { return int(getSysYf()+0.5f); } ''  but the actual tablet
'int getWinX() const { return int(getWinXf()+0.5f); } ''  precision is often sub-
'int getWinY() const { return int(getWinYf()+0.5f); } ''  pixel.
'int getWinX(void *win_handle) const { return int(getWinXf(win_handle)+0.5f); }  
'int getWinY(void *win_handle) const { return int(getWinYf(win_handle)+0.5f); } 
function bbTabletEvent.getSysX () as integer: return cint(getSysXf()): end function
function bbTabletEvent.getSysY () as integer: return cint(getSysYf()): end function
function bbTabletEvent.getWinX () as integer: return cint(getWinXf()): end function
function bbTabletEvent.getWinY () as integer: return cint(getWinYf()): end function
function bbTabletEvent.getWinX (byval win_handle as any ptr) as integer: return cint(getWinXf(win_handle)): end function
function bbTabletEvent.getWinY (byval win_handle as any ptr) as integer: return cint(getWinYf(win_handle)): end function


enum
  BBT_ALL_DEVICES=-1,
  BBT_INTEGRATED_DEVICES=-2,
  BBT_NONINTEGRATED_DEVICES=-3
end enum

'class _bbTabletInternal;

''============================================================================
/' @class bbTabletObserver
 '
 '  This class defines the callback interface for using bbTablet via callbacks
 '  rather than polling.  
 '/
'class bbTabletObserver
'{
'public:
'  virtual int OnTabletEvent(const bbTabletEvent &evt) = 0;
'};
#ifdef VIRTUAL_FUNCTIONS '' virtual functions supported in next FB release
type bbTabletObserver alias "bbTabletObserver" extends Object
    declare abstract function OnTabletEvent alias "OnTabletEvent" (byref evt as const bbTabletEvent) as integer
end type
#else
'type OnTabletEvent as function(byref evt as const bbTabletEvent) as integer
#endif

''============================================================================
/'*
 ' @class bbTablet
 '
 '   This class is a singleton. If multiple simultaneous tablets are supported
 '   by the drivers, this will be able get all their events.
 '/
'class bbTablet
'{
type bbTablet alias "bbTablet"
private:
  '' bbTablet is a singleton, so it can't be user-instantiated or copied
  '' Use getInstance() instead.
  'bbTablet(); 
  'bbTablet(const bbTablet&);
  '~bbTablet();
  declare constructor()
  declare constructor(byref as const bbTablet)
  declare destructor()

public:
  'enum { SYSTEM_POINTER, SEPARATE_POINTER };
  enum: SYSTEM_POINTER: SEPARATE_POINTER: end enum

  'static bbTablet &getInstance();
  'declare static function getInstance alias "getInstance" () byref as bbTablet '' byref returns supported in next FB release
  declare static function getInstance alias "getInstance" () as bbTablet ptr

  /'* 
   ' initSystem
   ' @param system_window  should be an HWND on Windows, e.g.
   ' @param mode 
   '      SYSTEM_POINTER if this tablet is to drive  the system cursor
   '      SEPARATE_POINTER if this tablet doesn't affect the system cursor
   ' @return true if successfully initialized
   '/
  'bool initSystem( void *system_window, int mode = SYSTEM_POINTER );
  declare function initSystem alias "initSystem" (byval system_window as any ptr, byval mode as integer = SYSTEM_POINTER) as bool
  
  /'* 
   ' initTablet
   ' @deprecated Call initSystem instead, which is all this method does now.
   '/
  'bool initTablet( void *system_window, int mode = SYSTEM_POINTER ) 
  '{ return initSystem(system_window, mode); }


  /'* 
   ' reinitTablets
   ' Close and reopen all the tablet contexts in use.  May help if something
   ' changes in the tablet environment.  Basically, if things go wonky, try 
   ' calling this.  But generally there's no need.
   '/
  'bool reinitTablets();
  declare function reinitTablets alias "reinitTablets" () as bool
  

  /'*
   ' setPointerMode
   ' @param mode
   '      SYSTEM_POINTER if this tablet is to drive  the system cursor
   '      SEPARATE_POINTER if this tablet doesn't affect the system cursor
   ' @param devID
   '      The device ID.  If BBT_ALL_DEVICES set mode for all devices
   '                      If BBT_INTEGRATED_DEVICES set mode for all devices with screens
   '                      If BBT_NONINTEGRATED_DEVICES set mode for all devices without screens
   ' @return true if pointer mode successfully set
   '/
  'bool setPointerMode( int mode, int devID = BBT_ALL_DEVICES );
  declare function setPointerMode alias "setPointerMode" (byval mode as integer, byval devID as integer = BBT_ALL_DEVICES) as bool
  
  /'*
   ' pointerMode
   ' Returns the current pointer mode, either SYSTEM_POINTER or SEPARATE_POINTER
   '/
  'int pointerMode( int devID=0 ) const;
  declare const function pointerMode alias "pointerMode" (byval devID as integer = 0) as integer

  #ifdef bbTabletObserver '' needs virtual functions
  /'*
   ' addObserver
   '    Adds a tablet event observer.  With this, users can get tablet events
   '    via callbacks rather than polling.  The observer's OnTabletEvent 
   '    method will be called whenever new events are ready.  Returns false
   '    if the observer couldn't be added (generally because it was already 
   '    added previously)
   '/
  'bool addObserver( bbTabletObserver& obs );
  declare function addObserver alias "addObserver" (byref obs as bbTabletObserver) as bool

  /**
   * removeObserver
   *    Removes a previously added tablet event observer.  
   *    Returns false if the observer couldn't be removed (generally because
   *    it was never added.)
   */
  'bool removeObserver( bbTabletObserver& obs );
  declare function removeObserver alias "removeObserver" (byref obs as bbTabletObserver) as bool
  #endif

  /'*
   ' isValid
   '    Returns true if the tablet has been successfully initialized
   '/
  'bool isValid( int devID = BBT_ALL_DEVICES ) const;
  declare const function isValid alias "isValid" (byval devID as integer = BBT_ALL_DEVICES) as integer

  /'*
   ' setDropOldEvents
   '    Sets whether getNextEvent will drop events if called when there is
   '    more than one event waiting in the queue.  Off by default.  Turning this on is not 
   '    recommended if you have multiple tablets or plan to use multiple 
   '    styluses simultaneously.
   '/
  'void setDropOldEvents(bool onOff);
  'bool getDropOldEvents() const;
  declare sub setDropOldEvents(byval onOff as bool)
  declare const function getDropOldEvents() as bool

  /'*
   ' getNumDroppedEvents
   '     If setDropOldEvents() is on, then this will return the number of
   '     events that were dropped.
   '/
  'long getNumDroppedEvents() const;
  'void resetNumDroppedEvents();
  declare const function getNumDroppedEvents alias "getNumDroppedEvents" () as long
  declare sub resetNumDroppedEvents alias "resetNumDroppedEvents" ()
  
  'bool getNextEvent(bbTabletEvent &evt, int devID = BBT_ALL_DEVICES);
  'bool waitForNextEvent(bbTabletEvent &evt, unsigned int msec = 0);
  declare function getNextEvent(byref evt as const bbTabletEvent, byval devID as integer = BBT_ALL_DEVICES) as bool
  declare function waitForNextEvent(byref evt as bbTabletEvent, byval msec as uinteger = 0) as bool

  'const char *getCursorName(int csrtype);
  'int getCursorNumButtons(int csrtype);
  'const char *getCursorButtonName(int csrtype, int buttonnum);
  declare function getCursorName alias "getCursorName" (byval csrtype as integer) as const zstring ptr
  declare function getCursorNumButtons alias "getCursorNumButtons" (byval csrtype as integer) as integer
  declare function getCursorButtonName alias "getCursorButtonName" (byval csrtype as integer, byval buttonnum as integer) as const zstring ptr
  

  'int getNumActiveDevices() const;
  declare const function getNumActiveDevices alias "getNumActiveDevices" () as integer

  'int getNumDevices() const;
  'bool isDeviceIntegrated(int devID) const;
  declare const function getNumDevices alias "getNumDevices" () as integer
  declare const function isDeviceIntegrated alias "isDeviceIntegrated" (byval devID as integer) as bool


private:
  '_bbTabletInternal *m_data;
  'friend class bbTabletEvent;
  'friend class _bbTabletInternal;
  m_data as /'_bbTabletInternal'/any ptr

end type

'' For backwards compatibility with previous versions of bbTablet
'typedef bbTablet bbTabletDevice;

end extern

#endif /' BB_TABLET_HEADER '/
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Use BBTablet Library to Access Wacom Tablet?

Post by counting_pine »

Just a quick update: the source doesn't like it's designed specifically to work with MSVC++, so it may well compile without too much difficulty in G++. I just had a go, and I managed to persuade bbtablet.cpp to compile without incident, it just didn't link.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Use BBTablet Library to Access Wacom Tablet?

Post by TJF »

EXTERN "C++" ... END EXTERN
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Use BBTablet Library to Access Wacom Tablet?

Post by counting_pine »

Thanks TJF. Can you be of any further help?
EDIT: updated above header.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Use BBTablet Library to Access Wacom Tablet?

Post by TJF »

Sorry, no test environment ...
Post Reply