Proportional Reiszing

This commit is contained in:
Lior Halphon 2016-07-03 20:58:25 +03:00
parent 9321df9630
commit 39f91f0dd6
4 changed files with 45 additions and 5 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="14F1713" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="Document"> <customObject id="-2" userLabel="File's Owner" customClass="Document">
@ -25,12 +25,18 @@
<view key="contentView" id="gIp-Ho-8D9"> <view key="contentView" id="gIp-Ho-8D9">
<rect key="frame" x="0.0" y="0.0" width="160" height="144"/> <rect key="frame" x="0.0" y="0.0" width="160" height="144"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews>
<customView id="KTk-4M-J7t" customClass="GBBorderView">
<rect key="frame" x="0.0" y="0.0" width="160" height="144"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<openGLView colorSize="5bit_RGB_8bit_Alpha" useAuxiliaryDepthBufferStencil="NO" allowOffline="YES" wantsBestResolutionOpenGLSurface="YES" id="uqf-pe-VAF" customClass="GBView"> <openGLView colorSize="5bit_RGB_8bit_Alpha" useAuxiliaryDepthBufferStencil="NO" allowOffline="YES" wantsBestResolutionOpenGLSurface="YES" id="uqf-pe-VAF" customClass="GBView">
<rect key="frame" x="0.0" y="0.0" width="160" height="144"/> <rect key="frame" x="0.0" y="0.0" width="160" height="144"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</openGLView> </openGLView>
</subviews> </subviews>
</customView>
</subviews>
</view> </view>
<connections> <connections>
<outlet property="delegate" destination="-2" id="jvM-lC-fKb"/> <outlet property="delegate" destination="-2" id="jvM-lC-fKb"/>

5
Cocoa/GBBorderView.h Normal file
View File

@ -0,0 +1,5 @@
#import <Cocoa/Cocoa.h>
@interface GBBorderView : NSView
@end

11
Cocoa/GBBorderView.m Normal file
View File

@ -0,0 +1,11 @@
#import "GBBorderView.h"
@implementation GBBorderView
- (void)drawRect:(NSRect)dirtyRect {
[[NSColor blackColor] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
}
@end

View File

@ -87,6 +87,25 @@
return self; 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 { - (void)drawRect:(NSRect)dirtyRect {
if (!self.shader) { if (!self.shader) {
self.shader = [[GBShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]]; self.shader = [[GBShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]];
@ -110,7 +129,6 @@
glFlush(); glFlush();
} }
- (void) flip - (void) flip
{ {
current_buffer = (current_buffer + 1) % self.numberOfBuffers; current_buffer = (current_buffer + 1) % self.numberOfBuffers;