2016-03-30 20:07:55 +00:00
|
|
|
#import "AppDelegate.h"
|
2017-01-24 19:00:56 +00:00
|
|
|
#include "GBButtons.h"
|
2017-10-12 21:02:02 +00:00
|
|
|
#include <Core/gb.h>
|
2017-01-24 19:00:56 +00:00
|
|
|
#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
|
|
|
|
{
|
2017-01-24 19:00:56 +00:00
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
for (unsigned i = 0; i < GBButtonCount; i++) {
|
2018-12-04 22:00:16 +00:00
|
|
|
if ([[defaults objectForKey:button_to_preference_name(i, 0)] isKindOfClass:[NSString class]]) {
|
|
|
|
[defaults removeObjectForKey:button_to_preference_name(i, 0)];
|
2017-01-24 19:00:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-13 19:43:16 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
|
2017-01-24 19:00:56 +00:00
|
|
|
@"GBRight": @(kVK_RightArrow),
|
|
|
|
@"GBLeft": @(kVK_LeftArrow),
|
|
|
|
@"GBUp": @(kVK_UpArrow),
|
|
|
|
@"GBDown": @(kVK_DownArrow),
|
2016-04-13 19:43:16 +00:00
|
|
|
|
2017-01-24 19:00:56 +00:00
|
|
|
@"GBA": @(kVK_ANSI_X),
|
|
|
|
@"GBB": @(kVK_ANSI_Z),
|
|
|
|
@"GBSelect": @(kVK_Delete),
|
|
|
|
@"GBStart": @(kVK_Return),
|
2016-04-13 19:43:16 +00:00
|
|
|
|
2017-01-24 19:00:56 +00:00
|
|
|
@"GBTurbo": @(kVK_Space),
|
2018-02-10 12:42:14 +00:00
|
|
|
@"GBRewind": @(kVK_Tab),
|
2018-02-10 21:30:30 +00:00
|
|
|
@"GBSlow-Motion": @(kVK_Shift),
|
2016-04-28 20:07:05 +00:00
|
|
|
|
|
|
|
@"GBFilter": @"NearestNeighbor",
|
2017-10-12 14:22:22 +00:00
|
|
|
@"GBColorCorrection": @(GB_COLOR_CORRECTION_EMULATE_HARDWARE),
|
2018-02-10 12:42:14 +00:00
|
|
|
@"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
|
|
|
|
2017-01-24 19:00:56 +00:00
|
|
|
- (IBAction)toggleDeveloperMode:(id)sender
|
|
|
|
{
|
2016-04-08 10:54:34 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2016-04-08 10:54:34 +00:00
|
|
|
- (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-08 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
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-09-10 16:46:42 +00:00
|
|
|
|
2016-10-01 21:10:09 +00:00
|
|
|
- (BOOL)applicationOpenUntitledFile:(NSApplication *)sender
|
2016-09-10 16:46:42 +00:00
|
|
|
{
|
2016-10-01 21:10:09 +00:00
|
|
|
[[NSDocumentController sharedDocumentController] openDocument:self];
|
|
|
|
return YES;
|
2016-09-10 16:46:42 +00:00
|
|
|
}
|
2016-10-01 21:10:09 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
@end
|