1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-18 01:07:58 +00:00
CLK/OSBindings/Mac/Clock Signal/Joystick Manager/CSJoystickManager.h
Thomas Harte 1362906f94 Wires joystick support all the way through to machines.
Ensures there's only one joystick manager, which is shared by all machines, with input going only to the key window.
2018-07-22 16:55:47 -04:00

81 lines
2.3 KiB
Objective-C

//
// CSJoystickManager.h
// Clock Signal
//
// Created by Thomas Harte on 19/07/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#import <Foundation/Foundation.h>
/*!
Models a single joystick button.
Buttons have an index and are either currently pressed, or not.
*/
@interface CSJoystickButton: NSObject
/// The button index. By convention the USB spec defines the first button as number 1.
@property(nonatomic, readonly) NSInteger index;
@property(nonatomic, readonly) bool isPressed;
@end
typedef NS_ENUM(NSInteger, CSJoystickAxisType) {
CSJoystickAxisTypeX,
CSJoystickAxisTypeY,
CSJoystickAxisTypeZ,
};
/*!
Models a joystick axis.
Axes have a nominated type and a continuous value between 0 and 1.
*/
@interface CSJoystickAxis: NSObject
@property(nonatomic, readonly) CSJoystickAxisType type;
/// The current position of this axis in the range [0, 1].
@property(nonatomic, readonly) float position;
@end
typedef NS_OPTIONS(NSInteger, CSJoystickHatDirection) {
CSJoystickHatDirectionUp = 1 << 0,
CSJoystickHatDirectionDown = 1 << 1,
CSJoystickHatDirectionLeft = 1 << 2,
CSJoystickHatDirectionRight = 1 << 3,
};
/*!
Models a joystick hat.
A hat is a digital directional input, so e.g. this is how thumbpads are represented.
*/
@interface CSJoystickHat: NSObject
@property(nonatomic, readonly) CSJoystickHatDirection direction;
@end
/*!
Models a joystick.
A joystick is a collection of buttons, axes and hats, each of which holds a current
state. The holder must use @c update to cause this joystick to read a fresh copy
of its state.
*/
@interface CSJoystick: NSObject
@property(nonatomic, readonly) NSArray<CSJoystickButton *> *buttons;
@property(nonatomic, readonly) NSArray<CSJoystickAxis *> *axes;
@property(nonatomic, readonly) NSArray<CSJoystickHat *> *hats;
- (void)update;
@end
/*!
The joystick manager watches for joystick connections and disconnections and
offers a list of joysticks currently attached.
Be warned: this means using Apple's IOKit directly to watch for Bluetooth and
USB HID devices. So to use this code, make sure you have USB and Bluetooth
enabled for the app's sandbox.
*/
@interface CSJoystickManager : NSObject
@property(nonatomic, readonly) NSArray<CSJoystick *> *joysticks;
/// Updates all joysticks.
- (void)update;
@end