SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
iOS/GBVerticalLayout.m
1 #define GBLayoutInternal
2 #import "GBVerticalLayout.h"
3
4 @implementation GBVerticalLayout
5
6 - (instancetype)initWithTheme:(GBTheme *)theme
7 {
8 self = [super initWithTheme:theme];
9 if (!self) return nil;
10
11 CGSize resolution = self.resolution;
12
13 CGRect screenRect = {0,};
14 screenRect.size.width = self.hasFractionalPixels? resolution.width : floor(resolution.width / 160) * 160;
15 screenRect.size.height = screenRect.size.width / 160 * 144;
16
17 screenRect.origin.x = (resolution.width - screenRect.size.width) / 2;
18 screenRect.origin.y = (resolution.height - screenRect.size.height) / 2;
19 self.fullScreenRect = screenRect;
20
21 double screenBorderWidth = MIN(screenRect.size.width / 40, 16 * self.factor);
22 screenRect.origin.y = self.minY + MIN(screenBorderWidth * 2, 20 * self.factor);
23 self.screenRect = screenRect;
24
25 double controlAreaStart = screenRect.origin.y + screenRect.size.height + MIN(screenBorderWidth * 2, 20 * self.factor);
26
27 self.selectLocation = (CGPoint){
28 MIN(resolution.width / 4, 120 * self.factor),
29 MIN(resolution.height - 80 * self.factor, (resolution.height - controlAreaStart) * 0.75 + controlAreaStart)
30 };
31
32 self.startLocation = (CGPoint){
33 resolution.width - self.selectLocation.x,
34 self.selectLocation.y
35 };
36
37 double buttonRadius = 36 * self.factor;
38 CGSize buttonsDelta = [self buttonDeltaForMaxHorizontalDistance:resolution.width / 2 - buttonRadius * 2 - screenBorderWidth * 2];
39
40 self.dpadLocation = (CGPoint) {
41 self.selectLocation.x,
42 self.selectLocation.y - 140 * self.factor
43 };
44
45 CGPoint buttonsCenter = {
46 resolution.width - self.dpadLocation.x,
47 self.dpadLocation.y,
48 };
49
50 self.aLocation = (CGPoint) {
51 round(buttonsCenter.x + buttonsDelta.width / 2),
52 round(buttonsCenter.y - buttonsDelta.height / 2)
53 };
54
55 self.bLocation = (CGPoint) {
56 round(buttonsCenter.x - buttonsDelta.width / 2),
57 round(buttonsCenter.y + buttonsDelta.height / 2)
58 };
59
60 self.abComboLocation = buttonsCenter;
61
62 double controlsTop = self.dpadLocation.y - 80 * self.factor;
63 double middleSpace = self.bLocation.x - buttonRadius - (self.dpadLocation.x + 80 * self.factor);
64
65 if (theme.renderingPreview) {
66 UIGraphicsBeginImageContextWithOptions((CGSize){resolution.width / 8, resolution.height / 8}, true, 1);
67 CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1 / 8.0, 1 / 8.0);
68 }
69 else {
70 UIGraphicsBeginImageContextWithOptions(resolution, true, 1);
71 }
72 [self drawBackground];
73 [self drawScreenBezels];
74
75 [self drawThemedLabelsWithBlock:^{
76 if (controlsTop - controlAreaStart > 24 * self.factor + screenBorderWidth * 2) {
77 [self drawLogoInVerticalRange:(NSRange){controlAreaStart + screenBorderWidth, 24 * self.factor}
78 controlPadding:0];
79 }
80 else if (middleSpace > 160 * self.factor) {
81 [self drawLogoInVerticalRange:(NSRange){controlAreaStart + screenBorderWidth, 24 * self.factor}
82 controlPadding:self.dpadLocation.x * 2];
83 }
84
85 [self drawLabels];
86 }];
87
88 self.background = UIGraphicsGetImageFromCurrentImageContext();
89 UIGraphicsEndImageContext();
90 return self;
91 }
92
93 @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.