This commit is contained in:
Lior Halphon 2024-09-01 01:00:15 +03:00
parent 11f70c09af
commit 50a56a4b68
7 changed files with 97 additions and 45 deletions

View File

@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>
@interface GBActivityViewController : UIActivityViewController
@end

View File

@ -0,0 +1,10 @@
#import "GBActivityViewController.h"
@implementation GBActivityViewController
- (UIModalPresentationStyle)modalPresentationStyle
{
return UIModalPresentationFormSheet;
}
@end

View File

@ -487,6 +487,12 @@ static GB_key_mask_t angleToKeyMask(double angle)
screenFrame.origin.y += 8;
screenFrame.size.width -= 16;
screenFrame.size.height -= 16;
if (@available(iOS 13.0, *)) {
self.overrideUserInterfaceStyle = layout.theme.isDark? UIUserInterfaceStyleDark : UIUserInterfaceStyleLight;
self.tintColor = layout.theme.brandColor;
}
_screenLabel.frame = screenFrame;
}

View File

@ -1,5 +1,11 @@
#import "GBCheckableAlertController.h"
/* Private API */
@interface UIAlertAction()
- (bool)_isChecked;
- (void)_setChecked:(bool)checked;
@end
@implementation GBCheckableAlertController
{
bool _addedChecks;
@ -7,25 +13,30 @@
- (void)viewWillAppear:(BOOL)animated
{
if (!_addedChecks && _selectedAction) {
_addedChecks = true;
NSMutableSet *set = [NSMutableSet setWithObject:self.view];
while (set.count) {
UIView *view = [set anyObject];
[set removeObject:view];
if ([view.debugDescription containsString:_selectedAction.debugDescription]) {
UIImageView *checkImage = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"checkmark"]];
CGRect bounds = view.bounds;
CGRect frame = checkImage.frame;
frame.origin.x = bounds.size.width - frame.size.width - 12;
frame.origin.y = round((bounds.size.height - frame.size.height) / 2);
checkImage.frame = frame;
[view addSubview:checkImage];
break;
if (@available(iOS 13.0, *)) {
if (!_addedChecks && _selectedAction) {
_addedChecks = true;
NSMutableSet *set = [NSMutableSet setWithObject:self.view];
while (set.count) {
UIView *view = [set anyObject];
[set removeObject:view];
if ([view.debugDescription containsString:_selectedAction.debugDescription]) {
UIImageView *checkImage = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"checkmark"]];
CGRect bounds = view.bounds;
CGRect frame = checkImage.frame;
frame.origin.x = bounds.size.width - frame.size.width - 12;
frame.origin.y = round((bounds.size.height - frame.size.height) / 2);
checkImage.frame = frame;
[view addSubview:checkImage];
break;
}
[set addObjectsFromArray:view.subviews];
}
[set addObjectsFromArray:view.subviews];
}
}
else {
[_selectedAction _setChecked:true];
}
[super viewWillAppear:animated];
}

View File

@ -2,6 +2,5 @@
@interface GBPrinterFeedController : UINavigationController
- (instancetype)initWithImage:(UIImage *)image;
- (void)emptyPrinterFeed;
@end

View File

@ -1,27 +1,32 @@
#import "GBPrinterFeedController.h"
#import "GBViewController.h"
#import "GBActivityViewController.h"
@implementation GBPrinterFeedController
{
UIViewController *_scrollViewController;
UIImage *_image;
}
- (instancetype)initWithImage:(UIImage *)image
{
_image = image;
_scrollViewController = [[UIViewController alloc] init];
_scrollViewController.title = @"Printer Feed";
_scrollViewController.view.backgroundColor = [UIColor systemBackgroundColor];
UIViewController *scrollViewController = [[UIViewController alloc] init];
scrollViewController.title = @"Printer Feed";
if (@available(iOS 13.0, *)) {
scrollViewController.view.backgroundColor = [UIColor systemBackgroundColor];
}
else {
scrollViewController.view.backgroundColor = [UIColor whiteColor];
}
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:_scrollViewController.view.bounds];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewController.view.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.scrollEnabled = true;
scrollView.pagingEnabled = false;
scrollView.showsVerticalScrollIndicator = true;
scrollView.showsHorizontalScrollIndicator = false;
[_scrollViewController.view addSubview:scrollView];
[scrollViewController.view addSubview:scrollView];
CGSize size = image.size;
while (size.width < 320) {
@ -39,13 +44,13 @@
CGSize contentSize = size;
self.preferredContentSize = contentSize;
self = [self initWithRootViewController:_scrollViewController];
self = [self initWithRootViewController:scrollViewController];
UIBarButtonItem *close = [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain
target:self
action:@selector(dismissFromParent)];
[self.visibleViewController.navigationItem setLeftBarButtonItem:close];
[_scrollViewController setToolbarItems:@[
[scrollViewController setToolbarItems:@[
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(presentShareSheet)],
@ -61,24 +66,37 @@
return self;
}
- (UIView *)viewToMask
{
UIView *targetView = self.view;
while (targetView.superview != targetView.window &&
targetView.superview.superview != targetView.window){
targetView = targetView.superview;
}
return targetView;
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad) {
CGRect frame = self.view.frame;
UIView *targetView = self.view;
CGRect frame = targetView.frame;
frame.origin.x = ([UIScreen mainScreen].bounds.size.width - 320) / 2;
frame.size.width = 320;
self.view.frame = frame;
targetView.frame = frame;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(frame.origin.x, 0,
320, 4096)
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(12.0, 12.0)];
cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
self.viewToMask.layer.mask = maskLayer;
self.view.layer.mask = maskLayer;
}
}
@ -86,7 +104,7 @@
{
NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"Game Boy Printer Image.png"]];
[UIImagePNGRepresentation(_image) writeToURL:url atomically:false];
[self presentViewController:[[UIActivityViewController alloc] initWithActivityItems:@[url]
[self presentViewController:[[GBActivityViewController alloc] initWithActivityItems:@[url]
applicationActivities:nil]
animated:true
completion:nil];

View File

@ -222,7 +222,8 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
GBTheme *theme = [GBSettingsViewController themeNamed:newValue];
_horizontalLayout = [[GBHorizontalLayout alloc] initWithTheme:theme];
_verticalLayout = [[GBVerticalLayout alloc] initWithTheme:theme];
_printerSpinner.color = theme.brandColor;
[self willRotateToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation
duration:0];
[_backgroundView reloadThemeImages];
@ -301,11 +302,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
}
_backCaptureDevices = filteredBackCameras;
UIEdgeInsets insets = self.window.safeAreaInsets;
_cameraPositionButton = [[UIButton alloc] initWithFrame:CGRectMake(insets.left + 8,
_backgroundView.bounds.size.height - 8 - insets.bottom - 32,
32,
32)];
_cameraPositionButton = [[UIButton alloc] init];
[self didRotateFromInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation];
if (@available(iOS 13.0, *)) {
[_cameraPositionButton setImage:[UIImage systemImageNamed:@"camera.rotate"
@ -314,10 +311,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
_cameraPositionButton.backgroundColor = [UIColor systemBackgroundColor];
// Configure the change camera button stacked on top of the camera position button
_changeCameraButton = [[UIButton alloc] initWithFrame:CGRectMake(insets.left + 8,
_backgroundView.bounds.size.height - 8 - insets.bottom - 32 - 32 - 8,
32,
32)];
_changeCameraButton = [[UIButton alloc] init];
[_changeCameraButton setImage:[UIImage systemImageNamed:@"camera.aperture"
withConfiguration:[UIImageSymbolConfiguration configurationWithScale:UIImageSymbolScaleLarge]]
forState:UIControlStateNormal];
@ -374,6 +368,8 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
_printerButton = [[UIButton alloc] init];
_printerSpinner = [[UIActivityIndicatorView alloc] init];
_printerSpinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
_printerSpinner.color = _verticalLayout.theme.brandColor;
[self didRotateFromInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation];
if (@available(iOS 13.0, *)) {
@ -873,13 +869,19 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIEdgeInsets insets = self.window.safeAreaInsets;
bool landscape = true;
if (_orientation == UIInterfaceOrientationPortrait || _orientation == UIInterfaceOrientationPortraitUpsideDown) {
landscape = false;
}
_cameraPositionButton.frame = CGRectMake(insets.left + 8,
_backgroundView.bounds.size.height - 8 - insets.bottom - 32,
32,
32);
if (_changeCameraButton) {
_changeCameraButton.frame = CGRectMake(insets.left + 8,
_backgroundView.bounds.size.height - 8 - insets.bottom - 32 - 32 - 8,
_changeCameraButton.frame = CGRectMake(insets.left + 8 + (landscape? (32 + 8) : 0 ),
_backgroundView.bounds.size.height - 8 - insets.bottom - 32 - (landscape? 0 : (32 + 8)),
32,
32);
}
@ -888,8 +890,8 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
32,
32);
_printerSpinner.frame = CGRectMake(_backgroundView.bounds.size.width - 8 - insets.right - 32,
_backgroundView.bounds.size.height - 8 - insets.bottom - 32 - 32 - 8,
_printerSpinner.frame = CGRectMake(_backgroundView.bounds.size.width - 8 - insets.right - 32 - (landscape? (32 + 4) : 0),
_backgroundView.bounds.size.height - 8 - insets.bottom - 32 - (landscape? 0 : (32 + 4)),
32,
32);
@ -1707,6 +1709,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
width:160
height:_currentPrinterImageData.length / 160 / sizeof(uint32_t)];
_window.backgroundColor = [UIColor blackColor];
[self presentViewController:[[GBPrinterFeedController alloc] initWithImage:image]
animated:true
completion:nil];