More tablet woes..
Sep. 20th, 2005 04:41 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
So my current understanding is this.
1) I need normal mouse stuff for the GUI, but I would like subpixel-accurate strokes for the canvas.
2) To get full-resolution (not screen) coordinates, one has to initialize JTablet with fullControl == 1.
3) fullControl disables automatic mouse-movement by the pen.
4) So fine. I run a background thread to handle the tablet, mouse cursor and stroke notifications.
5) The canvas needs to work with the mouse, too.
6) Thus the canvas gets both real mouse events and fake ones from the tablet thread.
7) The thread can't afford to notify synchronously; if it did the cursor would be jerky.
8) So there's no way to tell the real and fake events apart! Way to screw up the drawing.
*scratchscratchscratch...*
One way to fix this would be to ask if the pen is currently over the tablet. But JTablet conveniently left that function out! So maybe there's another hack... hrmmm..
Another idea is to increment a counter for every event in the tablet thread and decrement it (to zero) after every mouse event goes through. However this depends on the GUI code to keep things running smoothly, and the user not moving the mouse at the same time too. :-) Anyway it was finicky and only worked half the time.
I suppose I could turn off manual mouse-movement whilst the cursor is on the canvas. However this presents the nice catch-22 that the cursor will never leave it. Would have to continually check hover events to be sure.
Or I could merge all handling into the mouse events, and *if* the cursor is near the last tablet coordinate, use the latter. That begs for race problems, but minus this hack, it looks like it's the way JTablet was meant to be used.
Option five is to stick with pixel coordinates. This is usable, I guess. Otherwise, modifying/replacing JTablet might just be better in the long run.
Edit: I see what's up. Turns out the tablet driver requires a window so it can send you notifies. Except JTablet hands it the system desktop, which will just ignore them! Pretty rude, too, since it could break newer Windows versions. But Java/Swing doesn't exactly LET you get at your app's window, so what to do? Yet another hack (albeit would be simpler than the above crap)!
1) I need normal mouse stuff for the GUI, but I would like subpixel-accurate strokes for the canvas.
2) To get full-resolution (not screen) coordinates, one has to initialize JTablet with fullControl == 1.
3) fullControl disables automatic mouse-movement by the pen.
4) So fine. I run a background thread to handle the tablet, mouse cursor and stroke notifications.
5) The canvas needs to work with the mouse, too.
6) Thus the canvas gets both real mouse events and fake ones from the tablet thread.
7) The thread can't afford to notify synchronously; if it did the cursor would be jerky.
8) So there's no way to tell the real and fake events apart! Way to screw up the drawing.
*scratchscratchscratch...*
One way to fix this would be to ask if the pen is currently over the tablet. But JTablet conveniently left that function out! So maybe there's another hack... hrmmm..
Another idea is to increment a counter for every event in the tablet thread and decrement it (to zero) after every mouse event goes through. However this depends on the GUI code to keep things running smoothly, and the user not moving the mouse at the same time too. :-) Anyway it was finicky and only worked half the time.
I suppose I could turn off manual mouse-movement whilst the cursor is on the canvas. However this presents the nice catch-22 that the cursor will never leave it. Would have to continually check hover events to be sure.
Or I could merge all handling into the mouse events, and *if* the cursor is near the last tablet coordinate, use the latter. That begs for race problems, but minus this hack, it looks like it's the way JTablet was meant to be used.
Option five is to stick with pixel coordinates. This is usable, I guess. Otherwise, modifying/replacing JTablet might just be better in the long run.
Edit: I see what's up. Turns out the tablet driver requires a window so it can send you notifies. Except JTablet hands it the system desktop, which will just ignore them! Pretty rude, too, since it could break newer Windows versions. But Java/Swing doesn't exactly LET you get at your app's window, so what to do? Yet another hack (albeit would be simpler than the above crap)!