Added source menu item to restore the aspect ratio to the input AR

This commit is contained in:
Zakk 2017-01-01 14:23:14 -05:00
parent 448f51b44b
commit 5978c7f85e
4 changed files with 63 additions and 1 deletions

View file

@ -245,6 +245,9 @@ typedef enum resize_style_t {
-(void)autoCenter:(NSRect)containerRect;
-(void)autoSize;
-(void)layerUpdated;
-(void)resetAspectRatio;

View file

@ -1938,6 +1938,33 @@ static NSArray *_sourceTypes = nil;
}
-(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
{
@ -1962,7 +1989,6 @@ static NSArray *_sourceTypes = nil;
height = width/inputAR;
delta_h = height - oldLayout.size.height;
}
}
if (self.layer)

View file

@ -283,10 +283,15 @@
} 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)
@ -1167,6 +1172,34 @@
}
-(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;