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
Stylus tilt, which I get with event_x_tilt() and event_y_tilt() need some
corrections:
1. On Windows, Y tilt value is inversed comparatively to Linux
implementation.
2. On Linux, with LinuxWacom drivers version 0.7.2 - 0.7.6, tilt values
are incorrect.
I have a small patch which fixes this, and also improves tablet support
with new TABLET event, which allows to retrieve tablet's native position
(so you can use high-resolution input from modern tablets).
The patch is for both Linux and Windows, and I've added stubs for Mac OS
X, as we don't have tablet support there.
See my posts at fltk.development for details:
http://www.fltk.org/newsgroups.php?s3680+gfltk.development+v4621+T0
http://www.fltk.org/newsgroups.php?s3680+gfltk.development+v4622+T0
http://www.fltk.org/newsgroups.php?s3680+gfltk.development+v4660+T0
Link: http://www.fltk.org/str.php?L1924
Version: 2.0-current
Index: src/win32/run.cxx
===================================================================
--- src/win32/run.cxx (revision 6088)
+++ 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_x_max_ = TabletX.axMax;
+ tablet_y_max_ = TabletY.axMax;
+
if (wintab_ctx) wintab_hwnd = hWnd;
}
@@ -1311,6 +1315,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 = 0;
e_device = DEVICE_MOUSE;
}
@@ -1795,14 +1800,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 = pkt.pkX;
+ e_y_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 = atanf( sinf(az)/tanf(al) ) * 180.0f / M_PI;
+ e_y_tilt = -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 6088)
+++ src/run.cxx (working copy)
@@ -78,6 +78,10 @@
fltk::e_is_click,
fltk::e_length,
fltk::e_key_repeated;
+int fltk::e_x_tablet,
+ fltk::e_y_tablet,
+ fltk::tablet_x_max_,
+ fltk::tablet_y_max_;
float fltk::e_pressure,
fltk::e_x_tilt,
fltk::e_y_tilt;
Index: src/osx/run.cxx
===================================================================
--- src/osx/run.cxx (revision 6088)
+++ 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 = 0;
e_device = DEVICE_MOUSE;
//}
}
Index: src/x11/run.cxx
===================================================================
--- src/x11/run.cxx (revision 6088)
+++ 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_x_max_ = a->max_value;
+ break;
+ case tablet_y_ix: // native tablet y position
+ 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;
}
}
@@ -1249,6 +1255,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 = 0;
}
}
@@ -1935,20 +1942,30 @@
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)
+ {
+ e_x_tablet = me->axis_data[tablet_x_ix-me->first_axis];
+ }
+ if (axis <= tablet_y_ix && axis+me->axes_count >= tablet_y_ix)
+ {
+ e_y_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 6088)
+++ 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,10 @@
extern FL_API unsigned e_length;
extern FL_API const char* e_text;
extern FL_API unsigned e_key_repeated;
+extern FL_API int e_x_tablet;
+extern FL_API int e_y_tablet;
+extern FL_API int tablet_x_max_;
+extern FL_API int tablet_y_max_;
extern FL_API float e_pressure;
extern FL_API float e_x_tilt;
extern FL_API float e_y_tilt;
@@ -262,6 +267,8 @@
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 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 +293,8 @@
FL_API bool get_key_state(unsigned);
FL_API void get_mouse(int &,int &);
FL_API bool warp_mouse(int, int);
+inline int tablet_x_max() { return tablet_x_max_; }
+inline int tablet_y_max() { return tablet_y_max_; }
// event destinations:
FL_API bool handle(int, Window*);
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs