From 1268bf3a357c379acdf5e522ff3868c6b8743d0c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 5 Jul 2016 21:23:55 +0300 Subject: [PATCH] Keeping aspect ratio is now optional (but default) --- Cocoa/GBPreferencesWindow.h | 1 + Cocoa/GBPreferencesWindow.m | 19 +++++++++++++++++++ Cocoa/GBView.m | 32 ++++++++++++++++++++------------ Cocoa/Preferences.xib | 21 ++++++++++++++++----- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h index 7e1876d..f4f3c6b 100644 --- a/Cocoa/GBPreferencesWindow.h +++ b/Cocoa/GBPreferencesWindow.h @@ -3,4 +3,5 @@ @interface GBPreferencesWindow : NSWindow @property IBOutlet NSTableView *controlsTableView; @property IBOutlet NSPopUpButton *graphicsFilterPopupButton; +@property (strong) IBOutlet NSButton *aspectRatioCheckbox; @end diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m index 0aee2c2..aa04b73 100644 --- a/Cocoa/GBPreferencesWindow.m +++ b/Cocoa/GBPreferencesWindow.m @@ -8,6 +8,7 @@ NSInteger button_being_modified; NSPopUpButton *_graphicsFilterPopupButton; + NSButton *_aspectRatioCheckbox; } + (NSArray *)filterList @@ -100,4 +101,22 @@ [[NSNotificationCenter defaultCenter] postNotificationName:@"GBFilterChanged" object:nil]; } +- (IBAction)changeAspectRatio:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setBool: [(NSButton *)sender state] != NSOnState + forKey:@"GBAspectRatioUnkept"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"GBAspectChanged" object:nil]; +} + +- (NSButton *)aspectRatioCheckbox +{ + return _aspectRatioCheckbox; +} + +- (void)setAspectRatioCheckbox:(NSButton *)aspectRatioCheckbox +{ + _aspectRatioCheckbox = aspectRatioCheckbox; + [_aspectRatioCheckbox setState: ![[NSUserDefaults standardUserDefaults] boolForKey:@"GBAspectRatioUnkept"]]; +} + @end diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 0b1261f..f6581de 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -41,6 +41,7 @@ image_buffers[2] = malloc(160 * 144 * 4); _shouldBlendFrameWithPrevious = 1; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(filterChanged) name:@"GBFilterChanged" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ratioKeepingChanged) name:@"GBAspectChanged" object:nil]; } - (void) filterChanged @@ -49,6 +50,11 @@ self.shader = nil; } +- (void) ratioKeepingChanged +{ + [self setFrame:self.superview.frame]; +} + - (void) setShouldBlendFrameWithPrevious:(BOOL)shouldBlendFrameWithPrevious { _shouldBlendFrameWithPrevious = shouldBlendFrameWithPrevious; @@ -90,18 +96,20 @@ - (void)setFrame:(NSRect)frame { frame = self.superview.frame; - double ratio = frame.size.width / frame.size.height; - if (ratio >= 160.0/144.0) { - double new_width = round(frame.size.height / 144.0 * 160.0); - frame.origin.x = floor((frame.size.width - new_width) / 2); - frame.size.width = new_width; - frame.origin.y = 0; - } - else { - double new_height = round(frame.size.width / 160.0 * 144.0); - frame.origin.y = floor((frame.size.height - new_height) / 2); - frame.size.height = new_height; - frame.origin.x = 0; + if (![[NSUserDefaults standardUserDefaults] boolForKey:@"GBAspectRatioUnkept"]) { + double ratio = frame.size.width / frame.size.height; + if (ratio >= 160.0/144.0) { + double new_width = round(frame.size.height / 144.0 * 160.0); + frame.origin.x = floor((frame.size.width - new_width) / 2); + frame.size.width = new_width; + frame.origin.y = 0; + } + else { + double new_height = round(frame.size.width / 160.0 * 144.0); + frame.origin.y = floor((frame.size.height - new_height) / 2); + frame.size.height = new_height; + frame.origin.x = 0; + } } [super setFrame:frame]; } diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib index 43b27b4..a932646 100644 --- a/Cocoa/Preferences.xib +++ b/Cocoa/Preferences.xib @@ -15,10 +15,10 @@ - + - + @@ -30,7 +30,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -70,6 +70,16 @@ + @@ -130,11 +140,12 @@ + - +