Skip to content

Commit

Permalink
Update auto fit code to work with new resizing/layer bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
zakk4223 committed Jan 1, 2017
1 parent 9c56c90 commit 448f51b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
Binary file not shown.
37 changes: 17 additions & 20 deletions CocoaSplit/InputSource.m
Expand Up @@ -1880,9 +1880,7 @@ -(void)autoCenter:(NSRect)containerRect

if (NSContainsRect(containerRect, myRect))
{
CGFloat newX = (containerRect.origin.x + containerRect.size.width/2) - myRect.size.width/2;
CGFloat newY = (containerRect.origin.y + containerRect.size.height/2) - myRect.size.height/2;
[self positionOrigin:newX y:newY];
[self autoFit];
} else {
//We're bigger than the container! Set ourselves to the exact same size and origin
[self directSize:containerRect.size.width height:containerRect.size.height];
Expand All @@ -1894,20 +1892,13 @@ -(void)autoCenter:(NSRect)containerRect
-(void)autoFit
{

NSMutableDictionary *newConstraints = [NSMutableDictionary dictionary];

[self initDictionaryForConstraints:newConstraints];

newConstraints[@"HorizontalCenter"][@"attr"] = @(kCAConstraintMidX);
newConstraints[@"Width"][@"attr"] = @(kCAConstraintWidth);
newConstraints[@"VerticalCenter"][@"attr"] = @(kCAConstraintMidY);
newConstraints[@"Height"][@"attr"] = @(kCAConstraintHeight);
self.constraintMap = newConstraints;

[self buildLayerConstraints];
//self.layer.bounds = self.layer.superlayer.bounds;
//self.layer.position = CGPointMake(self.layer.bounds.size.width/2, self.layer.bounds.size.height/2);

float wr = self.size.width / self.canvas_width;
float hr = self.size.height / self.canvas_height;
float ratio = (hr < wr ? wr : hr);
[self directSize:self.size.width / ratio height:self.size.height / ratio];
CGFloat newX = (self.canvas_width/2) - self.layer.bounds.size.width/2;
CGFloat newY = (self.canvas_height/2) - self.layer.bounds.size.height/2;
[self positionOrigin:newX y:newY];
}


Expand Down Expand Up @@ -1958,13 +1949,19 @@ -(void) updateSize:(CGFloat)width height:(CGFloat)height
CGFloat delta_w, delta_h;
delta_w = width - oldLayout.size.width;
delta_h = height - oldLayout.size.height;
//Preserve aspect ratio on resize. Take the dimension with the biggest change, and fit the other dimension to it
//Preserve aspect ratio on resize. Take the largest dimension and figure out hte other one

if (self.videoInput && !NSEqualSizes(self.videoInput.captureSize, NSZeroSize) && !(self.resizeType & kResizeFree) && !(self.resizeType & kResizeCrop))
{
CGFloat inputAR = oldLayout.size.width / oldLayout.size.height;
height = width/inputAR;
delta_h = height - oldLayout.size.height;
if (height > width)
{
width = inputAR * height;
delta_w = width - oldLayout.size.width;
} else {
height = width/inputAR;
delta_h = height - oldLayout.size.height;
}

}

Expand Down
11 changes: 5 additions & 6 deletions CocoaSplit/PreviewView.m
Expand Up @@ -751,10 +751,7 @@ - (void)mouseDragged:(NSEvent *)theEvent

if (self.isResizing)
{
if (0)
{
} else {


if (theEvent.modifierFlags & NSAlternateKeyMask)
{
self.resizeType |= kResizeCenter;
Expand Down Expand Up @@ -797,7 +794,6 @@ - (void)mouseDragged:(NSEvent *)theEvent

[self.selectedSource updateSize:new_width height:new_height];

}

} else {

Expand All @@ -821,7 +817,6 @@ - (void)mouseDragged:(NSEvent *)theEvent
-(void)adjustDeltas:(CGFloat *)dx dy:(CGFloat *)dy
{

return;
InputSource *superInput = self.selectedSource.parentInput;

NSPoint c_lb_snap;
Expand Down Expand Up @@ -868,6 +863,10 @@ -(void)adjustDeltas:(CGFloat *)dx dy:(CGFloat *)dy
int snap_idx = 3;
for (InputSource *src in srcs)
{
if (src == self.selectedSource)
{
continue;
}
NSRect srect = src.globalLayoutPosition;
c_snaps[snap_idx++] = srect.origin;
c_snaps[snap_idx++] = NSMakePoint(NSMaxX(srect), NSMaxY(srect));
Expand Down

0 comments on commit 448f51b

Please sign in to comment.