-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query_touch_device() function basically works!
* Double tap and hold if Talkback is running for now, will improve later. Also get_touch_devices() and get_touch_device_name functions are wrapped. * Includes documentation and quick test, though uint64[]@ get_touch_devices() and string get_touch_device_name(uint64) still need docs. * Updates SDL3, including windev and droidev packages.
- Loading branch information
Showing
7 changed files
with
128 additions
and
26 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
doc/src/references/builtin/User Interface/Functions/query_touch_device.nvgt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
Check what fingers are in contact with a touch device and where they are on the screen, if any. | ||
vector[]@ query_touch_device(uint64 device_id = 0); | ||
## Arguments: | ||
* uint64 device_id = 0: The device to query, 0 for the last device that received input. | ||
## Returns: | ||
touch_finger[]@: An array of structures containing touch coordinates and pressure (see remarks). | ||
## Remarks: | ||
Each structure in the returned array represents a finger, thus the length of the array indicates how many fingers are touching the device. | ||
Touch_finger objects contain only 4 properties. Int64 id is a unique identifier of the finger that will remain the same as long as the finger touches the devices, float x and float y contain the coordinates of the finger on the device, and the float pressure property indicates how much force or pressure the finger is being applied to the device with. | ||
Usage of this structure other than to receive touch input is not endorsed by the NVGT developers and may lead to unexpected results, most notably creating a touch_finger instance manually will likely set it's properties to random uninitialized memory on the stack. You have been warned. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
// Report the number of fingers touching the device. | ||
show_window("touch example"); | ||
tts_voice tts; | ||
int prev_finger_count = 0; | ||
tts.speak("ready", true); | ||
while (!key_pressed(KEY_ESCAPE) and !key_pressed(KEY_AC_BACK)) { | ||
wait(5); | ||
touch_finger[]@ fingers = query_touch_device(); // This will query the last device that was touched. | ||
if (fingers.length() != prev_finger_count) { | ||
tts.speak(fingers.length() + (fingers.length() != 1? " fingers" : " finger"), true); | ||
prev_finger_count = fingers.length(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// NonVisual Gaming Toolkit (NVGT) | ||
// Copyright (C) 2022-2024 Sam Tupy | ||
// License: zlib (see license.md in the root of the NVGT distribution) | ||
|
||
void main() { | ||
show_window("touch test"); | ||
tts_voice tts; | ||
uint64[]@ devs = get_touch_devices(); | ||
if (devs.length() < 1) { | ||
alert("oops", "no touch devices available"); | ||
return; | ||
} | ||
int prev_finger_count = 0; | ||
tts.speak("ready", true); | ||
while (!key_pressed(KEY_ESCAPE) and !key_pressed(KEY_AC_BACK)) { | ||
wait(5); | ||
touch_finger[]@ fingers = query_touch_device(); | ||
if (fingers.length() != prev_finger_count) { | ||
tts.speak(fingers.length() + " fingers", true); | ||
prev_finger_count = fingers.length(); | ||
} | ||
} | ||
} |