From 5d84ee250ee5976281baa76fd750e4e999582e3a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 15 Aug 2017 21:59:53 +0300 Subject: [PATCH] Added Cocoa GUI for the High-Pass filter selection --- Cocoa/AppDelegate.m | 2 + Cocoa/Document.m | 13 +++++++ Cocoa/GBPreferencesWindow.h | 1 + Cocoa/GBPreferencesWindow.m | 21 ++++++++++- Cocoa/Preferences.xib | 75 +++++++++++++++++++++++++++---------- 5 files changed, 92 insertions(+), 20 deletions(-) diff --git a/Cocoa/AppDelegate.m b/Cocoa/AppDelegate.m index 7a69b56..c1fc504 100644 --- a/Cocoa/AppDelegate.m +++ b/Cocoa/AppDelegate.m @@ -1,5 +1,6 @@ #import "AppDelegate.h" #include "GBButtons.h" +#include "gb.h" #import @implementation AppDelegate @@ -29,6 +30,7 @@ @"GBTurbo": @(kVK_Space), @"GBFilter": @"NearestNeighbor", + @"GBHighpassFilter": @(GB_HIGHPASS_REMOVE_DC_OFFSET), }]; } diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 5ed7673..ffcf870 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -148,6 +148,7 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height, GB_set_rgb_encode_callback(&gb, rgbEncode); GB_set_camera_get_pixel_callback(&gb, cameraGetPixel); GB_set_camera_update_request_callback(&gb, cameraRequestUpdate); + GB_set_highpass_filter_mode(&gb, (GB_highpass_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBHighpassFilter"]); [self loadROM]; } @@ -292,6 +293,11 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height, [titleView addSubview: self.feedSaveButton]; self.feedSaveButton.frame = (NSRect){{268, 2}, {48, 17}}; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(updateHighpassFilter) + name:@"GBHighpassFilterChanged" + object:nil]; + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateDMG"]) { [self initDMG]; } @@ -1265,4 +1271,11 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height, }]; } +- (void) updateHighpassFilter +{ + if (GB_is_inited(&gb)) { + GB_set_highpass_filter_mode(&gb, (GB_highpass_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBHighpassFilter"]); + } +} + @end diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h index f4f3c6b..c8f3191 100644 --- a/Cocoa/GBPreferencesWindow.h +++ b/Cocoa/GBPreferencesWindow.h @@ -4,4 +4,5 @@ @property IBOutlet NSTableView *controlsTableView; @property IBOutlet NSPopUpButton *graphicsFilterPopupButton; @property (strong) IBOutlet NSButton *aspectRatioCheckbox; +@property (strong) IBOutlet NSPopUpButton *highpassFilterPopupButton; @end diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m index 689e600..38b4f3b 100644 --- a/Cocoa/GBPreferencesWindow.m +++ b/Cocoa/GBPreferencesWindow.m @@ -9,6 +9,7 @@ NSInteger button_being_modified; NSPopUpButton *_graphicsFilterPopupButton; + NSPopUpButton *_highpassFilterPopupButton; NSButton *_aspectRatioCheckbox; } @@ -46,6 +47,17 @@ [_graphicsFilterPopupButton selectItemAtIndex:[[[self class] filterList] indexOfObject:filter]]; } +- (NSPopUpButton *)highpassFilterPopupButton +{ + return _highpassFilterPopupButton; +} + +- (void)setHighpassFilterPopupButton:(NSPopUpButton *)highpassFilterPopupButton +{ + _highpassFilterPopupButton = highpassFilterPopupButton; + [_highpassFilterPopupButton selectItemAtIndex:[[[NSUserDefaults standardUserDefaults] objectForKey:@"GBHighpassFilter"] unsignedIntegerValue]]; +} + - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { return GBButtonCount; @@ -94,14 +106,21 @@ [self.controlsTableView reloadData]; [self makeFirstResponder:self.controlsTableView]; } + - (IBAction)graphicFilterChanged:(NSPopUpButton *)sender { - [[NSUserDefaults standardUserDefaults] setObject:[[self class] filterList][[sender indexOfSelectedItem]] forKey:@"GBFilter"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"GBFilterChanged" object:nil]; } +- (IBAction)highpassFilterChanged:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem]) + forKey:@"GBHighpassFilter"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"GBHighpassFilterChanged" object:nil]; +} + - (IBAction)changeAspectRatio:(id)sender { [[NSUserDefaults standardUserDefaults] setBool: [(NSButton *)sender state] != NSOnState diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib index a932646..61ce4ce 100644 --- a/Cocoa/Preferences.xib +++ b/Cocoa/Preferences.xib @@ -1,7 +1,9 @@ - - + + - + + + @@ -15,22 +17,15 @@ - + - + - - - - - - - - - - + + + @@ -38,7 +33,8 @@ - + + @@ -70,8 +66,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -129,7 +165,7 @@