From 19e3852ba50460472faab6493a46180b6adcadf2 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 5 Dec 2015 10:26:01 +0100 Subject: [PATCH] MacGui: default to custom picture size in the add preset sheet if the current job size is less than the maximum size. --- macosx/English.lproj/AddPreset.xib | 6 ++- macosx/HBAddPresetController.h | 14 +++--- macosx/HBAddPresetController.m | 71 +++++++++++++++++++----------- macosx/HBController.m | 9 +++- 4 files changed, 62 insertions(+), 38 deletions(-) diff --git a/macosx/English.lproj/AddPreset.xib b/macosx/English.lproj/AddPreset.xib index 07ffb9f62..b08b559f0 100644 --- a/macosx/English.lproj/AddPreset.xib +++ b/macosx/English.lproj/AddPreset.xib @@ -1,9 +1,9 @@ - + - + @@ -102,6 +102,7 @@ Select the maximum width allowed by the preset (has no effect if the preset specifies Strict anamorphic). 0 means no limit is placed on the width. + @@ -124,6 +125,7 @@ Select the maximum height allowed by the preset (has no effect if the preset specifies Strict anamorphic). 0 means no limit is placed on the height. + diff --git a/macosx/HBAddPresetController.h b/macosx/HBAddPresetController.h index 7162767fd..fe73e20fe 100644 --- a/macosx/HBAddPresetController.h +++ b/macosx/HBAddPresetController.h @@ -1,10 +1,8 @@ -// -// HBAddPresetController.h -// HandBrake -// -// Created by Damiano Galassi on 23/11/14. -// -// +/* HBAddPresetController.h + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ #import @@ -14,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @interface HBAddPresetController : NSWindowController -- (instancetype)initWithPreset:(HBPreset *)preset videoSize:(NSSize)size; +- (instancetype)initWithPreset:(HBPreset *)preset customWidth:(int)customWidth customHeight:(int)customHeight defaultToCustom:(BOOL)defaultToCustom; @property (nonatomic, readonly) HBPreset *preset; diff --git a/macosx/HBAddPresetController.m b/macosx/HBAddPresetController.m index 10165ecb5..e086d55fc 100644 --- a/macosx/HBAddPresetController.m +++ b/macosx/HBAddPresetController.m @@ -1,15 +1,19 @@ -// -// HBAddPresetController.m -// HandBrake -// -// Created by Damiano Galassi on 23/11/14. -// -// +/* HBAddPresetController.m + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ #import "HBAddPresetController.h" #import "HBPreset.h" #import "HBMutablePreset.h" +typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) { + HBAddPresetControllerModeNone, + HBAddPresetControllerModeCustom, + HBAddPresetControllerModeSourceMaximum, +}; + @interface HBAddPresetController () @property (unsafe_unretained) IBOutlet NSTextField *name; @@ -21,20 +25,26 @@ @property (unsafe_unretained) IBOutlet NSBox *picWidthHeightBox; @property (nonatomic, strong) HBPreset *preset; -@property NSSize size; +@property (nonatomic) int width; +@property (nonatomic) int height; + +@property (nonatomic) BOOL defaultToCustom; + @end @implementation HBAddPresetController -- (instancetype)initWithPreset:(HBPreset *)preset videoSize:(NSSize)size; +- (instancetype)initWithPreset:(HBPreset *)preset customWidth:(int)customWidth customHeight:(int)customHeight defaultToCustom:(BOOL)defaultToCustom { self = [super initWithWindowNibName:@"AddPreset"]; if (self) { NSParameterAssert(preset); _preset = preset; - _size = size; + _width = customWidth; + _height = customHeight; + _defaultToCustom = defaultToCustom; } return self; } @@ -49,30 +59,39 @@ * * Use [NSMenuItem tag] to store preset values for each option. */ - [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"None", @"")]; - [[self.picSettingsPopUp lastItem] setTag: 0]; + + // Default to Source Maximum + HBAddPresetControllerMode mode = HBAddPresetControllerModeSourceMaximum; + + [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"None", nil)]; + [[self.picSettingsPopUp lastItem] setTag:HBAddPresetControllerModeNone]; if (![self.preset[@"PicturePAR"] isEqualToString:@"strict"]) { // not Strict, Custom is applicable - [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Custom", @"")]; - [[self.picSettingsPopUp lastItem] setTag: 1]; + [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Custom", nil)]; + [[self.picSettingsPopUp lastItem] setTag:HBAddPresetControllerModeCustom]; + + if (self.defaultToCustom) + { + mode = HBAddPresetControllerModeCustom; + } } - [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Source Maximum (post source scan)", @"")]; - [[self.picSettingsPopUp lastItem] setTag: 2]; + [self.picSettingsPopUp addItemWithTitle:NSLocalizedString(@"Source Maximum (post source scan)", nil)]; + [[self.picSettingsPopUp lastItem] setTag:HBAddPresetControllerModeSourceMaximum]; + - //Default to Source Maximum - [self.picSettingsPopUp selectItemWithTag:2]; + [self.picSettingsPopUp selectItemWithTag:mode]; - /* Initialize custom height and width settings to current values */ - [self.picWidth setStringValue: [NSString stringWithFormat:@"%d", (int)self.size.width]]; - [self.picHeight setStringValue: [NSString stringWithFormat:@"%d",(int)self.size.height]]; + // Initialize custom height and width settings to current values + [self.picWidth setIntValue:self.width]; + [self.picHeight setIntValue:self.height]; [self addPresetPicDropdownChanged:nil]; } - (IBAction)addPresetPicDropdownChanged:(id)sender { - if (self.picSettingsPopUp.selectedItem.tag == 1) + if (self.picSettingsPopUp.selectedItem.tag == HBAddPresetControllerModeCustom) { self.picWidthHeightBox.hidden = NO; } @@ -112,15 +131,15 @@ self.preset = [newPreset copy]; - [[self window] orderOut:nil]; - [NSApp endSheet:[self window] returnCode:NSModalResponseContinue]; + [self.window orderOut:nil]; + [NSApp endSheet:self.window returnCode:NSModalResponseContinue]; } } - (IBAction)cancel:(id)sender { - [[self window] orderOut:nil]; - [NSApp endSheet:[self window] returnCode:NSModalResponseAbort]; + [self.window orderOut:nil]; + [NSApp endSheet:self.window returnCode:NSModalResponseAbort]; } @end diff --git a/macosx/HBController.m b/macosx/HBController.m index a0591bb67..9fcc8d20f 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -1371,9 +1371,14 @@ - (IBAction)showAddPresetPanel:(id)sender { - // Show the add panel + BOOL defaultToCustom = ((self.job.picture.width + self.job.picture.cropRight + self.job.picture.cropLeft) < self.job.picture.sourceWidth) || + ((self.job.picture.height + self.job.picture.cropTop + self.job.picture.cropBottom) < self.job.picture.sourceHeight); + + // Show the add panel HBAddPresetController *addPresetController = [[HBAddPresetController alloc] initWithPreset:[self createPresetFromCurrentSettings] - videoSize:NSMakeSize(self.job.picture.width, self.job.picture.height)]; + customWidth:self.job.picture.width + customHeight:self.job.picture.height + defaultToCustom:defaultToCustom]; [NSApp beginSheet:addPresetController.window modalForWindow:self.window modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain(addPresetController)]; } -- 2.40.0