+- (int) detelecine
+{
+ return fPictureFilterSettings.detelecine;
+}
+
+- (void) setDetelecine: (int) setting
+{
+ fPictureFilterSettings.detelecine = setting;
+}
+
+- (int) deinterlace
+{
+ return fPictureFilterSettings.deinterlace;
+}
+
+- (void) setDeinterlace: (int) setting {
+ fPictureFilterSettings.deinterlace = setting;
+}
+
+- (int) denoise
+{
+ return fPictureFilterSettings.denoise;
+}
+
+- (void) setDenoise: (int) setting
+{
+ fPictureFilterSettings.denoise = setting;
+}
+
+- (void)showPanelInWindow: (NSWindow *)fWindow forTitle: (hb_title_t *)title
+{
+ [self SetTitle:title];
+
+ [NSApp beginSheet:fPicturePanel
+ modalForWindow:fWindow
+ modalDelegate:nil
+ didEndSelector:nil
+ contextInfo:NULL];
+}
+
+- (BOOL) loadMyNibFile
+{
+ if(![NSBundle loadNibNamed:@"PictureSettings" owner:self])
+ {
+ NSLog(@"Warning! Could not load myNib file.\n");
+ return NO;
+ }
+
+ return YES;
+}
+
+@end
+
+@implementation PictureController (Private)
+
+//
+// -[PictureController(Private) optimalViewSizeForImageSize:]
+//
+// Given the size of the preview image to be shown, returns the best possible
+// size for the OpenGL view.
+//
+- (NSSize)optimalViewSizeForImageSize: (NSSize)imageSize
+{
+ // The min size is 320x240
+ float minWidth = 320.0;
+ float minHeight = 240.0;
+
+ // The max size of the view is when the sheet is taking up 85% of the screen.
+ NSSize screenSize = [[NSScreen mainScreen] frame].size;
+ NSSize sheetSize = [fPicturePanel frame].size;
+ NSSize viewAreaSize = [fPictureGLViewArea frame].size;
+ float paddingX = sheetSize.width - viewAreaSize.width;
+ float paddingY = sheetSize.height - viewAreaSize.height;
+ float maxWidth = (0.85 * screenSize.width) - paddingX;
+ float maxHeight = (0.85 * screenSize.height) - paddingY;
+
+ NSSize resultSize = imageSize;
+
+ // Its better to have a view that's too small than a view that's too big, so
+ // apply the maximum constraints last.
+ if( resultSize.width < minWidth )
+ {
+ resultSize.height *= (minWidth / resultSize.width);
+ resultSize.width = minWidth;
+ }
+ if( resultSize.height < minHeight )
+ {
+ resultSize.width *= (minHeight / resultSize.height);
+ resultSize.height = minHeight;
+ }
+ if( resultSize.width > maxWidth )
+ {
+ resultSize.height *= (maxWidth / resultSize.width);
+ resultSize.width = maxWidth;
+ }
+ if( resultSize.height > maxHeight )
+ {
+ resultSize.width *= (maxHeight / resultSize.height);
+ resultSize.height = maxHeight;
+ }
+
+ return resultSize;
+}
+
+//
+// -[PictureController(Private) resizePanelForViewSize:animate:]
+//
+// Resizes the entire sheet to accomodate an OpenGL view of a particular size.
+//
+- (void)resizeSheetForViewSize: (NSSize)viewSize
+{
+ // Figure out the deltas for the new frame area
+ NSSize currentSize = [fPictureGLViewArea frame].size;
+ float deltaX = viewSize.width - currentSize.width;
+ float deltaY = viewSize.height - currentSize.height;
+
+ // Now resize the whole panel by those same deltas, but don't exceed the min
+ NSRect frame = [fPicturePanel frame];
+ NSSize maxSize = [fPicturePanel maxSize];
+ NSSize minSize = [fPicturePanel minSize];
+ frame.size.width += deltaX;
+ frame.size.height += deltaY;
+ if( frame.size.width < minSize.width )
+ {
+ frame.size.width = minSize.width;
+ }
+ if( frame.size.height < minSize.height )
+ {
+ frame.size.height = minSize.height;
+ }
+
+ // But now the sheet is off-center, so also shift the origin to center it and
+ // keep the top aligned.
+ frame.origin.x -= (deltaX / 2.0);
+ frame.origin.y -= deltaY;
+
+ [fPicturePanel setFrame:frame display:YES animate:YES];
+}
+
+//
+// -[PictureController(Private) setViewSize:]
+//
+// Changes the OpenGL view's size and centers it vertially inside of its area.
+// Assumes resizeSheetForViewSize: has already been called.
+//
+- (void)setViewSize: (NSSize)viewSize
+{
+ [fPictureGLView setFrameSize:viewSize];
+
+ // center it vertically
+ NSPoint origin = [fPictureGLViewArea frame].origin;
+ origin.y += ([fPictureGLViewArea frame].size.height -
+ [fPictureGLView frame].size.height) / 2.0;
+ [fPictureGLView setFrameOrigin:origin];
+}
+
+//
+// -[PictureController(Private) viewNeedsToResizeToSize:]
+//
+// Returns YES if the view will need to resize to match the given size.
+//
+- (BOOL)viewNeedsToResizeToSize: (NSSize)newSize
+{
+ NSSize viewSize = [fPictureGLView frame].size;
+ return (newSize.width != viewSize.width || newSize.height != viewSize.height);
+}
+
+