mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-06-29 02:29:37 +00:00
Merge pull request #35 from narbs/master
Add support for mouse pointer interaction introduced in iOS 13.4
This commit is contained in:
commit
3af32e9acc
|
@ -10,7 +10,12 @@
|
||||||
#import "ScreenView.h"
|
#import "ScreenView.h"
|
||||||
#import "KBKeyboardView.h"
|
#import "KBKeyboardView.h"
|
||||||
|
|
||||||
|
#ifdef __IPHONE_13_4
|
||||||
|
API_AVAILABLE(ios(13.4))
|
||||||
|
@interface ViewController : UIViewController <UIPointerInteractionDelegate, KBKeyboardViewDelegate>
|
||||||
|
#else
|
||||||
@interface ViewController : UIViewController <KBKeyboardViewDelegate>
|
@interface ViewController : UIViewController <KBKeyboardViewDelegate>
|
||||||
|
#endif
|
||||||
|
|
||||||
@property (weak, nonatomic) IBOutlet ScreenView *screenView;
|
@property (weak, nonatomic) IBOutlet ScreenView *screenView;
|
||||||
@property (nonatomic, getter=isKeyboardVisible) BOOL keyboardVisible;
|
@property (nonatomic, getter=isKeyboardVisible) BOOL keyboardVisible;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#import "KBKeyboardView.h"
|
#import "KBKeyboardView.h"
|
||||||
#import "KBKeyboardLayout.h"
|
#import "KBKeyboardLayout.h"
|
||||||
|
|
||||||
|
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
|
||||||
|
|
||||||
@interface ViewController ()
|
@interface ViewController ()
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -22,8 +24,36 @@
|
||||||
KBKeyboardView *keyboardView;
|
KBKeyboardView *keyboardView;
|
||||||
UISwipeGestureRecognizer *showKeyboardGesture, *hideKeyboardGesture, *insertDiskGesture, *showSettingsGesture;
|
UISwipeGestureRecognizer *showKeyboardGesture, *hideKeyboardGesture, *insertDiskGesture, *showSettingsGesture;
|
||||||
UIControl *pointingDeviceView;
|
UIControl *pointingDeviceView;
|
||||||
|
#ifdef __IPHONE_13_4
|
||||||
|
UIPointerInteraction* interaction;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (Point)mouseLocForCGPoint:(CGPoint)point {
|
||||||
|
Point mouseLoc;
|
||||||
|
CGRect screenBounds = self.screenView.screenBounds;
|
||||||
|
CGSize screenSize = self.screenView.screenSize;
|
||||||
|
mouseLoc.h = (point.x - screenBounds.origin.x) * (screenSize.width/screenBounds.size.width);
|
||||||
|
mouseLoc.v = (point.y - screenBounds.origin.y) * (screenSize.height/screenBounds.size.height);
|
||||||
|
return mouseLoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __IPHONE_13_4
|
||||||
|
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)){
|
||||||
|
if (request != nil) {
|
||||||
|
Point mouseLoc = [self mouseLocForCGPoint:request.location];
|
||||||
|
// NSLog(@"Interaction: x2: %hi, y2: %hi", (short)mouseLoc.h, (short)mouseLoc.v);
|
||||||
|
[[AppDelegate sharedEmulator] setMouseX:mouseLoc.h Y:mouseLoc.v];
|
||||||
|
}
|
||||||
|
return defaultRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region {
|
||||||
|
return [UIPointerStyle hiddenPointerStyle];
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
[self installKeyboardGestures];
|
[self installKeyboardGestures];
|
||||||
|
@ -63,6 +93,12 @@
|
||||||
[pointingDeviceView removeFromSuperview];
|
[pointingDeviceView removeFromSuperview];
|
||||||
pointingDeviceView = nil;
|
pointingDeviceView = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.4")) {
|
||||||
|
interaction = [[UIPointerInteraction alloc] initWithDelegate: self];
|
||||||
|
[self.view addInteraction:interaction];
|
||||||
|
}
|
||||||
|
|
||||||
BOOL useTrackPad = [[NSUserDefaults standardUserDefaults] boolForKey:@"trackpad"];
|
BOOL useTrackPad = [[NSUserDefaults standardUserDefaults] boolForKey:@"trackpad"];
|
||||||
Class pointingDeviceClass = useTrackPad ? [TrackPad class] : [TouchScreen class];
|
Class pointingDeviceClass = useTrackPad ? [TrackPad class] : [TouchScreen class];
|
||||||
pointingDeviceView = [[pointingDeviceClass alloc] initWithFrame:self.view.bounds];
|
pointingDeviceView = [[pointingDeviceClass alloc] initWithFrame:self.view.bounds];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user