add settings to choose display scaling filter

resolves #23
This commit is contained in:
Jesús A. Álvarez 2017-11-30 20:09:08 +01:00
parent 838f7b241e
commit 6d5d57787b
4 changed files with 76 additions and 9 deletions

View File

@ -59,7 +59,8 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
@"machine": @"MacPlus4M",
@"speedValue": @(sharedEmulator.initialSpeed),
@"runInBackground": @NO,
@"autoSlow": @(sharedEmulator.initialAutoSlow)
@"autoSlow": @(sharedEmulator.initialAutoSlow),
@"screenFilter": kCAFilterLinear
};
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

View File

@ -61,8 +61,8 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="3" translatesAutoresizingMaskIntoConstraints="NO" id="gQ6-2l-dni">
<rect key="frame" x="8" y="8" width="584" height="29"/>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="3" translatesAutoresizingMaskIntoConstraints="NO" id="gQ6-2l-dni">
<rect key="frame" x="16" y="11" width="343" height="29"/>
<segments>
<segment title="1x"/>
<segment title="2x"/>
@ -91,10 +91,10 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="jgK-lW-V9w">
<rect key="frame" x="178" y="7" width="244" height="29"/>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="jgK-lW-V9w">
<rect key="frame" x="65.666666666666686" y="7" width="244" height="29"/>
<constraints>
<constraint firstAttribute="width" constant="244" id="5ej-m2-BJ6"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="244" id="5ej-m2-BJ6"/>
</constraints>
<segments>
<segment title="Touchscreen"/>
@ -108,6 +108,8 @@
<constraints>
<constraint firstItem="jgK-lW-V9w" firstAttribute="centerY" secondItem="iUk-se-WGk" secondAttribute="centerY" id="h3J-dj-xrn"/>
<constraint firstItem="jgK-lW-V9w" firstAttribute="centerX" secondItem="iUk-se-WGk" secondAttribute="centerX" id="jma-Qa-lXw"/>
<constraint firstItem="jgK-lW-V9w" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="iUk-se-WGk" secondAttribute="leadingMargin" id="nfl-WM-x5W"/>
<constraint firstAttribute="trailingMargin" relation="greaterThanOrEqual" secondItem="jgK-lW-V9w" secondAttribute="trailing" id="ukC-5e-F8T"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
@ -153,9 +155,35 @@
</tableViewCellContentView>
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="about" textLabel="YWX-qF-gPj" detailTextLabel="xr3-v1-hzM" style="IBUITableViewCellStyleValue1" id="Mon-vq-IrO">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="display" id="P6n-Bf-s6h">
<rect key="frame" x="0.0" y="231.33333333333334" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="P6n-Bf-s6h" id="NgN-Fe-hXo">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="aS2-J4-gUP">
<rect key="frame" x="16" y="7" width="343" height="29"/>
<segments>
<segment title="Nearest"/>
<segment title="Linear"/>
<segment title="Trilinear"/>
</segments>
<connections>
<action selector="changeScreenScaling:" destination="WUA-f8-k8g" eventType="valueChanged" id="DAu-Xq-RX5"/>
</connections>
</segmentedControl>
</subviews>
<constraints>
<constraint firstItem="aS2-J4-gUP" firstAttribute="leading" secondItem="NgN-Fe-hXo" secondAttribute="leadingMargin" id="5XQ-sf-kkg"/>
<constraint firstItem="aS2-J4-gUP" firstAttribute="centerY" secondItem="NgN-Fe-hXo" secondAttribute="centerY" id="Kcr-hh-DwN"/>
<constraint firstAttribute="trailingMargin" secondItem="aS2-J4-gUP" secondAttribute="trailing" id="dCR-FP-Zgm"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="about" textLabel="YWX-qF-gPj" detailTextLabel="xr3-v1-hzM" style="IBUITableViewCellStyleValue1" id="Mon-vq-IrO">
<rect key="frame" x="0.0" y="275.33333333333337" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Mon-vq-IrO" id="mGZ-Jb-6j4">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
@ -178,7 +206,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="toggle" textLabel="a1l-XI-MEz" style="IBUITableViewCellStyleDefault" id="1nB-54-Qfk">
<rect key="frame" x="0.0" y="275.33333333333337" width="375" height="44"/>
<rect key="frame" x="0.0" y="319.33333333333337" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1nB-54-Qfk" id="fZu-5X-Z4B">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666666666666664"/>

View File

@ -23,6 +23,9 @@ static ScreenView *sharedScreenView = nil;
[super awakeFromNib];
sharedScreenView = self;
videoLayer = [CALayer layer];
NSString *screenFilter = [[NSUserDefaults standardUserDefaults] stringForKey:@"screenFilter"];
videoLayer.magnificationFilter = screenFilter;
videoLayer.minificationFilter = screenFilter;
[AppDelegate sharedEmulator].screenLayer = videoLayer;
if ([AppDelegate sharedEmulator]) {
screenSize = [AppDelegate sharedEmulator].screenSize;
@ -30,6 +33,7 @@ static ScreenView *sharedScreenView = nil;
screenSize = CGSizeMake(1, 1);
}
[self.layer addSublayer:videoLayer];
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"screenFilter" options:NSKeyValueObservingOptionNew context:NULL];
}
+ (instancetype)sharedScreenView {
@ -54,4 +58,17 @@ static ScreenView *sharedScreenView = nil;
videoLayer.frame = screenBounds;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([object isEqual:[NSUserDefaults standardUserDefaults]]) {
if ([keyPath isEqualToString:@"screenFilter"]) {
NSString *value = change[NSKeyValueChangeNewKey];
videoLayer.magnificationFilter = value;
videoLayer.minificationFilter = value;
}
}
}
- (void)dealloc {
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"screenFilter" context:NULL];
}
@end

View File

@ -17,6 +17,7 @@ typedef enum : NSInteger {
SettingsSectionSpeed,
SettingsSectionMouse,
SettingsSectionKeyboard,
SettingsSectionDisplay,
SettingsSectionMachine,
SettingsSectionAbout
} SettingsSection;
@ -122,6 +123,13 @@ typedef enum : NSInteger {
}
}
- (IBAction)changeScreenScaling:(UISegmentedControl*)sender {
if ([sender isKindOfClass:[UISegmentedControl class]]) {
NSString *filter = @[kCAFilterNearest, kCAFilterLinear, kCAFilterTrilinear][sender.selectedSegmentIndex];
[[NSUserDefaults standardUserDefaults] setObject:filter forKey:@"screenFilter"];
}
}
- (void)changeRunInBackground:(UISwitch*)sender {
if ([sender isKindOfClass:[UISwitch class]]) {
[[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"runInBackground"];
@ -137,7 +145,7 @@ typedef enum : NSInteger {
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 5;
return 6;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@ -168,6 +176,8 @@ typedef enum : NSInteger {
return NSLocalizedString(@"Emulated Machine", nil);
case SettingsSectionKeyboard:
return NSLocalizedString(@"Keyboard Layout", nil);
case SettingsSectionDisplay:
return NSLocalizedString(@"Display Scaling", nil);
case SettingsSectionAbout:
return aboutTitle;
default:return nil;
@ -268,6 +278,17 @@ typedef enum : NSInteger {
cell.detailTextLabel.text = detailText;
}
cell.accessoryType = item[@"link"] == nil ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator;
} else if (section == SettingsSectionDisplay) {
cell = [tableView dequeueReusableCellWithIdentifier:@"display" forIndexPath:indexPath];
UISegmentedControl *filterControl = (UISegmentedControl*)[cell viewWithTag:128];
NSString *filter = [defaults stringForKey:@"screenFilter"];
if ([filter isEqualToString:kCAFilterNearest]) {
filterControl.selectedSegmentIndex = 0;
} else if ([filter isEqualToString:kCAFilterTrilinear]) {
filterControl.selectedSegmentIndex = 2;
} else {
filterControl.selectedSegmentIndex = 1;
}
}
return cell;
}