Index: src/hid/Makefile ================================================================== --- src/hid/Makefile +++ src/hid/Makefile @@ -8,10 +8,11 @@ LIB_MAJOR = ${OBJFWHID_LIB_MAJOR} LIB_MINOR = ${OBJFWHID_LIB_MINOR} LIB_PATCH = ${OBJFWHID_LIB_PATCH} SRCS = OHCombinedJoyCons.m \ + OHExtendedGamepad.m \ OHGameController.m \ OHGameControllerAxis.m \ OHGameControllerButton.m \ OHGameControllerDirectionalPad.m \ OHGameControllerElement.m \ @@ -19,21 +20,21 @@ OHGamepad.m \ ${USE_SRCS_EVDEV} \ ${USE_SRCS_NINTENDO_3DS} \ ${USE_SRCS_NINTENDO_DS} \ ${USE_SRCS_XINPUT} -SRCS_EVDEV = OHEvdevDualSense.m \ - OHEvdevDualShock4.m \ - OHEvdevGameController.m \ - OHEvdevGamepad.m \ - OHEvdevPlayStationGamepad.m \ - OHEvdevStadiaGamepad.m +SRCS_EVDEV = OHEvdevDualSense.m \ + OHEvdevDualShock4.m \ + OHEvdevExtendedGamepad.m \ + OHEvdevGameController.m \ + OHEvdevPlayStationExtendedGamepad.m \ + OHEvdevStadiaExtendedGamepad.m SRCS_NINTENDO_3DS = OHNintendo3DSGameController.m \ - OHNintendo3DSGamepad.m + OHNintendo3DSExtendedGamepad.m SRCS_NINTENDO_DS = OHNintendoDSGameController.m -SRCS_XINPUT = OHXInputGameController.m \ - OHXInputGamepad.m +SRCS_XINPUT = OHXInputExtendedGamepad.m \ + OHXInputGameController.m INCLUDES := ${SRCS:.m=.h} \ ObjFWHID.h SRCS += OHGameControllerEmulatedAxis.m \ Index: src/hid/OHCombinedJoyCons.h ================================================================== --- src/hid/OHCombinedJoyCons.h +++ src/hid/OHCombinedJoyCons.h @@ -22,10 +22,12 @@ OF_ASSUME_NONNULL_BEGIN @class OHGameController; /** + * @class OHCombinedJoyCons OHCombinedJoyCons.h ObjFWHID/OHCombinedJoyCons.h + * * @brief Combines a left and a right Joy-Con into a gamepad. */ @interface OHCombinedJoyCons: OHGamepad { OHGameControllerProfile *_leftJoyCon, *_rightJoyCon; Index: src/hid/OHEvdevDualSense.h ================================================================== --- src/hid/OHEvdevDualSense.h +++ src/hid/OHEvdevDualSense.h @@ -15,13 +15,13 @@ * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ -#import "OHEvdevPlayStationGamepad.h" +#import "OHEvdevPlayStationExtendedGamepad.h" OF_ASSUME_NONNULL_BEGIN -@interface OHEvdevDualSense: OHEvdevPlayStationGamepad +@interface OHEvdevDualSense: OHEvdevPlayStationExtendedGamepad @end OF_ASSUME_NONNULL_END Index: src/hid/OHEvdevDualShock4.h ================================================================== --- src/hid/OHEvdevDualShock4.h +++ src/hid/OHEvdevDualShock4.h @@ -15,13 +15,13 @@ * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * . */ -#import "OHEvdevPlayStationGamepad.h" +#import "OHEvdevPlayStationExtendedGamepad.h" OF_ASSUME_NONNULL_BEGIN -@interface OHEvdevDualShock4: OHEvdevPlayStationGamepad +@interface OHEvdevDualShock4: OHEvdevPlayStationExtendedGamepad @end OF_ASSUME_NONNULL_END ADDED src/hid/OHEvdevExtendedGamepad.h Index: src/hid/OHEvdevExtendedGamepad.h ================================================================== --- /dev/null +++ src/hid/OHEvdevExtendedGamepad.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#import "OHExtendedGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OHEvdevGameController; +@class OHGameControllerProfile; + +@interface OHEvdevExtendedGamepad: OHExtendedGamepad +{ + OHGameControllerProfile *_rawProfile; +} + +- (instancetype)initWithController: (OHEvdevGameController *)controller; +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHEvdevExtendedGamepad.m Index: src/hid/OHEvdevExtendedGamepad.m ================================================================== --- /dev/null +++ src/hid/OHEvdevExtendedGamepad.m @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OHEvdevExtendedGamepad.h" +#import "OFDictionary.h" +#import "OHEvdevGameController.h" +#import "OHGameControllerDirectionalPad.h" +#import "OHGameControllerEmulatedTriggerButton.h" + +#import "OFInvalidArgumentException.h" + +@implementation OHEvdevExtendedGamepad +- (instancetype)initWithController: (OHEvdevGameController *)controller +{ + self = [super init]; + + @try { + void *pool = objc_autoreleasePoolPush(); + + _rawProfile = [controller.rawProfile retain]; + + if (self.northButton == nil || self.southButton == nil || + self.westButton == nil || self.eastButton == nil || + self.leftShoulderButton == nil || + self.rightShoulderButton == nil || + self.leftTriggerButton == nil || + self.rightTriggerButton == nil || self.menuButton == nil || + self.optionsButton == nil || self.leftThumbstick == nil || + self.rightThumbstick == nil || self.dPad == nil) + @throw [OFInvalidArgumentException exception]; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_rawProfile release]; + + [super dealloc]; +} + +- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons +{ + OFMutableDictionary *buttons = + [[_rawProfile.buttons mutableCopy] autorelease]; + + [buttons removeObjectForKey: @"D-Pad Up"]; + [buttons removeObjectForKey: @"D-Pad Down"]; + [buttons removeObjectForKey: @"D-Pad Left"]; + [buttons removeObjectForKey: @"D-Pad Right"]; + + if ([_rawProfile.axes objectForKey: @"Z"] != nil) + [buttons setObject: self.leftTriggerButton forKey: @"LT"]; + + if ([_rawProfile.axes objectForKey: @"RZ"] != nil) + [buttons setObject: self.rightTriggerButton forKey: @"RT"]; + + [buttons makeImmutable]; + + return buttons; +} + +- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes +{ + OFMutableDictionary *axes = + [[_rawProfile.axes mutableCopy] autorelease]; + + [axes removeObjectForKey: @"X"]; + [axes removeObjectForKey: @"Y"]; + [axes removeObjectForKey: @"RX"]; + [axes removeObjectForKey: @"RY"]; + [axes removeObjectForKey: @"Z"]; + [axes removeObjectForKey: @"RZ"]; + [axes removeObjectForKey: @"HAT0X"]; + [axes removeObjectForKey: @"HAT0Y"]; + + [axes makeImmutable]; + + return axes; +} + +- (OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *) + directionalPads +{ + return [OFDictionary dictionaryWithKeysAndObjects: + @"Left Thumbstick", self.leftThumbstick, + @"Right Thumbstick", self.rightThumbstick, + @"D-Pad", self.dPad, nil]; +} + +- (OHGameControllerButton *)northButton +{ + return [_rawProfile.buttons objectForKey: @"Y"]; +} + +- (OHGameControllerButton *)southButton +{ + return [_rawProfile.buttons objectForKey: @"A"]; +} + +- (OHGameControllerButton *)westButton +{ + return [_rawProfile.buttons objectForKey: @"X"]; +} + +- (OHGameControllerButton *)eastButton +{ + return [_rawProfile.buttons objectForKey: @"B"]; +} + +- (OHGameControllerButton *)leftShoulderButton +{ + return [_rawProfile.buttons objectForKey: @"LB"]; +} + +- (OHGameControllerButton *)rightShoulderButton +{ + return [_rawProfile.buttons objectForKey: @"RB"]; +} + +- (OHGameControllerButton *)leftTriggerButton +{ + OHGameControllerAxis *axis = [_rawProfile.axes objectForKey: @"Z"]; + + if (axis != nil) + return [[[OHGameControllerEmulatedTriggerButton alloc] + initWithName: @"LT" + axis: axis] autorelease]; + + return [_rawProfile.buttons objectForKey: @"LT"]; +} + +- (OHGameControllerButton *)rightTriggerButton +{ + OHGameControllerAxis *axis = [_rawProfile.axes objectForKey: @"RZ"]; + + if (axis != nil) + return [[[OHGameControllerEmulatedTriggerButton alloc] + initWithName: @"RT" + axis: axis] autorelease]; + + return [_rawProfile.buttons objectForKey: @"RT"]; +} + +- (OHGameControllerButton *)leftThumbstickButton +{ + return [_rawProfile.buttons objectForKey: @"LSB"]; +} + +- (OHGameControllerButton *)rightThumbstickButton +{ + return [_rawProfile.buttons objectForKey: @"RSB"]; +} + +- (OHGameControllerButton *)menuButton +{ + return [_rawProfile.buttons objectForKey: @"Start"]; +} + +- (OHGameControllerButton *)optionsButton +{ + return [_rawProfile.buttons objectForKey: @"Back"]; +} + +- (OHGameControllerButton *)homeButton +{ + return [_rawProfile.buttons objectForKey: @"Guide"]; +} + +- (OHGameControllerDirectionalPad *)leftThumbstick +{ + OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"X"]; + OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"Y"]; + + if (xAxis == nil || yAxis == nil) + return nil; + + return [[[OHGameControllerDirectionalPad alloc] + initWithName: @"Left Thumbstick" + xAxis: xAxis + yAxis: yAxis] autorelease]; +} + +- (OHGameControllerDirectionalPad *)rightThumbstick +{ + OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"RX"]; + OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"RY"]; + + if (xAxis == nil || yAxis == nil) + return nil; + + return [[[OHGameControllerDirectionalPad alloc] + initWithName: @"Right Thumbstick" + xAxis: xAxis + yAxis: yAxis] autorelease]; +} + +- (OHGameControllerDirectionalPad *)dPad +{ + OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"HAT0X"]; + OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"HAT0Y"]; + OHGameControllerButton *up, *down, *left, *right; + + if (xAxis != nil && yAxis != nil) + return [[[OHGameControllerDirectionalPad alloc] + initWithName: @"D-Pad" + xAxis: xAxis + yAxis: yAxis] autorelease]; + + up = [_rawProfile.buttons objectForKey: @"D-Pad Up"]; + down = [_rawProfile.buttons objectForKey: @"D-Pad Down"]; + left = [_rawProfile.buttons objectForKey: @"D-Pad Left"]; + right = [_rawProfile.buttons objectForKey: @"D-Pad Right"]; + + if (up != nil && down != nil && left != nil && right != nil) + return [[[OHGameControllerDirectionalPad alloc] + initWithName: @"D-Pad" + up: up + down: down + left: left + right: right] autorelease]; + + return nil; +} +@end Index: src/hid/OHEvdevGameController.m ================================================================== --- src/hid/OHEvdevGameController.m +++ src/hid/OHEvdevGameController.m @@ -31,12 +31,12 @@ #import "OFLocale.h" #import "OFNumber.h" #import "OHEvdevDualSense.h" #import "OHEvdevDualShock4.h" -#import "OHEvdevGamepad.h" -#import "OHEvdevStadiaGamepad.h" +#import "OHEvdevExtendedGamepad.h" +#import "OHEvdevStadiaExtendedGamepad.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerProfile.h" #include @@ -729,10 +729,15 @@ } } - (OHGamepad *)gamepad { + return self.extendedGamepad; +} + +- (OHExtendedGamepad *)extendedGamepad +{ @try { if (_vendorID == OHVendorIDSony && _productID == OHProductIDDualSense) return [[[OHEvdevDualSense alloc] initWithController: self] autorelease]; @@ -740,14 +745,14 @@ _productID == OHProductIDDualShock4) return [[[OHEvdevDualShock4 alloc] initWithController: self] autorelease]; else if (_vendorID == OHVendorIDGoogle && _productID == OHProductIDStadiaController) - return [[[OHEvdevStadiaGamepad alloc] + return [[[OHEvdevStadiaExtendedGamepad alloc] initWithController: self] autorelease]; else - return [[[OHEvdevGamepad alloc] + return [[[OHEvdevExtendedGamepad alloc] initWithController: self] autorelease]; } @catch (OFInvalidArgumentException *e) { return nil; } } DELETED src/hid/OHEvdevGamepad.h Index: src/hid/OHEvdevGamepad.h ================================================================== --- src/hid/OHEvdevGamepad.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#import "OHGamepad.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OHEvdevGameController; -@class OHGameControllerProfile; - -@interface OHEvdevGamepad: OHGamepad -{ - OHGameControllerProfile *_rawProfile; -} - -- (instancetype)initWithController: (OHEvdevGameController *)controller; -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHEvdevGamepad.m Index: src/hid/OHEvdevGamepad.m ================================================================== --- src/hid/OHEvdevGamepad.m +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#include "config.h" - -#import "OHEvdevGamepad.h" -#import "OFDictionary.h" -#import "OHEvdevGameController.h" -#import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedTriggerButton.h" - -#import "OFInvalidArgumentException.h" - -@implementation OHEvdevGamepad -- (instancetype)initWithController: (OHEvdevGameController *)controller -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - _rawProfile = [controller.rawProfile retain]; - - if (self.northButton == nil || self.southButton == nil || - self.westButton == nil || self.eastButton == nil || - self.leftShoulderButton == nil || - self.rightShoulderButton == nil || - self.leftTriggerButton == nil || - self.rightTriggerButton == nil || self.menuButton == nil || - self.optionsButton == nil || self.leftThumbstick == nil || - self.rightThumbstick == nil || self.dPad == nil) - @throw [OFInvalidArgumentException exception]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_rawProfile release]; - - [super dealloc]; -} - -- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons -{ - OFMutableDictionary *buttons = - [[_rawProfile.buttons mutableCopy] autorelease]; - - [buttons removeObjectForKey: @"D-Pad Up"]; - [buttons removeObjectForKey: @"D-Pad Down"]; - [buttons removeObjectForKey: @"D-Pad Left"]; - [buttons removeObjectForKey: @"D-Pad Right"]; - - if ([_rawProfile.axes objectForKey: @"Z"] != nil) - [buttons setObject: self.leftTriggerButton forKey: @"LT"]; - - if ([_rawProfile.axes objectForKey: @"RZ"] != nil) - [buttons setObject: self.rightTriggerButton forKey: @"RT"]; - - [buttons makeImmutable]; - - return buttons; -} - -- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes -{ - OFMutableDictionary *axes = - [[_rawProfile.axes mutableCopy] autorelease]; - - [axes removeObjectForKey: @"X"]; - [axes removeObjectForKey: @"Y"]; - [axes removeObjectForKey: @"RX"]; - [axes removeObjectForKey: @"RY"]; - [axes removeObjectForKey: @"Z"]; - [axes removeObjectForKey: @"RZ"]; - [axes removeObjectForKey: @"HAT0X"]; - [axes removeObjectForKey: @"HAT0Y"]; - - [axes makeImmutable]; - - return axes; -} - -- (OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *) - directionalPads -{ - return [OFDictionary dictionaryWithKeysAndObjects: - @"Left Thumbstick", self.leftThumbstick, - @"Right Thumbstick", self.rightThumbstick, - @"D-Pad", self.dPad, nil]; -} - -- (OHGameControllerButton *)northButton -{ - return [_rawProfile.buttons objectForKey: @"Y"]; -} - -- (OHGameControllerButton *)southButton -{ - return [_rawProfile.buttons objectForKey: @"A"]; -} - -- (OHGameControllerButton *)westButton -{ - return [_rawProfile.buttons objectForKey: @"X"]; -} - -- (OHGameControllerButton *)eastButton -{ - return [_rawProfile.buttons objectForKey: @"B"]; -} - -- (OHGameControllerButton *)leftShoulderButton -{ - return [_rawProfile.buttons objectForKey: @"LB"]; -} - -- (OHGameControllerButton *)rightShoulderButton -{ - return [_rawProfile.buttons objectForKey: @"RB"]; -} - -- (OHGameControllerButton *)leftTriggerButton -{ - OHGameControllerAxis *axis = [_rawProfile.axes objectForKey: @"Z"]; - - if (axis != nil) - return [[[OHGameControllerEmulatedTriggerButton alloc] - initWithName: @"LT" - axis: axis] autorelease]; - - return [_rawProfile.buttons objectForKey: @"LT"]; -} - -- (OHGameControllerButton *)rightTriggerButton -{ - OHGameControllerAxis *axis = [_rawProfile.axes objectForKey: @"RZ"]; - - if (axis != nil) - return [[[OHGameControllerEmulatedTriggerButton alloc] - initWithName: @"RT" - axis: axis] autorelease]; - - return [_rawProfile.buttons objectForKey: @"RT"]; -} - -- (OHGameControllerButton *)leftThumbstickButton -{ - return [_rawProfile.buttons objectForKey: @"LSB"]; -} - -- (OHGameControllerButton *)rightThumbstickButton -{ - return [_rawProfile.buttons objectForKey: @"RSB"]; -} - -- (OHGameControllerButton *)menuButton -{ - return [_rawProfile.buttons objectForKey: @"Start"]; -} - -- (OHGameControllerButton *)optionsButton -{ - return [_rawProfile.buttons objectForKey: @"Back"]; -} - -- (OHGameControllerButton *)homeButton -{ - return [_rawProfile.buttons objectForKey: @"Guide"]; -} - -- (OHGameControllerDirectionalPad *)leftThumbstick -{ - OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"X"]; - OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"Y"]; - - if (xAxis == nil || yAxis == nil) - return nil; - - return [[[OHGameControllerDirectionalPad alloc] - initWithName: @"Left Thumbstick" - xAxis: xAxis - yAxis: yAxis] autorelease]; -} - -- (OHGameControllerDirectionalPad *)rightThumbstick -{ - OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"RX"]; - OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"RY"]; - - if (xAxis == nil || yAxis == nil) - return nil; - - return [[[OHGameControllerDirectionalPad alloc] - initWithName: @"Right Thumbstick" - xAxis: xAxis - yAxis: yAxis] autorelease]; -} - -- (OHGameControllerDirectionalPad *)dPad -{ - OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"HAT0X"]; - OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"HAT0Y"]; - OHGameControllerButton *up, *down, *left, *right; - - if (xAxis != nil && yAxis != nil) - return [[[OHGameControllerDirectionalPad alloc] - initWithName: @"D-Pad" - xAxis: xAxis - yAxis: yAxis] autorelease]; - - up = [_rawProfile.buttons objectForKey: @"D-Pad Up"]; - down = [_rawProfile.buttons objectForKey: @"D-Pad Down"]; - left = [_rawProfile.buttons objectForKey: @"D-Pad Left"]; - right = [_rawProfile.buttons objectForKey: @"D-Pad Right"]; - - if (up != nil && down != nil && left != nil && right != nil) - return [[[OHGameControllerDirectionalPad alloc] - initWithName: @"D-Pad" - up: up - down: down - left: left - right: right] autorelease]; - - return nil; -} -@end ADDED src/hid/OHEvdevPlayStationExtendedGamepad.h Index: src/hid/OHEvdevPlayStationExtendedGamepad.h ================================================================== --- /dev/null +++ src/hid/OHEvdevPlayStationExtendedGamepad.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#import "OHEvdevExtendedGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OHEvdevPlayStationExtendedGamepad: OHEvdevExtendedGamepad +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHEvdevPlayStationExtendedGamepad.m Index: src/hid/OHEvdevPlayStationExtendedGamepad.m ================================================================== --- /dev/null +++ src/hid/OHEvdevPlayStationExtendedGamepad.m @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OHEvdevPlayStationExtendedGamepad.h" +#import "OFDictionary.h" +#import "OHGameControllerEmulatedTriggerButton.h" + +@implementation OHEvdevPlayStationExtendedGamepad +- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons +{ + OFMutableDictionary *buttons = + [[_rawProfile.buttons mutableCopy] autorelease]; + + [buttons setObject: self.leftTriggerButton forKey: @"L2"]; + [buttons setObject: self.rightTriggerButton forKey: @"R2"]; + + [buttons makeImmutable]; + + return buttons; +} + +- (OHGameControllerButton *)northButton +{ + return [_rawProfile.buttons objectForKey: @"Triangle"]; +} + +- (OHGameControllerButton *)southButton +{ + return [_rawProfile.buttons objectForKey: @"Cross"]; +} + +- (OHGameControllerButton *)westButton +{ + return [_rawProfile.buttons objectForKey: @"Square"]; +} + +- (OHGameControllerButton *)eastButton +{ + return [_rawProfile.buttons objectForKey: @"Circle"]; +} + +- (OHGameControllerButton *)leftShoulderButton +{ + return [_rawProfile.buttons objectForKey: @"L1"]; +} + +- (OHGameControllerButton *)rightShoulderButton +{ + return [_rawProfile.buttons objectForKey: @"R1"]; +} + +- (OHGameControllerButton *)leftTriggerButton +{ + return [[[OHGameControllerEmulatedTriggerButton alloc] + initWithName: @"L2" + axis: [_rawProfile.axes objectForKey: @"Z"]] autorelease]; +} + +- (OHGameControllerButton *)rightTriggerButton +{ + return [[[OHGameControllerEmulatedTriggerButton alloc] + initWithName: @"R2" + axis: [_rawProfile.axes objectForKey: @"RZ"]] autorelease]; +} + +- (OHGameControllerButton *)leftThumbstickButton +{ + return [_rawProfile.buttons objectForKey: @"L3"]; +} + +- (OHGameControllerButton *)rightThumbstickButton +{ + return [_rawProfile.buttons objectForKey: @"R3"]; +} + +- (OHGameControllerButton *)menuButton +{ + return [_rawProfile.buttons objectForKey: @"Options"]; +} + +- (OHGameControllerButton *)homeButton +{ + return [_rawProfile.buttons objectForKey: @"PS"]; +} +@end DELETED src/hid/OHEvdevPlayStationGamepad.h Index: src/hid/OHEvdevPlayStationGamepad.h ================================================================== --- src/hid/OHEvdevPlayStationGamepad.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#import "OHEvdevGamepad.h" - -OF_ASSUME_NONNULL_BEGIN - -@interface OHEvdevPlayStationGamepad: OHEvdevGamepad -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHEvdevPlayStationGamepad.m Index: src/hid/OHEvdevPlayStationGamepad.m ================================================================== --- src/hid/OHEvdevPlayStationGamepad.m +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#include "config.h" - -#import "OHEvdevPlayStationGamepad.h" -#import "OFDictionary.h" -#import "OHGameControllerEmulatedTriggerButton.h" - -@implementation OHEvdevPlayStationGamepad -- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons -{ - OFMutableDictionary *buttons = - [[_rawProfile.buttons mutableCopy] autorelease]; - - [buttons setObject: self.leftTriggerButton forKey: @"L2"]; - [buttons setObject: self.rightTriggerButton forKey: @"R2"]; - - [buttons makeImmutable]; - - return buttons; -} - -- (OHGameControllerButton *)northButton -{ - return [_rawProfile.buttons objectForKey: @"Triangle"]; -} - -- (OHGameControllerButton *)southButton -{ - return [_rawProfile.buttons objectForKey: @"Cross"]; -} - -- (OHGameControllerButton *)westButton -{ - return [_rawProfile.buttons objectForKey: @"Square"]; -} - -- (OHGameControllerButton *)eastButton -{ - return [_rawProfile.buttons objectForKey: @"Circle"]; -} - -- (OHGameControllerButton *)leftShoulderButton -{ - return [_rawProfile.buttons objectForKey: @"L1"]; -} - -- (OHGameControllerButton *)rightShoulderButton -{ - return [_rawProfile.buttons objectForKey: @"R1"]; -} - -- (OHGameControllerButton *)leftTriggerButton -{ - return [[[OHGameControllerEmulatedTriggerButton alloc] - initWithName: @"L2" - axis: [_rawProfile.axes objectForKey: @"Z"]] autorelease]; -} - -- (OHGameControllerButton *)rightTriggerButton -{ - return [[[OHGameControllerEmulatedTriggerButton alloc] - initWithName: @"R2" - axis: [_rawProfile.axes objectForKey: @"RZ"]] autorelease]; -} - -- (OHGameControllerButton *)leftThumbstickButton -{ - return [_rawProfile.buttons objectForKey: @"L3"]; -} - -- (OHGameControllerButton *)rightThumbstickButton -{ - return [_rawProfile.buttons objectForKey: @"R3"]; -} - -- (OHGameControllerButton *)menuButton -{ - return [_rawProfile.buttons objectForKey: @"Options"]; -} - -- (OHGameControllerButton *)homeButton -{ - return [_rawProfile.buttons objectForKey: @"PS"]; -} -@end ADDED src/hid/OHEvdevStadiaExtendedGamepad.h Index: src/hid/OHEvdevStadiaExtendedGamepad.h ================================================================== --- /dev/null +++ src/hid/OHEvdevStadiaExtendedGamepad.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#import "OHEvdevExtendedGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OHEvdevStadiaExtendedGamepad: OHEvdevExtendedGamepad +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHEvdevStadiaExtendedGamepad.m Index: src/hid/OHEvdevStadiaExtendedGamepad.m ================================================================== --- /dev/null +++ src/hid/OHEvdevStadiaExtendedGamepad.m @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OHEvdevStadiaExtendedGamepad.h" +#import "OFDictionary.h" +#import "OHGameControllerAxis.h" +#import "OHGameControllerDirectionalPad.h" +#import "OHGameControllerEmulatedTriggerButton.h" + +@implementation OHEvdevStadiaExtendedGamepad +- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons +{ + OFMutableDictionary *buttons = + [[_rawProfile.buttons mutableCopy] autorelease]; + + [buttons setObject: self.leftTriggerButton forKey: @"L2"]; + [buttons setObject: self.rightTriggerButton forKey: @"R2"]; + + [buttons makeImmutable]; + + return buttons; +} + +- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes +{ + OFMutableDictionary *axes = + [[_rawProfile.axes mutableCopy] autorelease]; + + [axes removeObjectForKey: @"X"]; + [axes removeObjectForKey: @"Y"]; + [axes removeObjectForKey: @"Z"]; + [axes removeObjectForKey: @"RZ"]; + [axes removeObjectForKey: @"Gas"]; + [axes removeObjectForKey: @"Brake"]; + [axes removeObjectForKey: @"HAT0X"]; + [axes removeObjectForKey: @"HAT0Y"]; + + [axes makeImmutable]; + + return axes; +} + +- (OHGameControllerButton *)leftShoulderButton +{ + return [_rawProfile.buttons objectForKey: @"L1"]; +} + +- (OHGameControllerButton *)rightShoulderButton +{ + return [_rawProfile.buttons objectForKey: @"R1"]; +} + +- (OHGameControllerButton *)leftTriggerButton +{ + OHGameControllerAxis *axis = [_rawProfile.axes objectForKey: @"Brake"]; + + return [[[OHGameControllerEmulatedTriggerButton alloc] + initWithName: @"L2" + axis: axis] autorelease]; +} + +- (OHGameControllerButton *)rightTriggerButton +{ + return [[[OHGameControllerEmulatedTriggerButton alloc] + initWithName: @"R2" + axis: [_rawProfile.axes objectForKey: @"Gas"]] autorelease]; +} + +- (OHGameControllerButton *)leftThumbstickButton +{ + return [_rawProfile.buttons objectForKey: @"L3"]; +} + +- (OHGameControllerButton *)rightThumbstickButton +{ + return [_rawProfile.buttons objectForKey: @"R3"]; +} + +- (OHGameControllerButton *)menuButton +{ + return [_rawProfile.buttons objectForKey: @"Menu"]; +} + +- (OHGameControllerButton *)optionsButton +{ + return [_rawProfile.buttons objectForKey: @"Options"]; +} + +- (OHGameControllerButton *)homeButton +{ + return [_rawProfile.buttons objectForKey: @"Stadia"]; +} + +- (OHGameControllerDirectionalPad *)rightThumbstick +{ + OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"Z"]; + OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"RZ"]; + + return [[[OHGameControllerDirectionalPad alloc] + initWithName: @"Right Thumbstick" + xAxis: xAxis + yAxis: yAxis] autorelease]; +} +@end DELETED src/hid/OHEvdevStadiaGamepad.h Index: src/hid/OHEvdevStadiaGamepad.h ================================================================== --- src/hid/OHEvdevStadiaGamepad.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#import "OHEvdevGamepad.h" - -OF_ASSUME_NONNULL_BEGIN - -@interface OHEvdevStadiaGamepad: OHEvdevGamepad -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHEvdevStadiaGamepad.m Index: src/hid/OHEvdevStadiaGamepad.m ================================================================== --- src/hid/OHEvdevStadiaGamepad.m +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#include "config.h" - -#import "OHEvdevStadiaGamepad.h" -#import "OFDictionary.h" -#import "OHGameControllerAxis.h" -#import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedTriggerButton.h" - -@implementation OHEvdevStadiaGamepad -- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons -{ - OFMutableDictionary *buttons = - [[_rawProfile.buttons mutableCopy] autorelease]; - - [buttons setObject: self.leftTriggerButton forKey: @"L2"]; - [buttons setObject: self.rightTriggerButton forKey: @"R2"]; - - [buttons makeImmutable]; - - return buttons; -} - -- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes -{ - OFMutableDictionary *axes = - [[_rawProfile.axes mutableCopy] autorelease]; - - [axes removeObjectForKey: @"X"]; - [axes removeObjectForKey: @"Y"]; - [axes removeObjectForKey: @"Z"]; - [axes removeObjectForKey: @"RZ"]; - [axes removeObjectForKey: @"Gas"]; - [axes removeObjectForKey: @"Brake"]; - [axes removeObjectForKey: @"HAT0X"]; - [axes removeObjectForKey: @"HAT0Y"]; - - [axes makeImmutable]; - - return axes; -} - -- (OHGameControllerButton *)leftShoulderButton -{ - return [_rawProfile.buttons objectForKey: @"L1"]; -} - -- (OHGameControllerButton *)rightShoulderButton -{ - return [_rawProfile.buttons objectForKey: @"R1"]; -} - -- (OHGameControllerButton *)leftTriggerButton -{ - OHGameControllerAxis *axis = [_rawProfile.axes objectForKey: @"Brake"]; - - return [[[OHGameControllerEmulatedTriggerButton alloc] - initWithName: @"L2" - axis: axis] autorelease]; -} - -- (OHGameControllerButton *)rightTriggerButton -{ - return [[[OHGameControllerEmulatedTriggerButton alloc] - initWithName: @"R2" - axis: [_rawProfile.axes objectForKey: @"Gas"]] autorelease]; -} - -- (OHGameControllerButton *)leftThumbstickButton -{ - return [_rawProfile.buttons objectForKey: @"L3"]; -} - -- (OHGameControllerButton *)rightThumbstickButton -{ - return [_rawProfile.buttons objectForKey: @"R3"]; -} - -- (OHGameControllerButton *)menuButton -{ - return [_rawProfile.buttons objectForKey: @"Menu"]; -} - -- (OHGameControllerButton *)optionsButton -{ - return [_rawProfile.buttons objectForKey: @"Options"]; -} - -- (OHGameControllerButton *)homeButton -{ - return [_rawProfile.buttons objectForKey: @"Stadia"]; -} - -- (OHGameControllerDirectionalPad *)rightThumbstick -{ - OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"Z"]; - OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"RZ"]; - - return [[[OHGameControllerDirectionalPad alloc] - initWithName: @"Right Thumbstick" - xAxis: xAxis - yAxis: yAxis] autorelease]; -} -@end ADDED src/hid/OHExtendedGamepad.h Index: src/hid/OHExtendedGamepad.h ================================================================== --- /dev/null +++ src/hid/OHExtendedGamepad.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#import "OHGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OHExtendedGamepad OHExtendedGamepad.h ObjFWHID/OHExtendedGamepad.h + * + * @brief A game controller profile representing a gamepad. + */ +@interface OHExtendedGamepad: OHGamepad +{ + OF_RESERVE_IVARS(OHExtendedGamepad, 4) +} + +/** + * @brief The left trigger button. + */ +@property (readonly, nonatomic) OHGameControllerButton *leftTriggerButton; + +/** + * @brief The right trigger button. + */ +@property (readonly, nonatomic) OHGameControllerButton *rightTriggerButton; + +/** + * @brief The left thumb stick button. + * + * This button is optional and may be `nil`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) + OHGameControllerButton *leftThumbstickButton; + +/** + * @brief The right thumb stick button. + * + * This button is optional and may be `nil`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) + OHGameControllerButton *rightThumbstickButton; + +/** + * @brief The home button. + * + * This button is optional and may be `nil`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) + OHGameControllerButton *homeButton; + +/** + * @brief The left thumb stick. + */ +@property (readonly, nonatomic) OHGameControllerDirectionalPad *leftThumbstick; + +/** + * @brief The right thumb stick. + */ +@property (readonly, nonatomic) OHGameControllerDirectionalPad *rightThumbstick; +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHExtendedGamepad.m Index: src/hid/OHExtendedGamepad.m ================================================================== --- /dev/null +++ src/hid/OHExtendedGamepad.m @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OHExtendedGamepad.h" + +@implementation OHExtendedGamepad +@dynamic leftTriggerButton, rightTriggerButton, leftThumbstick, rightThumbstick; +@dynamic dPad; + +- (OHGameControllerButton *)leftThumbstickButton +{ + return nil; +} + +- (OHGameControllerButton *)rightThumbstickButton +{ + return nil; +} + +- (OHGameControllerButton *)homeButton +{ + return nil; +} +@end Index: src/hid/OHGameController.h ================================================================== --- src/hid/OHGameController.h +++ src/hid/OHGameController.h @@ -31,10 +31,11 @@ OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFNumber; +@class OHExtendedGamepad; @class OHGameControllerProfile; @class OHGamepad; /** * @class OHGameController OHGameController.h ObjFWHID/OHGameController.h @@ -76,10 +77,17 @@ * @brief The gamepad profile for the game controller, or `nil` if not * supported. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OHGamepad *gamepad; +/** + * @brief The extended gamepad profile for the game controller, or `nil` if not + * supported. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) + OHExtendedGamepad *extendedGamepad; + /** * @brief Returns the available controllers. * * @return The available controllers */ Index: src/hid/OHGameController.m ================================================================== --- src/hid/OHGameController.m +++ src/hid/OHGameController.m @@ -21,11 +21,10 @@ #import "OHGameController.h" #import "OFArray.h" #import "OFNumber.h" #import "OFSet.h" -#import "OHGamepad.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # import "OHEvdevGameController.h" #endif #ifdef OF_WINDOWS @@ -97,10 +96,15 @@ OF_UNRECOGNIZED_SELECTOR } - (OHGamepad *)gamepad { + return nil; +} + +- (OHExtendedGamepad *)extendedGamepad +{ return nil; } - (OFString *)description { Index: src/hid/OHGamepad.h ================================================================== --- src/hid/OHGamepad.h +++ src/hid/OHGamepad.h @@ -59,36 +59,10 @@ /** * @brief The right shoulder button. */ @property (readonly, nonatomic) OHGameControllerButton *rightShoulderButton; -/** - * @brief The left trigger button. - */ -@property (readonly, nonatomic) OHGameControllerButton *leftTriggerButton; - -/** - * @brief The right trigger button. - */ -@property (readonly, nonatomic) OHGameControllerButton *rightTriggerButton; - -/** - * @brief The left thumb stick button. - * - * This button is optional and may be `nil`. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) - OHGameControllerButton *leftThumbstickButton; - -/** - * @brief The right thumb stick button. - * - * This button is optional and may be `nil`. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) - OHGameControllerButton *rightThumbstickButton; - /** * @brief The menu button, sometimes also called start button. */ @property (readonly, nonatomic) OHGameControllerButton *menuButton; @@ -95,30 +69,12 @@ /** * @brief The options button, sometimes also called select button. */ @property (readonly, nonatomic) OHGameControllerButton *optionsButton; -/** - * @brief The home button. - * - * This button is optional and may be `nil`. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) - OHGameControllerButton *homeButton; - -/** - * @brief The left thumb stick. - */ -@property (readonly, nonatomic) OHGameControllerDirectionalPad *leftThumbstick; - -/** - * @brief The right thumb stick. - */ -@property (readonly, nonatomic) OHGameControllerDirectionalPad *rightThumbstick; - /** * @brief The D-Pad. */ @property (readonly, nonatomic) OHGameControllerDirectionalPad *dPad; @end OF_ASSUME_NONNULL_END Index: src/hid/OHGamepad.m ================================================================== --- src/hid/OHGamepad.m +++ src/hid/OHGamepad.m @@ -21,23 +21,7 @@ #import "OHGamepad.h" @implementation OHGamepad @dynamic northButton, southButton, westButton, eastButton, leftShoulderButton; -@dynamic rightShoulderButton, leftTriggerButton, rightTriggerButton; -@dynamic menuButton, optionsButton, leftThumbstick, rightThumbstick, dPad; - -- (OHGameControllerButton *)leftThumbstickButton -{ - return nil; -} - -- (OHGameControllerButton *)rightThumbstickButton -{ - return nil; -} - -- (OHGameControllerButton *)homeButton -{ - return nil; -} +@dynamic rightShoulderButton, menuButton, optionsButton, dPad; @end ADDED src/hid/OHNintendo3DSExtendedGamepad.h Index: src/hid/OHNintendo3DSExtendedGamepad.h ================================================================== --- /dev/null +++ src/hid/OHNintendo3DSExtendedGamepad.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#import "OHExtendedGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OHNintendo3DSExtendedGamepad: OHExtendedGamepad +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHNintendo3DSExtendedGamepad.m Index: src/hid/OHNintendo3DSExtendedGamepad.m ================================================================== --- /dev/null +++ src/hid/OHNintendo3DSExtendedGamepad.m @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OHNintendo3DSExtendedGamepad.h" +#import "OFDictionary.h" +#import "OHGameControllerAxis.h" +#import "OHGameControllerButton.h" +#import "OHGameControllerDirectionalPad.h" + +static OFString *const buttonNames[] = { + @"A", @"B", @"X", @"Y", @"L", @"R", @"ZL", @"ZR", @"Start", @"Select" +}; +static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); + +@implementation OHNintendo3DSExtendedGamepad +- (instancetype)init +{ + self = [super init]; + + @try { + void *pool = objc_autoreleasePoolPush(); + OFMutableDictionary *buttons = + [OFMutableDictionary dictionaryWithCapacity: numButtons]; + OFMutableDictionary *directionalPads; + OHGameControllerAxis *xAxis, *yAxis; + OHGameControllerDirectionalPad *directionalPad; + OHGameControllerButton *up, *down, *left, *right; + + for (size_t i = 0; i < numButtons; i++) { + OHGameControllerButton *button = + [[[OHGameControllerButton alloc] + initWithName: buttonNames[i]] autorelease]; + [buttons setObject: button forKey: buttonNames[i]]; + } + [buttons makeImmutable]; + _buttons = [buttons retain]; + + _axes = [[OFDictionary alloc] init]; + + directionalPads = + [OFMutableDictionary dictionaryWithCapacity: 3]; + + xAxis = [[[OHGameControllerAxis alloc] + initWithName: @"X"] autorelease]; + yAxis = [[[OHGameControllerAxis alloc] + initWithName: @"Y"] autorelease]; + directionalPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"Circle Pad" + xAxis: xAxis + yAxis: yAxis] autorelease]; + [directionalPads setObject: directionalPad + forKey: @"Circle Pad"]; + + xAxis = [[[OHGameControllerAxis alloc] + initWithName: @"CX"] autorelease]; + yAxis = [[[OHGameControllerAxis alloc] + initWithName: @"CY"] autorelease]; + directionalPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"C-Stick" + xAxis: xAxis + yAxis: yAxis] autorelease]; + [directionalPads setObject: directionalPad + forKey: @"C-Stick"]; + + up = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Up"] autorelease]; + down = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Down"] autorelease]; + left = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Left"] autorelease]; + right = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Right"] autorelease]; + directionalPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"D-Pad" + up: up + down: down + left: left + right: right] autorelease]; + [directionalPads setObject: directionalPad forKey: @"D-Pad"]; + + [directionalPads makeImmutable]; + _directionalPads = [directionalPads retain]; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (OHGameControllerButton *)northButton +{ + return [_buttons objectForKey: @"X"]; +} + +- (OHGameControllerButton *)southButton +{ + return [_buttons objectForKey: @"B"]; +} + +- (OHGameControllerButton *)westButton +{ + return [_buttons objectForKey: @"Y"]; +} + +- (OHGameControllerButton *)eastButton +{ + return [_buttons objectForKey: @"A"]; +} + +- (OHGameControllerButton *)leftShoulderButton +{ + return [_buttons objectForKey: @"L"]; +} + +- (OHGameControllerButton *)rightShoulderButton +{ + return [_buttons objectForKey: @"R"]; +} + +- (OHGameControllerButton *)leftTriggerButton +{ + return [_buttons objectForKey: @"ZL"]; +} + +- (OHGameControllerButton *)rightTriggerButton +{ + return [_buttons objectForKey: @"ZR"]; +} + +- (OHGameControllerButton *)menuButton +{ + return [_buttons objectForKey: @"Start"]; +} + +- (OHGameControllerButton *)optionsButton +{ + return [_buttons objectForKey: @"Select"]; +} + +- (OHGameControllerDirectionalPad *)leftThumbstick +{ + return [_directionalPads objectForKey: @"Circle Pad"]; +} + +- (OHGameControllerDirectionalPad *)rightThumbstick +{ + return [_directionalPads objectForKey: @"C-Stick"]; +} + +- (OHGameControllerDirectionalPad *)dPad +{ + return [_directionalPads objectForKey: @"D-Pad"]; +} +@end Index: src/hid/OHNintendo3DSGameController.h ================================================================== --- src/hid/OHNintendo3DSGameController.h +++ src/hid/OHNintendo3DSGameController.h @@ -19,14 +19,14 @@ #import "OHGameController.h" OF_ASSUME_NONNULL_BEGIN -@class OHNintendo3DSGamepad; +@class OHNintendo3DSExtendedGamepad; @interface OHNintendo3DSGameController: OHGameController { - OHNintendo3DSGamepad *_gamepad; + OHNintendo3DSExtendedGamepad *_extendedGamepad; } @end OF_ASSUME_NONNULL_END Index: src/hid/OHNintendo3DSGameController.m ================================================================== --- src/hid/OHNintendo3DSGameController.m +++ src/hid/OHNintendo3DSGameController.m @@ -24,11 +24,11 @@ #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" -#import "OHNintendo3DSGamepad.h" +#import "OHNintendo3DSExtendedGamepad.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #define id id_3ds @@ -36,11 +36,11 @@ #undef id static OFArray OF_GENERIC(OHGameController *) *controllers; @implementation OHNintendo3DSGameController -@synthesize gamepad = _gamepad; +@synthesize extendedGamepad = _extendedGamepad; + (void)initialize { void *pool; @@ -61,11 +61,11 @@ - (instancetype)init { self = [super init]; @try { - _gamepad = [[OHNintendo3DSGamepad alloc] init]; + _extendedGamepad = [[OHNintendo3DSExtendedGamepad alloc] init]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; @@ -74,11 +74,11 @@ return self; } - (void)dealloc { - [_gamepad release]; + [_extendedGamepad release]; [super dealloc]; } - (void)retrieveState @@ -90,20 +90,20 @@ keys = hidKeysHeld(); hidCircleRead(&leftPos); hidCstickRead(&rightPos); - [_gamepad.northButton setValue: !!(keys & KEY_X)]; - [_gamepad.southButton setValue: !!(keys & KEY_B)]; - [_gamepad.westButton setValue: !!(keys & KEY_Y)]; - [_gamepad.eastButton setValue: !!(keys & KEY_A)]; - [_gamepad.leftShoulderButton setValue: !!(keys & KEY_L)]; - [_gamepad.rightShoulderButton setValue: !!(keys & KEY_R)]; - [_gamepad.leftTriggerButton setValue: !!(keys & KEY_ZL)]; - [_gamepad.rightTriggerButton setValue: !!(keys & KEY_ZR)]; - [_gamepad.menuButton setValue: !!(keys & KEY_START)]; - [_gamepad.optionsButton setValue: !!(keys & KEY_SELECT)]; + [_extendedGamepad.northButton setValue: !!(keys & KEY_X)]; + [_extendedGamepad.southButton setValue: !!(keys & KEY_B)]; + [_extendedGamepad.westButton setValue: !!(keys & KEY_Y)]; + [_extendedGamepad.eastButton setValue: !!(keys & KEY_A)]; + [_extendedGamepad.leftShoulderButton setValue: !!(keys & KEY_L)]; + [_extendedGamepad.rightShoulderButton setValue: !!(keys & KEY_R)]; + [_extendedGamepad.leftTriggerButton setValue: !!(keys & KEY_ZL)]; + [_extendedGamepad.rightTriggerButton setValue: !!(keys & KEY_ZR)]; + [_extendedGamepad.menuButton setValue: !!(keys & KEY_START)]; + [_extendedGamepad.optionsButton setValue: !!(keys & KEY_SELECT)]; if (leftPos.dx > 150) leftPos.dx = 150; if (leftPos.dx < -150) leftPos.dx = -150; @@ -119,26 +119,32 @@ if (rightPos.dy > 150) rightPos.dy = 150; if (rightPos.dy < -150) rightPos.dy = -150; - _gamepad.leftThumbstick.xAxis.value = (float)leftPos.dx / 150; - _gamepad.leftThumbstick.yAxis.value = -(float)leftPos.dy / 150; - _gamepad.rightThumbstick.xAxis.value = (float)rightPos.dx / 150; - _gamepad.rightThumbstick.yAxis.value = -(float)rightPos.dy / 150; - - [_gamepad.dPad.up setValue: !!(keys & KEY_DUP)]; - [_gamepad.dPad.down setValue: !!(keys & KEY_DDOWN)]; - [_gamepad.dPad.left setValue: !!(keys & KEY_DLEFT)]; - [_gamepad.dPad.right setValue: !!(keys & KEY_DRIGHT)]; + _extendedGamepad.leftThumbstick.xAxis.value = (float)leftPos.dx / 150; + _extendedGamepad.leftThumbstick.yAxis.value = -(float)leftPos.dy / 150; + _extendedGamepad.rightThumbstick.xAxis.value = (float)rightPos.dx / 150; + _extendedGamepad.rightThumbstick.yAxis.value = + -(float)rightPos.dy / 150; + + [_extendedGamepad.dPad.up setValue: !!(keys & KEY_DUP)]; + [_extendedGamepad.dPad.down setValue: !!(keys & KEY_DDOWN)]; + [_extendedGamepad.dPad.left setValue: !!(keys & KEY_DLEFT)]; + [_extendedGamepad.dPad.right setValue: !!(keys & KEY_DRIGHT)]; } - (OFString *)name { return @"Nintendo 3DS"; } - (OHGameControllerProfile *)rawProfile { - return _gamepad; + return _extendedGamepad; +} + +- (OHGamepad *)gamepad +{ + return _extendedGamepad; } @end DELETED src/hid/OHNintendo3DSGamepad.h Index: src/hid/OHNintendo3DSGamepad.h ================================================================== --- src/hid/OHNintendo3DSGamepad.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#import "OHGamepad.h" - -OF_ASSUME_NONNULL_BEGIN - -@interface OHNintendo3DSGamepad: OHGamepad -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHNintendo3DSGamepad.m Index: src/hid/OHNintendo3DSGamepad.m ================================================================== --- src/hid/OHNintendo3DSGamepad.m +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#include "config.h" - -#import "OHNintendo3DSGamepad.h" -#import "OFDictionary.h" -#import "OHGameControllerAxis.h" -#import "OHGameControllerButton.h" -#import "OHGameControllerDirectionalPad.h" - -static OFString *const buttonNames[] = { - @"A", @"B", @"X", @"Y", @"L", @"R", @"ZL", @"ZR", @"Start", @"Select" -}; -static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); - -@implementation OHNintendo3DSGamepad -- (instancetype)init -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - OFMutableDictionary *buttons = - [OFMutableDictionary dictionaryWithCapacity: numButtons]; - OFMutableDictionary *directionalPads; - OHGameControllerAxis *xAxis, *yAxis; - OHGameControllerDirectionalPad *directionalPad; - OHGameControllerButton *up, *down, *left, *right; - - for (size_t i = 0; i < numButtons; i++) { - OHGameControllerButton *button = - [[[OHGameControllerButton alloc] - initWithName: buttonNames[i]] autorelease]; - [buttons setObject: button forKey: buttonNames[i]]; - } - [buttons makeImmutable]; - _buttons = [buttons retain]; - - _axes = [[OFDictionary alloc] init]; - - directionalPads = - [OFMutableDictionary dictionaryWithCapacity: 3]; - - xAxis = [[[OHGameControllerAxis alloc] - initWithName: @"X"] autorelease]; - yAxis = [[[OHGameControllerAxis alloc] - initWithName: @"Y"] autorelease]; - directionalPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"Circle Pad" - xAxis: xAxis - yAxis: yAxis] autorelease]; - [directionalPads setObject: directionalPad - forKey: @"Circle Pad"]; - - xAxis = [[[OHGameControllerAxis alloc] - initWithName: @"CX"] autorelease]; - yAxis = [[[OHGameControllerAxis alloc] - initWithName: @"CY"] autorelease]; - directionalPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"C-Stick" - xAxis: xAxis - yAxis: yAxis] autorelease]; - [directionalPads setObject: directionalPad - forKey: @"C-Stick"]; - - up = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Up"] autorelease]; - down = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Down"] autorelease]; - left = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Left"] autorelease]; - right = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Right"] autorelease]; - directionalPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"D-Pad" - up: up - down: down - left: left - right: right] autorelease]; - [directionalPads setObject: directionalPad forKey: @"D-Pad"]; - - [directionalPads makeImmutable]; - _directionalPads = [directionalPads retain]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (OHGameControllerButton *)northButton -{ - return [_buttons objectForKey: @"X"]; -} - -- (OHGameControllerButton *)southButton -{ - return [_buttons objectForKey: @"B"]; -} - -- (OHGameControllerButton *)westButton -{ - return [_buttons objectForKey: @"Y"]; -} - -- (OHGameControllerButton *)eastButton -{ - return [_buttons objectForKey: @"A"]; -} - -- (OHGameControllerButton *)leftShoulderButton -{ - return [_buttons objectForKey: @"L"]; -} - -- (OHGameControllerButton *)rightShoulderButton -{ - return [_buttons objectForKey: @"R"]; -} - -- (OHGameControllerButton *)leftTriggerButton -{ - return [_buttons objectForKey: @"ZL"]; -} - -- (OHGameControllerButton *)rightTriggerButton -{ - return [_buttons objectForKey: @"ZR"]; -} - -- (OHGameControllerButton *)menuButton -{ - return [_buttons objectForKey: @"Start"]; -} - -- (OHGameControllerButton *)optionsButton -{ - return [_buttons objectForKey: @"Select"]; -} - -- (OHGameControllerDirectionalPad *)leftThumbstick -{ - return [_directionalPads objectForKey: @"Circle Pad"]; -} - -- (OHGameControllerDirectionalPad *)rightThumbstick -{ - return [_directionalPads objectForKey: @"C-Stick"]; -} - -- (OHGameControllerDirectionalPad *)dPad -{ - return [_directionalPads objectForKey: @"D-Pad"]; -} -@end ADDED src/hid/OHXInputExtendedGamepad.h Index: src/hid/OHXInputExtendedGamepad.h ================================================================== --- /dev/null +++ src/hid/OHXInputExtendedGamepad.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#import "OHExtendedGamepad.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OHXInputExtendedGamepad: OHExtendedGamepad +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHXInputExtendedGamepad.m Index: src/hid/OHXInputExtendedGamepad.m ================================================================== --- /dev/null +++ src/hid/OHXInputExtendedGamepad.m @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3.0 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3.0 along with this program. If not, see + * . + */ + +#include "config.h" + +#import "OHXInputExtendedGamepad.h" +#import "OFDictionary.h" +#import "OHGameControllerAxis.h" +#import "OHGameControllerButton.h" +#import "OHGameControllerDirectionalPad.h" +#import "OHXInputGameController.h" + +static OFString *const buttonNames[] = { + @"A", @"B", @"X", @"Y", @"LB", @"RB", @"LT", @"RT", @"LSB", @"RSB", + @"Start", @"Back", @"Guide" +}; +static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); + +@implementation OHXInputExtendedGamepad +- (instancetype)init +{ + self = [super init]; + + @try { + void *pool = objc_autoreleasePoolPush(); + OFMutableDictionary *buttons = + [OFMutableDictionary dictionaryWithCapacity: numButtons]; + OFMutableDictionary *directionalPads; + OHGameControllerAxis *xAxis, *yAxis; + OHGameControllerDirectionalPad *directionalPad; + OHGameControllerButton *up, *down, *left, *right; + + for (size_t i = 0; i < numButtons; i++) { + OHGameControllerButton *button; + + if ([buttonNames[i] isEqual: @"Guide"] && + OHXInputVersion == 910) + continue; + + button = [[OHGameControllerButton alloc] + initWithName: buttonNames[i]]; + [buttons setObject: button forKey: buttonNames[i]]; + } + [buttons makeImmutable]; + _buttons = [buttons retain]; + + _axes = [[OFDictionary alloc] init]; + + directionalPads = + [OFMutableDictionary dictionaryWithCapacity: 3]; + + xAxis = [[[OHGameControllerAxis alloc] + initWithName: @"X"] autorelease]; + yAxis = [[[OHGameControllerAxis alloc] + initWithName: @"Y"] autorelease]; + directionalPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"Left Thumbstick" + xAxis: xAxis + yAxis: yAxis] autorelease]; + [directionalPads setObject: directionalPad + forKey: @"Left Thumbstick"]; + + xAxis = [[[OHGameControllerAxis alloc] + initWithName: @"RX"] autorelease]; + yAxis = [[[OHGameControllerAxis alloc] + initWithName: @"RY"] autorelease]; + directionalPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"Right Thumbstick" + xAxis: xAxis + yAxis: yAxis] autorelease]; + [directionalPads setObject: directionalPad + forKey: @"Right Thumbstick"]; + + up = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Up"] autorelease]; + down = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Down"] autorelease]; + left = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Left"] autorelease]; + right = [[[OHGameControllerButton alloc] + initWithName: @"D-Pad Right"] autorelease]; + directionalPad = [[[OHGameControllerDirectionalPad alloc] + initWithName: @"D-Pad" + up: up + down: down + left: left + right: right] autorelease]; + [directionalPads setObject: directionalPad forKey: @"D-Pad"]; + + [directionalPads makeImmutable]; + _directionalPads = [directionalPads retain]; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (OHGameControllerButton *)northButton +{ + return [_buttons objectForKey: @"Y"]; +} + +- (OHGameControllerButton *)southButton +{ + return [_buttons objectForKey: @"A"]; +} + +- (OHGameControllerButton *)westButton +{ + return [_buttons objectForKey: @"X"]; +} + +- (OHGameControllerButton *)eastButton +{ + return [_buttons objectForKey: @"B"]; +} + +- (OHGameControllerButton *)leftShoulderButton +{ + return [_buttons objectForKey: @"LB"]; +} + +- (OHGameControllerButton *)rightShoulderButton +{ + return [_buttons objectForKey: @"RB"]; +} + +- (OHGameControllerButton *)leftTriggerButton +{ + return [_buttons objectForKey: @"LT"]; +} + +- (OHGameControllerButton *)rightTriggerButton +{ + return [_buttons objectForKey: @"RT"]; +} + +- (OHGameControllerButton *)leftThumbstickButton +{ + return [_buttons objectForKey: @"LSB"]; +} + +- (OHGameControllerButton *)rightThumbstickButton +{ + return [_buttons objectForKey: @"RSB"]; +} + +- (OHGameControllerButton *)menuButton +{ + return [_buttons objectForKey: @"Start"]; +} + +- (OHGameControllerButton *)optionsButton +{ + return [_buttons objectForKey: @"Back"]; +} + +- (OHGameControllerButton *)homeButton +{ + return [_buttons objectForKey: @"Guide"]; +} + +- (OHGameControllerDirectionalPad *)leftThumbstick +{ + return [_directionalPads objectForKey: @"Left Thumbstick"]; +} + +- (OHGameControllerDirectionalPad *)rightThumbstick +{ + return [_directionalPads objectForKey: @"Right Thumbstick"]; +} + +- (OHGameControllerDirectionalPad *)dPad +{ + return [_directionalPads objectForKey: @"D-Pad"]; +} +@end Index: src/hid/OHXInputGameController.h ================================================================== --- src/hid/OHXInputGameController.h +++ src/hid/OHXInputGameController.h @@ -21,17 +21,17 @@ #include OF_ASSUME_NONNULL_BEGIN -@class OHXInputGamepad; +@class OHXInputExtendedGamepad; @interface OHXInputGameController: OHGameController { DWORD _index; OFNumber *_Nullable _vendorID, *_Nullable _productID; - OHXInputGamepad *_gamepad; + OHXInputExtendedGamepad *_extendedGamepad; } - (instancetype)oh_initWithIndex: (DWORD)index OF_METHOD_FAMILY(init); @end Index: src/hid/OHXInputGameController.m ================================================================== --- src/hid/OHXInputGameController.m +++ src/hid/OHXInputGameController.m @@ -24,11 +24,11 @@ #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" -#import "OHXInputGamepad.h" +#import "OHXInputExtendedGamepad.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #include @@ -50,11 +50,12 @@ static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *); static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD, struct XInputCapabilitiesEx *); @implementation OHXInputGameController -@synthesize vendorID = _vendorID, productID = _productID, gamepad = _gamepad; +@synthesize vendorID = _vendorID, productID = _productID; +@synthesize extendedGamepad = _extendedGamepad; + (void)initialize { HMODULE module; @@ -138,11 +139,11 @@ initWithUnsignedShort: capabilities.productID]; } } - _gamepad = [[OHXInputGamepad alloc] init]; + _extendedGamepad = [[OHXInputExtendedGamepad alloc] init]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; @@ -153,11 +154,11 @@ - (void)dealloc { [_vendorID release]; [_productID release]; - [_gamepad release]; + [_extendedGamepad release]; [super dealloc]; } - (void)retrieveState @@ -167,59 +168,59 @@ if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(state) errNo: 0]; - _gamepad.northButton.value = + _extendedGamepad.northButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y); - _gamepad.southButton.value = + _extendedGamepad.southButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_A); - _gamepad.westButton.value = + _extendedGamepad.westButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_X); - _gamepad.eastButton.value = + _extendedGamepad.eastButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_B); - _gamepad.leftShoulderButton.value = + _extendedGamepad.leftShoulderButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER); - _gamepad.rightShoulderButton.value = + _extendedGamepad.rightShoulderButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER); - _gamepad.leftThumbstickButton.value = + _extendedGamepad.leftThumbstickButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); - _gamepad.rightThumbstickButton.value = + _extendedGamepad.rightThumbstickButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); - _gamepad.menuButton.value = + _extendedGamepad.menuButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_START); - _gamepad.optionsButton.value = + _extendedGamepad.optionsButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK); if (OHXInputVersion != 910) - _gamepad.homeButton.value = + _extendedGamepad.homeButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE); - _gamepad.leftTriggerButton.value = + _extendedGamepad.leftTriggerButton.value = (float)state.Gamepad.bLeftTrigger / 255; - _gamepad.rightTriggerButton.value = + _extendedGamepad.rightTriggerButton.value = (float)state.Gamepad.bRightTrigger / 255; - _gamepad.leftThumbstick.xAxis.value = + _extendedGamepad.leftThumbstick.xAxis.value = (float)state.Gamepad.sThumbLX / (state.Gamepad.sThumbLX < 0 ? -INT16_MIN : INT16_MAX); - _gamepad.leftThumbstick.yAxis.value = + _extendedGamepad.leftThumbstick.yAxis.value = -(float)state.Gamepad.sThumbLY / (state.Gamepad.sThumbLY < 0 ? -INT16_MIN : INT16_MAX); - _gamepad.rightThumbstick.xAxis.value = + _extendedGamepad.rightThumbstick.xAxis.value = (float)state.Gamepad.sThumbRX / (state.Gamepad.sThumbRX < 0 ? -INT16_MIN : INT16_MAX); - _gamepad.rightThumbstick.yAxis.value = + _extendedGamepad.rightThumbstick.yAxis.value = -(float)state.Gamepad.sThumbRY / (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX); - _gamepad.dPad.up.value = + _extendedGamepad.dPad.up.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP); - _gamepad.dPad.down.value = + _extendedGamepad.dPad.down.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN); - _gamepad.dPad.left.value = + _extendedGamepad.dPad.left.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT); - _gamepad.dPad.right.value = + _extendedGamepad.dPad.right.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT); } - (OFString *)name { @@ -235,8 +236,13 @@ return nil; } - (OHGameControllerProfile *)rawProfile { - return _gamepad; + return _extendedGamepad; +} + +- (OHGamepad *)gamepad +{ + return _extendedGamepad; } @end DELETED src/hid/OHXInputGamepad.h Index: src/hid/OHXInputGamepad.h ================================================================== --- src/hid/OHXInputGamepad.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#import "OHGamepad.h" - -OF_ASSUME_NONNULL_BEGIN - -@interface OHXInputGamepad: OHGamepad -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHXInputGamepad.m Index: src/hid/OHXInputGamepad.m ================================================================== --- src/hid/OHXInputGamepad.m +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3.0 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * version 3.0 for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * version 3.0 along with this program. If not, see - * . - */ - -#include "config.h" - -#import "OHXInputGamepad.h" -#import "OFDictionary.h" -#import "OHGameControllerAxis.h" -#import "OHGameControllerButton.h" -#import "OHGameControllerDirectionalPad.h" -#import "OHXInputGameController.h" - -static OFString *const buttonNames[] = { - @"A", @"B", @"X", @"Y", @"LB", @"RB", @"LT", @"RT", @"LSB", @"RSB", - @"Start", @"Back", @"Guide" -}; -static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); - -@implementation OHXInputGamepad -- (instancetype)init -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - OFMutableDictionary *buttons = - [OFMutableDictionary dictionaryWithCapacity: numButtons]; - OFMutableDictionary *directionalPads; - OHGameControllerAxis *xAxis, *yAxis; - OHGameControllerDirectionalPad *directionalPad; - OHGameControllerButton *up, *down, *left, *right; - - for (size_t i = 0; i < numButtons; i++) { - OHGameControllerButton *button; - - if ([buttonNames[i] isEqual: @"Guide"] && - OHXInputVersion == 910) - continue; - - button = [[OHGameControllerButton alloc] - initWithName: buttonNames[i]]; - [buttons setObject: button forKey: buttonNames[i]]; - } - [buttons makeImmutable]; - _buttons = [buttons retain]; - - _axes = [[OFDictionary alloc] init]; - - directionalPads = - [OFMutableDictionary dictionaryWithCapacity: 3]; - - xAxis = [[[OHGameControllerAxis alloc] - initWithName: @"X"] autorelease]; - yAxis = [[[OHGameControllerAxis alloc] - initWithName: @"Y"] autorelease]; - directionalPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"Left Thumbstick" - xAxis: xAxis - yAxis: yAxis] autorelease]; - [directionalPads setObject: directionalPad - forKey: @"Left Thumbstick"]; - - xAxis = [[[OHGameControllerAxis alloc] - initWithName: @"RX"] autorelease]; - yAxis = [[[OHGameControllerAxis alloc] - initWithName: @"RY"] autorelease]; - directionalPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"Right Thumbstick" - xAxis: xAxis - yAxis: yAxis] autorelease]; - [directionalPads setObject: directionalPad - forKey: @"Right Thumbstick"]; - - up = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Up"] autorelease]; - down = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Down"] autorelease]; - left = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Left"] autorelease]; - right = [[[OHGameControllerButton alloc] - initWithName: @"D-Pad Right"] autorelease]; - directionalPad = [[[OHGameControllerDirectionalPad alloc] - initWithName: @"D-Pad" - up: up - down: down - left: left - right: right] autorelease]; - [directionalPads setObject: directionalPad forKey: @"D-Pad"]; - - [directionalPads makeImmutable]; - _directionalPads = [directionalPads retain]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (OHGameControllerButton *)northButton -{ - return [_buttons objectForKey: @"Y"]; -} - -- (OHGameControllerButton *)southButton -{ - return [_buttons objectForKey: @"A"]; -} - -- (OHGameControllerButton *)westButton -{ - return [_buttons objectForKey: @"X"]; -} - -- (OHGameControllerButton *)eastButton -{ - return [_buttons objectForKey: @"B"]; -} - -- (OHGameControllerButton *)leftShoulderButton -{ - return [_buttons objectForKey: @"LB"]; -} - -- (OHGameControllerButton *)rightShoulderButton -{ - return [_buttons objectForKey: @"RB"]; -} - -- (OHGameControllerButton *)leftTriggerButton -{ - return [_buttons objectForKey: @"LT"]; -} - -- (OHGameControllerButton *)rightTriggerButton -{ - return [_buttons objectForKey: @"RT"]; -} - -- (OHGameControllerButton *)leftThumbstickButton -{ - return [_buttons objectForKey: @"LSB"]; -} - -- (OHGameControllerButton *)rightThumbstickButton -{ - return [_buttons objectForKey: @"RSB"]; -} - -- (OHGameControllerButton *)menuButton -{ - return [_buttons objectForKey: @"Start"]; -} - -- (OHGameControllerButton *)optionsButton -{ - return [_buttons objectForKey: @"Back"]; -} - -- (OHGameControllerButton *)homeButton -{ - return [_buttons objectForKey: @"Guide"]; -} - -- (OHGameControllerDirectionalPad *)leftThumbstick -{ - return [_directionalPads objectForKey: @"Left Thumbstick"]; -} - -- (OHGameControllerDirectionalPad *)rightThumbstick -{ - return [_directionalPads objectForKey: @"Right Thumbstick"]; -} - -- (OHGameControllerDirectionalPad *)dPad -{ - return [_directionalPads objectForKey: @"D-Pad"]; -} -@end Index: src/hid/ObjFWHID.h ================================================================== --- src/hid/ObjFWHID.h +++ src/hid/ObjFWHID.h @@ -17,8 +17,12 @@ * . */ #import "OHGameController.h" #import "OHGameControllerElement.h" -#import "OHGameControllerButton.h" #import "OHGameControllerAxis.h" +#import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" +#import "OHGameControllerProfile.h" +#import "OHGamepad.h" +#import "OHExtendedGamepad.h" +#import "OHCombinedJoyCons.h"