SameBoy/Cocoa/AppDelegate.m

72 lines
2.9 KiB
Mathematica
Raw Normal View History

2016-03-30 20:07:55 +00:00
#import "AppDelegate.h"
#include "GBButtons.h"
2017-10-12 21:02:02 +00:00
#include <Core/gb.h>
#import <Carbon/Carbon.h>
2016-03-30 20:07:55 +00:00
@implementation AppDelegate
2016-04-13 19:43:16 +00:00
{
NSWindow *preferences_window;
}
- (void) applicationDidFinishLaunching:(NSNotification *)notification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
for (unsigned i = 0; i < GBButtonCount; i++) {
if ([[defaults objectForKey:button_to_preference_name(i)] isKindOfClass:[NSString class]]) {
[defaults removeObjectForKey:button_to_preference_name(i)];
}
}
2016-04-13 19:43:16 +00:00
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
@"GBRight": @(kVK_RightArrow),
@"GBLeft": @(kVK_LeftArrow),
@"GBUp": @(kVK_UpArrow),
@"GBDown": @(kVK_DownArrow),
2016-04-13 19:43:16 +00:00
@"GBA": @(kVK_ANSI_X),
@"GBB": @(kVK_ANSI_Z),
@"GBSelect": @(kVK_Delete),
@"GBStart": @(kVK_Return),
2016-04-13 19:43:16 +00:00
@"GBTurbo": @(kVK_Space),
@"GBRewind": @(kVK_Tab),
@"GBSlow-Motion": @(kVK_Shift),
@"GBFilter": @"NearestNeighbor",
@"GBColorCorrection": @(GB_COLOR_CORRECTION_EMULATE_HARDWARE),
@"GBHighpassFilter": @(GB_HIGHPASS_REMOVE_DC_OFFSET),
@"GBRewindLength": @(10)
2016-04-13 19:43:16 +00:00
}];
}
2016-03-30 20:07:55 +00:00
- (IBAction)toggleDeveloperMode:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:![defaults boolForKey:@"DeveloperMode"] forKey:@"DeveloperMode"];
2016-03-30 20:07:55 +00:00
}
- (BOOL)validateMenuItem:(NSMenuItem *)anItem
{
if ([anItem action] == @selector(toggleDeveloperMode:)) {
[(NSMenuItem*)anItem setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"DeveloperMode"]];
}
2016-04-13 19:43:16 +00:00
return true;
2016-03-30 20:07:55 +00:00
}
2016-04-13 19:43:16 +00:00
- (IBAction) showPreferences: (id) sender
{
NSArray *objects;
if (!_preferencesWindow) {
[[NSBundle mainBundle] loadNibNamed:@"Preferences" owner:self topLevelObjects:&objects];
}
[_preferencesWindow makeKeyAndOrderFront:self];
}
2016-10-01 21:10:09 +00:00
- (BOOL)applicationOpenUntitledFile:(NSApplication *)sender
{
2016-10-01 21:10:09 +00:00
[[NSDocumentController sharedDocumentController] openDocument:self];
return YES;
}
2016-10-01 21:10:09 +00:00
2016-03-30 20:07:55 +00:00
@end