From 39f91f0dd61488d6e9fb0faac1279a7e46191aec Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 3 Jul 2016 20:58:25 +0300 Subject: [PATCH] Proportional Reiszing --- Cocoa/Document.xib | 14 ++++++++++---- Cocoa/GBBorderView.h | 5 +++++ Cocoa/GBBorderView.m | 11 +++++++++++ Cocoa/GBView.m | 20 +++++++++++++++++++- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 Cocoa/GBBorderView.h create mode 100644 Cocoa/GBBorderView.m diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib index b3066894..754e92fa 100644 --- a/Cocoa/Document.xib +++ b/Cocoa/Document.xib @@ -1,7 +1,7 @@ - + - + @@ -26,10 +26,16 @@ - + - + + + + + + + diff --git a/Cocoa/GBBorderView.h b/Cocoa/GBBorderView.h new file mode 100644 index 00000000..477add17 --- /dev/null +++ b/Cocoa/GBBorderView.h @@ -0,0 +1,5 @@ +#import + +@interface GBBorderView : NSView + +@end diff --git a/Cocoa/GBBorderView.m b/Cocoa/GBBorderView.m new file mode 100644 index 00000000..c81adb4a --- /dev/null +++ b/Cocoa/GBBorderView.m @@ -0,0 +1,11 @@ +#import "GBBorderView.h" + +@implementation GBBorderView + +- (void)drawRect:(NSRect)dirtyRect { + [[NSColor blackColor] setFill]; + NSRectFill(dirtyRect); + [super drawRect:dirtyRect]; +} + +@end diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 28224301..0b1261f2 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -87,6 +87,25 @@ return self; } +- (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; + } + [super setFrame:frame]; +} + - (void)drawRect:(NSRect)dirtyRect { if (!self.shader) { self.shader = [[GBShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]]; @@ -110,7 +129,6 @@ glFlush(); } - - (void) flip { current_buffer = (current_buffer + 1) % self.numberOfBuffers;