mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
[WIP] Stickers editor
This commit is contained in:
parent
a51c65e268
commit
1e155f3243
4 changed files with 18 additions and 17 deletions
|
|
@ -544,7 +544,7 @@ private final class StickerPackContainer: ASDisplayNode {
|
|||
if let strongSelf = self {
|
||||
let _ = (strongSelf.context.engine.stickers.toggleStickerSaved(file: item.file, saved: !isStarred)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] result in
|
||||
if let self, let contorller = self.controller, case .generic = result {
|
||||
if let self, let contorller = self.controller {
|
||||
contorller.present(UndoOverlayController(presentationData: self.presentationData, content: .sticker(context: context, file: item.file, loop: true, title: nil, text: !isStarred ? self.presentationData.strings.Conversation_StickerAddedToFavorites : self.presentationData.strings.Conversation_StickerRemovedFromFavorites, undoText: nil, customAction: nil), elevatedLayout: false, action: { _ in return false }), in: .window(.root))
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -34,9 +34,6 @@ public func classifyImage(_ image: UIImage) -> Signal<[(String, Float)], NoError
|
|||
subscriber.putNext(filteredResult.map { ($0.identifier, $0.confidence) })
|
||||
subscriber.putCompletion()
|
||||
}
|
||||
#if targetEnvironment(simulator)
|
||||
request.usesCPUOnly = true
|
||||
#endif
|
||||
try? handler.perform([request])
|
||||
return ActionDisposable {
|
||||
request.cancel()
|
||||
|
|
|
|||
|
|
@ -3437,7 +3437,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||
return
|
||||
}
|
||||
let currentTimestamp = CACurrentMediaTime()
|
||||
if let previousPanTimestamp = self.previousPanTimestamp, currentTimestamp - previousPanTimestamp < 0.016 {
|
||||
if let previousPanTimestamp = self.previousPanTimestamp, currentTimestamp - previousPanTimestamp < 0.016, case .changed = gestureRecognizer.state {
|
||||
return
|
||||
}
|
||||
self.previousPanTimestamp = currentTimestamp
|
||||
|
|
@ -3449,7 +3449,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||
return
|
||||
}
|
||||
let currentTimestamp = CACurrentMediaTime()
|
||||
if let previousPinchTimestamp = self.previousPinchTimestamp, currentTimestamp - previousPinchTimestamp < 0.016 {
|
||||
if let previousPinchTimestamp = self.previousPinchTimestamp, currentTimestamp - previousPinchTimestamp < 0.016, case .changed = gestureRecognizer.state {
|
||||
return
|
||||
}
|
||||
self.previousPinchTimestamp = currentTimestamp
|
||||
|
|
@ -3461,7 +3461,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||
return
|
||||
}
|
||||
let currentTimestamp = CACurrentMediaTime()
|
||||
if let previousRotateTimestamp = self.previousRotateTimestamp, currentTimestamp - previousRotateTimestamp < 0.016 {
|
||||
if let previousRotateTimestamp = self.previousRotateTimestamp, currentTimestamp - previousRotateTimestamp < 0.016, case .changed = gestureRecognizer.state {
|
||||
return
|
||||
}
|
||||
self.entitiesView.handleRotate(gestureRecognizer)
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ final class StickerCutoutOutlineView: UIView {
|
|||
self.strokeLayer.shadowRadius = 4.0
|
||||
|
||||
self.layer.allowsGroupOpacity = true
|
||||
|
||||
// self.imageLayer.contentsGravity = .resizeAspect
|
||||
|
||||
|
||||
self.layer.addSublayer(self.strokeLayer)
|
||||
self.layer.addSublayer(self.imageLayer)
|
||||
}
|
||||
|
|
@ -95,8 +93,8 @@ final class StickerCutoutOutlineView: UIView {
|
|||
lineEmitterCell.color = UIColor.white.cgColor
|
||||
lineEmitterCell.contents = UIImage(named: "Media Editor/ParticleDot")?.cgImage
|
||||
lineEmitterCell.lifetime = 2.2
|
||||
lineEmitterCell.birthRate = 700
|
||||
lineEmitterCell.scale = 0.17
|
||||
lineEmitterCell.birthRate = 800
|
||||
lineEmitterCell.scale = 0.18
|
||||
lineEmitterCell.alphaSpeed = -0.4
|
||||
|
||||
self.outlineLayer.emitterCells = [lineEmitterCell]
|
||||
|
|
@ -193,6 +191,7 @@ private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaE
|
|||
}
|
||||
let minSide = min(size.width, size.height)
|
||||
let scaledImageSize = image.extent.size.aspectFilled(CGSize(width: minSide, height: minSide))
|
||||
let contourImageSize = image.extent.size.aspectFilled(CGSize(width: 256.0, height: 256.0))
|
||||
|
||||
var contour = findContours(pixelBuffer: pixelBuffer)
|
||||
guard !contour.isEmpty else {
|
||||
|
|
@ -202,10 +201,9 @@ private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaE
|
|||
contour = simplify(contour, tolerance: 1.0)
|
||||
let path = BezierPath(points: contour, smooth: true)
|
||||
|
||||
let firstScale = min(size.width, size.height) / 256.0
|
||||
let secondScale = size.width / 1080.0
|
||||
let contoursScale = min(size.width, size.height) / 256.0
|
||||
let valuesScale = size.width / 1080.0
|
||||
|
||||
var transform = CGAffineTransform.identity
|
||||
let position = values.cropOffset
|
||||
let rotation = values.cropRotation
|
||||
let scale = values.cropScale
|
||||
|
|
@ -215,9 +213,15 @@ private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaE
|
|||
y: (size.height - scaledImageSize.height * scale) / 2.0
|
||||
)
|
||||
|
||||
transform = transform.translatedBy(x: positionOffset.x + position.x * secondScale, y: positionOffset.y + position.y * secondScale)
|
||||
var transform = CGAffineTransform.identity
|
||||
transform = transform.translatedBy(x: contourImageSize.width / 2.0, y: contourImageSize.height / 2.0)
|
||||
transform = transform.rotated(by: rotation)
|
||||
transform = transform.scaledBy(x: scale * firstScale, y: scale * firstScale)
|
||||
transform = transform.translatedBy(x: -contourImageSize.width / 2.0, y: -contourImageSize.height / 2.0)
|
||||
path.apply(transform, scale: 1.0)
|
||||
|
||||
transform = CGAffineTransform.identity
|
||||
transform = transform.translatedBy(x: positionOffset.x + position.x * valuesScale, y: positionOffset.y + position.y * valuesScale)
|
||||
transform = transform.scaledBy(x: scale * contoursScale, y: scale * contoursScale)
|
||||
|
||||
if !path.path.isEmpty {
|
||||
path.apply(transform, scale: scale)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue