git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

SDL/open_dialog/cocoa.m

      1 #import <AppKit/AppKit.h>
      2 #include "open_dialog.h"
      3 
      4 char *do_open_rom_dialog(void)
      5 {
      6     @autoreleasepool {
      7         int stderr_fd = dup(STDERR_FILENO);
      8         close(STDERR_FILENO);
      9         NSWindow *key = [NSApp keyWindow];
     10         NSOpenPanel *dialog = [NSOpenPanel openPanel];
     11         dialog.title = @"Open ROM";
     12         dialog.allowedFileTypes = @[@"gb", @"gbc", @"sgb", @"isx"];
     13         if ([dialog runModal] != NSModalResponseOK) return nil;
     14         [key makeKeyAndOrderFront:nil];
     15         NSString *ret = [[[dialog URLs] firstObject] path];
     16         dup2(stderr_fd, STDERR_FILENO);
     17         if (ret) {
     18             return strdup(ret.UTF8String);
     19         }
     20         return NULL;
     21     }
     22 }
     23 
     24 char *do_open_folder_dialog(void)
     25 {
     26     @autoreleasepool {
     27         int stderr_fd = dup(STDERR_FILENO);
     28         close(STDERR_FILENO);
     29         NSWindow *key = [NSApp keyWindow];
     30         NSOpenPanel *dialog = [NSOpenPanel openPanel];
     31         dialog.title = @"Select Boot ROMs Folder";
     32         dialog.canChooseDirectories = true;
     33         dialog.canChooseFiles = false;
     34         if ([dialog runModal] != NSModalResponseOK) return nil;
     35         [key makeKeyAndOrderFront:nil];
     36         NSString *ret = [[[dialog URLs] firstObject] path];
     37         dup2(stderr_fd, STDERR_FILENO);
     38         if (ret) {
     39             return strdup(ret.UTF8String);
     40         }
     41         return NULL;
     42     }
     43 }
     44 
     45 /* The Cocoa variant of this function isn't as fully featured as the GTK and Windows ones, as Mac users would use
     46    the fully featured Cocoa port of SameBoy anyway*/
     47 char *do_save_recording_dialog(unsigned frequency)
     48 {
     49     @autoreleasepool {
     50         int stderr_fd = dup(STDERR_FILENO);
     51         close(STDERR_FILENO);
     52         NSWindow *key = [NSApp keyWindow];
     53         NSSavePanel *dialog = [NSSavePanel savePanel];
     54         dialog.title = @"Audio recording save location";
     55         dialog.allowedFileTypes = @[@"aiff", @"aif", @"aifc", @"wav", @"raw", @"pcm"];
     56         if ([dialog runModal] != NSModalResponseOK) return nil;
     57         [key makeKeyAndOrderFront:nil];
     58         NSString *ret = [[dialog URL] path];
     59         dup2(stderr_fd, STDERR_FILENO);
     60         if (ret) {
     61             return strdup(ret.UTF8String);
     62         }
     63         return NULL;
     64     }
     65 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.