git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

iOS/GBAboutController.m

      1 #import "GBAboutController.h"
      2 
      3 @implementation GBAboutController
      4 {
      5     UILabel *_titleLabel;
      6     UILabel *_versionLabel;
      7     UIImageView *_logo;
      8     UITextView *_licenseView;
      9     UILabel *_copyrightLabel;
     10     UIView *_buttonsView;
     11 }
     12 
     13 - (UIImage *)buttonImageNamed:(NSString *)name
     14 {
     15     if (@available(iOS 13.0, *)) {
     16         return [UIImage systemImageNamed:name withConfiguration:[UIImageSymbolConfiguration configurationWithScale:UIImageSymbolScaleLarge]];
     17     }
     18     return nil;
     19 }
     20 
     21 - (void)alignButton:(UIButton *)button
     22 {
     23     if (!button.imageView.image) return;
     24     CGSize imageSize = button.imageView.frame.size;
     25     
     26     button.imageEdgeInsets = UIEdgeInsetsMake(0, (32 - imageSize.width) / 2, 0, 0);
     27     button.titleEdgeInsets = UIEdgeInsetsMake(0, 32 - imageSize.width, 0, 0);
     28 }
     29 
     30 - (void)viewDidLoad
     31 {
     32     [super viewDidLoad];
     33     UIVisualEffect *effect = [UIBlurEffect effectWithStyle:(UIBlurEffectStyle)UIBlurEffectStyleProminent];
     34     self.view = [[UIVisualEffectView alloc] initWithEffect:effect];
     35     UIView *root = ((UIVisualEffectView *)self.view).contentView;
     36     
     37     _titleLabel = [[UILabel alloc] init];
     38     _titleLabel.text = @"SameBoy";
     39     _titleLabel.font = [UIFont systemFontOfSize:34 weight:UIFontWeightHeavy];
     40     [root addSubview:_titleLabel];
     41 
     42     _versionLabel = [[UILabel alloc] init];
     43     _versionLabel.text = @"Version " GB_VERSION;
     44     _versionLabel.font = [UIFont systemFontOfSize:24 weight:UIFontWeightLight];
     45     [root addSubview:_versionLabel];
     46 
     47     _logo = [[UIImageView alloc] init];
     48     _logo.image = [UIImage imageNamed:@"logo"];
     49     _logo.contentMode = UIViewContentModeCenter;
     50     [root addSubview:_logo];
     51 
     52     _licenseView = [[UITextView alloc] init];
     53     NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"License" ofType:@"html"]];
     54     _licenseView.attributedText = [[NSAttributedString alloc] initWithData:data
     55                                                            options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
     56                                                                      NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
     57                                                 documentAttributes:nil
     58                                                              error:nil];
     59     _licenseView.editable = false;
     60     if (@available(iOS 13.0, *)) {
     61         _licenseView.backgroundColor = [UIColor systemBackgroundColor];
     62         _licenseView.textColor = [UIColor labelColor];
     63     }
     64     else {
     65         _licenseView.backgroundColor = [UIColor whiteColor];
     66     }
     67     _licenseView.hidden = true;
     68     _licenseView.userInteractionEnabled = false;
     69     _licenseView.layer.cornerRadius = 6;
     70     [root addSubview:_licenseView];
     71     
     72     _buttonsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
     73     
     74     UIButton *websiteButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 0, 280, 37)];
     75     [websiteButton setTitle:@"Website" forState:UIControlStateNormal];
     76     [websiteButton setImage:[self buttonImageNamed:@"globe"] forState:UIControlStateNormal];
     77     websiteButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
     78     [websiteButton setTitleColor:websiteButton.tintColor forState:UIControlStateNormal];
     79     websiteButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
     80     [websiteButton addTarget:self action:@selector(openWebsite) forControlEvents:UIControlEventTouchUpInside];
     81     [self alignButton:websiteButton];
     82     [_buttonsView addSubview:websiteButton];
     83     
     84     UIButton *sponsorButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 45, 280, 37)];
     85     [sponsorButton setTitle:@"Sponsor SameBoy" forState:UIControlStateNormal];
     86     [sponsorButton setImage:[self buttonImageNamed:@"heart"] forState:UIControlStateNormal];
     87     sponsorButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
     88     [sponsorButton setTitleColor:sponsorButton.tintColor forState:UIControlStateNormal];
     89     sponsorButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
     90     [sponsorButton addTarget:self action:@selector(openSponsor) forControlEvents:UIControlEventTouchUpInside];
     91     [self alignButton:sponsorButton];
     92     [_buttonsView addSubview:sponsorButton];
     93     
     94     UIButton *licenseButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 90, 280, 37)];
     95     [licenseButton setTitle:@"License" forState:UIControlStateNormal];
     96     [licenseButton setImage:[self buttonImageNamed:@"doc.plaintext"] forState:UIControlStateNormal];
     97     licenseButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
     98     licenseButton.titleLabel.textColor = licenseButton.tintColor;
     99     [licenseButton setTitleColor:licenseButton.tintColor forState:UIControlStateNormal];
    100     licenseButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    101     [licenseButton addTarget:self action:@selector(showLicense) forControlEvents:UIControlEventTouchUpInside];
    102     [self alignButton:licenseButton];
    103     [_buttonsView addSubview:licenseButton];
    104     
    105     [root addSubview:_buttonsView];
    106 
    107     _copyrightLabel = [[UILabel alloc] init];
    108     _copyrightLabel.text = [[NSBundle mainBundle] infoDictionary][@"NSHumanReadableCopyright"];
    109     _copyrightLabel.textAlignment = NSTextAlignmentCenter;
    110     _copyrightLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    111     _copyrightLabel.font = [UIFont systemFontOfSize:13];
    112     [root addSubview:_copyrightLabel];
    113     
    114     [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
    115                                                                             action:@selector(dismissSelf)]];
    116 }
    117 
    118 - (void)layoutForVerticalLayout
    119 {
    120     UIView *root = ((UIVisualEffectView *)self.view).contentView;
    121     CGRect savedFrame = root.frame;
    122     root.frame = CGRectMake(0, 0, 320, 480);
    123     
    124     _titleLabel.frame = CGRectMake(0, 20, 320, 47);
    125     _titleLabel.textAlignment = NSTextAlignmentCenter;
    126     _titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
    127     
    128     _versionLabel.frame = CGRectMake(0, 75, 320, 36);
    129     _versionLabel.textAlignment = NSTextAlignmentCenter;
    130     _versionLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
    131     
    132     _logo.frame = CGRectMake(0, 119, 320, 128);
    133     _logo.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
    134     
    135     _buttonsView.frame = CGRectMake(0, 255, 320, 176);
    136     _buttonsView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    137     
    138     _licenseView.frame = CGRectMake(20, 255, 280, 176);
    139     _licenseView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    140 
    141 
    142     _copyrightLabel.frame = CGRectMake(0, 450, 320, 21);
    143     _copyrightLabel.textAlignment = NSTextAlignmentCenter;
    144     _copyrightLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    145 
    146     root.frame = savedFrame;
    147 }
    148 
    149 - (void)layoutForHorizontalLayout
    150 {
    151     UIView *root = ((UIVisualEffectView *)self.view).contentView;
    152     CGRect savedFrame = root.frame;
    153     root.frame = CGRectMake(0, 0, 568, 320);
    154     
    155     _titleLabel.frame = CGRectMake(20, 20, 260, 47);
    156     _titleLabel.textAlignment = NSTextAlignmentLeft;
    157     _titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth |
    158                                    UIViewAutoresizingFlexibleBottomMargin |
    159                                    UIViewAutoresizingFlexibleRightMargin;
    160     
    161     _versionLabel.frame = CGRectMake(20, 75, 260, 36);
    162     _versionLabel.textAlignment = NSTextAlignmentLeft;
    163     _versionLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth |
    164                                      UIViewAutoresizingFlexibleBottomMargin |
    165                                      UIViewAutoresizingFlexibleRightMargin;
    166     
    167     _logo.frame = CGRectMake(0, 119, 284, 152);
    168     _logo.autoresizingMask = UIViewAutoresizingFlexibleWidth |
    169     UIViewAutoresizingFlexibleRightMargin |
    170     UIViewAutoresizingFlexibleHeight;
    171     
    172     _buttonsView.frame = _licenseView.frame = CGRectMake(284, 20, 284, 280);
    173     _buttonsView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
    174                                     UIViewAutoresizingFlexibleHeight |
    175                                     UIViewAutoresizingFlexibleLeftMargin;
    176     _licenseView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
    177                                     UIViewAutoresizingFlexibleHeight |
    178                                     UIViewAutoresizingFlexibleLeftMargin;
    179 
    180     
    181     _copyrightLabel.frame = CGRectMake(20, 288, 260, 21);
    182     _copyrightLabel.textAlignment = NSTextAlignmentLeft;
    183     _copyrightLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth |
    184                                        UIViewAutoresizingFlexibleTopMargin |
    185                                        UIViewAutoresizingFlexibleRightMargin;
    186 
    187     root.frame = savedFrame;
    188     CGRect licenseFrame = _licenseView.frame;
    189     licenseFrame.size.width -= 40;
    190     licenseFrame.origin.x += 20;
    191     _licenseView.frame = licenseFrame;
    192 }
    193 
    194 - (void)openWebsite
    195 {
    196     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://sameboy.github.io"] options:nil completionHandler:nil];
    197 }
    198 
    199 - (void)openSponsor
    200 {
    201     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://github.com/sponsors/LIJI32"] options:nil completionHandler:nil];
    202 }
    203 
    204 - (void)showLicense
    205 {
    206     _buttonsView.hidden = true;
    207     _licenseView.hidden = false;
    208     _licenseView.userInteractionEnabled = true;
    209 }
    210 
    211 - (void)viewDidLayoutSubviews
    212 {
    213     [super viewDidLayoutSubviews];
    214     if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad) {
    215         UIEdgeInsets insets = self.view.window.safeAreaInsets;
    216         UIView *view = ((UIVisualEffectView *)self.view).contentView;
    217         CGRect parentFrame = self.view.frame;
    218         view.frame = CGRectMake(insets.left,
    219                                 0,
    220                                 parentFrame.size.width - insets.left  - insets.right,
    221                                 parentFrame.size.height - insets.bottom);
    222     }
    223     if (self.view.frame.size.width > self.view.frame.size.height) {
    224         [self layoutForHorizontalLayout];
    225     }
    226     else {
    227         [self layoutForVerticalLayout];
    228     }
    229 }
    230      
    231 - (void)dismissSelf
    232 {
    233     [self.presentingViewController dismissViewControllerAnimated:true completion:nil];
    234 }
    235 
    236 - (UIModalPresentationStyle)modalPresentationStyle
    237 {
    238     return UIModalPresentationFormSheet;
    239 }
    240 
    241 - (void)dismissViewController
    242 {
    243     [self dismissViewControllerAnimated:true completion:nil];
    244 }
    245 @end

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.