-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathInspectorClipView.swift
More file actions
97 lines (89 loc) · 3.36 KB
/
Copy pathInspectorClipView.swift
File metadata and controls
97 lines (89 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Foundation
import SpriteKit
/// A property inspector view for a single clip.
final class InspectorClipView: SKNode {
private var state: MiniCutState!
private var selectionSubscriptions: [Subscription] = []
private var trackId: UUID!
private var clipId: UUID!
private var clip: OffsetClip? {
get { state.timeline[trackId]?[clipId] }
set { state.timeline[trackId]?[clipId] = newValue }
}
private var content: ClipContent? {
get { clip?.clip.content }
set { clip?.clip.content = newValue! }
}
init(
state: MiniCutState,
textFieldSelection: TextFieldSelectionController,
trackId: UUID,
clipId: UUID,
size: CGSize
) {
super.init()
self.state = state
self.trackId = trackId
self.clipId = clipId
var props = [(String, (CGFloat) -> SKNode)]()
switch content {
case .text(let text):
props += [
("Text", { [weak self] in
let textField = TextField(size: CGSize(width: $0, height: ViewDefaults.textFieldHeight), text: text.text) {
guard case .text(var newText) = self?.content else { return }
newText.text = $0
self?.content = .text(newText)
}
self?.selectionSubscriptions.append(textFieldSelection.register(textField: textField))
return textField
}),
("Size", { [weak self] in
Slider<CGFloat>(value: text.size, range: 1..<300, width: $0) {
guard case .text(var newText) = self?.content else { return }
newText.size = $0
self?.content = .text(newText)
}
})
]
case .audiovisual(_):
props += [
("Speed", { [weak self] in
Slider<Double>(value: self?.clip?.clip.speed ?? 1, range: 0.25..<4, width: $0) {
self?.clip?.clip.speed = $0
}
})
]
default:
break
}
props += [
("X", { [weak self] in
Slider<Double>(value: self?.clip?.clip.visualOffsetDx ?? 0, range: -1..<1, width: $0) {
self?.clip?.clip.visualOffsetDx = $0
}
}),
("Y", { [weak self] in
Slider<Double>(value: self?.clip?.clip.visualOffsetDy ?? 0, range: -1..<1, width: $0) {
self?.clip?.clip.visualOffsetDy = $0
}
}),
("Scale", { [weak self] in
Slider<Double>(value: self?.clip?.clip.visualScale ?? 1, range: 0..<4, width: $0) {
self?.clip?.clip.visualScale = $0
}
}),
("Alpha", { [weak self] in
Slider<Double>(value: self?.clip?.clip.visualAlpha ?? 1, range: 0..<1, width: $0) {
self?.clip?.clip.visualAlpha = $0
}
})
]
let form = Form(size: size, childs: props)
form.position = CGPoint(x: -(size.width / 2), y: size.height / 2)
addChild(form)
}
required init?(coder aDecoder: NSCoder) {
nil
}
}