DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L1924
Version: 2.0-current





Link: http://www.fltk.org/str.php?L1924
Version: 2.0-current
Index: src/win32/run.cxx
===================================================================
--- src/win32/run.cxx   (revision 6140)
+++ src/win32/run.cxx   (working copy)
@@ -681,7 +681,7 @@
 ////////////////////////////////////////////////////////////////
 // Tablet initialisation and event handling
 #include "wintab.h"
-#define PACKETDATA (PK_NORMAL_PRESSURE|PK_ORIENTATION|PK_CURSOR)
+#define PACKETDATA (PK_X|PK_Y|PK_NORMAL_PRESSURE|PK_ORIENTATION|PK_CURSOR)
 #define PACKETMODE 0
 #include "pktdef.h"
 
@@ -769,11 +769,11 @@
   lcMine.lcInExtX = TabletX.axMax;
   lcMine.lcInExtY = TabletY.axMax;
 
-  /* output the data in screen coords */
+  /* output the data in tablet coords */
   lcMine.lcOutOrgX = lcMine.lcOutOrgY = 0;
-  lcMine.lcOutExtX = GetSystemMetrics(SM_CXSCREEN);
+  lcMine.lcOutExtX = TabletX.axMax;
   /* move origin to upper left */
-  lcMine.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN);
+  lcMine.lcOutExtY = -TabletY.axMax;
   /* open the region */
   wintab_ctx = wtOpen(hWnd, &lcMine, TRUE);
   if (!wintab_ctx) {
@@ -782,6 +782,10 @@
 #endif
       return;
   }
+  /* store constant parameters */
+  tablet_root_x_max_ = tablet_x_max_ = TabletX.axMax;
+  tablet_root_y_max_ = tablet_y_max_ = TabletY.axMax;
+
   if (wintab_ctx) wintab_hwnd = hWnd;
 }
 
@@ -819,6 +823,7 @@
 #if DEBUG_TABLET
     printf("'Wintab32.dll' not found. There seems to be no tablet installed on 
this machine\n");
 #endif
+    tablet_enabled_ = false;
     return false;
   }
   wtInfo = (WTINFO)GetProcAddress(wintab_dll, "WTInfoA");
@@ -834,6 +839,8 @@
 #endif
     FreeLibrary(wintab_dll);
     wintab_dll = 0;
+    
+    tablet_enabled_ = false;
     return false;
   }
   AXIS pressure;
@@ -842,6 +849,8 @@
   pressure_mul = 1.0f/pressure.axMax;
   //++ get information about the availability of tilt data
   tablet_open(0, 0);
+
+  tablet_enabled_ = true;
   return true;
 }
 
@@ -1311,6 +1320,7 @@
   if (!stylus_data_valid) {
     e_pressure = e_state&BUTTON1 ? 1.0f : 0.0f;
     e_x_tilt = e_y_tilt = 0.0f;
+    e_x_tablet = e_y_tablet = e_x_root_tablet = e_y_root_tablet = 0;
     e_device = DEVICE_MOUSE;
   }
 
@@ -1795,14 +1805,17 @@
     //if (wtPacket((HCTX)lParam, wParam, &pkt)) {
     if (wtPacket(wintab_ctx, wParam, &pkt)) {
       e_pressure = (((float)pkt.pkNormalPressure)+pressure_add)*pressure_mul;
-      float a = pkt.pkOrientation.orAzimuth / 1800.0f * 3.141592654f;
-      float b = (900-pkt.pkOrientation.orAltitude) / 900.0f;
-      e_x_tilt = sinf(a) * b;
-      e_y_tilt = cosf(a) * b;
+      e_x_tablet = e_x_root_tablet = pkt.pkX;
+      e_y_tablet = e_x_root_tablet = pkt.pkY;
+      float az = pkt.pkOrientation.orAzimuth  / 1800.0f * M_PI; // rad
+      float al = pkt.pkOrientation.orAltitude / 1800.0f * M_PI; // rad
+      e_x_tilt = (int)( atanf( sinf(az)/tanf(al) ) * 180.0f / M_PI); 
+      e_y_tilt = (int)(-atanf( cosf(az)/tanf(al) ) * 180.0f / M_PI);
       //++ incidently, the device numbers are correct for pen and eraser on 
Wacom
       //++ however, this code must be updated for other devices to function 
properly
       e_device = pkt.pkCursor;
     } }
+    handle(TABLET, xmousewin);
     return 1;
 
   case WT_PROXIMITY: // stylus proximity packet
Index: src/run.cxx
===================================================================
--- src/run.cxx (revision 6140)
+++ src/run.cxx (working copy)
@@ -78,6 +78,15 @@
          fltk::e_is_click,
          fltk::e_length,
          fltk::e_key_repeated;
+bool      fltk::tablet_enabled_ = false;
+int       fltk::e_x_tablet,
+         fltk::e_y_tablet,
+         fltk::e_x_root_tablet,
+         fltk::e_y_root_tablet,
+         fltk::tablet_x_max_,
+         fltk::tablet_y_max_,
+         fltk::tablet_root_x_max_,
+         fltk::tablet_root_y_max_;
 float     fltk::e_pressure,
           fltk::e_x_tilt,
           fltk::e_y_tilt;
Index: src/osx/run.cxx
===================================================================
--- src/osx/run.cxx     (revision 6140)
+++ src/osx/run.cxx     (working copy)
@@ -696,6 +696,7 @@
   //if (no_stylus) {
   e_pressure = e_state&BUTTON1 ? 1.0f : 0.0f;
   e_x_tilt = e_y_tilt = 0.0f;
+  e_x_tablet = e_y_tablet = e_x_root_tablet = e_y_root_tablet = 0;
   e_device = DEVICE_MOUSE;
   //}
 }
Index: src/Widget.cxx
===================================================================
--- src/Widget.cxx      (revision 6140)
+++ src/Widget.cxx      (working copy)
@@ -29,6 +29,7 @@
 #include <fltk/layout.h>
 #include <fltk/Group.h>
 #include <fltk/run.h>
+#include <fltk/Monitor.h> // for tablet calculations
 #include <fltk/string.h> // for newstring
 #include <stdlib.h> // for free
 #include <config.h>
@@ -718,7 +719,30 @@
   int save_y = e_y;
   e_x = e_x_root-dx;
   e_y = e_y_root-dy;
+  
+  // tablet position
+  int save_tablet_x;
+  int save_tablet_y;
+  int save_tablet_x_max;
+  int save_tablet_y_max;
 
+  if (tablet_enabled_)
+  {
+      save_tablet_x = e_x_tablet;
+      save_tablet_y = e_y_tablet;
+      save_tablet_x_max = tablet_x_max_;
+      save_tablet_y_max = tablet_y_max_;
+      
+      Monitor monitor = Monitor::find(x()+w()/2, y()+h()/2);
+      float tabl_per_pixel_x = (float)tablet_root_x_max_/(float)monitor.w();
+      float tabl_per_pixel_y = (float)tablet_root_y_max_/(float)monitor.h();
+      e_x_tablet = e_x_root_tablet - (int)(dx*tabl_per_pixel_x);
+      e_y_tablet = e_y_root_tablet - (int)(dy*tabl_per_pixel_y);
+      tablet_x_max_ = (int)(w()*tabl_per_pixel_x);
+      tablet_y_max_ = (int)(h()*tabl_per_pixel_y);
+  }
+  //////////////
+
   int ret = 0;
   switch (event) {
 
@@ -810,6 +834,14 @@
   }
 
   e_x = save_x; e_y = save_y;
+  if (tablet_enabled_)
+  {
+      e_x_tablet = save_tablet_x;
+      e_y_tablet = save_tablet_y;
+      tablet_x_max_ = save_tablet_x_max;
+      tablet_y_max_ = save_tablet_y_max;
+  }
+
   return ret;
 }
 
Index: src/x11/run.cxx
===================================================================
--- src/x11/run.cxx     (revision 6140)
+++ src/x11/run.cxx     (working copy)
@@ -920,9 +920,9 @@
 static int stylus_motion_event,
           stylus_proximity_in_event, stylus_proximity_out_event;
 static float pressure_mul[n_stylus_device];
-static float x_tilt_add, x_tilt_mul;
-static float y_tilt_add, y_tilt_mul;
 
+const int tablet_x_ix = 0;
+const int tablet_y_ix = 1;
 const int tablet_pressure_ix = 2;
 const int tablet_x_tilt_ix = 3;
 const int tablet_y_tilt_ix = 4;
@@ -939,16 +939,22 @@
       XAxisInfoPtr a = (XAxisInfoPtr)((char *)v+sizeof(XValuatorInfo));
       int k; for (k=0; k<v->num_axes; k++, a++) {
        switch (k) {
-         case tablet_pressure_ix: // pressure
+          case tablet_x_ix: // native tablet x position
+            tablet_root_x_max_ = tablet_x_max_ = a->max_value;
+            break;
+          case tablet_y_ix: // native tablet y position
+            tablet_root_y_max_ = tablet_y_max_ = a->max_value;
+            break;
+          case tablet_pressure_ix: // pressure
            pressure_mul[n] = 1.0f/a->max_value;
            break;
          case tablet_x_tilt_ix: // x-tilt
-           x_tilt_add = 0.0f;
-           x_tilt_mul = 1.0f/(FLTK_T_MAX(a->max_value, -a->min_value));
+//         x_tilt_add = 0.0f;
+//         x_tilt_mul = 1.0f/(FLTK_T_MAX(a->max_value, -a->min_value));
            break;
          case tablet_y_tilt_ix: // y-tilt
-           y_tilt_add = 0.0f;
-           y_tilt_mul = 1.0f/(FLTK_T_MAX(a->max_value, -a->min_value));
+//         y_tilt_add = 0.0f;
+//         y_tilt_mul = 1.0f/(FLTK_T_MAX(a->max_value, -a->min_value));
            break;
        }
       }
@@ -991,6 +997,7 @@
 #if DEBUG_TABLET
     printf("fltk: no XInput extension found\n");
 #endif
+    tablet_enabled_ = false;
     return false;
   }
   XFree(version);
@@ -1006,6 +1013,8 @@
     }
   }
   XFreeDeviceList(list);
+
+  tablet_enabled_ = ret;
   return ret;
 }
 
@@ -1249,6 +1258,7 @@
   if (e_device==0) {
     e_pressure = e_state&BUTTON(1) ? 1.0f : 0.0f;
     e_x_tilt = e_y_tilt = 0.0f;
+    e_x_tablet = e_y_tablet = e_x_root_tablet = e_y_root_tablet = 0;
   }
 }
 
@@ -1936,20 +1946,32 @@
       e_device = 0;
       return true;
     }
-    // get pressure and tilt data
+    // get pressure, position and tilt data
     axis = me->first_axis;
     if (axis <= tablet_pressure_ix && axis+me->axes_count >= 
tablet_pressure_ix) {
       float v = (float)me->axis_data[tablet_pressure_ix-me->first_axis];
       e_pressure = v*pressure_mul[n];
     }
+    if (axis <= tablet_x_ix && axis+me->axes_count >= tablet_x_ix)
+    {
+      // FIXME duplication
+      e_x_tablet = e_x_root_tablet = me->axis_data[tablet_x_ix-me->first_axis];
+    }
+    if (axis <= tablet_y_ix && axis+me->axes_count >= tablet_y_ix)
+    {
+      // FIXME duplication
+      e_y_tablet = e_y_root_tablet = me->axis_data[tablet_y_ix-me->first_axis];
+    }
+
     if (axis <= tablet_x_tilt_ix && axis+me->axes_count >= tablet_x_tilt_ix) {
-      float v = (float)me->axis_data[tablet_x_tilt_ix-me->first_axis];
-      e_x_tilt = (v+x_tilt_add)*x_tilt_mul;
+//    during linuxwacom 0.7.2 - 0.7.6 tilt valuator was changed (only low 
bytes contained tilt value)
+      e_x_tilt = 
(short)(me->axis_data[tablet_x_tilt_ix-me->first_axis]&0xffff);
     }
     if (axis <= tablet_y_tilt_ix && axis+me->axes_count >= tablet_y_tilt_ix) {
-      float v = (float)me->axis_data[tablet_y_tilt_ix-me->first_axis];
-      e_y_tilt = (v+y_tilt_add)*y_tilt_mul;
+//    during linuxwacom 0.7.2 - 0.7.6 tilt valuator was changed (only low 
bytes contained tilt value)
+      e_y_tilt = 
(short)(me->axis_data[tablet_y_tilt_ix-me->first_axis]&0xffff);
     }
+    handle(TABLET, xmousewin);
     return true;
     // should we send some kind of PEN_DOWN/ERASER_DOWN events?
   }
Index: fltk/events.h
===================================================================
--- fltk/events.h       (revision 6140)
+++ fltk/events.h       (working copy)
@@ -55,7 +55,8 @@
   DND_DRAG     = 21,
   DND_LEAVE    = 22,
   DND_RELEASE  = 23,
-  TOOLTIP      = 24
+  TOOLTIP      = 24,
+  TABLET       = 25
 };
 
 /*! Values returned by event_key(), passed to event_key_state() and
@@ -227,6 +228,15 @@
 extern FL_API unsigned e_length;
 extern FL_API const char* e_text;
 extern FL_API unsigned e_key_repeated;
+extern FL_API bool tablet_enabled_;
+extern FL_API int e_x_tablet;
+extern FL_API int e_y_tablet;
+extern FL_API int e_x_root_tablet;
+extern FL_API int e_y_root_tablet;
+extern FL_API int tablet_x_max_;
+extern FL_API int tablet_y_max_;
+extern FL_API int tablet_root_x_max_;
+extern FL_API int tablet_root_y_max_;
 extern FL_API float e_pressure;
 extern FL_API float e_x_tilt;
 extern FL_API float e_y_tilt;
@@ -262,6 +272,10 @@
 inline unsigned event_length()                 {return e_length;}
 inline unsigned event_key_repeated()   {return e_key_repeated;}
 inline float event_pressure()          {return e_pressure;}
+inline int event_x_tablet()            {return e_x_tablet;}
+inline int event_y_tablet()            {return e_y_tablet;}
+inline int event_x_root_tablet()       {return e_x_root_tablet;}
+inline int event_y_root_tablet()       {return e_y_root_tablet;}
 inline float event_x_tilt()            {return e_x_tilt;}
 inline float event_y_tilt()            {return e_y_tilt;}
 inline int  event_device()             {return e_device;}
@@ -286,6 +300,11 @@
 FL_API bool get_key_state(unsigned);
 FL_API void get_mouse(int &,int &);
 FL_API bool warp_mouse(int, int);
+inline bool tablet_enabled() { return tablet_enabled_; }
+inline int tablet_x_max() { return tablet_x_max_; } // current widget's tablet 
x
+inline int tablet_y_max() { return tablet_y_max_; }
+inline int tablet_root_x_max() { return tablet_root_x_max_; } // root tablet x
+inline int tablet_root_y_max() { return tablet_root_y_max_; }
 
 // event destinations:
 FL_API bool handle(int, Window*);
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to