diff --git a/Cocoa/Document.h b/Cocoa/Document.h
index b9ec66ed6..e1b19949d 100644
--- a/Cocoa/Document.h
+++ b/Cocoa/Document.h
@@ -89,5 +89,6 @@ enum model {
- (void) connectLinkCable:(NSMenuItem *)sender;
- (int)loadStateFile:(const char *)path noErrorOnNotFound:(bool)noErrorOnFileNotFound;
- (NSString *)captureOutputForBlock: (void (^)())block;
+- (NSFont *)debuggerFontOfSize:(unsigned)size;
@end
diff --git a/Cocoa/Document.m b/Cocoa/Document.m
index 284bd3b94..0d3f39a1b 100644
--- a/Cocoa/Document.m
+++ b/Cocoa/Document.m
@@ -337,6 +337,14 @@ - (void)initCommon
[self observeStandardDefaultsKey:@"GBRumbleMode" withBlock:^(NSNumber *value) {
GB_set_rumble_mode(gb, value.unsignedIntValue);
}];
+
+ [self observeStandardDefaultsKey:@"GBDebuggerFont" withBlock:^(NSString *value) {
+ [self updateFonts];
+ }];
+
+ [self observeStandardDefaultsKey:@"GBDebuggerFontSize" withBlock:^(NSString *value) {
+ [self updateFonts];
+ }];
}
- (void)updateMinSize
@@ -766,6 +774,65 @@ - (void)dealloc
}
}
+- (NSFont *)debuggerFontOfSize:(unsigned)size
+{
+ if (!size) {
+ size = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBDebuggerFontSize"];
+ }
+
+ bool retry = false;
+
+again:;
+ NSString *selectedFont = [[NSUserDefaults standardUserDefaults] stringForKey:@"GBDebuggerFont"];
+ if (@available(macOS 10.15, *)) {
+ if ([selectedFont isEqual:@"SF Mono"]) {
+ return [NSFont monospacedSystemFontOfSize:size weight:NSFontWeightRegular];
+ }
+ }
+
+ NSFont *ret = [NSFont fontWithName:selectedFont size:size];
+ if (ret) return ret;
+
+ if (retry) {
+ return [NSFont userFixedPitchFontOfSize:size];
+ }
+ [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"GBDebuggerFont"];
+ retry = true;
+ goto again;
+}
+
+
+- (void)updateFonts
+{
+ _hexController.font = [self debuggerFontOfSize:12];
+ [self.paletteView reloadData:self];
+ [self.objectView reloadData:self];
+
+ NSFont *newFont = [self debuggerFontOfSize:0];
+ NSFont *newBoldFont = [[NSFontManager sharedFontManager] convertFont:newFont toHaveTrait:NSBoldFontMask];
+ self.debuggerSideViewInput.font = newFont;
+ for (NSTextView *view in @[_debuggerSideView, _consoleOutput]) {
+ NSMutableAttributedString *newString = view.attributedString.mutableCopy;
+ [view.attributedString enumerateAttribute:NSFontAttributeName
+ inRange:NSMakeRange(0, view.attributedString.length)
+ options:0
+ usingBlock:^(NSFont *value, NSRange range, BOOL *stop) {
+ if ([[NSFontManager sharedFontManager] fontNamed:value.fontName hasTraits:NSBoldFontMask]) {
+ [newString addAttributes:@{
+ NSFontAttributeName: newBoldFont
+ } range:range];
+ }
+ else {
+ [newString addAttributes:@{
+ NSFontAttributeName: newFont
+ } range:range];
+ }
+ }];
+ [view.textStorage setAttributedString:newString];
+ }
+ [_consoleOutput scrollToEndOfDocument:nil];
+}
+
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
@@ -781,7 +848,7 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController
NSMutableParagraphStyle *paragraph_style = [[NSMutableParagraphStyle alloc] init];
[paragraph_style setLineSpacing:2];
- self.debuggerSideViewInput.font = [NSFont userFixedPitchFontOfSize:12];
+ self.debuggerSideViewInput.font = [self debuggerFontOfSize:0];
self.debuggerSideViewInput.textColor = [NSColor whiteColor];
self.debuggerSideViewInput.defaultParagraphStyle = paragraph_style;
[self.debuggerSideViewInput setString:@"registers\nbacktrace\n"];
@@ -907,9 +974,10 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController
}
}
-- (void) initMemoryView
+- (void)initMemoryView
{
_hexController = [[HFController alloc] init];
+ _hexController.font = [self debuggerFontOfSize:12];
[_hexController setBytesPerColumn:1];
[_hexController setEditMode:HFOverwriteMode];
@@ -953,6 +1021,16 @@ - (void) initMemoryView
[self.memoryView addSubview:layoutView];
self.memoryView = layoutView;
+ CGSize contentSize = _memoryWindow.contentView.frame.size;
+ while (_hexController.bytesPerLine < 16) {
+ contentSize.width += 4;
+ [_memoryWindow setContentSize:contentSize];
+ }
+ while (_hexController.bytesPerLine > 16) {
+ contentSize.width -= 4;
+ [_memoryWindow setContentSize:contentSize];
+ }
+
self.memoryBankItem.enabled = false;
}
@@ -1456,7 +1534,7 @@ - (void) appendPendingOutput
[_consoleOutputLock unlock];
}
-- (void) log: (const char *) string withAttributes: (GB_log_attributes) attributes
+- (void)log:(const char *)string withAttributes:(GB_log_attributes)attributes
{
NSString *nsstring = @(string); // For ref-counting
if (_capturedOutput) {
@@ -1465,7 +1543,7 @@ - (void) log: (const char *) string withAttributes: (GB_log_attributes) attribut
}
- NSFont *font = [NSFont userFixedPitchFontOfSize:12];
+ NSFont *font = [self debuggerFontOfSize:0];
NSUnderlineStyle underline = NSUnderlineStyleNone;
if (attributes & GB_LOG_BOLD) {
font = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSBoldFontMask];
diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib
index 476aad7ca..2447d810d 100644
--- a/Cocoa/Document.xib
+++ b/Cocoa/Document.xib
@@ -241,18 +241,18 @@
-
+
-
+
-
+
-
+
@@ -266,27 +266,27 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -301,7 +301,7 @@
-
+
@@ -746,7 +746,7 @@
-
+
diff --git a/Cocoa/GBApp.m b/Cocoa/GBApp.m
index e6d4b5dca..ea5cdd4ab 100644
--- a/Cocoa/GBApp.m
+++ b/Cocoa/GBApp.m
@@ -48,6 +48,11 @@ - (void) applicationDidFinishLaunching:(NSNotification *)notification
[defaults removeObjectForKey:button_to_preference_name(i, 0)];
}
}
+
+ bool hasSFMono = false;
+ if (@available(macOS 10.15, *)) {
+ hasSFMono = [[NSFont monospacedSystemFontOfSize:12 weight:NSFontWeightRegular].displayName containsString:@"SF"];
+ }
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
@"GBRight": @(kVK_RightArrow),
@"GBLeft": @(kVK_LeftArrow),
@@ -85,6 +90,9 @@ - (void) applicationDidFinishLaunching:(NSNotification *)notification
@"GBEmulatedModel": @(MODEL_AUTO),
+ @"GBDebuggerFont": hasSFMono? @"SF Mono" : @"Menlo",
+ @"GBDebuggerFontSize": @12,
+
// Default themes
@"GBThemes": @{
@"Canyon": @{
diff --git a/Cocoa/GBObjectView.m b/Cocoa/GBObjectView.m
index 0fb22a158..719d66d0b 100644
--- a/Cocoa/GBObjectView.m
+++ b/Cocoa/GBObjectView.m
@@ -57,6 +57,9 @@ - (void)reloadData:(Document *)document
uint8_t length = document.oamCount;
bool cgb = GB_is_cgb(document.gb);
uint8_t height = document.oamHeight;
+ NSFont *font = [document debuggerFontOfSize:11];
+ NSFont *boldFont = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSBoldFontMask];
+
for (unsigned i = 0; i < 40; i++) {
GBObjectViewItem *item = _items[i];
if (i >= length) {
@@ -64,6 +67,13 @@ - (void)reloadData:(Document *)document
}
else {
item.view.hidden = false;
+
+ item.oamAddress.font = boldFont;
+ item.position.font = font;
+ item.attributes.font = font;
+ item.tile.font = font;
+ item.tileAddress.font = font;
+
item.oamAddress.stringValue = [NSString stringWithFormat:@"$%04X", info[i].oam_addr];
item.position.stringValue = [NSString stringWithFormat:@"(%d, %d)",
((signed)(unsigned)info[i].x) - 8,
diff --git a/Cocoa/GBObjectViewItem.xib b/Cocoa/GBObjectViewItem.xib
index 85b37820e..0ba1d5d8e 100644
--- a/Cocoa/GBObjectViewItem.xib
+++ b/Cocoa/GBObjectViewItem.xib
@@ -1,8 +1,8 @@
-
+
-
+
diff --git a/Cocoa/GBPaletteView.m b/Cocoa/GBPaletteView.m
index 6aeddc05c..d123a2b4a 100644
--- a/Cocoa/GBPaletteView.m
+++ b/Cocoa/GBPaletteView.m
@@ -43,6 +43,7 @@ - (void)reloadData:(Document *)document
GB_gameboy_t *gb = document.gb;
uint8_t *bg = GB_get_direct_access(gb, GB_DIRECT_ACCESS_BGP, NULL, NULL);
uint8_t *obj = GB_get_direct_access(gb, GB_DIRECT_ACCESS_OBP, NULL, NULL);
+ NSFont *font = [document debuggerFontOfSize:13];
for (unsigned i = 0; i < 4 * 8 * 2; i++) {
uint8_t index = i % (4 * 8);
@@ -58,6 +59,7 @@ - (void)reloadData:(Document *)document
field.stringValue = [NSString stringWithFormat:@"$%04X", color];
field.textColor = r * 3 + g * 4 + b * 2 > 120? [NSColor blackColor] : [NSColor whiteColor];
field.toolTip = [NSString stringWithFormat:@"Red: %d, Green: %d, Blue: %d", r, g, b];
+ field.font = font;
field.backgroundColor = [NSColor colorWithRed:(nativeColor & 0xFF) / 255.0
green:((nativeColor >> 8) & 0xFF) / 255.0
blue:((nativeColor >> 16) & 0xFF) / 255.0
diff --git a/Cocoa/GBPaletteViewRow.xib b/Cocoa/GBPaletteViewRow.xib
index 950b199a7..1a7697cb6 100644
--- a/Cocoa/GBPaletteViewRow.xib
+++ b/Cocoa/GBPaletteViewRow.xib
@@ -1,8 +1,8 @@
-
+
-
+
diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h
index 293ccacbd..a75d8a974 100644
--- a/Cocoa/GBPreferencesWindow.h
+++ b/Cocoa/GBPreferencesWindow.h
@@ -1,6 +1,7 @@
#import
#import
#import "GBPaletteEditorController.h"
+#import "GBTitledPopUpButton.h"
@interface GBPreferencesWindow : NSWindow
@property IBOutlet NSTableView *controlsTableView;
@@ -18,4 +19,7 @@
@property IBOutlet NSPopUpButton *colorPalettePopupButton;
@property IBOutlet NSPopUpButton *hotkey1PopupButton;
@property IBOutlet NSPopUpButton *hotkey2PopupButton;
+
+@property IBOutlet GBTitledPopUpButton *fontPopupButton;
+@property IBOutlet NSStepper *fontSizeStepper;
@end
diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m
index ee2be916a..a941c8b4c 100644
--- a/Cocoa/GBPreferencesWindow.m
+++ b/Cocoa/GBPreferencesWindow.m
@@ -339,6 +339,63 @@ - (void)awakeFromNib
else {
[_colorPalettePopupButton selectItemWithTitle:[[NSUserDefaults standardUserDefaults] stringForKey:@"GBCurrentTheme"] ?: @""];
}
+
+ _fontSizeStepper.intValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBDebuggerFontSize"];
+ [self updateFonts];
+}
+
+- (IBAction)fontSizeChanged:(id)sender
+{
+ NSString *selectedFont = [[NSUserDefaults standardUserDefaults] stringForKey:@"GBDebuggerFont"];
+ [[NSUserDefaults standardUserDefaults] setInteger:[sender intValue] forKey:@"GBDebuggerFontSize"];
+ [_fontPopupButton setDisplayTitle:[NSString stringWithFormat:@"%@ %upt", selectedFont, (unsigned)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBDebuggerFontSize"]]];
+}
+
+- (IBAction)fontChanged:(id)sender
+{
+ NSString *selectedFont = _fontPopupButton.selectedItem.title;
+ [[NSUserDefaults standardUserDefaults] setObject:selectedFont forKey:@"GBDebuggerFont"];
+ [_fontPopupButton setDisplayTitle:[NSString stringWithFormat:@"%@ %upt", selectedFont, (unsigned)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBDebuggerFontSize"]]];
+
+}
+
+- (void)updateFonts
+{
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ NSFontManager *fontManager = [NSFontManager sharedFontManager];
+ NSArray *allFamilies = [fontManager availableFontFamilies];
+ NSMutableSet *families = [NSMutableSet set];
+ for (NSString *family in allFamilies) {
+ if ([fontManager fontNamed:family hasTraits:NSFixedPitchFontMask]) {
+ [families addObject:family];
+ }
+ }
+
+ bool hasSFMono = false;
+ if (@available(macOS 10.15, *)) {
+ hasSFMono = [[NSFont monospacedSystemFontOfSize:12 weight:NSFontWeightRegular].displayName containsString:@"SF"];
+ }
+
+ if (hasSFMono) {
+ [families addObject:@"SF Mono"];
+ }
+
+ NSArray *sortedFamilies = [[families allObjects] sortedArrayUsingSelector:@selector(compare:)];
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (![families containsObject:[[NSUserDefaults standardUserDefaults] stringForKey:@"GBDebuggerFont"]]) {
+ [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"GBDebuggerFont"];
+ }
+
+ [_fontPopupButton.menu removeAllItems];
+ for (NSString *family in sortedFamilies) {
+ [_fontPopupButton addItemWithTitle:family];
+ }
+ NSString *selectedFont = [[NSUserDefaults standardUserDefaults] stringForKey:@"GBDebuggerFont"];
+ [_fontPopupButton selectItemWithTitle:selectedFont];
+ [_fontPopupButton setDisplayTitle:[NSString stringWithFormat:@"%@ %upt", selectedFont, (unsigned)[[NSUserDefaults standardUserDefaults] integerForKey:@"GBDebuggerFontSize"]]];
+ });
+ });
}
- (void)dealloc
diff --git a/Cocoa/GBTitledPopUpButton.h b/Cocoa/GBTitledPopUpButton.h
new file mode 100644
index 000000000..2e8cc469a
--- /dev/null
+++ b/Cocoa/GBTitledPopUpButton.h
@@ -0,0 +1,5 @@
+#import
+
+@interface GBTitledPopUpButton : NSPopUpButton
+@property NSString *displayTitle;
+@end
diff --git a/Cocoa/GBTitledPopUpButton.m b/Cocoa/GBTitledPopUpButton.m
new file mode 100644
index 000000000..29b7b5913
--- /dev/null
+++ b/Cocoa/GBTitledPopUpButton.m
@@ -0,0 +1,22 @@
+#import "GBTitledPopUpButton.h"
+
+@implementation GBTitledPopUpButton
+
+- (void)setDisplayTitle:(NSString *)displayTitle
+{
+ if (!displayTitle) {
+ ((NSPopUpButtonCell *)self.cell).usesItemFromMenu = true;
+ ((NSPopUpButtonCell *)self.cell).menuItem = nil;
+ return;
+ }
+ ((NSPopUpButtonCell *)self.cell).usesItemFromMenu = false;
+ ((NSPopUpButtonCell *)self.cell).menuItem = [[NSMenuItem alloc] initWithTitle:displayTitle action:nil keyEquivalent:@""];
+}
+
+
+- (NSString *)displayTitle
+{
+ return ((NSPopUpButtonCell *)self.cell).menuItem.title;
+}
+
+@end
diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib
index 95f9b822e..9979ba224 100644
--- a/Cocoa/Preferences.xib
+++ b/Cocoa/Preferences.xib
@@ -1,8 +1,8 @@
-
+
-
+
@@ -24,7 +24,7 @@
-
+
@@ -32,26 +32,36 @@
+
+
+
+
+
+
+
+
+
+
@@ -73,6 +83,8 @@
+
+
@@ -86,20 +98,20 @@
-
+
-
+
-
+
-
+
@@ -193,9 +205,9 @@
-
+
@@ -213,7 +225,7 @@
-
+
@@ -239,7 +251,7 @@
-
+
@@ -250,7 +262,7 @@
-
+
@@ -259,7 +271,7 @@
-
+
@@ -268,7 +280,7 @@
-
+
@@ -288,7 +300,7 @@
-
+
@@ -297,7 +309,7 @@
-
+
@@ -318,7 +330,7 @@
-
+
@@ -326,8 +338,17 @@
+
+
+
+
+
+
+
+
+
-
+
@@ -346,8 +367,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -677,7 +737,7 @@