SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
iOS/GBThemesViewController.m
1 #import "GBThemesViewController.h"
2 #import "GBThemePreviewController.h"
3 #import "GBTheme.h"
4
5 @interface GBThemesViewController ()
6
7 @end
8
9 @implementation GBThemesViewController
10 {
11 NSArray<NSArray<GBTheme *> *> *_themes;
12 }
13
14 + (NSArray<NSArray<GBTheme *> *> *)themes
15 {
16 static __weak NSArray<NSArray<GBTheme *> *> *cache = nil;
17 if (cache) return cache;
18 id ret = @[
19 @[
20 [[GBTheme alloc] initDefaultTheme],
21 [[GBTheme alloc] initDarkTheme],
22 ],
23 ];
24 cache = ret;
25 return ret;
26 }
27
28 - (void)viewDidLoad
29 {
30 [super viewDidLoad];
31
32 _themes = [[self class] themes];
33 }
34
35 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
36 {
37 return _themes.count;
38 }
39
40 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
41 {
42 return _themes[section].count;
43 }
44
45 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
46 {
47 return 60;
48 }
49
50 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
51 {
52
53 UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
54 GBTheme *theme = _themes[indexPath.section][indexPath.row];
55 cell.textLabel.text = theme.name;
56
57 cell.accessoryType = [[[NSUserDefaults standardUserDefaults] stringForKey:@"GBInterfaceTheme"] isEqual:theme.name]? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
58 bool horizontal = self.interfaceOrientation >= UIInterfaceOrientationLandscapeRight;
59 UIImage *preview = horizontal? [theme horizontalPreview] : [theme verticalPreview];
60 UIGraphicsBeginImageContextWithOptions((CGSize){60, 60}, false, self.view.window.screen.scale);
61 unsigned width = 60;
62 unsigned height = 56;
63 if (horizontal) {
64 height = round(preview.size.height / preview.size.width * 60);
65 }
66 else {
67 width = round(preview.size.width / preview.size.height * 56);
68 }
69 UIBezierPath *mask = [UIBezierPath bezierPathWithRoundedRect:CGRectMake((60 - width) / 2, (60 - height) / 2, width, height) cornerRadius:4];
70 [mask addClip];
71 [preview drawInRect:mask.bounds];
72 if (@available(iOS 13.0, *)) {
73 [[UIColor tertiaryLabelColor] set];
74 }
75 else {
76 [[UIColor colorWithWhite:0 alpha:0.5] set];
77 }
78 [mask stroke];
79 cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
80 UIGraphicsEndImageContext();
81
82
83 return cell;
84 }
85
86 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
87 {
88 [self.tableView reloadData];
89 [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
90 }
91
92 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
93 {
94 GBTheme *theme = _themes[indexPath.section][indexPath.row];
95 GBThemePreviewController *preview = [[GBThemePreviewController alloc] initWithTheme:theme];
96 [self presentViewController:preview animated:true completion:nil];
97 }
98
99 - (void)viewWillAppear:(BOOL)animated
100 {
101 [self.tableView reloadData];
102 [super viewWillAppear:animated];
103 }
104
105 @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.