Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Getting tablet data (eg. pressure) in DBP - a demonstration

Author
Message
MonoCoder
19
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 12th Jun 2013 02:48 Edited at: 14th Jun 2013 02:03


see latest post for updated version


Tablet pressure data is one of those things a few people need and most people don't, and the off-putting learning curve involved in its acquisition (not to mention total inaccessibility without plugins) probably goes some way to explaining why (as far as I have searched, and I have searched a great deal) it hasn't been demonstrated in DBP yet.

Tablet data is useful for such programs as image and landscape editors, and you can probably base a half-decent game around it too.



So if you have a WACOM tablet with up-to-date drivers, and you have "Wintab32.dll" in your system32 folder (the first implies the second), and you have the matrix1utils plugins, please try this work-in-progress code.


Wintab - How it works
Reading
- Main WACOM Windows developer support page.
- Wintab Documentation at WACOM
- Other: Pressure in PyGame, handy constants reference

Wintab works with things called contexts. Essentially your program will have a context kinda like it has a window (except you must make the context manually). A context has a lot of configurables but the system can provide you with a perfectly functional starting point to make tweaks to.

I make reference here and there to "our local copy" of the context data and the "active" or "current" context. First you get the above-mentioned system default. A copy of these properties are placed in memory where you can edit them (our copy). These edits are not reflected until you apply them back to the active context (or when you first open the context).

Once you have a context, using your tablet with your program will generate packets, from which you can read pen position, pressure, and so on. You can look at all packets or just the latest, as you need.


Reference
(pre-emptive apologies for inevitable indentation issues)




WT_Include.dba - this should be included in your project. (#include is fine but in your own projects you'll want to include it using the project include list. You may then also need to wrap the types in a gosub and call that.)




And here's a test project source to try it in.




Here's a source boiled down to most basic no-frills elements. bar height = pen pressure.




Status
- You can get tablet pressure! That's what you came for, right?
- The pen coordinate should always be returned correctly (subtract the position of your app's client area and you get DBP coords, assuming your DBP display mode and client size match). This stands even if you have additional monitors out in negative virtual screen space.
- You can use the tablet independent of the mouse (ie. the mouse still responds to the mouse only, is not dragged by pen) by omitting CXO_SYSTEM when specifying context options. There may be scenarios in which this is useful.
- No apparent memory leaks to report.


To-Do
- Graceful handling of the most common cases (eg. can probably safely assume no more than one tablet at a time per computer). Replace assumptions (eg. "pressure is in the range 0-1023") with correct data.
- Respond to messages from WndProc and update to reflect changing state of window, devices, etc. For example, the user changing setting in control panel may leave your context info outdated.
- Fill out more info-getting stuff and remainder of constants. Probably introduce convenience functions for common situations.


Issues
As mentioned, this is WIP, but I figured that since it's already in a quite usable state I should open it up to scrutiny as I work on it. Also, of course, a lot of possible issues will be shown up by a range of different software/hardware configurations which I do not have personal access to. (And finally, if for whatever reason I hit a dead end or otherwise stop working on it, it's here for someone to pick up and run with, not sitting on my hard drive.)

- If you move the cursor over the Quick Launch taskbar menu's show hidden items button (the chevron), the context stops delivering packets for some reason, until you click away from then back on to your window. No idea what happens there, nothing else seems to do that.
- Returned packet positions are always a little behind the mouse cursor. Might just be an inherent quirk, might not.
- If you request data that your device doesn't provide, packet data will be treated wrongly. For now, if you get strange results consider cutting requests for some data (orientation and rotation in particular).
- Some properties are 32-bit fixed-point numbers (16:16 format, or 16 bits either side of radix). I'm not confident that I have any idea what I'm doing with them, but so far they've not really mattered.


Questions/Concerns
Some of these I'll get round to testing on my own in due time, but help is always appreciated.

- If anyone has a tablet that support orientation/rotation, does it work? Could you write a simple demonstration for it (along the lines of varying circle radius with pressure)?
- Anything unusual on a tablet with integrated screen (intuous, I think)?
- What happens on a 64-bit system? What happens on non-vista computers?
- What user behaviour causes crashes? (eg. uninstalling the tablet while program is running, but less dramatic.)
- Do changes to an already-open context have the potential to cause problems?
- Haven't tried moving the primary monitor around yet... or while the program is running (sample code doesn't include checking for this latter yet though, so moot for now).
- What, if anything, happens when you have, say, Photoshop running in the background, or open it while the app is running? Can you swap back and forth without problem or bizarre crosstalk?
- Not 100% sure if and when to flush packets yet.
- If anyone has, say, an editor or other program they'd like to try dropping this in, please tell how it performs in practice, if it plays nice with GUI stuff, multiple child windows etc.

Finally, if I'm unwittingly making mistakes of code style, handling of the whole DBP-WT "interface", playing with fire regarding memory poking or whatever, please let me know.


Hope this helps someone!


[note to mods: if this thread should be elsewhere, please do move it.]
Mage
Valued Member
18
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 13th Jun 2013 10:36
Thanks for contributing. I'm sure this will come in handy.

MonoCoder
19
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 14th Jun 2013 01:54 Edited at: 14th Jun 2013 15:27
No probs. Myself, I have something in the works that I'll be using it in, so there's that.


Done a bit more work. Now you can find out what information your device supports and base packet requests on that, so no more guessing. Likewise, tablet pressure now normalises based on actual device range.

To use this you'll now need Diggsey's Arguments Library (ArgLib_Include.dba, as named in examples in this post). If it's cool with Diggsey, I'll include it here for convenience.

Changes




WT_Include.dba - v0.2




Long Example - now includes a very basic painting mode.




Short Example
No changes, except at the top:



.
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 14th Jun 2013 02:24
Very interesting indeed... Keeping my eyes on this as I have a BAMBOO PEN AND TOUCH

Burning Feet Man
17
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 14th Jun 2013 03:06 Edited at: 14th Jun 2013 03:37
Amazing work Monocoder!

I struggle with getting even the simplest things to work, but your ability to interface with Windows is second to none, inspiring myself to persevere with my coding endeavor!

I learn so much from your postings, one day I'll have something to show for it.


Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia

Login to post a reply

Server time is: 2025-06-29 11:30:25
Your offset time is: 2025-06-29 11:30:25