Touch input library written in Ruby for DragonRuby GTK!
Portions of this library used by the developer (Rabia Alhaffar) to adapt his DragonRuby games to run on mobile platforms, Also the library supports touch emulation of one finger via mouse input.
NOTE: drtouch requires "Pro" version of DragonRuby GTK!
drtouch.rb as raw to
app folder of your project and in
main.rb require it:
Install package with
smaug add drtouch and then require
smaug.rb as ya used to!
Once you setup and installed drtouch, In your
tick function initialize drtouch and update with following:
drtouch = DRTouch.new # As DRTouch is class, We create instance of classdrtouch.initdrtouch.update
samples folder to see how drtouch works.
All drtouch library functions exposed in class
DRTouch and API made to be simple to use.
# Functionsinit() # Initializes drtouch library.update() # Updates touches.down(i) # Returns true if finger by index held/exists on screen or false if not.up(i) # Returns true if finger by index not on screen or false if not.tap(i) # Returns true if tapped/pressed with finger by index on screen or false if not.release(i) # Returns true if left finger by index after tap on screen or false if not.touches() # Returns touches count.pos(i) # Returns position of a finger touch on screen by index.find(x, y) # Returns finger index by position.touched_rect(i, rect) # Returns true if finger by index touches a rectangle on screen or false if not.mobile() # Returns true if device is mobile or false if not.# Internals, Used within the library$gtk.args.state.drtouch.emulated # State of touch emulation, 1 if emulated via mouse of 0 if on mobile.$gtk.args.state.drtouch.current_touches # Array of 1s and 0s of current touches state.$gtk.args.state.drtouch.touches_pos # Array of touches positions.$gtk.args.state.drtouch.previous_touches # Array of 1s and 0s of old touches state.
- drtouch by default handles limit of touches from 2 hands, Which is 10 fingers.
- drtouch initialized in hash
$gtk.args.state.drtouchand that's to make it easy to serialize away of the state if data is big.
MIT LicenseCopyright (c) 2021 - 2022 Rabia AlhaffarPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
2 months ago