From 75b03440279a592648912aa323e506f6c7e32cda Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 25 May 2020 18:17:10 +0300 Subject: [PATCH] Video editor fixes --- .../LegacyComponents/TGCameraController.h | 3 + .../TGModernGalleryEditableItem.h | 2 + .../LegacyComponents/TGPaintingData.h | 2 + .../TGPhotoPaintStickersContext.h | 5 + .../LegacyComponents/TGPhotoVideoEditor.h | 2 +- .../Sources/TGCameraController.m | 2 + .../Sources/TGMediaEditingContext.m | 5 + .../Sources/TGMediaPickerGalleryGifItem.m | 1 + .../TGMediaPickerGalleryInterfaceView.m | 2 +- .../Sources/TGMediaPickerGalleryPhotoItem.m | 1 + .../TGMediaPickerGalleryPhotoItemView.m | 101 +++++++-- .../Sources/TGMediaPickerGalleryVideoItem.m | 1 + .../TGMediaPickerGalleryVideoItemView.m | 99 +++++--- .../Sources/TGMediaPickerModernGalleryMixin.m | 73 +----- .../LegacyComponents/Sources/TGPaintingData.m | 10 + .../Sources/TGPhotoEditorController.m | 5 +- .../Sources/TGPhotoEditorPreviewView.h | 1 + .../Sources/TGPhotoEditorPreviewView.m | 6 +- .../Sources/TGPhotoEntitiesContainerView.h | 8 + .../Sources/TGPhotoEntitiesContainerView.m | 43 ++++ .../Sources/TGPhotoPaintController.h | 5 + .../Sources/TGPhotoPaintController.m | 213 ++++++++---------- .../Sources/TGPhotoVideoEditor.m | 5 +- .../Sources/LegacyAttachmentMenu.swift | 2 +- .../Sources/LegacyMediaPickers.swift | 12 +- .../Sources/LegacyPaintStickerView.swift | 4 + .../Sources/LegacyPaintStickersContext.swift | 35 +++ .../TelegramUI/Sources/ChatController.swift | 16 ++ .../TelegramUI/Sources/LegacyCamera.swift | 12 +- .../Sources/LegacyWebSearchGallery.swift | 2 +- 30 files changed, 427 insertions(+), 251 deletions(-) diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraController.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraController.h index 087ed30219..1dc899f8e6 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraController.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGCameraController.h @@ -10,6 +10,8 @@ @class TGSuggestionContext; @class TGVideoEditAdjustments; +@protocol TGPhotoPaintStickersContext; + typedef enum { TGCameraControllerGenericIntent, TGCameraControllerPassportIntent, @@ -39,6 +41,7 @@ typedef enum { @property (nonatomic, assign) bool hasSchedule; @property (nonatomic, assign) bool reminder; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; +@property (nonatomic, strong) id stickersContext; @property (nonatomic, assign) bool shortcut; @property (nonatomic, strong) NSString *forcedCaption; diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernGalleryEditableItem.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernGalleryEditableItem.h index 3ab08a8602..9b5cc50370 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernGalleryEditableItem.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernGalleryEditableItem.h @@ -3,10 +3,12 @@ @protocol TGMediaEditableItem; @class TGMediaEditingContext; +@protocol TGPhotoPaintStickersContext; @protocol TGModernGalleryEditableItem @property (nonatomic, strong) TGMediaEditingContext *editingContext; +@property (nonatomic, strong) id stickersContext; - (id)editableMediaItem; - (TGPhotoEditorTab)toolbarTabs; diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPaintingData.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPaintingData.h index 99c180874b..d752c9d70e 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPaintingData.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPaintingData.h @@ -18,6 +18,8 @@ @property (nonatomic, readonly) UIImage *stillImage; +@property (nonatomic, readonly) bool hasAnimation; + + (instancetype)dataWithPaintingData:(NSData *)data image:(UIImage *)image stillImage:(UIImage *)stillImage entities:(NSArray *)entities undoManager:(TGPaintUndoManager *)undoManager; + (instancetype)dataWithPaintingImagePath:(NSString *)imagePath entities:(NSArray *)entities; diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h index 0fabec411e..33a0ab91c7 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h @@ -3,6 +3,7 @@ #import @class TGPaintingData; +@class TGStickerMaskDescription; @protocol TGPhotoPaintEntityRenderer @@ -12,12 +13,16 @@ @protocol TGPhotoPaintStickerRenderView +- (int64_t)documentId; - (UIImage *)image; @end @protocol TGPhotoPaintStickersContext +- (int64_t)documentIdForDocument:(id)document; +- (TGStickerMaskDescription *)maskDescriptionForDocument:(id)document; + - (UIView *)stickerViewForDocument:(id)document; @property (nonatomic, copy) void(^presentStickersController)(void(^)(id, bool, UIView *, CGRect)); diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h index 666a17ec58..d71f9344cf 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h @@ -2,6 +2,6 @@ @interface TGPhotoVideoEditor : NSObject -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed; ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName stickersContext:(id)stickersContext completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed; @end diff --git a/submodules/LegacyComponents/Sources/TGCameraController.m b/submodules/LegacyComponents/Sources/TGCameraController.m index 0472dc6420..5b55b4d80f 100644 --- a/submodules/LegacyComponents/Sources/TGCameraController.m +++ b/submodules/LegacyComponents/Sources/TGCameraController.m @@ -1147,6 +1147,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus galleryItem.selectionContext = _selectionContext; galleryItem.editingContext = _editingContext; + galleryItem.stickersContext = _stickersContext; if (enumerationBlock != nil) enumerationBlock(galleryItem); @@ -1652,6 +1653,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus intent = TGPhotoEditorControllerSignupAvatarIntent; } TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:windowContext item:image intent:(TGPhotoEditorControllerFromCameraIntent | intent) adjustments:nil caption:nil screenImage:image availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + controller.stickersContext = _stickersContext; __weak TGPhotoEditorController *weakController = controller; controller.beginTransitionIn = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView) { diff --git a/submodules/LegacyComponents/Sources/TGMediaEditingContext.m b/submodules/LegacyComponents/Sources/TGMediaEditingContext.m index fc5f82f9e0..02007a64e1 100644 --- a/submodules/LegacyComponents/Sources/TGMediaEditingContext.m +++ b/submodules/LegacyComponents/Sources/TGMediaEditingContext.m @@ -12,6 +12,8 @@ #import "TGMemoryImageCache.h" #import "TGMediaAsset.h" +#import "TGPaintingData.h" + @interface TGMediaImageUpdate : NSObject @property (nonatomic, readonly, strong) id item; @@ -749,6 +751,9 @@ if (![editorValues toolsApplied] && ![editorValues hasPainting]) return [SSignal complete]; + if ([editorValues.paintingData hasAnimation]) + return [SSignal complete]; + NSURL *url = [self _fullSizeImageUrlForItem:item]; if (url != nil) return [SSignal single:url]; diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryGifItem.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryGifItem.m index b3ae39fe4d..60b4674cf4 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryGifItem.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryGifItem.m @@ -7,6 +7,7 @@ @synthesize selectionContext; @synthesize editingContext; +@synthesize stickersContext; - (NSString *)uniqueId { diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m index d08466c329..b855f0c47b 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m @@ -900,7 +900,7 @@ } if (adjustments.sendAsGif) - disabledButtons |= TGPhotoEditorToolsTab | TGPhotoEditorQualityTab; + disabledButtons |= TGPhotoEditorQualityTab; [_portraitToolbarView setEditButtonsHighlighted:highlightedButtons]; [_landscapeToolbarView setEditButtonsHighlighted:highlightedButtons]; diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItem.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItem.m index 374b458e60..1f7f3fce7d 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItem.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItem.m @@ -7,6 +7,7 @@ @synthesize selectionContext; @synthesize editingContext; +@synthesize stickersContext; - (NSString *)uniqueId { diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItemView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItemView.m index dd4a37e10c..9c6d8cafcc 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItemView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryPhotoItemView.m @@ -20,6 +20,9 @@ #import "TGMediaPickerGalleryPhotoItem.h" +#import "TGPhotoEntitiesContainerView.h" +#import "TGPhotoPaintController.h" + #import @interface TGMediaPickerGalleryPhotoItemView () @@ -33,6 +36,10 @@ UIView *_temporaryRepView; PHLivePhotoView *_livePhotoView; + UIView *_contentWrapperView; + TGPhotoEntitiesContainerView *_entitiesContainerView; + + SMetaDisposable *_adjustmentsDisposable; SMetaDisposable *_attributesDisposable; TGMenuContainerView *_tooltipContainerView; @@ -54,6 +61,7 @@ { __weak TGMediaPickerGalleryPhotoItemView *weakSelf = self; _imageView = [[TGModernGalleryImageItemImageView alloc] init]; + _imageView.clipsToBounds = true; _imageView.progressChanged = ^(CGFloat value) { __strong TGMediaPickerGalleryPhotoItemView *strongSelf = weakSelf; @@ -70,17 +78,27 @@ }; [self.scrollView addSubview:_imageView]; + _contentWrapperView = [[UIView alloc] init]; + [_imageView addSubview:_contentWrapperView]; + + _entitiesContainerView = [[TGPhotoEntitiesContainerView alloc] init]; + _entitiesContainerView.userInteractionEnabled = false; + [_contentWrapperView addSubview:_entitiesContainerView]; + _fileInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)]; _fileInfoLabel.backgroundColor = [UIColor clearColor]; _fileInfoLabel.font = TGSystemFontOfSize(13); _fileInfoLabel.textAlignment = NSTextAlignmentCenter; _fileInfoLabel.textColor = [UIColor whiteColor]; + + _adjustmentsDisposable = [[SMetaDisposable alloc] init]; } return self; } - (void)dealloc { + [_adjustmentsDisposable dispose]; [_attributesDisposable dispose]; } @@ -106,6 +124,8 @@ { [super setItem:item synchronously:synchronously]; + _entitiesContainerView.stickersContext = item.stickersContext; + _imageSize = item.asset.originalSize; [self reset]; @@ -175,6 +195,17 @@ }]; } }]; + + SSignal *adjustmentsSignal = [item.editingContext adjustmentsSignalForItem:item.editableMediaItem]; + [_adjustmentsDisposable setDisposable:[[adjustmentsSignal deliverOn:[SQueue mainQueue]] startWithNext:^(__unused id next) + { + __strong TGMediaPickerGalleryPhotoItemView *strongSelf = weakSelf; + if (strongSelf == nil) + return; + + [strongSelf layoutEntities]; + [strongSelf->_entitiesContainerView setupWithPaintingData:next.paintingData]; + }]]; } if (item.immediateThumbnailImage != nil) @@ -199,25 +230,6 @@ strongSelf->_livePhotoView.frame = strongSelf->_imageView.frame; }]]; -// if (item.asset.subtypes & TGMediaAssetSubtypePhotoLive) -// { -// _livePhotoView = [[PHLivePhotoView alloc] init]; -// _livePhotoView.muted = true; -// _livePhotoView.contentMode = UIViewContentModeScaleAspectFill; -// _livePhotoView.hidden = self.imageView.hidden; -// _livePhotoView.frame = CGRectMake((self.containerView.frame.size.width - _imageSize.width) / 2.0f, (self.containerView.frame.size.height - _imageSize.height) / 2.0f, _imageSize.width, _imageSize.height); -// [self.containerView addSubview:_livePhotoView]; -// -// [[[TGMediaAssetImageSignals livePhotoForAsset:item.asset] deliverOn:[SQueue mainQueue]] startWithNext:^(PHLivePhoto *next) -// { -// __strong TGMediaPickerGalleryPhotoItemView *strongSelf = weakSelf; -// if (strongSelf == nil) -// return; -// -// strongSelf->_livePhotoView.livePhoto = next; -// }]; -// } - if (!item.asFile) return; @@ -407,4 +419,55 @@ } } +- (void)setFrame:(CGRect)frame { + [super setFrame:frame]; + + [self layoutEntities]; +} + +- (void)layoutEntities { + if (self.item == nil) { + return; + } + TGVideoEditAdjustments *adjustments = (TGVideoEditAdjustments *)[self.item.editingContext adjustmentsForItem:self.item.editableMediaItem]; + CGSize videoFrameSize = self.item.asset.originalSize; + CGRect cropRect = CGRectMake(0, 0, videoFrameSize.width, videoFrameSize.height); + UIImageOrientation orientation = UIImageOrientationUp; + bool mirrored = false; + if (adjustments != nil) + { + videoFrameSize = adjustments.cropRect.size; + cropRect = adjustments.cropRect; + orientation = adjustments.cropOrientation; + mirrored = adjustments.cropMirrored; + } + + [self _layoutPlayerViewWithCropRect:cropRect videoFrameSize:videoFrameSize orientation:orientation mirrored:mirrored]; +} + +- (void)_layoutPlayerViewWithCropRect:(CGRect)cropRect videoFrameSize:(CGSize)videoFrameSize orientation:(UIImageOrientation)orientation mirrored:(bool)mirrored +{ + CGSize originalSize = self.item.asset.originalSize; + CGRect rect = [TGPhotoPaintController fittedCropRect:cropRect originalSize:originalSize keepOriginalSize:true]; + _entitiesContainerView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); + + CGSize fittedOriginalSize = TGScaleToSize(originalSize, [TGPhotoPaintController maximumPaintingSize]); + CGSize rotatedSize = fittedOriginalSize; + CGPoint centerPoint = CGPointMake(rotatedSize.width / 2.0f, rotatedSize.height / 2.0f); + + CGFloat scale = fittedOriginalSize.width / originalSize.width; + CGPoint offset = TGPaintSubtractPoints(centerPoint, [TGPhotoPaintController fittedCropRect:cropRect centerScale:scale]); + + CGPoint boundsCenter = TGPaintCenterOfRect(_contentWrapperView.bounds); + _entitiesContainerView.center = TGPaintAddPoints(boundsCenter, offset); + + CGSize fittedContentSize = [TGPhotoPaintController fittedContentSize:cropRect orientation:UIImageOrientationUp originalSize:originalSize]; + CGRect fittedCropRect = [TGPhotoPaintController fittedCropRect:cropRect originalSize:originalSize keepOriginalSize:false]; + _contentWrapperView.frame = CGRectMake(0.0f, 0.0f, fittedContentSize.width, fittedContentSize.height); + + CGFloat contentScale = _imageView.bounds.size.width / fittedCropRect.size.width; + _contentWrapperView.transform = CGAffineTransformMakeScale(contentScale, contentScale); + _contentWrapperView.frame = CGRectMake(0.0f, 0.0f, _imageView.bounds.size.width, _imageView.bounds.size.height); +} + @end diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m index 24c0669722..227dcaae33 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m @@ -12,6 +12,7 @@ @synthesize selectionContext; @synthesize editingContext; +@synthesize stickersContext; - (CGSize)dimensions { diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m index 4a2e070b02..e8359a6088 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m @@ -30,6 +30,8 @@ #import "TGMediaPickerScrubberHeaderView.h" #import "TGPhotoEditorPreviewView.h" +#import "TGPhotoEntitiesContainerView.h" +#import "TGPhotoPaintController.h" #import #import "TGModernGalleryVideoContentView.h" @@ -69,11 +71,12 @@ UILabel *_fileInfoLabel; -// TGModernGalleryVideoView *_videoView; TGPhotoEditorPreviewView *_videoView; PGPhotoEditor *_photoEditor; UIImageView *_paintingImageView; + UIView *_contentWrapperView; + TGPhotoEntitiesContainerView *_entitiesContainerView; NSTimer *_positionTimer; TGObserverProxy *_didPlayToEndObserver; @@ -101,8 +104,6 @@ bool _sendAsGif; bool _autoplayed; - - bool _ignoreNextAdjustmentsChange; } @property (nonatomic, strong) TGMediaPickerGalleryVideoItem *item; @@ -149,6 +150,14 @@ _paintingImageView = [[UIImageView alloc] init]; [_playerContainerView addSubview:_paintingImageView]; + _contentWrapperView = [[UIView alloc] init]; + [_playerContainerView addSubview:_contentWrapperView]; + + _entitiesContainerView = [[TGPhotoEntitiesContainerView alloc] init]; + _entitiesContainerView.hidden = true; + _entitiesContainerView.userInteractionEnabled = false; + [_contentWrapperView addSubview:_entitiesContainerView]; + _curtainView = [[UIView alloc] init]; _curtainView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _curtainView.backgroundColor = [UIColor blackColor]; @@ -363,6 +372,7 @@ _scrubberView.allowsTrimming = false; _videoDimensions = item.dimensions; + _entitiesContainerView.stickersContext = item.stickersContext; __weak TGMediaPickerGalleryVideoItemView *weakSelf = self; [_videoDurationVar set:[[[item.durationSignal deliverOn:[SQueue mainQueue]] catch:^SSignal *(__unused id error) @@ -427,24 +437,18 @@ if (strongSelf == nil) return; - if (!strongSelf->_ignoreNextAdjustmentsChange) - { - [strongSelf _layoutPlayerView]; - TGVideoEditAdjustments *adjustments = (TGVideoEditAdjustments *)[strongSelf.item.editingContext adjustmentsForItem:strongSelf.item.editableMediaItem]; - strongSelf->_paintingImageView.image = adjustments.paintingData.image; - - strongSelf->_sendAsGif = adjustments.sendAsGif; - [strongSelf _mutePlayer:adjustments.sendAsGif]; - - if (adjustments.sendAsGif || ([strongSelf itemIsLivePhoto])) - [strongSelf setPlayButtonHidden:true animated:false]; - - [_photoEditor importAdjustments:adjustments]; - } - else - { - strongSelf->_ignoreNextAdjustmentsChange = false; - } + [strongSelf _layoutPlayerView]; + TGVideoEditAdjustments *adjustments = (TGVideoEditAdjustments *)[strongSelf.item.editingContext adjustmentsForItem:strongSelf.item.editableMediaItem]; + strongSelf->_paintingImageView.image = adjustments.paintingData.image; + + strongSelf->_sendAsGif = adjustments.sendAsGif; + [strongSelf _mutePlayer:adjustments.sendAsGif]; + + if (adjustments.sendAsGif || ([strongSelf itemIsLivePhoto])) + [strongSelf setPlayButtonHidden:true animated:false]; + + [strongSelf->_entitiesContainerView setupWithPaintingData:adjustments.paintingData]; + [strongSelf->_photoEditor importAdjustments:adjustments]; }]]; } else @@ -740,6 +744,27 @@ _imageView.frame = CGRectMake(-cropRect.origin.x * ratio, -cropRect.origin.y * ratio, _videoDimensions.width * ratio, _videoDimensions.height * ratio); _paintingImageView.frame = _imageView.frame; _videoView.frame = _imageView.frame; + + CGRect rect = [TGPhotoPaintController fittedCropRect:cropRect originalSize:_videoDimensions keepOriginalSize:true]; + _entitiesContainerView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); + + CGSize fittedOriginalSize = TGScaleToSize(_videoDimensions, [TGPhotoPaintController maximumPaintingSize]); + CGSize rotatedSize = fittedOriginalSize; + CGPoint centerPoint = CGPointMake(rotatedSize.width / 2.0f, rotatedSize.height / 2.0f); + + CGFloat scale = fittedOriginalSize.width / _videoDimensions.width; + CGPoint offset = TGPaintSubtractPoints(centerPoint, [TGPhotoPaintController fittedCropRect:cropRect centerScale:scale]); + + CGPoint boundsCenter = TGPaintCenterOfRect(_contentWrapperView.bounds); + _entitiesContainerView.center = TGPaintAddPoints(boundsCenter, offset); + + CGSize fittedContentSize = [TGPhotoPaintController fittedContentSize:cropRect orientation:UIImageOrientationUp originalSize:_videoDimensions]; + CGRect fittedCropRect = [TGPhotoPaintController fittedCropRect:cropRect originalSize:_videoDimensions keepOriginalSize:false]; + _contentWrapperView.frame = CGRectMake(0.0f, 0.0f, fittedContentSize.width, fittedContentSize.height); + + CGFloat contentScale = _playerWrapperView.bounds.size.width / fittedCropRect.size.width; + _contentWrapperView.transform = CGAffineTransformMakeScale(contentScale, contentScale); + _contentWrapperView.frame = CGRectMake(0.0f, 0.0f, _playerWrapperView.bounds.size.width, _playerWrapperView.bounds.size.height); } - (void)singleTap @@ -752,8 +777,10 @@ { [super setIsVisible:isVisible]; - if (!isVisible && _player != nil) + if (!isVisible && _player != nil) { [self stopPlayer]; + [self setPlayButtonHidden:false animated:false]; + } } - (UIView *)headerView @@ -994,6 +1021,8 @@ // }; // } // [_videoView cleanupPlayer]; + _photoEditor.previewOutput = nil; + [_videoView removeFromSuperview]; _videoView = nil; @@ -1054,23 +1083,20 @@ } strongSelf->_didPlayToEndObserver = [[TGObserverProxy alloc] initWithTarget:strongSelf targetSelector:@selector(playerItemDidPlayToEndTime:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem]; - -// strongSelf->_videoView = [[TGModernGalleryVideoView alloc] initWithFrame:strongSelf->_playerView.bounds player:strongSelf->_player]; -// strongSelf->_videoView.frame = strongSelf->_imageView.frame; -// strongSelf->_videoView.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; -// strongSelf->_videoView.playerLayer.opaque = false; -// strongSelf->_videoView.playerLayer.backgroundColor = nil; -// [strongSelf->_playerContainerView insertSubview:strongSelf->_videoView belowSubview:strongSelf->_paintingImageView]; - + TGVideoEditAdjustments *adjustments = (TGVideoEditAdjustments *)[strongSelf.item.editingContext adjustmentsForItem:strongSelf.item.editableMediaItem]; strongSelf->_videoView = [[TGPhotoEditorPreviewView alloc] initWithFrame:strongSelf->_imageView.frame]; + strongSelf->_videoView.customTouchDownHandling = true; + strongSelf->_videoView.userInteractionEnabled = false; [strongSelf->_playerContainerView insertSubview:strongSelf->_videoView belowSubview:strongSelf->_paintingImageView]; + strongSelf->_entitiesContainerView.hidden = false; + [strongSelf->_videoView setNeedsTransitionIn]; [strongSelf->_videoView performTransitionInIfNeeded]; - strongSelf->_photoEditor = [[PGPhotoEditor alloc] initWithOriginalSize:_videoDimensions adjustments:adjustments forVideo:true enableStickers:true]; + strongSelf->_photoEditor = [[PGPhotoEditor alloc] initWithOriginalSize:strongSelf->_videoDimensions adjustments:adjustments forVideo:true enableStickers:true]; strongSelf->_photoEditor.previewOutput = strongSelf->_videoView; [strongSelf->_photoEditor setPlayerItem:playerItem]; [strongSelf->_photoEditor processAnimated:false completion:nil]; @@ -1229,12 +1255,17 @@ _wasPlayingBeforeScrubbing = self.isPlaying; [self pausePressed]; + + [self setPlayButtonHidden:true animated:false]; } - (void)videoScrubberDidEndScrubbing:(TGMediaPickerGalleryVideoScrubber *)__unused videoScrubber { - if (_wasPlayingBeforeScrubbing) + if (_wasPlayingBeforeScrubbing) { [self play]; + } else { + [self setPlayButtonHidden:false animated:true]; + } } - (void)videoScrubber:(TGMediaPickerGalleryVideoScrubber *)__unused videoScrubber valueDidChange:(NSTimeInterval)position @@ -1260,6 +1291,8 @@ [self preparePlayerAndPlay:false]; [self pausePressed]; + + [self setPlayButtonHidden:true animated:false]; } - (void)videoScrubberDidEndEditing:(TGMediaPickerGalleryVideoScrubber *)__unused videoScrubber @@ -1267,6 +1300,8 @@ _shouldResetScrubber = false; [self updatePlayerRange:videoScrubber.trimEndValue]; [self updateEditAdjusments]; + + [self setPlayButtonHidden:false animated:true]; } - (void)videoScrubber:(TGMediaPickerGalleryVideoScrubber *)__unused videoScrubber editingStartValueDidChange:(NSTimeInterval)startValue diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m b/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m index b62ee3b8b3..b039a84f24 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m @@ -25,6 +25,7 @@ @interface TGMediaPickerModernGalleryMixin () { TGMediaEditingContext *_editingContext; + id _stickersContext; bool _asFile; __weak TGViewController *_parentController; @@ -59,6 +60,7 @@ _context = context; _parentController = parentController; _editingContext = asFile ? nil : editingContext; + _stickersContext = asFile? nil : stickersContext; _asFile = asFile; _itemsLimit = itemsLimit; @@ -81,7 +83,7 @@ } }; - NSArray *galleryItems = fetchResult != nil ? [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:selectionContext editingContext:editingContext asFile:asFile enumerationBlock:enumerationBlock] : [self prepareGalleryItemsForMomentList:momentList selectionContext:selectionContext editingContext:editingContext asFile:asFile enumerationBlock:enumerationBlock]; + NSArray *galleryItems = [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:selectionContext editingContext:editingContext stickersContext:stickersContext asFile:asFile enumerationBlock:enumerationBlock]; TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:[_windowManager context] items:galleryItems focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions hasSelectionPanel:true hasCamera:false recipientName:recipientName]; _galleryModel = model; @@ -312,7 +314,7 @@ } __block id focusItem = nil; - NSArray *galleryItems = [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:_galleryModel.selectionContext editingContext:_editingContext asFile:_asFile enumerationBlock:^(TGMediaPickerGalleryItem *item) + NSArray *galleryItems = [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:_galleryModel.selectionContext editingContext:_editingContext stickersContext:_stickersContext asFile:_asFile enumerationBlock:^(TGMediaPickerGalleryItem *item) { if (focusItem == nil && [item isEqual:_galleryController.currentItem]) focusItem = item; @@ -321,7 +323,7 @@ [_galleryModel _replaceItems:galleryItems focusingOnItem:focusItem]; } -- (NSArray *)prepareGalleryItemsForFetchResult:(TGMediaAssetFetchResult *)fetchResult selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext asFile:(bool)asFile enumerationBlock:(void (^)(TGMediaPickerGalleryItem *))enumerationBlock +- (NSArray *)prepareGalleryItemsForFetchResult:(TGMediaAssetFetchResult *)fetchResult selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext stickersContext:(id)stickersContext asFile:(bool)asFile enumerationBlock:(void (^)(TGMediaPickerGalleryItem *))enumerationBlock { NSMutableArray *galleryItems = [[NSMutableArray alloc] init]; @@ -350,16 +352,14 @@ default: { - if (false && asset.subtypes & TGMediaAssetSubtypePhotoLive) - galleryItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:asset]; - else - galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:asset]; + galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:asset]; } break; } galleryItem.selectionContext = selectionContext; galleryItem.editingContext = editingContext; + galleryItem.stickersContext = stickersContext; if (enumerationBlock != nil) enumerationBlock(galleryItem); @@ -373,65 +373,6 @@ return galleryItems; } -- (NSArray *)prepareGalleryItemsForMomentList:(TGMediaAssetMomentList *)momentList selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext asFile:(bool)asFile enumerationBlock:(void (^)(TGMediaPickerGalleryItem *))enumerationBlock -{ - NSMutableArray *galleryItems = [[NSMutableArray alloc] init]; - - for (NSUInteger i = 0; i < momentList.count; i++) - { - TGMediaAssetMoment *moment = momentList[i]; - - for (NSUInteger k = 0; k < moment.assetCount; k++) - { - TGMediaAsset *asset = [moment.fetchResult assetAtIndex:k]; - - TGMediaPickerGalleryItem *galleryItem = nil; - switch (asset.type) - { - case TGMediaAssetVideoType: - { - TGMediaPickerGalleryVideoItem *videoItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:asset]; - videoItem.selectionContext = selectionContext; - videoItem.editingContext = editingContext; - - galleryItem = videoItem; - } - break; - - case TGMediaAssetGifType: - { - TGMediaPickerGalleryGifItem *gifItem = [[TGMediaPickerGalleryGifItem alloc] initWithAsset:asset]; - gifItem.selectionContext = selectionContext; - gifItem.editingContext = editingContext; - - galleryItem = gifItem; - } - break; - - default: - { - TGMediaPickerGalleryPhotoItem *photoItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:asset]; - photoItem.selectionContext = selectionContext; - photoItem.editingContext = editingContext; - - galleryItem = photoItem; - } - break; - } - - if (enumerationBlock != nil) - enumerationBlock(galleryItem); - - galleryItem.asFile = asFile; - - if (galleryItem != nil) - [galleryItems addObject:galleryItem]; - } - } - - return galleryItems; -} - - (void)setThumbnailSignalForItem:(SSignal *(^)(id))thumbnailSignalForItem { [_galleryModel.interfaceView setThumbnailSignalForItem:thumbnailSignalForItem]; diff --git a/submodules/LegacyComponents/Sources/TGPaintingData.m b/submodules/LegacyComponents/Sources/TGPaintingData.m index 2cffd2f833..05d96c23e9 100644 --- a/submodules/LegacyComponents/Sources/TGPaintingData.m +++ b/submodules/LegacyComponents/Sources/TGPaintingData.m @@ -139,6 +139,16 @@ return [stickers allObjects]; } +- (bool)hasAnimation +{ + for (TGPhotoPaintEntity *entity in self.entities) + { + if ([entity isKindOfClass:[TGPhotoPaintStickerEntity class]] && ((TGPhotoPaintStickerEntity *)entity).animated) + return true; + } + return false; +} + - (BOOL)isEqual:(id)object { if (object == self) diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 1d00575973..47d3800cb3 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -587,6 +587,7 @@ bool hasImageAdjustments = editorValues.toolsApplied || saveOnly; bool hasPainting = editorValues.hasPainting; + bool hasAnimation = editorValues.paintingData.hasAnimation; SSignal *(^imageCropSignal)(UIImage *, bool) = ^(UIImage *image, bool resize) { @@ -647,14 +648,14 @@ { if (!hasImageAdjustments) { - if (hasPainting && self.didFinishRenderingFullSizeImage != nil) + if (hasPainting && !hasAnimation && self.didFinishRenderingFullSizeImage != nil) self.didFinishRenderingFullSizeImage(image); return image; } else { - if (!saveOnly && self.didFinishRenderingFullSizeImage != nil) + if (!saveOnly && !hasAnimation && self.didFinishRenderingFullSizeImage != nil) self.didFinishRenderingFullSizeImage(image); return TGPhotoEditorFitImage(image, TGPhotoEditorResultImageMaxSize); diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.h b/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.h index bda4935206..cfec872ce9 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.h +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.h @@ -14,6 +14,7 @@ @property (nonatomic, copy) void(^interactionEnded)(void); @property (nonatomic, readonly) bool isTracking; +@property (nonatomic, assign) bool customTouchDownHandling; - (void)setSnapshotImage:(UIImage *)image; - (void)setSnapshotView:(UIView *)view; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.m b/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.m index 004c437d20..b88dd69ab6 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorPreviewView.m @@ -228,7 +228,8 @@ if (self.touchedDown != nil) self.touchedDown(); - [self setActualImageHidden:true animated:false]; + if (!self.customTouchDownHandling) + [self setActualImageHidden:true animated:false]; } break; @@ -240,7 +241,8 @@ if (self.touchedUp != nil) self.touchedUp(); - [self setActualImageHidden:false animated:false]; + if (!self.customTouchDownHandling) + [self setActualImageHidden:false animated:false]; if (self.interactionEnded != nil) self.interactionEnded(); diff --git a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h index fa0909d874..f856159f02 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h +++ b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h @@ -1,13 +1,21 @@ #import "TGPhotoPaintSparseView.h" +#import "TGPhotoPaintStickersContext.h" +@class TGPaintingData; +@class TGPhotoPaintEntity; @class TGPhotoPaintEntityView; @interface TGPhotoEntitiesContainerView : TGPhotoPaintSparseView +@property (nonatomic, strong) id stickersContext; + @property (nonatomic, readonly) NSUInteger entitiesCount; @property (nonatomic, copy) void (^entitySelected)(TGPhotoPaintEntityView *); @property (nonatomic, copy) void (^entityRemoved)(TGPhotoPaintEntityView *); +- (void)setupWithPaintingData:(TGPaintingData *)paintingData; +- (TGPhotoPaintEntityView *)createEntityViewWithEntity:(TGPhotoPaintEntity *)entity; + - (TGPhotoPaintEntityView *)viewForUUID:(NSInteger)uuid; - (void)removeViewWithUUID:(NSInteger)uuid; - (void)removeAll; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m index f10718f5d0..7daca2f6c2 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m @@ -2,6 +2,7 @@ #import "TGPhotoPaintEntityView.h" #import "TGPhotoStickerEntityView.h" #import "TGPhotoTextEntityView.h" +#import "TGPaintingData.h" #import @@ -74,6 +75,48 @@ return MAX(0, (NSInteger)self.subviews.count - 1); } +- (void)setupWithPaintingData:(TGPaintingData *)paintingData { + [self removeAll]; + for (TGPhotoPaintEntity *entity in paintingData.entities) { + [self createEntityViewWithEntity:entity]; + } +} + +- (TGPhotoPaintEntityView *)createEntityViewWithEntity:(TGPhotoPaintEntity *)entity { + if ([entity isKindOfClass:[TGPhotoPaintStickerEntity class]]) + return [self _createStickerViewWithEntity:(TGPhotoPaintStickerEntity *)entity]; + else if ([entity isKindOfClass:[TGPhotoPaintTextEntity class]]) + return [self _createTextViewWithEntity:(TGPhotoPaintTextEntity *)entity]; + + return nil; +} + +- (TGPhotoStickerEntityView *)_createStickerViewWithEntity:(TGPhotoPaintStickerEntity *)entity +{ + TGPhotoStickerEntityView *stickerView = [[TGPhotoStickerEntityView alloc] initWithEntity:entity context:self.stickersContext]; + [self _commonEntityViewSetup:stickerView entity:entity]; + [self addSubview:stickerView]; + + return stickerView; +} + +- (TGPhotoTextEntityView *)_createTextViewWithEntity:(TGPhotoPaintTextEntity *)entity +{ + TGPhotoTextEntityView *textView = [[TGPhotoTextEntityView alloc] initWithEntity:entity]; + [textView sizeToFit]; + + [self _commonEntityViewSetup:textView entity:entity]; + [self addSubview:textView]; + + return textView; +} + +- (void)_commonEntityViewSetup:(TGPhotoPaintEntityView *)entityView entity:(TGPhotoPaintEntity *)entity +{ + entityView.transform = CGAffineTransformRotate(CGAffineTransformMakeScale(entity.scale, entity.scale), entity.angle); + entityView.center = entity.position; +} + - (TGPhotoPaintEntityView *)viewForUUID:(NSInteger)uuid { for (TGPhotoPaintEntityView *view in self.subviews) diff --git a/submodules/LegacyComponents/Sources/TGPhotoPaintController.h b/submodules/LegacyComponents/Sources/TGPhotoPaintController.h index 613341b8b2..1065af1daf 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoPaintController.h +++ b/submodules/LegacyComponents/Sources/TGPhotoPaintController.h @@ -17,6 +17,11 @@ + (CGRect)photoContainerFrameForParentViewFrame:(CGRect)parentViewFrame toolbarLandscapeSize:(CGFloat)toolbarLandscapeSize orientation:(UIInterfaceOrientation)orientation panelSize:(CGFloat)panelSize hasOnScreenNavigation:(bool)hasOnScreenNavigation; ++ (CGSize)fittedContentSize:(CGRect)cropRect orientation:(UIImageOrientation)orientation originalSize:(CGSize)originalSize; ++ (CGRect)fittedCropRect:(CGRect)cropRect originalSize:(CGSize)originalSize keepOriginalSize:(bool)originalSize; ++ (CGPoint)fittedCropRect:(CGRect)cropRect centerScale:(CGFloat)scale; ++ (CGSize)maximumPaintingSize; + @end extern const CGFloat TGPhotoPaintTopPanelSize; diff --git a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m index 3e808558a6..efc71959aa 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m @@ -163,7 +163,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; else _undoManager = [[TGPaintUndoManager alloc] init]; - CGSize size = TGScaleToSize(photoEditor.originalSize, [self maximumPaintingSize]); + CGSize size = TGScaleToSize(photoEditor.originalSize, [TGPhotoPaintController maximumPaintingSize]); _painting = [[TGPainting alloc] initWithSize:size undoManager:_undoManager imageData:[_photoEditor.paintingData data]]; _undoManager.painting = _painting; @@ -238,6 +238,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; _entitiesContainerView = [[TGPhotoEntitiesContainerView alloc] init]; _entitiesContainerView.clipsToBounds = true; + _entitiesContainerView.stickersContext = _stickersContext; _entitiesContainerView.entitySelected = ^(TGPhotoPaintEntityView *sender) { __strong TGPhotoPaintController *strongSelf = weakSelf; @@ -377,6 +378,11 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; [self controllerInsetUpdated:UIEdgeInsetsZero]; } +- (void)setStickersContext:(id)stickersContext { + _stickersContext = stickersContext; + _entitiesContainerView.stickersContext = stickersContext; +} + - (void)setupCanvas { __weak TGPhotoPaintController *weakSelf = self; @@ -451,7 +457,14 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; [super viewDidLoad]; PGPhotoEditor *photoEditor = _photoEditor; - [self setupWithPaintingData:photoEditor.paintingData]; + [_entitiesContainerView setupWithPaintingData:photoEditor.paintingData]; + for (TGPhotoPaintEntityView *view in _entitiesContainerView.subviews) + { + if (![view isKindOfClass:[TGPhotoPaintEntityView class]]) + continue; + + [self _commonEntityViewSetup:view]; + } __weak TGPhotoPaintController *weakSelf = self; _undoManager.historyChanged = ^ @@ -614,17 +627,6 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; #pragma mark - Data Handling -- (void)setupWithPaintingData:(TGPaintingData *)paintingData -{ - if (paintingData == nil) - return; - - for (TGPhotoPaintEntity *entity in paintingData.entities) - { - [self _createEntityViewWithEntity:entity]; - } -} - - (TGPaintingData *)_prepareResultData { if (_resultData != nil) @@ -782,12 +784,14 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; TGPhotoPaintEntityView *entityView = nil; if ([entity isKindOfClass:[TGPhotoPaintStickerEntity class]]) { - TGPhotoStickerEntityView *stickerView = [self _createStickerViewWithEntity:(TGPhotoPaintStickerEntity *)entity]; + TGPhotoStickerEntityView *stickerView = (TGPhotoStickerEntityView *)[_entitiesContainerView createEntityViewWithEntity:entity]; + [self _commonEntityViewSetup:stickerView]; entityView = stickerView; } else { - TGPhotoTextEntityView *textView = [self _createTextViewWithEntity:(TGPhotoPaintTextEntity *)entity]; + TGPhotoTextEntityView *textView = (TGPhotoTextEntityView *)[_entitiesContainerView createEntityViewWithEntity:entity]; + [self _commonEntityViewSetup:textView]; entityView = textView; } @@ -934,13 +938,10 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; } } -- (void)_commonEntityViewSetup:(TGPhotoPaintEntityView *)entityView entity:(TGPhotoPaintEntity *)entity +- (void)_commonEntityViewSetup:(TGPhotoPaintEntityView *)entityView { [self hideMenu]; - - entityView.transform = CGAffineTransformRotate(CGAffineTransformMakeScale(entity.scale, entity.scale), entity.angle); - entityView.center = entity.position; - + __weak TGPhotoPaintController *weakSelf = self; entityView.shouldTouchEntity = ^bool (__unused TGPhotoPaintEntityView *sender) { @@ -967,6 +968,29 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; [strongSelf updateActionsView]; }; + + if ([entityView isKindOfClass:[TGPhotoTextEntityView class]]) { + TGPhotoTextEntityView *textView = (TGPhotoTextEntityView *)entityView; + + __weak TGPhotoPaintController *weakSelf = self; + textView.beganEditing = ^(TGPhotoTextEntityView *sender) + { + __strong TGPhotoPaintController *strongSelf = weakSelf; + if (strongSelf == nil) + return; + + [strongSelf bringTextEntityViewFront:sender]; + }; + + textView.finishedEditing = ^(__unused TGPhotoTextEntityView *sender) + { + __strong TGPhotoPaintController *strongSelf = weakSelf; + if (strongSelf == nil) + return; + + [strongSelf sendTextEntityViewBack]; + }; + } } - (void)_registerEntityRemovalUndo:(TGPhotoPaintEntity *)entity @@ -977,55 +1001,6 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; }]; } -- (TGPhotoPaintEntityView *)_createEntityViewWithEntity:(TGPhotoPaintEntity *)entity -{ - if ([entity isKindOfClass:[TGPhotoPaintStickerEntity class]]) - return [self _createStickerViewWithEntity:(TGPhotoPaintStickerEntity *)entity]; - else if ([entity isKindOfClass:[TGPhotoPaintTextEntity class]]) - return [self _createTextViewWithEntity:(TGPhotoPaintTextEntity *)entity]; - - return nil; -} - -- (TGPhotoStickerEntityView *)_createStickerViewWithEntity:(TGPhotoPaintStickerEntity *)entity -{ - TGPhotoStickerEntityView *stickerView = [[TGPhotoStickerEntityView alloc] initWithEntity:entity context:self.stickersContext]; - [self _commonEntityViewSetup:stickerView entity:entity]; - [_entitiesContainerView addSubview:stickerView]; - - return stickerView; -} - -- (TGPhotoTextEntityView *)_createTextViewWithEntity:(TGPhotoPaintTextEntity *)entity -{ - TGPhotoTextEntityView *textView = [[TGPhotoTextEntityView alloc] initWithEntity:entity]; - [textView sizeToFit]; - - __weak TGPhotoPaintController *weakSelf = self; - textView.beganEditing = ^(TGPhotoTextEntityView *sender) - { - __strong TGPhotoPaintController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - [strongSelf bringTextEntityViewFront:sender]; - }; - - textView.finishedEditing = ^(__unused TGPhotoTextEntityView *sender) - { - __strong TGPhotoPaintController *strongSelf = weakSelf; - if (strongSelf == nil) - return; - - [strongSelf sendTextEntityViewBack]; - }; - - [self _commonEntityViewSetup:textView entity:entity]; - [_entitiesContainerView addSubview:textView]; - - return textView; -} - #pragma mark Stickers - (void)presentStickersView @@ -1034,7 +1009,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; _stickersContext.presentStickersController(^(id document, bool animated, UIView *view, CGRect rect) { __strong TGPhotoPaintController *strongSelf = weakSelf; if (strongSelf != nil) { - UIView *snapshot = [view snapshotViewAfterScreenUpdates:false]; +// UIView *snapshot = [view snapshotViewAfterScreenUpdates:false]; [strongSelf createNewStickerWithDocument:document animated:animated transitionPoint:CGPointZero stickersView:nil snapshotView:nil]; } }); @@ -1092,7 +1067,8 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; TGPhotoPaintStickerEntity *entity = [[TGPhotoPaintStickerEntity alloc] initWithDocument:document baseSize:[self _stickerBaseSizeForCurrentPainting] animated:animated]; [self _setStickerEntityPosition:entity]; - TGPhotoStickerEntityView *stickerView = [self _createStickerViewWithEntity:entity]; + TGPhotoStickerEntityView *stickerView = (TGPhotoStickerEntityView *)[_entitiesContainerView createEntityViewWithEntity:entity]; + [self _commonEntityViewSetup:stickerView]; // stickerView.hidden = true; CGFloat rotation = entity.angle - [self startRotation]; @@ -1137,7 +1113,8 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; entity.position = [self startPositionRelativeToEntity:nil]; entity.angle = [self startRotation]; - TGPhotoTextEntityView *textView = [self _createTextViewWithEntity:entity]; + TGPhotoTextEntityView *textView = (TGPhotoTextEntityView *)[_entitiesContainerView createEntityViewWithEntity:entity]; + [self _commonEntityViewSetup:textView]; [self selectEntityView:textView]; @@ -1293,7 +1270,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; return [self _brushBaseWeightForCurrentPainting] + [self _brushWeightRangeForCurrentPainting] * size; } -- (CGSize)maximumPaintingSize ++ (CGSize)maximumPaintingSize { static dispatch_once_t onceToken; static CGSize size; @@ -1511,11 +1488,15 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; - (CGSize)fittedContentSize { - CGSize fittedOriginalSize = TGScaleToSize(_photoEditor.originalSize, [self maximumPaintingSize]); - CGFloat scale = fittedOriginalSize.width / _photoEditor.originalSize.width; + return [TGPhotoPaintController fittedContentSize:_photoEditor.cropRect orientation:_photoEditor.cropOrientation originalSize:_photoEditor.originalSize]; +} + ++ (CGSize)fittedContentSize:(CGRect)cropRect orientation:(UIImageOrientation)orientation originalSize:(CGSize)originalSize { + CGSize fittedOriginalSize = TGScaleToSize(originalSize, [TGPhotoPaintController maximumPaintingSize]); + CGFloat scale = fittedOriginalSize.width / originalSize.width; - CGSize size = CGSizeMake(_photoEditor.cropRect.size.width * scale, _photoEditor.cropRect.size.height * scale); - if (_photoEditor.cropOrientation == UIImageOrientationLeft || _photoEditor.cropOrientation == UIImageOrientationRight) + CGSize size = CGSizeMake(cropRect.size.width * scale, cropRect.size.height * scale); + if (orientation == UIImageOrientationLeft || orientation == UIImageOrientationRight) size = CGSizeMake(size.height, size.width); return CGSizeMake(floor(size.width), floor(size.height)); @@ -1523,20 +1504,29 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; - (CGRect)fittedCropRect:(bool)originalSize { - CGSize fittedOriginalSize = TGScaleToSize(_photoEditor.originalSize, [self maximumPaintingSize]); - CGFloat scale = fittedOriginalSize.width / _photoEditor.originalSize.width; + return [TGPhotoPaintController fittedCropRect:_photoEditor.cropRect originalSize:_photoEditor.originalSize keepOriginalSize:originalSize]; +} + ++ (CGRect)fittedCropRect:(CGRect)cropRect originalSize:(CGSize)originalSize keepOriginalSize:(bool)keepOriginalSize { + CGSize fittedOriginalSize = TGScaleToSize(originalSize, [TGPhotoPaintController maximumPaintingSize]); + CGFloat scale = fittedOriginalSize.width / originalSize.width; CGSize size = fittedOriginalSize; - if (!originalSize) - size = CGSizeMake(_photoEditor.cropRect.size.width * scale, _photoEditor.cropRect.size.height * scale); + if (!keepOriginalSize) + size = CGSizeMake(cropRect.size.width * scale, cropRect.size.height * scale); - return CGRectMake(-_photoEditor.cropRect.origin.x * scale, -_photoEditor.cropRect.origin.y * scale, size.width, size.height); + return CGRectMake(-cropRect.origin.x * scale, -cropRect.origin.y * scale, size.width, size.height); } - (CGPoint)fittedCropCenterScale:(CGFloat)scale { - CGSize size = CGSizeMake(_photoEditor.cropRect.size.width * scale, _photoEditor.cropRect.size.height * scale); - CGRect rect = CGRectMake(_photoEditor.cropRect.origin.x * scale, _photoEditor.cropRect.origin.y * scale, size.width, size.height); + return [TGPhotoPaintController fittedCropRect:_photoEditor.cropRect centerScale:scale]; +} + ++ (CGPoint)fittedCropRect:(CGRect)cropRect centerScale:(CGFloat)scale +{ + CGSize size = CGSizeMake(cropRect.size.width * scale, cropRect.size.height * scale); + CGRect rect = CGRectMake(cropRect.origin.x * scale, cropRect.origin.y * scale, size.width, size.height); return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); } @@ -1615,10 +1605,6 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; if (ABS(maxScale - minScale) < 0.01f) maxScale = minScale; - - if (iosMajorVersion() >= 11) { - _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - } _scrollView.contentInset = UIEdgeInsetsZero; if (_scrollView.minimumZoomScale != 0.05f) @@ -1751,7 +1737,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; _entitiesContainerView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); _entitiesContainerView.transform = CGAffineTransformMakeRotation(_photoEditor.cropRotation); - CGSize fittedOriginalSize = TGScaleToSize(_photoEditor.originalSize, [self maximumPaintingSize]); + CGSize fittedOriginalSize = TGScaleToSize(_photoEditor.originalSize, [TGPhotoPaintController maximumPaintingSize]); CGSize rotatedSize = TGRotatedContentSize(fittedOriginalSize, _photoEditor.cropRotation); CGPoint centerPoint = CGPointMake(rotatedSize.width / 2.0f, rotatedSize.height / 2.0f); @@ -2269,18 +2255,9 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; - (void)_setStickerEntityPosition:(TGPhotoPaintStickerEntity *)entity { - TGDocumentMediaAttachment *document = entity.document; - TGDocumentAttributeSticker *sticker = nil; -// for (id attribute in document.attributes) -// { -// if ([attribute isKindOfClass:[TGDocumentAttributeSticker class]]) -// { -// sticker = (TGDocumentAttributeSticker *)attribute; -// break; -// } -// } - - TGPhotoMaskPosition *position = nil; // [self _positionForMask:sticker documentId:document.documentId]; + TGStickerMaskDescription *mask = [_stickersContext maskDescriptionForDocument:entity.document]; + int64_t documentId = [_stickersContext documentIdForDocument:entity.document]; + TGPhotoMaskPosition *position = [self _positionForMaskDescription:mask documentId:documentId]; if (position != nil) { entity.position = position.center; @@ -2294,12 +2271,12 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; } } -- (TGPhotoMaskPosition *)_positionForMask:(TGDocumentAttributeSticker *)sticker documentId:(int64_t)documentId +- (TGPhotoMaskPosition *)_positionForMaskDescription:(TGStickerMaskDescription *)mask documentId:(int64_t)documentId { - if (sticker.mask == nil) + if (mask == nil) return nil; - TGPhotoMaskAnchor anchor = [TGPhotoMaskPosition anchorOfMask:sticker.mask]; + TGPhotoMaskAnchor anchor = [TGPhotoMaskPosition anchorOfMask:mask]; if (anchor == TGPhotoMaskAnchorNone) return nil; @@ -2352,12 +2329,12 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; break; } - CGFloat scale = referenceWidth / baseSize.width * sticker.mask.zoom; + CGFloat scale = referenceWidth / baseSize.width * mask.zoom; - CGPoint xComp = CGPointMake(sin(M_PI_2 - angle) * referenceWidth * sticker.mask.point.x, - cos(M_PI_2 - angle) * referenceWidth * sticker.mask.point.x); - CGPoint yComp = CGPointMake(cos(M_PI_2 + angle) * referenceWidth * sticker.mask.point.y, - sin(M_PI_2 + angle) * referenceWidth * sticker.mask.point.y); + CGPoint xComp = CGPointMake(sin(M_PI_2 - angle) * referenceWidth * mask.point.x, + cos(M_PI_2 - angle) * referenceWidth * mask.point.x); + CGPoint yComp = CGPointMake(cos(M_PI_2 + angle) * referenceWidth * mask.point.y, + sin(M_PI_2 + angle) * referenceWidth * mask.point.y); CGPoint position = CGPointMake(referencePoint.x + xComp.x + yComp.x, referencePoint.y + xComp.y + yComp.y); @@ -2425,21 +2402,13 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; continue; TGPhotoPaintStickerEntity *entity = view.entity; - TGDocumentMediaAttachment *document = entity.document; - TGDocumentAttributeSticker *sticker = nil; - for (id attribute in document.attributes) - { - if ([attribute isKindOfClass:[TGDocumentAttributeSticker class]]) - { - sticker = (TGDocumentAttributeSticker *)attribute; - break; - } - } - - if ([TGPhotoMaskPosition anchorOfMask:sticker.mask] != anchor) + TGStickerMaskDescription *mask = [_stickersContext maskDescriptionForDocument:view.entity.document]; + int64_t maskDocumentId = [_stickersContext documentIdForDocument:entity.document]; + + if ([TGPhotoMaskPosition anchorOfMask:mask] != anchor) continue; - if ((documentId == document.documentId || _faces.count > 1) && TGPaintDistance(entity.position, anchorPoint) < minDistance) + if ((documentId == maskDocumentId || _faces.count > 1) && TGPaintDistance(entity.position, anchorPoint) < minDistance) return true; } diff --git a/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m b/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m index 666333a543..b5584c04d0 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m +++ b/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m @@ -1,6 +1,6 @@ #import "TGPhotoVideoEditor.h" -#import "TGMediaEditingContext.h"b +#import "TGMediaEditingContext.h" #import "TGMediaPickerGalleryModel.h" #import "TGMediaPickerGalleryPhotoItem.h" @@ -10,7 +10,7 @@ @implementation TGPhotoVideoEditor -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName stickersContext:(id)stickersContext completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed { id windowManager = [context makeOverlayWindowManager]; id windowContext = [windowManager context]; @@ -28,6 +28,7 @@ else galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:item]; galleryItem.editingContext = editingContext; + galleryItem.stickersContext = stickersContext; TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:true allowCaptionEntities:true hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName]; model.controller = galleryController; diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift index d267bba071..36ede9e279 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift @@ -256,7 +256,7 @@ public func legacyAttachmentMenu(context: AccountContext, peer: Peer, editMediaO present(legacyController, nil) - TGPhotoVideoEditor.present(with: legacyController.context, controller: emptyController, caption: "", entities: [], withItem: item, recipientName: recipientName, completion: { result, editingContext in + TGPhotoVideoEditor.present(with: legacyController.context, controller: emptyController, caption: "", entities: [], withItem: item, recipientName: recipientName, stickersContext: paintStickersContext, completion: { result, editingContext in let intent: TGMediaAssetsControllerIntent = TGMediaAssetsControllerSendMediaIntent let signals = TGCameraController.resultSignals(for: nil, editingContext: editingContext, currentItem: result as! TGMediaSelectableItem, storeAssets: false, saveEditedPhotos: false, descriptionGenerator: legacyAssetPickerItemGenerator()) sendMessagesWithSignals(signals, false, 0) diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift index 57096e96dc..9a955b3251 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift @@ -19,11 +19,21 @@ public func guessMimeTypeByFileExtension(_ ext: String) -> String { return TGMimeTypeMap.mimeType(forExtension: ext) ?? "application/binary" } -public func configureLegacyAssetPicker(_ controller: TGMediaAssetsController, context: AccountContext, peer: Peer, captionsEnabled: Bool = true, storeCreatedAssets: Bool = true, showFileTooltip: Bool = false, initialCaption: String, hasSchedule: Bool, presentWebSearch: (() -> Void)?, presentSelectionLimitExceeded: @escaping () -> Void, presentSchedulePicker: @escaping (@escaping (Int32) -> Void) -> Void) { +public func configureLegacyAssetPicker(_ controller: TGMediaAssetsController, context: AccountContext, peer: Peer, captionsEnabled: Bool = true, storeCreatedAssets: Bool = true, showFileTooltip: Bool = false, initialCaption: String, hasSchedule: Bool, presentWebSearch: (() -> Void)?, presentSelectionLimitExceeded: @escaping () -> Void, presentSchedulePicker: @escaping (@escaping (Int32) -> Void) -> Void, presentStickers: @escaping (@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> Void) { let isSecretChat = peer.id.namespace == Namespaces.Peer.SecretChat + let paintStickersContext = LegacyPaintStickersContext(context: context) + paintStickersContext.presentStickersController = { completion in + presentStickers({ file, animated, view, rect in + let coder = PostboxEncoder() + coder.encodeRootObject(file) + completion?(coder.makeData(), animated, view, rect) + }) + } + controller.captionsEnabled = captionsEnabled controller.inhibitDocumentCaptions = false + controller.stickersContext = paintStickersContext controller.suggestionContext = legacySuggestionContext(context: context, peerId: peer.id) if peer.id != context.account.peerId { if peer is TelegramUser { diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift index 60b4f7193f..0389c00eb1 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift @@ -50,6 +50,10 @@ class LegacyPaintStickerView: UIView, TGPhotoPaintStickerRenderView { } } + func documentId() -> Int64 { + return self.file.fileId.id + } + private func setup() { if let dimensions = self.file.dimensions { if self.file.isAnimatedSticker { diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift index a8be5baec7..fa40030035 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift @@ -301,6 +301,41 @@ public final class LegacyPaintStickersContext: NSObject, TGPhotoPaintStickersCon public init(context: AccountContext) { self.context = context } + + public func documentId(forDocument document: Any!) -> Int64 { + if let data = document as? Data{ + let decoder = PostboxDecoder(buffer: MemoryBuffer(data: data)) + if let file = decoder.decodeRootObject() as? TelegramMediaFile { + return file.fileId.id + } else { + return 0 + } + } else { + return 0 + } + } + + public func maskDescription(forDocument document: Any!) -> TGStickerMaskDescription? { + if let data = document as? Data{ + let decoder = PostboxDecoder(buffer: MemoryBuffer(data: data)) + if let file = decoder.decodeRootObject() as? TelegramMediaFile { + for attribute in file.attributes { + if case let .Sticker(_, _, maskData) = attribute { + if let maskData = maskData { + return TGStickerMaskDescription(n: maskData.n, point: CGPoint(x: maskData.x, y: maskData.y), zoom: CGFloat(maskData.zoom)) + } else { + return nil + } + } + } + return nil + } else { + return nil + } + } else { + return nil + } + } public func stickerView(forDocument document: Any!) -> (UIView & TGPhotoPaintStickerRenderView)! { if let data = document as? Data{ diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 13a1d8e838..19a2e21bec 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -6027,6 +6027,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } }) } + }, presentStickers: { [weak self] completion in + if let strongSelf = self { + let controller = DrawingStickersScreen(context: strongSelf.context, selectSticker: { fileReference, node, rect in + completion(fileReference.media, fileReference.media.isAnimatedSticker, node.view, rect) + return true + }) + strongSelf.present(controller, in: .window(.root)) + } }) } }, openFileGallery: { @@ -6268,6 +6276,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } }) } + }, presentStickers: { [weak self] completion in + if let strongSelf = self { + let controller = DrawingStickersScreen(context: strongSelf.context, selectSticker: { fileReference, node, rect in + completion(fileReference.media, fileReference.media.isAnimatedSticker, node.view, rect) + return true + }) + strongSelf.present(controller, in: .window(.root)) + } }) controller.descriptionGenerator = legacyAssetPickerItemGenerator() controller.completionBlock = { [weak legacyController] signals, silentPosting, scheduleTime in diff --git a/submodules/TelegramUI/Sources/LegacyCamera.swift b/submodules/TelegramUI/Sources/LegacyCamera.swift index 3a04cedcb3..aa7e83fbb3 100644 --- a/submodules/TelegramUI/Sources/LegacyCamera.swift +++ b/submodules/TelegramUI/Sources/LegacyCamera.swift @@ -11,7 +11,7 @@ import ShareController import LegacyUI import LegacyMediaPickerUI -func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAttachmentCameraView?, menuController: TGMenuSheetController?, parentController: ViewController, editingMedia: Bool, saveCapturedPhotos: Bool, mediaGrouping: Bool, initialCaption: String, hasSchedule: Bool, sendMessagesWithSignals: @escaping ([Any]?, Bool, Int32) -> Void, recognizedQRCode: @escaping (String) -> Void = { _ in }, presentSchedulePicker: @escaping (@escaping (Int32) -> Void) -> Void) { +func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAttachmentCameraView?, menuController: TGMenuSheetController?, parentController: ViewController, editingMedia: Bool, saveCapturedPhotos: Bool, mediaGrouping: Bool, initialCaption: String, hasSchedule: Bool, sendMessagesWithSignals: @escaping ([Any]?, Bool, Int32) -> Void, recognizedQRCode: @escaping (String) -> Void = { _ in }, presentSchedulePicker: @escaping (@escaping (Int32) -> Void) -> Void, presentStickers: @escaping (@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> Void) { let presentationData = context.sharedContext.currentPresentationData.with { $0 } let legacyController = LegacyController(presentation: .custom, theme: presentationData.theme) legacyController.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .portrait, compactSize: .portrait) @@ -58,6 +58,16 @@ func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAt } } + let paintStickersContext = LegacyPaintStickersContext(context: context) + paintStickersContext.presentStickersController = { completion in + presentStickers({ file, animated, view, rect in + let coder = PostboxEncoder() + coder.encodeRootObject(file) + completion?(coder.makeData(), animated, view, rect) + }) + } + + controller.stickersContext = paintStickersContext controller.isImportant = true controller.shouldStoreCapturedAssets = saveCapturedPhotos && !isSecretChat controller.allowCaptions = true diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift index aae94fae52..0107068844 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift @@ -112,8 +112,8 @@ class LegacyWebSearchItem: NSObject, TGMediaEditableItem, TGMediaSelectableItem private class LegacyWebSearchGalleryItem: TGModernGalleryImageItem, TGModernGalleryEditableItem, TGModernGallerySelectableItem { var selectionContext: TGMediaSelectionContext! - var editingContext: TGMediaEditingContext! + var stickersContext: TGPhotoPaintStickersContext! let item: LegacyWebSearchItem init(item: LegacyWebSearchItem) {