bsnes/Cocoa/AppDelegate.m

113 lines
5.1 KiB
Mathematica
Raw Normal View History

2016-03-30 20:07:55 +00:00
#import "AppDelegate.h"
#include "GBButtons.h"
2020-03-26 18:54:18 +00:00
#include "GBView.h"
2017-10-12 21:02:02 +00:00
#include <Core/gb.h>
#import <Carbon/Carbon.h>
#import <JoyKit/JoyKit.h>
2016-03-30 20:07:55 +00:00
@implementation AppDelegate
2016-04-13 19:43:16 +00:00
{
NSWindow *preferences_window;
2018-12-01 14:08:59 +00:00
NSArray<NSView *> *preferences_tabs;
2016-04-13 19:43:16 +00:00
}
- (void) applicationDidFinishLaunching:(NSNotification *)notification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
for (unsigned i = 0; i < GBButtonCount; i++) {
if ([[defaults objectForKey:button_to_preference_name(i, 0)] isKindOfClass:[NSString class]]) {
[defaults removeObjectForKey:button_to_preference_name(i, 0)];
}
}
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),
2018-12-01 15:16:50 +00:00
@"GBRewindLength": @(10),
2020-03-26 18:54:18 +00:00
@"GBFrameBlendingMode": @([defaults boolForKey:@"DisableFrameBlending"]? GB_FRAME_BLENDING_MODE_DISABLED : GB_FRAME_BLENDING_MODE_ACCURATE),
2018-12-01 15:16:50 +00:00
@"GBDMGModel": @(GB_MODEL_DMG_B),
@"GBCGBModel": @(GB_MODEL_CGB_E),
@"GBSGBModel": @(GB_MODEL_SGB2),
2020-04-29 13:50:31 +00:00
@"GBRumbleMode": @(GB_RUMBLE_CARTRIDGE_ONLY),
2016-04-13 19:43:16 +00:00
}];
[JOYController startOnRunLoop:[NSRunLoop currentRunLoop] withOptions:@{
JOYAxes2DEmulateButtonsKey: @YES,
JOYHatsEmulateButtonsKey: @YES,
}];
2020-05-23 11:50:54 +00:00
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"GBNotificationsUsed"]) {
[NSUserNotificationCenter defaultUserNotificationCenter].delegate = self;
}
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
}
2018-12-01 14:08:59 +00:00
- (IBAction)switchPreferencesTab:(id)sender
{
for (NSView *view in preferences_tabs) {
[view removeFromSuperview];
}
NSView *tab = preferences_tabs[[sender tag]];
NSRect old = [_preferencesWindow frame];
NSRect new = [_preferencesWindow frameRectForContentRect:tab.frame];
new.origin.x = old.origin.x;
new.origin.y = old.origin.y + (old.size.height - new.size.height);
[_preferencesWindow setFrame:new display:YES animate:_preferencesWindow.visible];
[_preferencesWindow.contentView addSubview:tab];
}
- (BOOL)validateMenuItem:(NSMenuItem *)anItem
{
if ([anItem action] == @selector(toggleDeveloperMode:)) {
2018-12-01 14:08:59 +00:00
[(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];
2018-12-01 14:08:59 +00:00
NSToolbarItem *first_toolbar_item = [_preferencesWindow.toolbar.items firstObject];
_preferencesWindow.toolbar.selectedItemIdentifier = [first_toolbar_item itemIdentifier];
preferences_tabs = @[self.emulationTab, self.graphicsTab, self.audioTab, self.controlsTab];
[self switchPreferencesTab:first_toolbar_item];
[_preferencesWindow center];
2016-04-13 19:43:16 +00:00
}
[_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
2020-05-23 11:50:54 +00:00
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfFile:notification.identifier display:YES];
}
2016-03-30 20:07:55 +00:00
@end