Play-/Source/ui_ios/VirtualPadButton.mm
Jean-Philip Desjardins 30568a057d
Some checks failed
Build macOS / build_macos (push) Has been cancelled
Build Android / build_android (apk) (push) Has been cancelled
Build Android / build_android (libretro) (push) Has been cancelled
Build Linux ARM32 / build_linux_arm32 (push) Has been cancelled
Build Linux ARM64 / build_linux_arm64 (push) Has been cancelled
Build Windows Psf / build_windows_psf (off, x86_64, Visual Studio 16 2019, installer64.nsi, x64) (push) Has been cancelled
Build Windows Psf / build_windows_psf (on, x86_64, Visual Studio 16 2019, installer64.nsi, x64) (push) Has been cancelled
Build Windows / build_windows (x86_32, Visual Studio 16 2019, installer32.nsi, win32_msvc2019, Win32) (push) Has been cancelled
Build Windows / build_windows (x86_64, Visual Studio 16 2019, installer64.nsi, win64_msvc2019_64, x64) (push) Has been cancelled
Check Format / run_clangformat (push) Has been cancelled
Build iOS / build_ios (push) Has been cancelled
Build JavaScript / build_js (push) Has been cancelled
Build Linux / build_linux (push) Has been cancelled
Use app_config module.
2025-03-11 16:18:58 -04:00

89 lines
2.4 KiB
Text

#import "AppConfig.h"
#import "PreferenceDefs.h"
#import "VirtualPadButton.h"
@interface VirtualPadButton ()
@property(strong, nonatomic) UIImpactFeedbackGenerator* impactFeedback;
@property(strong, nonatomic) UISelectionFeedbackGenerator* selectionFeedback;
@end
@implementation VirtualPadButton
- (id)init
{
self = [super init];
if(self)
{
_impactFeedback = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
_selectionFeedback = [[UISelectionFeedbackGenerator alloc] init];
}
return self;
}
- (void)draw:(CGContextRef)context
{
[self.image drawInRect:self.bounds];
if(self.pressed)
{
CGContextSaveGState(context);
CGContextSetBlendMode(context, kCGBlendModePlusDarker);
[self.image drawInRect:self.bounds];
CGContextRestoreGState(context);
}
if([self.caption length] != 0)
{
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary* attributes =
@{
NSParagraphStyleAttributeName : paragraphStyle,
NSForegroundColorAttributeName : [UIColor whiteColor]
};
CGSize textSize = [self.caption sizeWithAttributes:attributes];
CGRect textRect = CGRectOffset(self.bounds, 0, (self.bounds.size.height - textSize.height) / 2);
[self.caption drawInRect:textRect withAttributes:attributes];
}
}
- (void)onPointerDown:(CGPoint)position
{
self.pressed = YES;
self.padHandler->SetButtonState(self.code, true);
if(CAppConfig::GetInstance().GetPreferenceBoolean(PREFERENCE_UI_VIRTUALPAD_HAPTICFEEDBACK))
{
switch(self.code)
{
case PS2::CControllerInfo::BUTTON::START:
case PS2::CControllerInfo::BUTTON::SELECT:
case PS2::CControllerInfo::BUTTON::SQUARE:
case PS2::CControllerInfo::BUTTON::TRIANGLE:
case PS2::CControllerInfo::BUTTON::CROSS:
case PS2::CControllerInfo::BUTTON::CIRCLE:
case PS2::CControllerInfo::BUTTON::L1:
case PS2::CControllerInfo::BUTTON::L2:
case PS2::CControllerInfo::BUTTON::L3:
case PS2::CControllerInfo::BUTTON::R1:
case PS2::CControllerInfo::BUTTON::R2:
case PS2::CControllerInfo::BUTTON::R3:
[self.impactFeedback impactOccurred];
break;
default:
[self.selectionFeedback selectionChanged];
break;
}
}
[super onPointerDown:position];
}
- (void)onPointerUp
{
self.pressed = NO;
self.padHandler->SetButtonState(self.code, false);
[super onPointerUp];
}
@end