123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- SuperStrict
- Rem
- bbdoc: User input/Joystick
- End Rem
- Module Pub.Joystick
- ModuleInfo "Version: 1.00"
- ModuleInfo "Author: Bruce A Henderson"
- ModuleInfo "License: zlib/libpng"
- ModuleInfo "Copyright: Bruce A Henderson"
- ModuleInfo "History: 1.00 Release"
- Const JOY_X:Int = 0
- Const JOY_Y:Int = 1
- Const JOY_Z:Int = 2
- Const JOY_R:Int = 3
- Const JOY_U:Int = 4
- Const JOY_V:Int = 5
- Const JOY_YAW:Int = 6
- Const JOY_PITCH:Int = 7
- Const JOY_ROLL:Int = 8
- Const JOY_HAT:Int = 9
- Const JOY_WHEEL:Int = 10
- Private
- Global current_joystick:TJoystickDriver
- Public
- Function JoyCount:Int()
- Assert current_joystick
- Return current_joystick.JoyCount()
- End Function
- Function JoyName:String(port:Int)
- Assert current_joystick
- Return current_joystick.JoyName(port)
- End Function
- Rem
- bbdoc: Available buttons (on/off controls) on a joystick.
- returns: A bitfield representing which buttons are present.
- end rem
- Function JoyButtonCaps:Int(port:Int)
- Assert current_joystick
- Return current_joystick.JoyButtonCaps(port)
- End Function
- Rem
- bbdoc: Available axis (proportional controls) on a joystick.
- returns: A bitfield representing which axis are available.
- about:
- The bit positions of the returned value correspond to the following constants defined
- in the FreeJoy module:
- [ Const JOY_X=0
- * Const JOY_Y=1
- * Const JOY_Z=2
- * Const JOY_R=3
- * Const JOY_U=4
- * Const JOY_V=5
- * Const JOY_YAW=6
- * Const JOY_PITCH=7
- * Const JOY_ROLL=8
- * Const JOY_HAT=9
- * Const JOY_WHEEL=10
- ]
- End Rem
- Function JoyAxisCaps:Int(port:Int)
- Assert current_joystick
- Return current_joystick.JoyAxisCaps(port)
- End Function
- Rem
- bbdoc: Test the status of a joystick button.
- returns: True if the button is pressed.
- end rem
- Function JoyDown:Int( button:Int, port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyDown(button, port)
- End Function
- Rem
- bbdoc: Check for a joystick button press
- returns: Number of times @button has been hit.
- about:
- The returned value represents the number of the times @button has been hit since
- the last call to #JoyHit with the same specified @button.
- End Rem
- Function JoyHit:Int( button:Int, port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyHit(button, port)
- End Function
- Rem
- bbdoc: Reports the horizontal position of the joystick.
- returns: Zero if the joystick is centered, -1 if Left, 1 if Right or a value inbetween.
- End Rem
- Function JoyX:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyX(port)
- End Function
- Rem
- bbdoc: Reports the vertical position of the joystick.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- End Rem
- Function JoyY:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyY(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's Z axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- End Rem
- Function JoyZ:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyZ(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's R axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- End Rem
- Function JoyR:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyR(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's U axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- about:
- The U value of a joystick usually corresponds to a joystick's 'slider' or 'throttle' feature, although this may vary depending on the joystick, and will not be available with all joysticks.
- End Rem
- Function JoyU:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyU(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's V axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- about:
- The V value of a joystick usually corresponds to a joystick's 'slider' or 'throttle' feature, although this may vary depending on the joystick, and will not be available with all joysticks.
- End Rem
- Function JoyV:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyV(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's YAW axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- End Rem
- Function JoyYaw:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyYaw(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's PITCH axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- End Rem
- Function JoyPitch:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyPitch(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's ROLL axis if supported.
- returns: Zero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
- End Rem
- Function JoyRoll:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyRoll(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's HAT controller if supported.
- returns: -1.0 if the joystick is centered, and values between 0.0, 0.25, 0.5 and 0.75 for the directions Up, Right, Down, Left respectively.
- End Rem
- Function JoyHat:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyHat(port)
- End Function
- Rem
- bbdoc: Reports the position of the joystick's WHEEL controller if supported.
- returns: Zero if the joystick is centered, -1.0 if Left, 1.0 if Right or a value inbetween.
- End Rem
- Function JoyWheel:Float( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyWheel(port)
- End Function
- Function JoyType:Int( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyType(port)
- End Function
- Function JoyXDir:Int( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyXDir(port)
- End Function
- Function JoyYDir:Int( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyYDir(port)
- End Function
- Function JoyZDir:Int( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyZDir(port)
- End Function
- Function JoyUDir:Int( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyUDir(port)
- End Function
- Function JoyVDir:Int( port:Int=0 )
- Assert current_joystick
- Return current_joystick.JoyVDir(port)
- End Function
- Rem
- bbdoc: Flush joystick button states.
- End Rem
- Function FlushJoy( port_mask:Int=~0 )
- Assert current_joystick
- current_joystick.FlushJoy(port_mask)
- End Function
- Private
- Global joystick_drivers:TJoystickDriver
- Public
- Rem
- bbdoc: Abstract base type for joystick drivers.
- about:
- To create a new joystick driver, you should extend #TJoystickDriver and implement the #GetName method.
- To install your joystick driver, simply create an instance of it using #New.
- End Rem
- Type TJoystickDriver
- Field _succ:TJoystickDriver
-
- Rem
- bbdoc: Creates a new instance of a joystick driver.
- End Rem
- Method New()
- _succ=joystick_drivers
- joystick_drivers=Self
- End Method
-
- Rem
- bbdoc: Returns the name of the driver.
- End Rem
- Method GetName:String() Abstract
- Method JoyCount:Int() Abstract
- Method JoyName:String(port:Int) Abstract
- Method JoyButtonCaps:Int(port:Int) Abstract
- Method JoyAxisCaps:Int(port:Int) Abstract
- Method JoyDown:Int( button:Int, port:Int=0 ) Abstract
- Method JoyHit:Int( button:Int, port:Int=0 ) Abstract
- Method JoyX:Float( port:Int=0 ) Abstract
- Method JoyY:Float( port:Int=0 ) Abstract
- Method JoyZ:Float( port:Int=0 ) Abstract
- Method JoyR:Float( port:Int=0 ) Abstract
- Method JoyU:Float( port:Int=0 ) Abstract
- Method JoyV:Float( port:Int=0 ) Abstract
- Method JoyYaw:Float( port:Int=0 ) Abstract
- Method JoyPitch:Float( port:Int=0 ) Abstract
- Method JoyRoll:Float( port:Int=0 ) Abstract
- Method JoyHat:Float( port:Int=0 ) Abstract
- Method JoyWheel:Float( port:Int=0 ) Abstract
- Method JoyType:Int( port:Int=0 ) Abstract
- Method JoyXDir:Int( port:Int=0 ) Abstract
- Method JoyYDir:Int( port:Int=0 ) Abstract
- Method JoyZDir:Int( port:Int=0 ) Abstract
- Method JoyUDir:Int( port:Int=0 ) Abstract
- Method JoyVDir:Int( port:Int=0 ) Abstract
- Method FlushJoy( port_mask:Int=~0 ) Abstract
-
- End Type
- Function GetJoystickDriver:TJoystickDriver(name:String)
- Local driver:TJoystickDriver = joystick_drivers
-
- While driver
- If driver.GetName().ToLower() = name.ToLower() Then
- current_joystick = driver
- Return driver
- End If
- driver = driver._succ
- Wend
- End Function
|