Index: src/hid/Makefile ================================================================== --- src/hid/Makefile +++ src/hid/Makefile @@ -22,13 +22,13 @@ OHGamepad.h \ ObjFWHID.h SRCS += OHDualSenseGamepad.m \ OHDualShock4Gamepad.m \ - OHGameControllerEmulatedAxis.m \ - OHGameControllerEmulatedButton.m \ - OHGameControllerEmulatedTriggerButton.m \ + OHEmulatedGameControllerAxis.m \ + OHEmulatedGameControllerButton.m \ + OHEmulatedGameControllerTriggerButton.m \ OHStadiaGamepad.m \ OHXboxGamepad.m \ ${USE_SRCS_EVDEV} \ ${USE_SRCS_NINTENDO_3DS} \ ${USE_SRCS_NINTENDO_DS} \ Index: src/hid/OHDualSenseGamepad.m ================================================================== --- src/hid/OHDualSenseGamepad.m +++ src/hid/OHDualSenseGamepad.m @@ -19,14 +19,14 @@ #include "config.h" #import "OHDualSenseGamepad.h" #import "OFDictionary.h" +#import "OHEmulatedGameControllerTriggerButton.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedTriggerButton.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include #endif @@ -58,18 +58,18 @@ [buttons setObject: button forKey: buttonNames[i]]; } axis = [[[OHGameControllerAxis alloc] initWithName: @"L2"] autorelease]; - button = [[[OHGameControllerEmulatedTriggerButton alloc] + button = [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"L2" axis: axis] autorelease]; [buttons setObject: button forKey: @"L2"]; axis = [[[OHGameControllerAxis alloc] initWithName: @"R2"] autorelease]; - button = [[[OHGameControllerEmulatedTriggerButton alloc] + button = [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"R2" axis: axis] autorelease]; [buttons setObject: button forKey: @"R2"]; [buttons makeImmutable]; @@ -275,16 +275,16 @@ case ABS_HAT0X: return [[_directionalPads objectForKey: @"D-Pad"] xAxis]; case ABS_HAT0Y: return [[_directionalPads objectForKey: @"D-Pad"] yAxis]; case ABS_Z: - return ((OHGameControllerEmulatedTriggerButton *) + return ((OHEmulatedGameControllerTriggerButton *) [_buttons objectForKey: @"L2"]).axis; case ABS_RZ: - return ((OHGameControllerEmulatedTriggerButton *) + return ((OHEmulatedGameControllerTriggerButton *) [_buttons objectForKey: @"R2"]).axis; default: return nil; } } #endif @end Index: src/hid/OHDualShock4Gamepad.m ================================================================== --- src/hid/OHDualShock4Gamepad.m +++ src/hid/OHDualShock4Gamepad.m @@ -19,14 +19,14 @@ #include "config.h" #import "OHDualShock4Gamepad.h" #import "OFDictionary.h" +#import "OHEmulatedGameControllerTriggerButton.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedTriggerButton.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include #endif @@ -58,18 +58,18 @@ [buttons setObject: button forKey: buttonNames[i]]; } axis = [[[OHGameControllerAxis alloc] initWithName: @"L2"] autorelease]; - button = [[[OHGameControllerEmulatedTriggerButton alloc] + button = [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"L2" axis: axis] autorelease]; [buttons setObject: button forKey: @"L2"]; axis = [[[OHGameControllerAxis alloc] initWithName: @"R2"] autorelease]; - button = [[[OHGameControllerEmulatedTriggerButton alloc] + button = [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"R2" axis: axis] autorelease]; [buttons setObject: button forKey: @"R2"]; [buttons makeImmutable]; @@ -275,16 +275,16 @@ case ABS_HAT0X: return [[_directionalPads objectForKey: @"D-Pad"] xAxis]; case ABS_HAT0Y: return [[_directionalPads objectForKey: @"D-Pad"] yAxis]; case ABS_Z: - return ((OHGameControllerEmulatedTriggerButton *) + return ((OHEmulatedGameControllerTriggerButton *) [_buttons objectForKey: @"L2"]).axis; case ABS_RZ: - return ((OHGameControllerEmulatedTriggerButton *) + return ((OHEmulatedGameControllerTriggerButton *) [_buttons objectForKey: @"R2"]).axis; default: return nil; } } #endif @end ADDED src/hid/OHEmulatedGameControllerAxis.h Index: src/hid/OHEmulatedGameControllerAxis.h ================================================================== --- /dev/null +++ src/hid/OHEmulatedGameControllerAxis.h @@ -0,0 +1,38 @@ +/* + * 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 "OHGameControllerAxis.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OHGameControllerButton; + +OF_SUBCLASSING_RESTRICTED +@interface OHEmulatedGameControllerAxis: OHGameControllerAxis +{ + OHGameControllerButton *_negativeButton, *_positiveButton; +} + +- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; +- (instancetype) + initWithNegativeButton: (OHGameControllerButton *)negativeButton + positiveButton: (OHGameControllerButton *)positiveButton; +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHEmulatedGameControllerAxis.m Index: src/hid/OHEmulatedGameControllerAxis.m ================================================================== --- /dev/null +++ src/hid/OHEmulatedGameControllerAxis.m @@ -0,0 +1,80 @@ +/* + * 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 "config.h" + +#import "OHEmulatedGameControllerAxis.h" +#import "OHGameControllerButton.h" + +@implementation OHEmulatedGameControllerAxis +- (instancetype)initWithName: (OFString *)name +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithNegativeButton: (OHGameControllerButton *)negativeButton + positiveButton: (OHGameControllerButton *)positiveButton +{ + void *pool = objc_autoreleasePoolPush(); + OFString *name; + + @try { + name = [OFString stringWithFormat: + @"%@ and %@ as emulated axis", + negativeButton.name, positiveButton.name]; + } @catch (id e) { + [self release]; + @throw e; + } + + self = [super initWithName: name]; + + objc_autoreleasePoolPop(pool); + + _negativeButton = [negativeButton retain]; + _positiveButton = [positiveButton retain]; + + return self; +} + +- (void)dealloc +{ + [_negativeButton release]; + [_positiveButton release]; + + [super dealloc]; +} + +- (void)setValue: (float)value +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (float)value +{ + if (_negativeButton.pressed && _positiveButton.pressed) + return -0; + if (_negativeButton.pressed) + return -1; + if (_positiveButton.pressed) + return 1; + + return 0; +} +@end ADDED src/hid/OHEmulatedGameControllerButton.h Index: src/hid/OHEmulatedGameControllerButton.h ================================================================== --- /dev/null +++ src/hid/OHEmulatedGameControllerButton.h @@ -0,0 +1,38 @@ +/* + * 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 "OHGameControllerButton.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OHGameControllerAxis; + +OF_SUBCLASSING_RESTRICTED +@interface OHEmulatedGameControllerButton: OHGameControllerButton +{ + OHGameControllerAxis *_axis; + bool _positive; +} + +- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; +- (instancetype)initWithAxis: (OHGameControllerAxis *)axis + positive: (bool)positive; +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHEmulatedGameControllerButton.m Index: src/hid/OHEmulatedGameControllerButton.m ================================================================== --- /dev/null +++ src/hid/OHEmulatedGameControllerButton.m @@ -0,0 +1,74 @@ +/* + * 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 "OHEmulatedGameControllerButton.h" +#import "OHGameControllerAxis.h" + +@implementation OHEmulatedGameControllerButton +- (instancetype)initWithName: (OFString *)name +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithAxis: (OHGameControllerAxis *)axis + positive: (bool)positive +{ + void *pool = objc_autoreleasePoolPush(); + OFString *name; + + @try { + name = [OFString stringWithFormat: + @"%@%c", axis.name, (positive ? '+' : '-')]; + } @catch (id e) { + [self release]; + @throw e; + } + + self = [super initWithName: name]; + + objc_autoreleasePoolPop(pool); + + _axis = [axis retain]; + _positive = positive; + + return self; +} + +- (void)dealloc +{ + [_axis release]; + + [super dealloc]; +} + +- (bool)isPressed +{ + if (_positive) + return (_axis.value > 0); + else + return (_axis.value < 0); +} + +- (float)value +{ + return (self.isPressed ? 1 : 0); +} +@end ADDED src/hid/OHEmulatedGameControllerTriggerButton.h Index: src/hid/OHEmulatedGameControllerTriggerButton.h ================================================================== --- /dev/null +++ src/hid/OHEmulatedGameControllerTriggerButton.h @@ -0,0 +1,39 @@ +/* + * 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 "OHGameControllerButton.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OHGameControllerAxis; + +OF_SUBCLASSING_RESTRICTED +@interface OHEmulatedGameControllerTriggerButton: OHGameControllerButton +{ + OHGameControllerAxis *_axis; +} + +@property (readonly, nonatomic) OHGameControllerAxis *axis; + +- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; +- (instancetype)initWithName: (OFString *)name + axis: (OHGameControllerAxis *)axis; +@end + +OF_ASSUME_NONNULL_END ADDED src/hid/OHEmulatedGameControllerTriggerButton.m Index: src/hid/OHEmulatedGameControllerTriggerButton.m ================================================================== --- /dev/null +++ src/hid/OHEmulatedGameControllerTriggerButton.m @@ -0,0 +1,59 @@ +/* + * 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 "OHEmulatedGameControllerTriggerButton.h" +#import "OHGameControllerAxis.h" + +@implementation OHEmulatedGameControllerTriggerButton +@synthesize axis = _axis; + +- (instancetype)initWithName: (OFString *)name +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithName: (OFString *)name + axis: (OHGameControllerAxis *)axis +{ + self = [super initWithName: name]; + + _axis = [axis retain]; + + return self; +} + +- (void)dealloc +{ + [_axis release]; + + [super dealloc]; +} + +- (bool)isPressed +{ + return (_axis.value > -1); +} + +- (float)value +{ + return (_axis.value + 1) / 2; +} +@end Index: src/hid/OHEvdevExtendedGamepad.m ================================================================== --- src/hid/OHEvdevExtendedGamepad.m +++ src/hid/OHEvdevExtendedGamepad.m @@ -19,13 +19,13 @@ #include "config.h" #import "OHEvdevExtendedGamepad.h" #import "OFDictionary.h" +#import "OHEmulatedGameControllerTriggerButton.h" #import "OHEvdevGameController.h" #import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedTriggerButton.h" #import "OFInvalidArgumentException.h" @implementation OHEvdevExtendedGamepad - (instancetype)initWithKeyBits: (unsigned long *)keyBits @@ -143,11 +143,11 @@ - (OHGameControllerButton *)leftTriggerButton { OHGameControllerAxis *axis = [_axes objectForKey: @"Z"]; if (axis != nil) - return [[[OHGameControllerEmulatedTriggerButton alloc] + return [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"LT" axis: axis] autorelease]; return [_buttons objectForKey: @"LT"]; } @@ -155,11 +155,11 @@ - (OHGameControllerButton *)rightTriggerButton { OHGameControllerAxis *axis = [_axes objectForKey: @"RZ"]; if (axis != nil) - return [[[OHGameControllerEmulatedTriggerButton alloc] + return [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"RT" axis: axis] autorelease]; return [_buttons objectForKey: @"RT"]; } Index: src/hid/OHGameControllerDirectionalPad.m ================================================================== --- src/hid/OHGameControllerDirectionalPad.m +++ src/hid/OHGameControllerDirectionalPad.m @@ -18,12 +18,12 @@ */ #include "config.h" #import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedAxis.h" -#import "OHGameControllerEmulatedButton.h" +#import "OHEmulatedGameControllerAxis.h" +#import "OHEmulatedGameControllerButton.h" @implementation OHGameControllerDirectionalPad @synthesize xAxis = _xAxis, yAxis = _yAxis; @synthesize up = _up, down = _down, left = _left, right = _right; @@ -40,20 +40,20 @@ @try { _xAxis = [xAxis retain]; _yAxis = [yAxis retain]; - _up = [[OHGameControllerEmulatedButton alloc] + _up = [[OHEmulatedGameControllerButton alloc] initWithAxis: _yAxis positive: false]; - _down = [[OHGameControllerEmulatedButton alloc] + _down = [[OHEmulatedGameControllerButton alloc] initWithAxis: _yAxis positive: true]; - _left = [[OHGameControllerEmulatedButton alloc] + _left = [[OHEmulatedGameControllerButton alloc] initWithAxis: _xAxis positive: false]; - _right = [[OHGameControllerEmulatedButton alloc] + _right = [[OHEmulatedGameControllerButton alloc] initWithAxis: _xAxis positive: true]; } @catch (id e) { [self release]; @throw e; @@ -74,14 +74,14 @@ _up = [up retain]; _down = [down retain]; _left = [left retain]; _right = [right retain]; - _xAxis = [[OHGameControllerEmulatedAxis alloc] + _xAxis = [[OHEmulatedGameControllerAxis alloc] initWithNegativeButton: _left positiveButton: _right]; - _yAxis = [[OHGameControllerEmulatedAxis alloc] + _yAxis = [[OHEmulatedGameControllerAxis alloc] initWithNegativeButton: _up positiveButton: _down]; } @catch (id e) { [self release]; @throw e; DELETED src/hid/OHGameControllerEmulatedAxis.h Index: src/hid/OHGameControllerEmulatedAxis.h ================================================================== --- src/hid/OHGameControllerEmulatedAxis.h +++ /dev/null @@ -1,38 +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 "OHGameControllerAxis.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OHGameControllerButton; - -OF_SUBCLASSING_RESTRICTED -@interface OHGameControllerEmulatedAxis: OHGameControllerAxis -{ - OHGameControllerButton *_negativeButton, *_positiveButton; -} - -- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; -- (instancetype) - initWithNegativeButton: (OHGameControllerButton *)negativeButton - positiveButton: (OHGameControllerButton *)positiveButton; -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHGameControllerEmulatedAxis.m Index: src/hid/OHGameControllerEmulatedAxis.m ================================================================== --- src/hid/OHGameControllerEmulatedAxis.m +++ /dev/null @@ -1,80 +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 "config.h" - -#import "OHGameControllerEmulatedAxis.h" -#import "OHGameControllerButton.h" - -@implementation OHGameControllerEmulatedAxis -- (instancetype)initWithName: (OFString *)name -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithNegativeButton: (OHGameControllerButton *)negativeButton - positiveButton: (OHGameControllerButton *)positiveButton -{ - void *pool = objc_autoreleasePoolPush(); - OFString *name; - - @try { - name = [OFString stringWithFormat: - @"%@ and %@ as emulated axis", - negativeButton.name, positiveButton.name]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [super initWithName: name]; - - objc_autoreleasePoolPop(pool); - - _negativeButton = [negativeButton retain]; - _positiveButton = [positiveButton retain]; - - return self; -} - -- (void)dealloc -{ - [_negativeButton release]; - [_positiveButton release]; - - [super dealloc]; -} - -- (void)setValue: (float)value -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (float)value -{ - if (_negativeButton.pressed && _positiveButton.pressed) - return -0; - if (_negativeButton.pressed) - return -1; - if (_positiveButton.pressed) - return 1; - - return 0; -} -@end DELETED src/hid/OHGameControllerEmulatedButton.h Index: src/hid/OHGameControllerEmulatedButton.h ================================================================== --- src/hid/OHGameControllerEmulatedButton.h +++ /dev/null @@ -1,38 +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 "OHGameControllerButton.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OHGameControllerAxis; - -OF_SUBCLASSING_RESTRICTED -@interface OHGameControllerEmulatedButton: OHGameControllerButton -{ - OHGameControllerAxis *_axis; - bool _positive; -} - -- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; -- (instancetype)initWithAxis: (OHGameControllerAxis *)axis - positive: (bool)positive; -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHGameControllerEmulatedButton.m Index: src/hid/OHGameControllerEmulatedButton.m ================================================================== --- src/hid/OHGameControllerEmulatedButton.m +++ /dev/null @@ -1,74 +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 "OHGameControllerEmulatedButton.h" -#import "OHGameControllerAxis.h" - -@implementation OHGameControllerEmulatedButton -- (instancetype)initWithName: (OFString *)name -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithAxis: (OHGameControllerAxis *)axis - positive: (bool)positive -{ - void *pool = objc_autoreleasePoolPush(); - OFString *name; - - @try { - name = [OFString stringWithFormat: - @"%@%c", axis.name, (positive ? '+' : '-')]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [super initWithName: name]; - - objc_autoreleasePoolPop(pool); - - _axis = [axis retain]; - _positive = positive; - - return self; -} - -- (void)dealloc -{ - [_axis release]; - - [super dealloc]; -} - -- (bool)isPressed -{ - if (_positive) - return (_axis.value > 0); - else - return (_axis.value < 0); -} - -- (float)value -{ - return (self.isPressed ? 1 : 0); -} -@end DELETED src/hid/OHGameControllerEmulatedTriggerButton.h Index: src/hid/OHGameControllerEmulatedTriggerButton.h ================================================================== --- src/hid/OHGameControllerEmulatedTriggerButton.h +++ /dev/null @@ -1,39 +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 "OHGameControllerButton.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OHGameControllerAxis; - -OF_SUBCLASSING_RESTRICTED -@interface OHGameControllerEmulatedTriggerButton: OHGameControllerButton -{ - OHGameControllerAxis *_axis; -} - -@property (readonly, nonatomic) OHGameControllerAxis *axis; - -- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; -- (instancetype)initWithName: (OFString *)name - axis: (OHGameControllerAxis *)axis; -@end - -OF_ASSUME_NONNULL_END DELETED src/hid/OHGameControllerEmulatedTriggerButton.m Index: src/hid/OHGameControllerEmulatedTriggerButton.m ================================================================== --- src/hid/OHGameControllerEmulatedTriggerButton.m +++ /dev/null @@ -1,59 +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 "OHGameControllerEmulatedTriggerButton.h" -#import "OHGameControllerAxis.h" - -@implementation OHGameControllerEmulatedTriggerButton -@synthesize axis = _axis; - -- (instancetype)initWithName: (OFString *)name -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithName: (OFString *)name - axis: (OHGameControllerAxis *)axis -{ - self = [super initWithName: name]; - - _axis = [axis retain]; - - return self; -} - -- (void)dealloc -{ - [_axis release]; - - [super dealloc]; -} - -- (bool)isPressed -{ - return (_axis.value > -1); -} - -- (float)value -{ - return (_axis.value + 1) / 2; -} -@end Index: src/hid/OHStadiaGamepad.m ================================================================== --- src/hid/OHStadiaGamepad.m +++ src/hid/OHStadiaGamepad.m @@ -19,14 +19,14 @@ #include "config.h" #import "OHStadiaGamepad.h" #import "OFDictionary.h" +#import "OHEmulatedGameControllerTriggerButton.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" -#import "OHGameControllerEmulatedTriggerButton.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include #endif @@ -58,18 +58,18 @@ [buttons setObject: button forKey: buttonNames[i]]; } axis = [[[OHGameControllerAxis alloc] initWithName: @"L2"] autorelease]; - button = [[[OHGameControllerEmulatedTriggerButton alloc] + button = [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"L2" axis: axis] autorelease]; [buttons setObject: button forKey: @"L2"]; axis = [[[OHGameControllerAxis alloc] initWithName: @"R2"] autorelease]; - button = [[[OHGameControllerEmulatedTriggerButton alloc] + button = [[[OHEmulatedGameControllerTriggerButton alloc] initWithName: @"R2" axis: axis] autorelease]; [buttons setObject: button forKey: @"R2"]; [buttons makeImmutable]; @@ -281,16 +281,16 @@ case ABS_HAT0X: return [[_directionalPads objectForKey: @"D-Pad"] xAxis]; case ABS_HAT0Y: return [[_directionalPads objectForKey: @"D-Pad"] yAxis]; case ABS_BRAKE: - return ((OHGameControllerEmulatedTriggerButton *) + return ((OHEmulatedGameControllerTriggerButton *) [_buttons objectForKey: @"L2"]).axis; case ABS_GAS: - return ((OHGameControllerEmulatedTriggerButton *) + return ((OHEmulatedGameControllerTriggerButton *) [_buttons objectForKey: @"R2"]).axis; default: return nil; } } #endif @end