diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m index 7f8e0c90a0..4e8c6bcaea 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m @@ -800,7 +800,7 @@ CGRect fittedCropRect = [TGPhotoPaintController fittedCropRect:cropRect originalSize:originalSize keepOriginalSize:false]; _contentWrapperView.frame = CGRectMake(0.0f, 0.0f, fittedContentSize.width, fittedContentSize.height); - CGFloat contentScale = ratio;//_contentView.bounds.size.width / fittedCropRect.size.width; + CGFloat contentScale = ratio; _contentWrapperView.transform = CGAffineTransformMakeScale(contentScale, contentScale); _contentWrapperView.frame = CGRectMake(0.0f, 0.0f, _contentView.bounds.size.width, _contentView.bounds.size.height); diff --git a/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m b/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m index 7c8c1d69e0..ddc7a2d393 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m +++ b/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m @@ -42,6 +42,8 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200; CGFloat _currentDiameter; + UIView *_entitiesWrapperView; + __weak PGPhotoEditorView *_fullPreviewView; __weak UIImageView *_fullPaintingView; __weak TGPhotoEntitiesContainerView *_fullEntitiesView; @@ -91,9 +93,16 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200; _fullPaintingView.frame = _fullPreviewView.frame; [_wrapperView addSubview:_fullPaintingView]; + _entitiesWrapperView = [[UIView alloc] init]; _fullEntitiesView = fullEntitiesView; - _fullEntitiesView.frame = _fullPreviewView.frame; - [_wrapperView addSubview:_fullEntitiesView]; + _fullEntitiesView.frame = CGRectMake(0.0, 0.0, _fullEntitiesView.frame.size.width, _fullEntitiesView.frame.size.height); + _entitiesWrapperView.frame = _fullEntitiesView.frame; + + CGFloat entitiesScale = _fullPreviewView.frame.size.width / _entitiesWrapperView.frame.size.width; + _entitiesWrapperView.transform = CGAffineTransformMakeScale(entitiesScale, entitiesScale); + _entitiesWrapperView.frame = _fullPreviewView.frame; + [_entitiesWrapperView addSubview:_fullEntitiesView]; + [_wrapperView addSubview:_entitiesWrapperView]; _flashView = [[UIView alloc] init]; _flashView.alpha = 0.0; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 52a42133d0..ed1d18f949 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -346,7 +346,8 @@ _fullEntitiesView = [[TGPhotoEntitiesContainerView alloc] init]; _fullEntitiesView.userInteractionEnabled = false; - _fullEntitiesView.frame = _fullPreviewView.frame; + CGRect rect = [TGPhotoPaintController fittedCropRect:_photoEditor.cropRect originalSize:_photoEditor.originalSize keepOriginalSize:true]; + _fullEntitiesView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); } _dotMarkerView = [[UIImageView alloc] initWithImage:TGCircleImage(7.0, [TGPhotoEditorInterfaceAssets accentColor])]; diff --git a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m index 05fc3583a3..e554aef9a2 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m @@ -98,6 +98,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; id _stickersScreen; bool _appeared; + bool _skipEntitiesSetup; TGPhotoPaintFont *_selectedTextFont; TGPhotoPaintTextEntityStyle _selectedTextStyle; @@ -152,6 +153,9 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; self.photoEditor = photoEditor; self.previewView = previewView; _entitiesContainerView = entitiesView; + if (entitiesView != nil) { + _skipEntitiesSetup = true; + } entitiesView.userInteractionEnabled = true; _brushes = @ @@ -509,7 +513,9 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; [super viewDidLoad]; PGPhotoEditor *photoEditor = _photoEditor; - [_entitiesContainerView setupWithPaintingData:photoEditor.paintingData]; + if (!_skipEntitiesSetup) { + [_entitiesContainerView setupWithPaintingData:photoEditor.paintingData]; + } for (TGPhotoPaintEntityView *view in _entitiesContainerView.subviews) { if (![view isKindOfClass:[TGPhotoPaintEntityView class]]) diff --git a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m index 46c4751724..1d610335e2 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m @@ -22,6 +22,9 @@ #import "TGPhotoEditorPreviewView.h" #import "TGPhotoEditorHUDView.h" #import "TGPhotoEditorSparseView.h" +#import "TGPhotoEntitiesContainerView.h" + +#import "TGPhotoPaintController.h" const CGFloat TGPhotoEditorToolsPanelSize = 180.0f; const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize + 40.0f; @@ -53,6 +56,8 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize bool _preview; TGPhotoEditorTab _currentTab; + UIView *_entitiesWrapperView; + UIView *_toolAreaView; UIView *_portraitToolControlView; UIView *_landscapeToolControlView; @@ -101,6 +106,29 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize _landscapeCollectionView.toolsDataSource = nil; } +- (void)layoutEntitiesView { + CGSize fittedContentSize = [TGPhotoPaintController fittedContentSize:_photoEditor.cropRect orientation:_photoEditor.cropOrientation originalSize:_photoEditor.originalSize]; + CGRect fittedCropRect = [TGPhotoPaintController fittedCropRect:_photoEditor.cropRect originalSize:_photoEditor.originalSize keepOriginalSize:false]; + _entitiesWrapperView.frame = CGRectMake(0.0f, 0.0f, fittedContentSize.width, fittedContentSize.height); + + CGRect rect = [TGPhotoPaintController fittedCropRect:self.photoEditor.cropRect originalSize:self.photoEditor.originalSize keepOriginalSize:true]; + _entitiesView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); + _entitiesView.transform = CGAffineTransformMakeRotation(_photoEditor.cropRotation); + + CGSize fittedOriginalSize = TGScaleToSize(_photoEditor.originalSize, [TGPhotoPaintController maximumPaintingSize]); + CGSize rotatedSize = TGRotatedContentSize(fittedOriginalSize, _photoEditor.cropRotation); + CGPoint centerPoint = CGPointMake(rotatedSize.width / 2.0f, rotatedSize.height / 2.0f); + + CGFloat scale = fittedOriginalSize.width / _photoEditor.originalSize.width; + CGPoint offset = TGPaintSubtractPoints(centerPoint, [TGPhotoPaintController fittedCropRect:_photoEditor.cropRect centerScale:scale]); + + CGPoint boundsCenter = TGPaintCenterOfRect(_entitiesWrapperView.bounds); + _entitiesView.center = TGPaintAddPoints(boundsCenter, offset); + if (_entitiesView.superview != _entitiesWrapperView) { + [_entitiesWrapperView addSubview:_entitiesView]; + } +} + - (void)loadView { [super loadView]; @@ -191,6 +219,10 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize _wrapperView = [[TGPhotoEditorSparseView alloc] initWithFrame:CGRectZero]; [self.view addSubview:_wrapperView]; + _entitiesWrapperView = [[UIView alloc] init]; + _entitiesWrapperView.userInteractionEnabled = false; + [_wrapperView addSubview:_entitiesWrapperView]; + _portraitToolsWrapperView = [[UIView alloc] initWithFrame:CGRectZero]; _portraitToolsWrapperView.alpha = 0.0f; [_wrapperView addSubview:_portraitToolsWrapperView]; @@ -977,6 +1009,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize [_landscapeCollectionView.collectionViewLayout invalidateLayout]; [self updatePreviewView]; + [self layoutEntitiesView]; } - (TGPhotoEditorTab)availableTabs diff --git a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift index 323e978896..d3ee0bcda8 100644 --- a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift +++ b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift @@ -1307,7 +1307,6 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { strongSelf.hiddenPane?.removeFromSupernode() strongSelf.hiddenListView?.removeFromSupernode() strongSelf.isHidden = true - strongSelf.dismiss?() } }) }