mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-23 19:16:21 +00:00
IOS7: Implement getHardwareInputSet to get connected devices
Trigger EVENT_INPUT_CHANGED when devices connects to make the ScummVM engine update the hardware input set.
This commit is contained in:
parent
d76bc708c0
commit
e7759ac0ef
@ -44,7 +44,8 @@ enum InputEvent {
|
||||
kInputMainMenu,
|
||||
kInputJoystickAxisMotion,
|
||||
kInputJoystickButtonDown,
|
||||
kInputJoystickButtonUp
|
||||
kInputJoystickButtonUp,
|
||||
kInputChanged
|
||||
};
|
||||
|
||||
enum ScreenOrientation {
|
||||
|
@ -34,7 +34,6 @@
|
||||
@implementation GameController
|
||||
|
||||
@synthesize view;
|
||||
@synthesize isConnected;
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view {
|
||||
self = [super init];
|
||||
@ -45,6 +44,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
// Override the setter method
|
||||
- (void)setIsConnected:(BOOL)isConnected {
|
||||
// Inform that input changed
|
||||
_isConnected = isConnected;
|
||||
[view addEvent:InternalEvent(kInputChanged, 0, 0)];
|
||||
}
|
||||
|
||||
- (void)handlePointerMoveTo:(CGPoint)point {
|
||||
int x, y;
|
||||
|
||||
|
@ -137,6 +137,11 @@ bool OSystem_iOS7::pollEvent(Common::Event &event) {
|
||||
case kInputJoystickButtonUp:
|
||||
event.type = Common::EVENT_JOYBUTTON_UP;
|
||||
event.joystick.button = internalEvent.value1;
|
||||
|
||||
case kInputChanged:
|
||||
event.type = Common::EVENT_INPUT_CHANGED;
|
||||
_queuedInputEvent.type = Common::EVENT_INVALID;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "graphics/surface.h"
|
||||
#include "backends/platform/ios7/ios7_common.h"
|
||||
#include "backends/modular-backend.h"
|
||||
#include "backends/keymapper/hardware-input.h"
|
||||
#include "common/events.h"
|
||||
#include "common/str.h"
|
||||
#include "common/ustr.h"
|
||||
@ -193,6 +194,8 @@ public:
|
||||
void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
|
||||
void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
|
||||
|
||||
Common::HardwareInputSet *getHardwareInputSet() override;
|
||||
|
||||
Audio::Mixer *getMixer() override;
|
||||
|
||||
void startSoundsystem();
|
||||
|
@ -124,6 +124,23 @@ bool OSystem_iOS7::isConnectionLimited() {
|
||||
return (flags & kSCNetworkReachabilityFlagsIsWWAN);
|
||||
}
|
||||
|
||||
Common::HardwareInputSet *OSystem_iOS7::getHardwareInputSet() {
|
||||
using namespace Common;
|
||||
|
||||
CompositeHardwareInputSet *inputSet = new CompositeHardwareInputSet();
|
||||
// Ask view about connected controllers
|
||||
if ([[iOS7AppDelegate iPhoneView] isTouchControllerConnected] ||
|
||||
[[iOS7AppDelegate iPhoneView] isMouseControllerConnected]) {
|
||||
inputSet->addHardwareInputSet(new MouseHardwareInputSet(defaultMouseButtons));
|
||||
}
|
||||
|
||||
if ([[iOS7AppDelegate iPhoneView] isGamepadControllerConnected]) {
|
||||
inputSet->addHardwareInputSet(new JoystickHardwareInputSet(defaultJoystickButtons, defaultJoystickAxes));
|
||||
}
|
||||
|
||||
return inputSet;
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_applicationSaveState() {
|
||||
[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
|
||||
saveState();
|
||||
|
@ -133,7 +133,9 @@ typedef struct {
|
||||
- (bool)fetchEvent:(InternalEvent *)event;
|
||||
|
||||
- (bool)getMouseCoords:(CGPoint)point eventX:(int *)x eventY:(int *)y;
|
||||
|
||||
- (BOOL)isTouchControllerConnected;
|
||||
- (BOOL)isMouseControllerConnected;
|
||||
- (BOOL)isGamepadControllerConnected;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
@ -818,6 +818,39 @@ uint getSizeNextPOT(uint size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
- (BOOL)isControllerTypeConnected:(Class)controller {
|
||||
for (GameController *c : _controllers) {
|
||||
if ([c isConnected]) {
|
||||
if ([c isKindOfClass:controller]) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isTouchControllerConnected {
|
||||
return [self isControllerTypeConnected:TouchController.class];
|
||||
}
|
||||
|
||||
- (BOOL)isMouseControllerConnected {
|
||||
if (@available(iOS 14.0, *)) {
|
||||
return [self isControllerTypeConnected:MouseController.class];
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isGamepadControllerConnected {
|
||||
if (@available(iOS 14.0, *)) {
|
||||
return [self isControllerTypeConnected:GamepadController.class];
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deviceOrientationChanged:(UIDeviceOrientation)orientation {
|
||||
[self addEvent:InternalEvent(kInputOrientationChanged, orientation, 0)];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user