From 0eb6b5783f3c506123298cf004163c61e5712a31 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 25 May 2020 19:09:04 +0300 Subject: [PATCH] Video editor fixes --- .../LegacyComponents/Sources/PGCurvesTool.m | 8 + .../LegacyComponents/Sources/PGPhotoEditor.h | 2 + .../LegacyComponents/Sources/PGPhotoEditor.m | 9 + .../LegacyComponents/Sources/PGPhotoTool.m | 11 +- .../LegacyComponents/Sources/PGTintTool.m | 25 +- .../Sources/TGPhotoEditorController.m | 1 - .../Sources/TGPhotoEditorItemController.h | 26 - .../Sources/TGPhotoEditorItemController.m | 701 ------------------ .../Sources/TGPhotoToolsController.m | 24 +- 9 files changed, 63 insertions(+), 744 deletions(-) delete mode 100644 submodules/LegacyComponents/Sources/TGPhotoEditorItemController.h delete mode 100644 submodules/LegacyComponents/Sources/TGPhotoEditorItemController.m diff --git a/submodules/LegacyComponents/Sources/PGCurvesTool.m b/submodules/LegacyComponents/Sources/PGCurvesTool.m index 26cd42c9e8..c59b1b0929 100644 --- a/submodules/LegacyComponents/Sources/PGCurvesTool.m +++ b/submodules/LegacyComponents/Sources/PGCurvesTool.m @@ -286,6 +286,14 @@ const NSUInteger PGCurveDataStep = 2; return _parameters; } +- (id)displayValue { + if (self.disabled) { + return [PGCurvesToolValue defaultValue]; + } else { + return [super displayValue]; + } +} + - (void)updateParameters { PGCurvesToolValue *value = (PGCurvesToolValue *)self.displayValue; diff --git a/submodules/LegacyComponents/Sources/PGPhotoEditor.h b/submodules/LegacyComponents/Sources/PGPhotoEditor.h index 68a1408557..1e1f030d94 100644 --- a/submodules/LegacyComponents/Sources/PGPhotoEditor.h +++ b/submodules/LegacyComponents/Sources/PGPhotoEditor.h @@ -33,6 +33,8 @@ @property (nonatomic, assign) bool standalone; +@property (nonatomic, assign) bool disableAll; + - (instancetype)initWithOriginalSize:(CGSize)originalSize adjustments:(id)adjustments forVideo:(bool)forVideo enableStickers:(bool)enableStickers; - (void)cleanup; diff --git a/submodules/LegacyComponents/Sources/PGPhotoEditor.m b/submodules/LegacyComponents/Sources/PGPhotoEditor.m index d8d5d35f62..64f9db5523 100644 --- a/submodules/LegacyComponents/Sources/PGPhotoEditor.m +++ b/submodules/LegacyComponents/Sources/PGPhotoEditor.m @@ -477,6 +477,15 @@ } } +- (void)setDisableAll:(bool)disableAll { + _disableAll = disableAll; + + for (PGPhotoTool *tool in self.tools) + { + tool.disabled = disableAll; + } +} + - (SSignal *)histogramSignal { return [[SSignal single:_currentHistogram] then:_histogramPipe.signalProducer()]; diff --git a/submodules/LegacyComponents/Sources/PGPhotoTool.m b/submodules/LegacyComponents/Sources/PGPhotoTool.m index 7634ee9751..2ab09c6f42 100644 --- a/submodules/LegacyComponents/Sources/PGPhotoTool.m +++ b/submodules/LegacyComponents/Sources/PGPhotoTool.m @@ -81,6 +81,9 @@ - (id)displayValue { + if (self.disabled) + return @(self.defaultValue); + if (self.beingEdited) return self.tempValue; @@ -91,8 +94,14 @@ { _disabled = disabled; - if (self.beingEdited) + if (!self.beingEdited) { [self updateParameters]; + [self updatePassParameters]; + } +} + +- (void)updatePassParameters { + } - (void)setBeingEdited:(bool)beingEdited diff --git a/submodules/LegacyComponents/Sources/PGTintTool.m b/submodules/LegacyComponents/Sources/PGTintTool.m index 57d5ae28e8..c6f8148bc8 100644 --- a/submodules/LegacyComponents/Sources/PGTintTool.m +++ b/submodules/LegacyComponents/Sources/PGTintTool.m @@ -53,6 +53,15 @@ return true; } ++ (instancetype)defaultValue { + PGTintToolValue *value = [[PGTintToolValue alloc] init]; + value.shadowsColor = [UIColor clearColor]; + value.shadowsIntensity = 50.0f; + value.highlightsColor = [UIColor clearColor]; + value.highlightsIntensity = 50.0f; + return value; +} + @end @@ -80,13 +89,7 @@ _maximumValue = 100; _defaultValue = 0; - PGTintToolValue *value = [[PGTintToolValue alloc] init]; - value.shadowsColor = [UIColor clearColor]; - value.shadowsIntensity = 50.0f; - value.highlightsColor = [UIColor clearColor]; - value.highlightsIntensity = 50.0f; - - self.value = value; + self.value = [PGTintToolValue defaultValue]; } return self; } @@ -150,6 +153,14 @@ return _parameters; } +- (id)displayValue { + if (self.disabled) { + return [PGTintToolValue defaultValue]; + } else { + return [super displayValue]; + } +} + - (void)updateParameters { PGTintToolValue *value = (PGTintToolValue *)self.displayValue; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 47d3800cb3..1735660f5e 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -39,7 +39,6 @@ #import "TGPhotoToolsController.h" #import "TGPhotoPaintController.h" #import "TGPhotoQualityController.h" -#import "TGPhotoEditorItemController.h" #import "TGMessageImageViewOverlayView.h" diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorItemController.h b/submodules/LegacyComponents/Sources/TGPhotoEditorItemController.h deleted file mode 100644 index 008fd2eb10..0000000000 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorItemController.h +++ /dev/null @@ -1,26 +0,0 @@ -#import - -#import "PGPhotoEditorItem.h" - -@class PGPhotoEditor; -@class TGPhotoEditorPreviewView; - -@interface TGPhotoEditorItemController : TGViewController - -@property (nonatomic, copy) void(^editorItemUpdated)(void); -@property (nonatomic, copy) void(^beginTransitionIn)(void); -@property (nonatomic, copy) void(^beginTransitionOut)(void); -@property (nonatomic, copy) void(^finishedCombinedTransition)(void); - -@property (nonatomic, assign) CGFloat toolbarLandscapeSize; -@property (nonatomic, assign) bool initialAppearance; -@property (nonatomic, assign) bool skipProcessingOnCompletion; - -- (instancetype)initWithContext:(id)context editorItem:(id)editorItem photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView; - -- (void)attachPreviewView:(TGPhotoEditorPreviewView *)previewView; - -- (void)prepareForCombinedAppearance; -- (void)finishedCombinedAppearance; - -@end diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorItemController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorItemController.m deleted file mode 100644 index 659c96c8cd..0000000000 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorItemController.m +++ /dev/null @@ -1,701 +0,0 @@ -#import "TGPhotoEditorItemController.h" - -#import "LegacyComponentsInternal.h" -#import "TGImageUtils.h" - -#import "TGPhotoEditorTabController.h" - -#import - -#import "PGPhotoEditor.h" -#import "PGPhotoEditorItem.h" -#import "PGPhotoFilter.h" -#import "PGPhotoTool.h" - -#import "TGPhotoEditorPreviewView.h" -#import "TGPhotoEditorToolButtonsView.h" - -#import -#import "TGPhotoEditorInterfaceAssets.h" - -@interface TGPhotoEditorItemController () -{ - id _editorItem; - - UIView *_wrapperView; - UIView *_portraitToolsWrapperView; - UIView *_landscapeToolsWrapperView; - - UIView *_toolAreaView; - UIView *_portraitToolControlView; - UIView *_landscapeToolControlView; - - TGPhotoEditorToolButtonsView *_portraitButtonsView; - TGPhotoEditorToolButtonsView *_landscapeButtonsView; - - UIView *_initialPreviewSuperview; - bool _dismissing; - bool _animating; - - bool _enhanceInitialAppearance; -} - -@property (nonatomic, weak) PGPhotoEditor *photoEditor; -@property (nonatomic, weak) TGPhotoEditorPreviewView *previewView; - -@end - -@implementation TGPhotoEditorItemController - -- (instancetype)initWithContext:(id)context editorItem:(id)editorItem photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView -{ - self = [super initWithContext:context]; - if (self != nil) - { - _editorItem = editorItem; - _editorItem.beingEdited = true; - _editorItem.tempValue = [_editorItem.value copy]; - - self.photoEditor = photoEditor; - self.previewView = previewView; - - _initialPreviewSuperview = previewView.superview; - } - return self; -} - -- (void)dealloc -{ - TGPhotoEditorPreviewView *previewView = self.previewView; - previewView.touchedDown = nil; - previewView.touchedUp = nil; -} - -- (void)loadView -{ - [super loadView]; - - __weak TGPhotoEditorItemController *weakSelf = self; - void(^interactionEnded)(void) = ^ - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - if ([strongSelf shouldAutorotate]) - [TGViewController attemptAutorotation]; - }; - - _wrapperView = [[UIView alloc] initWithFrame:CGRectZero]; - _wrapperView.alpha = 0.0f; - _wrapperView.backgroundColor = [UIColor blackColor]; - [self.view addSubview:_wrapperView]; - - TGPhotoEditorPreviewView *previewView = self.previewView; - if (previewView != nil) - [self attachPreviewView:previewView]; - - PGPhotoEditor *photoEditor = self.photoEditor; - - _toolAreaView = [_editorItem itemAreaViewWithChangeBlock:^(id __unused newValue) - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - [strongSelf->_portraitToolControlView setValue:newValue]; - [strongSelf->_landscapeToolControlView setValue:newValue]; - - PGPhotoEditor *photoEditor = strongSelf.photoEditor; - [photoEditor processAnimated:false completion:nil]; - }]; - _toolAreaView.interactionEnded = interactionEnded; - - if (_toolAreaView != nil) - [self.view addSubview:_toolAreaView]; - - _portraitToolsWrapperView = [[UIView alloc] initWithFrame:CGRectZero]; - [_wrapperView addSubview:_portraitToolsWrapperView]; - - _landscapeToolsWrapperView = [[UIView alloc] initWithFrame:CGRectZero]; - [_wrapperView addSubview:_landscapeToolsWrapperView]; - - _portraitToolControlView = [_editorItem itemControlViewWithChangeBlock:^(id newValue, bool animated) - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - [strongSelf->_toolAreaView setValue:newValue]; - [strongSelf->_landscapeToolControlView setValue:newValue]; - - PGPhotoEditor *photoEditor = strongSelf.photoEditor; - [photoEditor processAnimated:animated completion:nil]; - }]; - _portraitToolControlView.backgroundColor = [TGPhotoEditorInterfaceAssets panelBackgroundColor]; - _portraitToolControlView.clipsToBounds = true; - _portraitToolControlView.interactionEnded = interactionEnded; - _portraitToolControlView.layer.rasterizationScale = TGScreenScaling(); - _portraitToolControlView.isLandscape = false; - - if ([_portraitToolControlView respondsToSelector:@selector(setHistogramSignal:)]) - [_portraitToolControlView setHistogramSignal:photoEditor.histogramSignal]; - - [_portraitToolsWrapperView addSubview:_portraitToolControlView]; - - _landscapeToolControlView = [_editorItem itemControlViewWithChangeBlock:^(id newValue, bool animated) - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - [strongSelf->_toolAreaView setValue:newValue]; - [strongSelf->_portraitToolControlView setValue:newValue]; - - PGPhotoEditor *photoEditor = strongSelf.photoEditor; - [photoEditor processAnimated:animated completion:nil]; - }]; - _landscapeToolControlView.backgroundColor = [TGPhotoEditorInterfaceAssets panelBackgroundColor]; - _landscapeToolControlView.clipsToBounds = true; - _landscapeToolControlView.interactionEnded = interactionEnded; - _landscapeToolControlView.layer.rasterizationScale = TGScreenScaling(); - _landscapeToolControlView.isLandscape = true; - _landscapeToolControlView.toolbarLandscapeSize = self.toolbarLandscapeSize; - - if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad) - { - if ([_landscapeToolControlView respondsToSelector:@selector(setHistogramSignal:)]) - [_landscapeToolControlView setHistogramSignal:photoEditor.histogramSignal]; - - [_landscapeToolsWrapperView addSubview:_landscapeToolControlView]; - } - - void(^cancelPressed)(void) = ^ - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - if (strongSelf->_toolAreaView.isTracking || strongSelf->_portraitToolControlView.isTracking || strongSelf->_landscapeToolControlView.isTracking || strongSelf->_animating) - return; - - - if (![strongSelf->_portraitToolControlView buttonPressed:true]) - return; - - strongSelf->_editorItem.beingEdited = false; - strongSelf->_editorItem.tempValue = nil; - - [strongSelf transitionOutWithCompletion:^ - { - [strongSelf removeFromParentViewController]; - [strongSelf.view removeFromSuperview]; - }]; - - PGPhotoEditor *photoEditor = strongSelf.photoEditor; - [photoEditor processAnimated:false completion:nil]; - }; - - void(^confirmPressed)(void) = ^ - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - if (strongSelf->_toolAreaView.isTracking || strongSelf->_portraitToolControlView.isTracking || strongSelf->_landscapeToolControlView.isTracking || strongSelf->_animating) - return; - - if (![strongSelf->_portraitToolControlView buttonPressed:false]) - return; - - id value = strongSelf->_editorItem.tempValue; - if ([value conformsToProtocol:@protocol(PGCustomToolValue)]) - value = [(id)value cleanValue]; - - strongSelf->_editorItem.value = value; - strongSelf->_editorItem.beingEdited = false; - strongSelf->_editorItem.tempValue = nil; - - if (strongSelf.editorItemUpdated != nil) - strongSelf.editorItemUpdated(); - - [strongSelf transitionOutWithCompletion:^ - { - [strongSelf removeFromParentViewController]; - [strongSelf.view removeFromSuperview]; - }]; - }; - - NSString *cancelButton = TGLocalized(@"Common.Cancel"); - if (self.initialAppearance) - cancelButton = TGLocalized(@"PhotoEditor.Skip"); - NSString *doneButton = TGLocalized(@"PhotoEditor.Set"); - - _portraitButtonsView = [[TGPhotoEditorToolButtonsView alloc] initWithCancelButton:cancelButton doneButton:doneButton]; - _portraitButtonsView.cancelPressed = cancelPressed; - _portraitButtonsView.confirmPressed = confirmPressed; - [_portraitToolsWrapperView addSubview:_portraitButtonsView]; - - _landscapeButtonsView = [[TGPhotoEditorToolButtonsView alloc] initWithCancelButton:cancelButton doneButton:doneButton]; - _landscapeButtonsView.cancelPressed = cancelPressed; - _landscapeButtonsView.confirmPressed = confirmPressed; - [_landscapeToolsWrapperView addSubview:_landscapeButtonsView]; -} - -- (void)attachPreviewView:(TGPhotoEditorPreviewView *)previewView -{ - self.previewView = previewView; - _initialPreviewSuperview = previewView.superview; - [self.view insertSubview:previewView aboveSubview:_wrapperView]; - - __weak TGPhotoEditorItemController *weakSelf = self; - void(^interactionEnded)(void) = ^ - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - if ([strongSelf shouldAutorotate]) - [TGViewController attemptAutorotation]; - }; - - previewView.touchedDown = ^ - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - strongSelf->_editorItem.beingEdited = false; - - PGPhotoEditor *photoEditor = strongSelf->_photoEditor; - [photoEditor processAnimated:false completion:nil]; - }; - - previewView.touchedUp = ^ - { - __strong TGPhotoEditorItemController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - strongSelf->_editorItem.beingEdited = true; - - PGPhotoEditor *photoEditor = strongSelf->_photoEditor; - [photoEditor processAnimated:false completion:nil]; - }; - previewView.interactionEnded = interactionEnded; - - if (!_enhanceInitialAppearance) - return; - - [_editorItem setTempValue:@(50)]; - - PGPhotoEditor *photoEditor = self.photoEditor; - if (photoEditor.readyForProcessing && !self.skipProcessingOnCompletion) - { - [photoEditor processAnimated:false completion:^ - { - TGDispatchOnMainThread(^ - { - TGPhotoEditorPreviewView *previewView = self.previewView; - [previewView performTransitionInWithCompletion:nil]; - }); - }]; - } - else - { - if (self.finishedCombinedTransition != nil) - self.finishedCombinedTransition(); - } -} - -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - [self transitionIn]; -} - -- (BOOL)shouldAutorotate -{ - TGPhotoEditorPreviewView *previewView = self.previewView; - return (!previewView.isTracking && !(_toolAreaView != nil && _toolAreaView.isTracking) && !_portraitToolControlView.isTracking && !_landscapeToolControlView.isTracking && [super shouldAutorotate]); -} - -- (BOOL)prefersStatusBarHidden -{ - if ([self inFormSheet]) - return false; - - return true; -} - -- (UIBarStyle)requiredNavigationBarStyle -{ - return UIBarStyleDefault; -} - -- (bool)navigationBarShouldBeHidden -{ - return true; -} - -- (void)_applyDefaultEnhanceIfNeeded -{ - if (_dismissing || fabsf([_editorItem.displayValue floatValue]) > FLT_EPSILON) - return; - - _animating = true; - - POPBasicAnimation *animation = [POPBasicAnimation animation]; - POPAnimatableProperty *valueProperty = [POPAnimatableProperty propertyWithName:@"org.telegram.enhanceValue" initializer:^(POPMutableAnimatableProperty *prop) - { - prop.readBlock = ^(TGPhotoEditorItemController *obj, CGFloat values[]) - { - values[0] = [[obj->_portraitToolControlView value] floatValue]; - }; - prop.writeBlock = ^(TGPhotoEditorItemController *obj, const CGFloat values[]) - { - [obj->_portraitToolControlView setValue:@(values[0])]; - [obj->_landscapeToolControlView setValue:@(values[0])]; - }; - }]; - animation.property = valueProperty; - animation.fromValue = @(0); - animation.toValue = @(50.0f); - animation.duration = 0.3f; - animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; - animation.completionBlock = ^(__unused POPAnimation *animation, __unused BOOL finished) - { - _animating = false; - - if (_enhanceInitialAppearance) - return; - - [_editorItem setTempValue:@(50)]; - - PGPhotoEditor *photoEditor = self.photoEditor; - [photoEditor processAnimated:true completion:nil]; - }; - [self pop_addAnimation:animation forKey:@"enhanceValue"]; -} - -#pragma mark - Transition - -- (void)prepareForCombinedAppearance -{ - _enhanceInitialAppearance = true; - - _wrapperView.backgroundColor = [UIColor clearColor]; - _portraitToolControlView.backgroundColor = [UIColor clearColor]; - _landscapeToolControlView.backgroundColor = [UIColor clearColor]; -} - -- (void)finishedCombinedAppearance -{ - _wrapperView.backgroundColor = [UIColor blackColor]; - _portraitToolControlView.backgroundColor = [TGPhotoEditorInterfaceAssets panelBackgroundColor]; - _landscapeToolControlView.backgroundColor = [TGPhotoEditorInterfaceAssets panelBackgroundColor]; -} - -- (void)transitionIn -{ - if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) - _portraitToolControlView.layer.shouldRasterize = true; - else - _landscapeToolControlView.layer.shouldRasterize = true; - - CGRect targetFrame; - CGRect toolTargetFrame; - switch (self.interfaceOrientation) - { - case UIInterfaceOrientationLandscapeLeft: - { - targetFrame = _landscapeButtonsView.frame; - _landscapeButtonsView.frame = CGRectOffset(_landscapeButtonsView.frame, -_landscapeButtonsView.frame.size.width, 0); - toolTargetFrame = _landscapeToolsWrapperView.frame; - _landscapeToolsWrapperView.frame = CGRectOffset(_landscapeToolsWrapperView.frame, -_landscapeToolsWrapperView.frame.size.width / 2 - 20, 0); - } - break; - case UIInterfaceOrientationLandscapeRight: - { - targetFrame = _landscapeButtonsView.frame; - _landscapeButtonsView.frame = CGRectOffset(_landscapeButtonsView.frame, _landscapeButtonsView.frame.size.width, 0); - toolTargetFrame = _landscapeToolsWrapperView.frame; - _landscapeToolsWrapperView.frame = CGRectOffset(_landscapeToolsWrapperView.frame, _landscapeToolsWrapperView.frame.size.width / 2 + 20, 0); - } - break; - - default: - { - targetFrame = _portraitButtonsView.frame; - _portraitButtonsView.frame = CGRectOffset(_portraitButtonsView.frame, 0, _portraitButtonsView.frame.size.height); - toolTargetFrame = _portraitToolsWrapperView.frame; - _portraitToolsWrapperView.frame = CGRectOffset(_portraitToolsWrapperView.frame, 0, _portraitToolsWrapperView.frame.size.height / 2 + 20); - } - break; - } - - void (^animationBlock)(void) = ^ - { - if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { - _portraitButtonsView.frame = targetFrame; - _portraitToolsWrapperView.frame = toolTargetFrame; - } - else { - _landscapeButtonsView.frame = targetFrame; - _landscapeToolsWrapperView.frame = toolTargetFrame; - } - }; - - [UIView animateWithDuration:0.3f animations:^ - { - _wrapperView.alpha = 1.0f; - } completion:^(BOOL finished) - { - if (finished) - { - _portraitToolControlView.layer.shouldRasterize = false; - _landscapeToolControlView.layer.shouldRasterize = false; - } - }]; - - if ([_editorItem.identifier isEqualToString:@"enhance"]) - [self _applyDefaultEnhanceIfNeeded]; - - if (iosMajorVersion() >= 7) - [UIView animateWithDuration:0.4f delay:0.0f usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveLinear animations:animationBlock completion:nil]; - else - [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionAllowUserInteraction animations:animationBlock completion:nil]; - - if (self.beginTransitionIn != nil) - self.beginTransitionIn(); -} - -- (void)transitionOutWithCompletion:(void (^)(void))completion -{ - _dismissing = true; - - TGPhotoEditorPreviewView *previewView = self.previewView; - previewView.interactionEnded = nil; - - if (self.beginTransitionOut != nil) - self.beginTransitionOut(); - - UIView *snapshotView = [previewView snapshotViewAfterScreenUpdates:false]; - snapshotView.frame = previewView.frame; - [previewView.superview addSubview:snapshotView]; - - _wrapperView.backgroundColor = [UIColor clearColor]; - - [_initialPreviewSuperview addSubview:self.previewView]; - - if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) - _portraitToolControlView.layer.shouldRasterize = true; - else - _landscapeToolControlView.layer.shouldRasterize = true; - - [_toolAreaView.superview bringSubviewToFront:_toolAreaView]; - - [UIView animateWithDuration:0.3f animations:^ - { - _wrapperView.alpha = 0.0f; - snapshotView.alpha = 0.0f; - _toolAreaView.alpha = 0.0f; - } completion:^(__unused BOOL finished) - { - dispatch_async(dispatch_get_main_queue(), ^ - { - if (completion != nil) - completion(); - }); - }]; - - void (^animationBlock)(void) = ^ - { - switch (self.interfaceOrientation) - { - case UIInterfaceOrientationLandscapeLeft: - { - _landscapeButtonsView.frame = CGRectOffset(_landscapeButtonsView.frame, -_landscapeButtonsView.frame.size.width, 0); - } - break; - case UIInterfaceOrientationLandscapeRight: - { - _landscapeButtonsView.frame = CGRectOffset(_landscapeButtonsView.frame, _landscapeButtonsView.frame.size.width, 0); - } - break; - - default: - { - _portraitButtonsView.frame = CGRectOffset(_portraitButtonsView.frame, 0, _portraitButtonsView.frame.size.height); - } - break; - } - }; - - UIInterfaceOrientation orientation = [[LegacyComponentsGlobals provider] applicationStatusBarOrientation]; - if ([self inFormSheet] || [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) - { - orientation = UIInterfaceOrientationPortrait; - } - else if ([self.presentingViewController isKindOfClass:[TGNavigationController class]] && - [(TGNavigationController *)self.presentingViewController presentationStyle] == TGNavigationControllerPresentationStyleInFormSheet) - { - orientation = UIInterfaceOrientationPortrait; - } - - if (UIInterfaceOrientationIsPortrait(orientation)) - _landscapeToolsWrapperView.hidden = true; - else - _portraitToolsWrapperView.hidden = true; - - if (iosMajorVersion() >= 7) - { - [UIView animateWithDuration:0.4f delay:0.0f usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveLinear animations:animationBlock completion:nil]; - } - else - { - [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionAllowUserInteraction animations:animationBlock completion:nil]; - } -} - -#pragma mark - Layout - -- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration -{ - [self.view setNeedsLayout]; - - if (_toolAreaView != nil) - { - _toolAreaView.alpha = 0.0f; - - [UIView animateWithDuration:duration / 2 delay:duration / 2 options:UIViewAnimationOptionCurveLinear animations:^ - { - _toolAreaView.alpha = 1.0f; - } completion:nil]; - } - - [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; -} - -- (void)viewWillLayoutSubviews -{ - [super viewWillLayoutSubviews]; - - [self updateLayout:[[LegacyComponentsGlobals provider] applicationStatusBarOrientation]]; -} - -- (CGSize)referenceViewSize -{ - if (self.parentViewController != nil) - { - TGPhotoEditorController *controller = (TGPhotoEditorController *)self.parentViewController; - return [controller referenceViewSize]; - } - - return CGSizeZero; -} - -- (void)updateLayout:(UIInterfaceOrientation)orientation -{ - CGSize referenceSize = [self referenceViewSize]; - - if ([self inFormSheet] || [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) - { - orientation = UIInterfaceOrientationPortrait; - } - else if ([self.presentingViewController isKindOfClass:[TGNavigationController class]] && - [(TGNavigationController *)self.presentingViewController presentationStyle] == TGNavigationControllerPresentationStyleInFormSheet) - { - orientation = UIInterfaceOrientationPortrait; - } - - CGFloat screenSide = MAX(referenceSize.width, referenceSize.height) + 2 * TGPhotoEditorPanelSize; - _wrapperView.frame = CGRectMake((referenceSize.width - screenSide) / 2, (referenceSize.height - screenSide) / 2, screenSide, screenSide); - - CGFloat panelToolbarPortraitSize = TGPhotoEditorPanelSize + TGPhotoEditorToolbarSize; - CGFloat panelToolbarLandscapeSize = TGPhotoEditorPanelSize + self.toolbarLandscapeSize; - - switch (orientation) - { - case UIInterfaceOrientationLandscapeLeft: - { - [UIView performWithoutAnimation:^ - { - _landscapeToolsWrapperView.frame = CGRectMake(0, (screenSide - referenceSize.height) / 2, panelToolbarLandscapeSize, _landscapeToolsWrapperView.frame.size.height); - _landscapeToolControlView.frame = CGRectMake(panelToolbarLandscapeSize - TGPhotoEditorPanelSize, 0, TGPhotoEditorPanelSize, _landscapeToolsWrapperView.frame.size.height); - - if (!_dismissing) - _landscapeButtonsView.frame = CGRectMake(0, 0, [_landscapeButtonsView landscapeSize], referenceSize.height); - }]; - - _landscapeToolsWrapperView.frame = CGRectMake((screenSide - referenceSize.width) / 2, (screenSide - referenceSize.height) / 2, panelToolbarLandscapeSize, referenceSize.height); - - _landscapeToolControlView.frame = CGRectMake(panelToolbarLandscapeSize - TGPhotoEditorPanelSize, 0, TGPhotoEditorPanelSize, _landscapeToolsWrapperView.frame.size.height); - - _portraitToolsWrapperView.frame = CGRectMake((screenSide - referenceSize.width) / 2, screenSide - panelToolbarPortraitSize, referenceSize.width, panelToolbarPortraitSize); - } - break; - - case UIInterfaceOrientationLandscapeRight: - { - [UIView performWithoutAnimation:^ - { - _landscapeToolsWrapperView.frame = CGRectMake(screenSide - panelToolbarLandscapeSize, (screenSide - referenceSize.height) / 2, panelToolbarLandscapeSize, _landscapeToolsWrapperView.frame.size.height); - _landscapeToolControlView.frame = CGRectMake(0, 0, TGPhotoEditorPanelSize, _landscapeToolsWrapperView.frame.size.height); - - if (!_dismissing) - _landscapeButtonsView.frame = CGRectMake(panelToolbarLandscapeSize - [_landscapeButtonsView landscapeSize], 0, [_landscapeButtonsView landscapeSize], referenceSize.height); - }]; - - _landscapeToolsWrapperView.frame = CGRectMake((screenSide + referenceSize.width) / 2 - panelToolbarLandscapeSize, (screenSide - referenceSize.height) / 2, panelToolbarLandscapeSize, referenceSize.height); - - _landscapeToolControlView.frame = CGRectMake(0, 0, TGPhotoEditorPanelSize, _landscapeToolsWrapperView.frame.size.height); - - _portraitToolsWrapperView.frame = CGRectMake((screenSide - referenceSize.width) / 2, screenSide - panelToolbarPortraitSize, referenceSize.width, panelToolbarPortraitSize); - } - break; - - default: - { - CGFloat x = _landscapeToolsWrapperView.frame.origin.x; - if (x < screenSide / 2) - x = 0; - else - x = screenSide - TGPhotoEditorPanelSize; - _landscapeToolsWrapperView.frame = CGRectMake(x, (screenSide - referenceSize.height) / 2, panelToolbarLandscapeSize, referenceSize.height); - - _portraitToolsWrapperView.frame = CGRectMake((screenSide - referenceSize.width) / 2, (screenSide + referenceSize.height) / 2 - panelToolbarPortraitSize, referenceSize.width, panelToolbarPortraitSize); - - if (!_dismissing) - _portraitButtonsView.frame = CGRectMake(0, _portraitToolsWrapperView.frame.size.height - TGPhotoEditorToolButtonsViewSize, _portraitToolsWrapperView.frame.size.width, TGPhotoEditorToolButtonsViewSize); - - _portraitToolControlView.frame = CGRectMake(0, 0, _portraitToolsWrapperView.frame.size.width, _portraitToolsWrapperView.frame.size.height - _portraitButtonsView.frame.size.height); - } - break; - } - - PGPhotoEditor *photoEditor = self.photoEditor; - TGPhotoEditorPreviewView *previewView = self.previewView; - - if (_dismissing || previewView.superview != self.view) - return; - - bool hasOnScreenNavigation = false; - if (iosMajorVersion() >= 11) - hasOnScreenNavigation = (self.viewLoaded && self.view.safeAreaInsets.bottom > FLT_EPSILON) || self.context.safeAreaInset.bottom > FLT_EPSILON; - - CGRect containerFrame = [TGPhotoEditorTabController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:orientation panelSize:TGPhotoEditorPanelSize hasOnScreenNavigation:hasOnScreenNavigation]; - CGSize fittedSize = TGScaleToSize(photoEditor.rotatedCropSize, containerFrame.size); - previewView.frame = CGRectMake(containerFrame.origin.x + (containerFrame.size.width - fittedSize.width) / 2, - containerFrame.origin.y + (containerFrame.size.height - fittedSize.height) / 2, - fittedSize.width, - fittedSize.height); - - [UIView performWithoutAnimation:^ - { - _toolAreaView.frame = CGRectMake(CGRectGetMidX(previewView.frame) - containerFrame.size.width / 2, CGRectGetMidY(previewView.frame) - containerFrame.size.height / 2, containerFrame.size.width, containerFrame.size.height); - _toolAreaView.actualAreaSize = previewView.frame.size; - }]; -} - -@end diff --git a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m index adbb4baf1a..d5507ea0d0 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m @@ -19,7 +19,6 @@ #import #import "TGPhotoEditorController.h" -#import "TGPhotoEditorItemController.h" #import "TGPhotoEditorPreviewView.h" #import "TGPhotoEditorHUDView.h" @@ -62,7 +61,6 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize @property (nonatomic, weak) PGPhotoEditor *photoEditor; @property (nonatomic, weak) TGPhotoEditorPreviewView *previewView; -@property (nonatomic, weak) TGPhotoEditorItemController *editorItemController; @end @@ -147,23 +145,36 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize TGPhotoEditorPreviewView *previewView = _previewView; previewView.hidden = true; previewView.interactionEnded = _interactionEnded; + + bool forVideo = _photoEditor.forVideo; previewView.touchedUp = ^ { __strong TGPhotoToolsController *strongSelf = weakSelf; - if (strongSelf != nil) + if (strongSelf != nil) { [strongSelf->_hudView setText:nil]; + + if (forVideo) { + strongSelf->_photoEditor.disableAll = false; + } + } }; previewView.touchedDown = ^ { __strong TGPhotoToolsController *strongSelf = weakSelf; - if (strongSelf != nil) + if (strongSelf != nil) { [strongSelf->_hudView setText:TGLocalized(@"PhotoEditor.Original")]; + + if (forVideo) { + strongSelf->_photoEditor.disableAll = true; + } + } }; previewView.tapped = ^{ __strong TGPhotoToolsController *strongSelf = weakSelf; if (strongSelf != nil) [strongSelf setPreview:!strongSelf->_preview animated:true]; }; + previewView.customTouchDownHandling = forVideo; [self.view addSubview:_previewView]; _wrapperView = [[TGPhotoToolsWrapperView alloc] initWithFrame:CGRectZero]; @@ -241,10 +252,6 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize - (BOOL)shouldAutorotate { - TGPhotoEditorItemController *controller = self.editorItemController; - if (controller != nil) - return [controller shouldAutorotate]; - bool toolTracking = _toolAreaView.isTracking || _portraitToolControlView.isTracking || _landscapeToolControlView.isTracking; TGPhotoEditorPreviewView *previewView = self.previewView; @@ -342,6 +349,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize TGPhotoEditorPreviewView *previewView = self.previewView; previewView.touchedUp = nil; previewView.touchedDown = nil; + previewView.tapped = nil; previewView.interactionEnded = nil; [_toolAreaView.superview bringSubviewToFront:_toolAreaView];