2016-03-30 20:07:55 +00:00
|
|
|
#import "AppDelegate.h"
|
2017-01-24 19:00:56 +00:00
|
|
|
#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>
|
2017-01-24 19:00:56 +00:00
|
|
|
#import <Carbon/Carbon.h>
|
2019-10-19 16:26:04 +00:00
|
|
|
#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
|
|
|
|
{
|
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),
|
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
|
|
|
}];
|
2019-10-19 16:26:04 +00:00
|
|
|
|
|
|
|
[JOYController startOnRunLoop:[NSRunLoop currentRunLoop] withOptions:@{
|
|
|
|
JOYAxes2DEmulateButtonsKey: @YES,
|
|
|
|
JOYHatsEmulateButtonsKey: @YES,
|
|
|
|
}];
|
2020-05-23 11:50:54 +00:00
|
|
|
|
2020-08-21 21:56:12 +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
|
|
|
|
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
|
|
|
}
|
2020-11-13 21:07:35 +00:00
|
|
|
|
|
|
|
if (anItem == self.linkCableMenuItem) {
|
|
|
|
return [[NSDocumentController sharedDocumentController] documents].count > 1;
|
|
|
|
}
|
2016-04-13 19:43:16 +00:00
|
|
|
return true;
|
2016-03-30 20:07:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 21:07:35 +00:00
|
|
|
- (void)menuNeedsUpdate:(NSMenu *)menu
|
|
|
|
{
|
|
|
|
NSMutableArray *items = [NSMutableArray array];
|
|
|
|
NSDocument *currentDocument = [[NSDocumentController sharedDocumentController] currentDocument];
|
|
|
|
|
|
|
|
for (NSDocument *document in [[NSDocumentController sharedDocumentController] documents]) {
|
|
|
|
if (document == currentDocument) continue;
|
|
|
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:document.displayName action:@selector(connectLinkCable:) keyEquivalent:@""];
|
|
|
|
item.representedObject = document;
|
|
|
|
item.image = [[NSWorkspace sharedWorkspace] iconForFile:document.fileURL.path];
|
|
|
|
[item.image setSize:NSMakeSize(16, 16)];
|
|
|
|
[items addObject:item];
|
|
|
|
}
|
|
|
|
menu.itemArray = items;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-02-25 15:12:01 +00:00
|
|
|
/* Bring an existing panel to the foreground */
|
|
|
|
for (NSWindow *window in [[NSApplication sharedApplication] windows]) {
|
|
|
|
if ([window isKindOfClass:[NSOpenPanel class]]) {
|
|
|
|
[(NSOpenPanel *)window makeKeyAndOrderFront:nil];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-01 21:10:09 +00:00
|
|
|
[[NSDocumentController sharedDocumentController] openDocument:self];
|
2021-02-25 15:12:01 +00:00
|
|
|
return true;
|
2016-09-10 16:46:42 +00:00
|
|
|
}
|
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];
|
|
|
|
}
|
2020-11-13 21:07:35 +00:00
|
|
|
|
|
|
|
- (IBAction)nop:(id)sender
|
|
|
|
{
|
|
|
|
}
|
2016-03-30 20:07:55 +00:00
|
|
|
@end
|