VMConfigDisplayViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // Copyright © 2019 Halts. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #import "VMConfigDisplayViewController.h"
  17. #import "UTMConfiguration.h"
  18. @interface VMConfigDisplayViewController ()
  19. @end
  20. @implementation VMConfigDisplayViewController
  21. @synthesize configuration;
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. }
  25. - (void)refreshViewFromConfiguration {
  26. [super refreshViewFromConfiguration];
  27. self.consoleOnly = self.configuration.displayConsoleOnly;
  28. self.maxResolutionPickerActive = NO;
  29. self.maxResolutionLabel.text = self.maxResolution;
  30. self.resolutionFixedSwitch.on = self.configuration.displayFixedResolution;
  31. self.zoomScaleFitSwitch.on = self.configuration.displayZoomScale;
  32. self.zoomLetterboxSwitch.on = self.configuration.displayZoomLetterBox;
  33. }
  34. #pragma mark - Properties
  35. - (void)setMaxResolutionPickerActive:(BOOL)maxResolutionPickerActive {
  36. _maxResolutionPickerActive = maxResolutionPickerActive;
  37. if (maxResolutionPickerActive) {
  38. NSUInteger index = [[UTMConfiguration supportedResolutions] indexOfObject:self.maxResolution];
  39. if (index != NSNotFound) {
  40. [self.maxResolutionPicker selectRow:index inComponent:0 animated:NO];
  41. }
  42. }
  43. [self pickerCell:self.maxResolutionPickerCell setActive:maxResolutionPickerActive];
  44. }
  45. - (void)setConsoleOnly:(BOOL)consoleOnly {
  46. _consoleOnly = consoleOnly;
  47. self.configuration.displayConsoleOnly = consoleOnly;
  48. if (consoleOnly) {
  49. [self cells:self.displayTypeCells setHidden:YES];
  50. [self reloadDataAnimated:self.doneLoadingConfiguration];
  51. [self cells:self.consoleTypeCells setHidden:NO];
  52. [self reloadDataAnimated:self.doneLoadingConfiguration];
  53. [self.graphicsTypeFullCell setAccessoryType:UITableViewCellAccessoryNone];
  54. [self.graphicsTypeConsoleCell setAccessoryType:UITableViewCellAccessoryCheckmark];
  55. } else {
  56. [self cells:self.consoleTypeCells setHidden:YES];
  57. [self reloadDataAnimated:self.doneLoadingConfiguration];
  58. [self cells:self.displayTypeCellsWithoutPicker setHidden:NO];
  59. [self reloadDataAnimated:self.doneLoadingConfiguration];
  60. _maxResolutionPickerActive = NO; // reset picker
  61. [self.graphicsTypeFullCell setAccessoryType:UITableViewCellAccessoryCheckmark];
  62. [self.graphicsTypeConsoleCell setAccessoryType:UITableViewCellAccessoryNone];
  63. }
  64. }
  65. - (void)setMaxResolution:(NSString *)maxResolution {
  66. NSArray<NSString *> *parts = [maxResolution componentsSeparatedByString:@"x"];
  67. self.configuration.displayFixedResolutionWidth = [NSNumber numberWithLong:[parts[0] integerValue]];
  68. self.configuration.displayFixedResolutionHeight = [NSNumber numberWithLong:[parts[1] integerValue]];
  69. }
  70. - (NSString *)maxResolution {
  71. return [NSString stringWithFormat:@"%@x%@", self.configuration.displayFixedResolutionWidth, self.configuration.displayFixedResolutionHeight];
  72. }
  73. #pragma mark - Table delegate
  74. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  75. if ([tableView cellForRowAtIndexPath:indexPath] == self.graphicsTypeFullCell) {
  76. self.consoleOnly = NO;
  77. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  78. }
  79. if ([tableView cellForRowAtIndexPath:indexPath] == self.graphicsTypeConsoleCell) {
  80. self.consoleOnly = YES;
  81. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  82. }
  83. if ([tableView cellForRowAtIndexPath:indexPath] == self.maxResolutionCell) {
  84. self.maxResolutionPickerActive = !self.maxResolutionPickerActive;
  85. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  86. }
  87. }
  88. #pragma mark - Picker delegate
  89. - (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
  90. if (pickerView == self.maxResolutionPicker) {
  91. return 1;
  92. } else {
  93. NSAssert(0, @"Invalid picker");
  94. }
  95. return 0;
  96. }
  97. - (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  98. NSAssert(component == 0, @"Invalid component");
  99. if (pickerView == self.maxResolutionPicker) {
  100. return [UTMConfiguration supportedResolutions].count;
  101. } else {
  102. NSAssert(0, @"Invalid picker");
  103. }
  104. return 0;
  105. }
  106. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  107. NSAssert(component == 0, @"Invalid component");
  108. if (pickerView == self.maxResolutionPicker) {
  109. return [UTMConfiguration supportedResolutions][row];
  110. } else {
  111. NSAssert(0, @"Invalid picker");
  112. }
  113. return nil;
  114. }
  115. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  116. NSAssert(component == 0, @"Invalid component");
  117. if (pickerView == self.maxResolutionPicker) {
  118. self.maxResolutionLabel.text = [UTMConfiguration supportedResolutions][row];
  119. self.maxResolution = self.maxResolutionLabel.text;
  120. } else {
  121. NSAssert(0, @"Invalid picker");
  122. }
  123. }
  124. #pragma mark - Event handlers
  125. - (IBAction)resolutionFixedSwitchChanged:(UISwitch *)sender {
  126. NSAssert(sender == self.resolutionFixedSwitch, @"Invalid sender");
  127. self.configuration.displayFixedResolution = sender.on;
  128. }
  129. - (IBAction)zoomScaleFitSwitchChanged:(UISwitch *)sender {
  130. NSAssert(sender == self.zoomScaleFitSwitch, @"Invalid sender");
  131. self.configuration.displayZoomScale = sender.on;
  132. }
  133. - (IBAction)zoomLetterboxSwitchChanged:(UISwitch *)sender {
  134. NSAssert(sender == self.zoomLetterboxSwitch, @"Invalid sender");
  135. self.configuration.displayZoomLetterBox = sender.on;
  136. }
  137. @end