Feature #333

Player window scale

Added by J W almost 2 years ago. Updated 12 months ago.

Status:Assigned Start Date:04/26/2010
Priority:Normal Due date:
Assigned to:Adrian Stutz % Done:

0%

Category:gui_controls
Target version:rev15

Description

When resizing a window to a larger/smaller size perhaps an option could be enabled so you can either resize it how you currently would or have it so the proportions are constrained instead of you having to get it right so there are no black bars on the edges.

History

Updated by Adrian Stutz almost 2 years ago

  • Status changed from New to Assigned
  • Target version changed from rev13 to rev15

Yeah, not sure who actually wants it to be free-form. If anyone prefers it, then please speak up. ^^

I could also imagine a snap-mode to work as a compromise: If the aspect is close to the actual video, it snaps to it. If it's far off, it stays.

Updated by Hermi G 12 months ago

I have implemented this feature. To activate this functionality, simply open PlayerWindow.m and paste the following text inside the @synthesize block. Easy.

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
{
    if([playerController videoOpenGLView].video_aspect <= 0)
        return NSMakeSize(proposedFrameSize.width, proposedFrameSize.height);

    CGEventRef event = CGEventCreate(NULL);

    if(CGEventGetFlags(event) & kCGEventFlagMaskShift) {
      CFRelease(event);

        NSRect frameRect = [sender frame];
        NSRect contentRect = [sender contentRectForFrameRect:[sender frame]];
        NSSize minSize = [sender contentMinSize];
        float heightOffset = frameRect.size.height - contentRect.size.height + minSize.height;

        float aspect = [playerController videoOpenGLView].video_aspect;
        float pWidth = proposedFrameSize.width;
        float pHeight = proposedFrameSize.height;
        float snapWidth = pWidth;
        float snapHeight = pHeight;

        if(pWidth-frameRect.size.width <= pHeight-frameRect.size.height) {
            snapHeight = (pWidth / aspect) + heightOffset;
            if (snapHeight < heightOffset) {
                snapHeight = heightOffset;
                snapWidth = minSize.width;
            }
        } else {
            snapWidth = ((pHeight - heightOffset) * aspect);
            if (snapWidth < minSize.width) {
                snapWidth = minSize.width;
                snapHeight = (minSize.width / aspect) + heightOffset;
            }
        }
        return(NSMakeSize(snapWidth, snapHeight));
    }

    CFRelease(event);

    return NSMakeSize(proposedFrameSize.width, proposedFrameSize.height);
}

Hold the shift key to keep the window at the correct aspect ratio. Release shift to resize the window in freeform.

I chose to keep freeform resizing as the default behavior for two reasons: Firstly, using the shift key to scale an object with a fixed ratio (such as making a circle with an oval tool) is a standard and familiar way to handle it, and secondly, for a personal reason. I use a program called Cinch, which allows me to drag a window to the side or top of the screen where it will become docked and resized just like windows 7's 'aero snap'. This half-screen docking works well with freeform resizing, but looks bad with the snapping behavior. I use this docking feature more often than I manually resize a window, so I would rather not hold shift key to get freeform resizing.

Update: Now uses [[playerController videoOpenGLView] video_aspect] (which required adding an @property accessor to the VideoOpenGLView class) so the chosen aspect ratio is used, rather than always using the original.

Also available in: Atom PDF