mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-27 18:30:56 +00:00
Add taptic feedback on virtual buttons
This commit is contained in:
parent
9baf83ea32
commit
0e474077e4
@ -14,6 +14,9 @@
|
||||
@interface PPSSPPUIApplication : UIApplication
|
||||
{
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) UISelectionFeedbackGenerator *feedbackGenerator;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
48
ios/main.mm
48
ios/main.mm
@ -98,15 +98,45 @@ PermissionStatus System_GetPermissionStatus(SystemPermission permission) { retur
|
||||
|
||||
FOUNDATION_EXTERN void AudioServicesPlaySystemSoundWithVibration(unsigned long, objc_object*, NSDictionary*);
|
||||
|
||||
void Vibrate(int length_ms) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
NSArray *pattern = @[@YES, @30, @NO, @2];
|
||||
|
||||
dictionary[@"VibePattern"] = pattern;
|
||||
dictionary[@"Intensity"] = @2;
|
||||
|
||||
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, dictionary);
|
||||
// TODO: Actually make use of length_ms if PPSSPP ever adds that in the config
|
||||
BOOL SupportsTaptic()
|
||||
{
|
||||
// we're on an iOS version that cannot instantiate UISelectionFeedbackGenerator, so no.
|
||||
if(!NSClassFromString(@"UISelectionFeedbackGenerator"))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// http://www.mikitamanko.com/blog/2017/01/29/haptic-feedback-with-uifeedbackgenerator/
|
||||
// use private API against UIDevice to determine the haptic stepping
|
||||
// 2 - iPhone 7 or above, full taptic feedback
|
||||
// 1 - iPhone 6S, limited taptic feedback
|
||||
// 0 - iPhone 6 or below, no taptic feedback
|
||||
NSNumber* val = (NSNumber*)[[UIDevice currentDevice] valueForKey:@"feedbackSupportLevel"];
|
||||
return [val intValue] >= 2;
|
||||
}
|
||||
|
||||
void Vibrate(int mode) {
|
||||
|
||||
if(SupportsTaptic())
|
||||
{
|
||||
PPSSPPUIApplication* app = (PPSSPPUIApplication*)[UIApplication sharedApplication];
|
||||
if(app.feedbackGenerator == nil)
|
||||
{
|
||||
app.feedbackGenerator = [[UISelectionFeedbackGenerator alloc] init];
|
||||
[app.feedbackGenerator prepare];
|
||||
}
|
||||
[app.feedbackGenerator selectionChanged];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
NSArray *pattern = @[@YES, @30, @NO, @2];
|
||||
|
||||
dictionary[@"VibePattern"] = pattern;
|
||||
dictionary[@"Intensity"] = @2;
|
||||
|
||||
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
Loading…
Reference in New Issue
Block a user