Skip to content

Commit

Permalink
Added source menu item to restore the aspect ratio to the input AR
Browse files Browse the repository at this point in the history
  • Loading branch information
zakk4223 committed Jan 1, 2017
1 parent 448f51b commit 5978c7f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Binary file not shown.
3 changes: 3 additions & 0 deletions CocoaSplit/InputSource.h
Expand Up @@ -245,6 +245,9 @@ typedef enum resize_style_t {
-(void)autoCenter:(NSRect)containerRect;
-(void)autoSize;
-(void)layerUpdated;
-(void)resetAspectRatio;





Expand Down
28 changes: 27 additions & 1 deletion CocoaSplit/InputSource.m
Expand Up @@ -1938,6 +1938,33 @@ -(void) directSize:(CGFloat)width height:(CGFloat)height
}


-(void)resetAspectRatio
{


if (!self.videoInput || NSEqualSizes(NSZeroSize, self.videoInput.captureSize))
{
return;
}

CGFloat height = self.height;
CGFloat width = self.width;

CGFloat inputAR = self.videoInput.captureSize.width / self.videoInput.captureSize.height;
if (height > width)
{
width = inputAR * height;
} else {
height = width/inputAR;
}

resize_style resizeSave = self.resizeType;
self.resizeType = kResizeTop | kResizeRight | kResizeFree;
[self updateSize:width height:height];
self.resizeType = resizeSave;
}


-(void) updateSize:(CGFloat)width height:(CGFloat)height
{

Expand All @@ -1962,7 +1989,6 @@ -(void) updateSize:(CGFloat)width height:(CGFloat)height
height = width/inputAR;
delta_h = height - oldLayout.size.height;
}

}

if (self.layer)
Expand Down
33 changes: 33 additions & 0 deletions CocoaSplit/PreviewView.m
Expand Up @@ -283,10 +283,15 @@ -(void) buildSettingsMenu
} else {
tmp = [self.sourceSettingsMenu insertItemWithTitle:@"Attach to underlying input" action:@selector(subLayerInputSource:) keyEquivalent:@"" atIndex:idx++];
}

tmp.target = self;

tmp = [self.sourceSettingsMenu insertItemWithTitle:@"Reset to source AR" action:@selector(resetSourceAR:) keyEquivalent:@"" atIndex:idx++];
tmp.target = self;
}



-(void)doLayoutMidi:(id)sender
{
if (self.sourceLayout)
Expand Down Expand Up @@ -1167,6 +1172,34 @@ -(void)setSourceAsTimer:(id)sender
}



-(void)resetSourceAR:(id)sender
{
InputSource *toReset = nil;

if (sender)
{
if ([sender isKindOfClass:[NSMenuItem class]])
{
NSMenuItem *item = (NSMenuItem *)sender;
toReset = (InputSource *)item.representedObject;
} else if ([sender isKindOfClass:[InputSource class]]) {
toReset = (InputSource *)sender;
}
}

if (!toReset)
{
toReset = self.selectedSource;
}

if (toReset)
{
[((InputSource *)toReset) resetAspectRatio];
}
}


-(void)detachSource:(id)sender
{
InputSource *toDetach = nil;
Expand Down

0 comments on commit 5978c7f

Please sign in to comment.