SameBoy/Cocoa/AppDelegate.m

96 lines
4.2 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;
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)] 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),
2018-12-01 15:16:50 +00:00
@"GBRewindLength": @(10),
@"GBDMGModel": @(GB_MODEL_DMG_B),
@"GBCGBModel": @(GB_MODEL_CGB_E),
@"GBSGBModel": @(GB_MODEL_SGB2),
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
2016-03-30 20:07:55 +00:00
@end