diff options
author | Damiano Galassi <[email protected]> | 2017-07-26 11:44:38 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2017-07-26 11:44:38 +0200 |
commit | 5dabd8e3f9d194047433a503234616bcf83b363d (patch) | |
tree | 12c81d07f105fde92aba97a41d46c172e6682bd2 /macosx/HBPicture.m | |
parent | 32154911403726fc89b257c073492d865198f0ce (diff) |
MacGui: allow crop values to be larger than sourceValue / 2
Diffstat (limited to 'macosx/HBPicture.m')
-rw-r--r-- | macosx/HBPicture.m | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/macosx/HBPicture.m b/macosx/HBPicture.m index 97b1631aa..5578245e4 100644 --- a/macosx/HBPicture.m +++ b/macosx/HBPicture.m @@ -269,52 +269,36 @@ NSString * const HBPictureChangedNotification = @"HBPictureChangedNotification"; - (BOOL)validateCropTop:(id *)ioValue error:(NSError * __autoreleasing *)outError { - [self validateVCrop:ioValue]; + [self validateCrop:ioValue max:self.maxTopCrop]; return YES; } - (BOOL)validateCropBottom:(id *)ioValue error:(NSError * __autoreleasing *)outError { - [self validateVCrop:ioValue]; + [self validateCrop:ioValue max:self.maxBottomCrop]; return YES; } - (BOOL)validateCropLeft:(id *)ioValue error:(NSError * __autoreleasing *)outError { - [self validateHCrop:ioValue]; + [self validateCrop:ioValue max:self.maxLeftCrop]; return YES; } - (BOOL)validateCropRight:(id *)ioValue error:(NSError * __autoreleasing *)outError { - [self validateHCrop:ioValue]; + [self validateCrop:ioValue max:self.maxRightCrop]; return YES; } -- (void)validateHCrop:(NSNumber **)ioValue +- (void)validateCrop:(NSNumber **)ioValue max:(int)maxCrop { if (nil != *ioValue) { int value = [*ioValue intValue]; - if (value >= self.maxHorizontalCrop) + if (value >= maxCrop) { - *ioValue = @(self.maxHorizontalCrop); - } - else if (value < 0) - { - *ioValue = @0; - } - } -} - -- (void)validateVCrop:(NSNumber **)ioValue -{ - if (nil != *ioValue) - { - int value = [*ioValue intValue]; - if (value >= self.maxVerticalCrop) - { - *ioValue = @(self.maxVerticalCrop); + *ioValue = @(maxCrop); } else if (value < 0) { @@ -414,14 +398,44 @@ NSString * const HBPictureChangedNotification = @"HBPictureChangedNotification"; return self.sourceHeight - self.cropTop - self.cropBottom; } -- (int)maxVerticalCrop ++ (NSSet<NSString *> *)keyPathsForValuesAffectingMaxTopCrop +{ + return [NSSet setWithObjects:@"cropBottom", nil]; +} + +- (int)maxTopCrop +{ + return self.sourceHeight - self.cropBottom - 32; +} + ++ (NSSet<NSString *> *)keyPathsForValuesAffectingMaxBottomCrop +{ + return [NSSet setWithObjects:@"cropTop", nil]; +} + +- (int)maxBottomCrop +{ + return self.sourceHeight - self.cropTop - 32; +} + ++ (NSSet<NSString *> *)keyPathsForValuesAffectingMaxLeftCrop +{ + return [NSSet setWithObjects:@"cropRight", nil]; +} + +- (int)maxLeftCrop +{ + return self.sourceWidth - self.cropRight - 32; +} + ++ (NSSet<NSString *> *)keyPathsForValuesAffectingMaxRightCrop { - return self.sourceHeight / 2 - 2; + return [NSSet setWithObjects:@"cropLeft", nil]; } -- (int)maxHorizontalCrop +- (int)maxRightCrop { - return self.sourceWidth / 2 - 2; + return self.sourceWidth - self.cropLeft - 32; } - (int)sourceDisplayWidth |