2016-04-13 19:43:16 +00:00
|
|
|
#import "GBPreferencesWindow.h"
|
|
|
|
#import "NSString+StringForKey.h"
|
|
|
|
#import "GBButtons.h"
|
2017-01-24 19:00:56 +00:00
|
|
|
#import <Carbon/Carbon.h>
|
2016-04-13 19:43:16 +00:00
|
|
|
|
|
|
|
@implementation GBPreferencesWindow
|
|
|
|
{
|
|
|
|
bool is_button_being_modified;
|
|
|
|
NSInteger button_being_modified;
|
2017-12-30 14:23:17 +00:00
|
|
|
signed joystick_configuration_state;
|
|
|
|
NSString *joystick_being_configured;
|
|
|
|
signed last_axis;
|
2016-04-28 20:07:05 +00:00
|
|
|
|
|
|
|
NSPopUpButton *_graphicsFilterPopupButton;
|
2017-08-15 18:59:53 +00:00
|
|
|
NSPopUpButton *_highpassFilterPopupButton;
|
2017-10-12 14:22:22 +00:00
|
|
|
NSPopUpButton *_colorCorrectionPopupButton;
|
2018-02-10 12:42:14 +00:00
|
|
|
NSPopUpButton *_rewindPopupButton;
|
2016-07-05 18:23:55 +00:00
|
|
|
NSButton *_aspectRatioCheckbox;
|
2016-04-28 20:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *)filterList
|
|
|
|
{
|
|
|
|
/* The filter list as ordered in the popup button */
|
|
|
|
static NSArray * filters = nil;
|
|
|
|
if (!filters) {
|
|
|
|
filters = @[
|
|
|
|
@"NearestNeighbor",
|
|
|
|
@"Bilinear",
|
|
|
|
@"SmoothBilinear",
|
|
|
|
@"Scale2x",
|
|
|
|
@"Scale4x",
|
|
|
|
@"AAScale2x",
|
|
|
|
@"AAScale4x",
|
2016-06-14 11:11:37 +00:00
|
|
|
@"HQ2x",
|
2016-06-08 21:06:55 +00:00
|
|
|
@"OmniScale",
|
2016-06-16 22:06:52 +00:00
|
|
|
@"OmniScaleLegacy",
|
|
|
|
@"AAOmniScaleLegacy",
|
2016-04-28 20:07:05 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
2017-12-30 14:23:17 +00:00
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
joystick_configuration_state = -1;
|
|
|
|
[self.configureJoypadButton setEnabled:YES];
|
|
|
|
[self.skipButton setEnabled:NO];
|
|
|
|
[self.configureJoypadButton setTitle:@"Configure Joypad"];
|
|
|
|
[super close];
|
|
|
|
}
|
|
|
|
|
2016-04-28 20:07:05 +00:00
|
|
|
- (NSPopUpButton *)graphicsFilterPopupButton
|
|
|
|
{
|
|
|
|
return _graphicsFilterPopupButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setGraphicsFilterPopupButton:(NSPopUpButton *)graphicsFilterPopupButton
|
|
|
|
{
|
|
|
|
_graphicsFilterPopupButton = graphicsFilterPopupButton;
|
|
|
|
NSString *filter = [[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"];
|
|
|
|
[_graphicsFilterPopupButton selectItemAtIndex:[[[self class] filterList] indexOfObject:filter]];
|
2016-04-13 19:43:16 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 18:59:53 +00:00
|
|
|
- (NSPopUpButton *)highpassFilterPopupButton
|
|
|
|
{
|
|
|
|
return _highpassFilterPopupButton;
|
|
|
|
}
|
|
|
|
|
2017-10-12 14:22:22 +00:00
|
|
|
- (void)setColorCorrectionPopupButton:(NSPopUpButton *)colorCorrectionPopupButton
|
|
|
|
{
|
|
|
|
_colorCorrectionPopupButton = colorCorrectionPopupButton;
|
|
|
|
NSInteger mode = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorCorrection"];
|
|
|
|
[_colorCorrectionPopupButton selectItemAtIndex:mode];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPopUpButton *)colorCorrectionPopupButton
|
|
|
|
{
|
|
|
|
return _colorCorrectionPopupButton;
|
|
|
|
}
|
|
|
|
|
2018-02-10 12:42:14 +00:00
|
|
|
- (void)setRewindPopupButton:(NSPopUpButton *)rewindPopupButton
|
|
|
|
{
|
|
|
|
_rewindPopupButton = rewindPopupButton;
|
|
|
|
NSInteger length = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBRewindLength"];
|
|
|
|
[_rewindPopupButton selectItemWithTag:length];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPopUpButton *)rewindPopupButton
|
|
|
|
{
|
|
|
|
return _rewindPopupButton;
|
|
|
|
}
|
|
|
|
|
2017-08-15 18:59:53 +00:00
|
|
|
- (void)setHighpassFilterPopupButton:(NSPopUpButton *)highpassFilterPopupButton
|
|
|
|
{
|
|
|
|
_highpassFilterPopupButton = highpassFilterPopupButton;
|
|
|
|
[_highpassFilterPopupButton selectItemAtIndex:[[[NSUserDefaults standardUserDefaults] objectForKey:@"GBHighpassFilter"] unsignedIntegerValue]];
|
|
|
|
}
|
|
|
|
|
2016-04-13 19:43:16 +00:00
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
|
|
|
|
{
|
|
|
|
return GBButtonCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
|
|
|
|
{
|
|
|
|
if ([tableColumn.identifier isEqualToString:@"keyName"]) {
|
|
|
|
return GBButtonNames[row];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_button_being_modified && button_being_modified == row) {
|
|
|
|
return @"Select a new key...";
|
|
|
|
}
|
|
|
|
|
2017-01-24 19:00:56 +00:00
|
|
|
return [NSString displayStringForKeyCode:[[NSUserDefaults standardUserDefaults] integerForKey:
|
2016-04-13 19:43:16 +00:00
|
|
|
button_to_preference_name(row)]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
|
|
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
is_button_being_modified = true;
|
|
|
|
button_being_modified = row;
|
|
|
|
tableView.enabled = NO;
|
|
|
|
[tableView reloadData];
|
|
|
|
[self makeFirstResponder:self];
|
|
|
|
});
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)keyDown:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
if (!is_button_being_modified) {
|
|
|
|
if (self.firstResponder != self.controlsTableView) {
|
|
|
|
[super keyDown:theEvent];
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_button_being_modified = false;
|
|
|
|
|
2017-01-24 19:00:56 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:theEvent.keyCode
|
2016-04-13 19:43:16 +00:00
|
|
|
forKey:button_to_preference_name(button_being_modified)];
|
|
|
|
self.controlsTableView.enabled = YES;
|
|
|
|
[self.controlsTableView reloadData];
|
|
|
|
[self makeFirstResponder:self.controlsTableView];
|
|
|
|
}
|
2017-08-15 18:59:53 +00:00
|
|
|
|
2016-04-28 20:07:05 +00:00
|
|
|
- (IBAction)graphicFilterChanged:(NSPopUpButton *)sender
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:[[self class] filterList][[sender indexOfSelectedItem]]
|
|
|
|
forKey:@"GBFilter"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"GBFilterChanged" object:nil];
|
|
|
|
}
|
2016-04-13 19:43:16 +00:00
|
|
|
|
2017-08-15 18:59:53 +00:00
|
|
|
- (IBAction)highpassFilterChanged:(id)sender
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem])
|
|
|
|
forKey:@"GBHighpassFilter"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"GBHighpassFilterChanged" object:nil];
|
|
|
|
}
|
|
|
|
|
2016-07-05 18:23:55 +00:00
|
|
|
- (IBAction)changeAspectRatio:(id)sender
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool: [(NSButton *)sender state] != NSOnState
|
|
|
|
forKey:@"GBAspectRatioUnkept"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"GBAspectChanged" object:nil];
|
|
|
|
}
|
|
|
|
|
2017-10-12 14:22:22 +00:00
|
|
|
- (IBAction)colorCorrectionChanged:(id)sender
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem])
|
|
|
|
forKey:@"GBColorCorrection"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"GBColorCorrectionChanged" object:nil];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-10 12:42:14 +00:00
|
|
|
- (IBAction)rewindLengthChanged:(id)sender
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:@([sender selectedTag])
|
|
|
|
forKey:@"GBRewindLength"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"GBRewindLengthChanged" object:nil];
|
|
|
|
}
|
|
|
|
|
2017-12-30 14:23:17 +00:00
|
|
|
- (IBAction) configureJoypad:(id)sender
|
|
|
|
{
|
|
|
|
[self.configureJoypadButton setEnabled:NO];
|
|
|
|
[self.skipButton setEnabled:YES];
|
|
|
|
joystick_being_configured = nil;
|
|
|
|
[self advanceConfigurationStateMachine];
|
|
|
|
last_axis = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) skipButton:(id)sender
|
|
|
|
{
|
|
|
|
[self advanceConfigurationStateMachine];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) advanceConfigurationStateMachine
|
|
|
|
{
|
|
|
|
joystick_configuration_state++;
|
|
|
|
if (joystick_configuration_state < GBButtonCount) {
|
|
|
|
[self.configureJoypadButton setTitle:[NSString stringWithFormat:@"Press Button for %@", GBButtonNames[joystick_configuration_state]]];
|
|
|
|
}
|
|
|
|
else if (joystick_configuration_state == GBButtonCount) {
|
|
|
|
[self.configureJoypadButton setTitle:@"Move the Analog Stick"];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
joystick_configuration_state = -1;
|
|
|
|
[self.configureJoypadButton setEnabled:YES];
|
|
|
|
[self.skipButton setEnabled:NO];
|
|
|
|
[self.configureJoypadButton setTitle:@"Configure Joypad"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) joystick:(NSString *)joystick_name button: (unsigned)button changedState: (bool) state
|
|
|
|
{
|
|
|
|
if (!state) return;
|
|
|
|
if (joystick_configuration_state == -1) return;
|
|
|
|
if (joystick_configuration_state == GBButtonCount) return;
|
|
|
|
if (!joystick_being_configured) {
|
|
|
|
joystick_being_configured = joystick_name;
|
|
|
|
}
|
|
|
|
else if (![joystick_being_configured isEqualToString:joystick_name]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *all_mappings = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"GBJoypadMappings"] mutableCopy];
|
|
|
|
|
|
|
|
if (!all_mappings) {
|
|
|
|
all_mappings = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *mapping = [[all_mappings objectForKey:joystick_name] mutableCopy];
|
|
|
|
|
|
|
|
if (!mapping) {
|
|
|
|
mapping = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
mapping[GBButtonNames[joystick_configuration_state]] = @(button);
|
|
|
|
|
|
|
|
all_mappings[joystick_name] = mapping;
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:all_mappings forKey:@"GBJoypadMappings"];
|
|
|
|
[self advanceConfigurationStateMachine];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) joystick:(NSString *)joystick_name axis: (unsigned)axis movedTo: (signed) value
|
|
|
|
{
|
|
|
|
if (abs(value) < 0x4000) return;
|
|
|
|
if (joystick_configuration_state != GBButtonCount) return;
|
|
|
|
if (!joystick_being_configured) {
|
|
|
|
joystick_being_configured = joystick_name;
|
|
|
|
}
|
|
|
|
else if (![joystick_being_configured isEqualToString:joystick_name]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_axis == -1) {
|
|
|
|
last_axis = axis;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (axis == last_axis) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *all_mappings = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"GBJoypadMappings"] mutableCopy];
|
|
|
|
|
|
|
|
if (!all_mappings) {
|
|
|
|
all_mappings = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *mapping = [[all_mappings objectForKey:joystick_name] mutableCopy];
|
|
|
|
|
|
|
|
if (!mapping) {
|
|
|
|
mapping = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
mapping[@"XAxis"] = @(MIN(axis, last_axis));
|
|
|
|
mapping[@"YAxis"] = @(MAX(axis, last_axis));
|
|
|
|
|
|
|
|
all_mappings[joystick_name] = mapping;
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:all_mappings forKey:@"GBJoypadMappings"];
|
|
|
|
[self advanceConfigurationStateMachine];
|
|
|
|
}
|
|
|
|
|
2016-07-05 18:23:55 +00:00
|
|
|
- (NSButton *)aspectRatioCheckbox
|
|
|
|
{
|
|
|
|
return _aspectRatioCheckbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAspectRatioCheckbox:(NSButton *)aspectRatioCheckbox
|
|
|
|
{
|
|
|
|
_aspectRatioCheckbox = aspectRatioCheckbox;
|
|
|
|
[_aspectRatioCheckbox setState: ![[NSUserDefaults standardUserDefaults] boolForKey:@"GBAspectRatioUnkept"]];
|
|
|
|
}
|
|
|
|
|
2017-01-24 19:00:56 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[super awakeFromNib];
|
|
|
|
[[NSDistributedNotificationCenter defaultCenter] addObserver:self.controlsTableView selector:@selector(reloadData) name:(NSString*)kTISNotifySelectedKeyboardInputSourceChanged object:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self.controlsTableView];
|
|
|
|
}
|
|
|
|
|
2016-04-13 19:43:16 +00:00
|
|
|
@end
|