From 6d5d57787b6af575e3aad6dddd1c1fcea77d263b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Thu, 30 Nov 2017 20:09:08 +0100 Subject: [PATCH] add settings to choose display scaling filter resolves #23 --- Mini vMac/AppDelegate.m | 3 +- Mini vMac/Base.lproj/Main.storyboard | 42 +++++++++++++++++++++++----- Mini vMac/ScreenView.m | 17 +++++++++++ Mini vMac/SettingsViewController.m | 23 ++++++++++++++- 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 3938487..112cca8 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -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]; diff --git a/Mini vMac/Base.lproj/Main.storyboard b/Mini vMac/Base.lproj/Main.storyboard index b164727..bd4ad34 100644 --- a/Mini vMac/Base.lproj/Main.storyboard +++ b/Mini vMac/Base.lproj/Main.storyboard @@ -61,8 +61,8 @@ - - + + @@ -91,10 +91,10 @@ - - + + - + @@ -108,6 +108,8 @@ + + @@ -153,9 +155,35 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -178,7 +206,7 @@ - + diff --git a/Mini vMac/ScreenView.m b/Mini vMac/ScreenView.m index 6d36491..fae8822 100644 --- a/Mini vMac/ScreenView.m +++ b/Mini vMac/ScreenView.m @@ -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 *)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 diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index 7919162..8edb8e7 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -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; }