forked from anatolyk82/ShaderTransitionView
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTView.qml
252 lines (214 loc) · 6.81 KB
/
STView.qml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import QtQuick 2.6
import "TransitionEffects"
import ShaderTransitionView 1.0
ShaderTransitionView {
id: root
property int duration: 700
property var itemList: []
property int depth: 0
property string currentItem: ""
property var transitionOptions: { "progress":0.0 }
transition: "Wind"
signal animationStarted();
signal animationCompleted();
property real progress: 0.0
property alias easing: animProperty.easing
/*onDepthChanged: {
console.log("["+itemList + "]:" + depth)
}*/
function push( itemPath )
{
itemList.push( itemPath )
currentItem = itemPath
depth = itemList.length
if( itemList.length > 1 ) {
if( (itemList.length % 2) == 0 ) {
loaderNextItem.source = itemPath
} else {
loaderCurrentItem.source = itemPath
}
loaderShaderEffect.setSource( __graphEffect(), transitionOptions )
} else {
loaderCurrentItem.source = itemPath
}
}
function pop()
{
if( itemList.length > 1 ) {
itemList.pop()
depth = itemList.length
var lastElement = itemList[ (itemList.length-1) ]
if( lastElement.indexOf("ShaderTransitionView::component:") == 0 )
{
var item = topQQuickItem()
if( lengthQQuickStack() > 1 ) {
item = popQQuickItem()
}
if( (itemList.length % 2) == 0 ) {
loaderNextItem.sourceComponent = item
} else {
loaderCurrentItem.sourceComponent = item
}
}
else
{
if( (itemList.length % 2) == 0 ) {
loaderNextItem.source = itemList[ (itemList.length-1) ]
currentItem = loaderNextItem.source
//console.log("(pop) l="+itemList.length + " [" + itemList + "] use NEXT")
} else {
loaderCurrentItem.source = itemList[ (itemList.length-1) ]
currentItem = loaderCurrentItem.source
//console.log("(pop) l="+itemList.length + " [" + itemList + "] use CURR")
}
}
loaderShaderEffect.setSource( __graphEffect(), transitionOptions )
}
}
function clear()
{
clearQQuickStack()
itemList.splice( 0, itemList.length )
depth = itemList.length
}
function top()
{
var lastElement = itemList[ (itemList.length-1) ]
if( lastElement.indexOf("ShaderTransitionView::component:") == 0 )
{
return topQQuickItem()
}
else
{
return lastElement
}
}
function pushItem( item )
{
var cmp = "ShaderTransitionView::component:" + lengthQQuickStack()
pushQQuickItem( item )
itemList.push( cmp )
currentItem = cmp
depth = itemList.length
if( itemList.length > 1 ) {
if( (itemList.length % 2) == 0 ) {
loaderNextItem.sourceComponent = item
} else {
loaderCurrentItem.sourceComponent = item
}
loaderShaderEffect.setSource( __graphEffect(), transitionOptions )
} else {
loaderCurrentItem.sourceComponent = item
}
}
function completeTransition()
{
animProgress.running = false
root.progress = 1.0
}
function __get( index )
{
var item = ""
if( (index < itemList.length) && (index >= 0) )
{
item = itemList[ index ]
currentItem = item
itemList.splice( index, 1 )
depth = itemList.length
if( item.indexOf("ShaderTransitionView::component:") == 0 )
{
var indxInsideStack = item.split(":")[3]
console.log("indxInsideStack="+indxInsideStack)
/*if( (itemList.length % 2) == 0 ) {
loaderNextItem.sourceComponent = getQQuickItem(indxInsideStack)
} else {
loaderCurrentItem.sourceComponent = getQQuickItem(indxInsideStack)
}*/
}
else
{
/*if( (itemList.length % 2) == 0 ) {
loaderNextItem.source = item
} else {
loaderCurrentItem.source = item
}*/
}
}
return item
}
function __graphEffect()
{
return "TransitionEffects/" + transition + ".qml";
}
SequentialAnimation on progress {
id: animProgress
running: false
ScriptAction {
script: {
root.animationStarted()
}
}
PropertyAnimation {
id: animProperty
from: 0.0
to: 1.0
duration: root.duration
}
ScriptAction {
script: {
if( (itemList.length % 2) ) {
loaderNextItem.source = ""
loaderNextItem.sourceComponent = undefined
//console.log("(clear NEXT) l="+itemList.length)
} else {
loaderCurrentItem.source = ""
loaderCurrentItem.sourceComponent = undefined
//console.log("(clear CURR) l="+itemList.length)
}
loaderShaderEffect.source = ""
transitionOptions = { "progress":0.0 }
root.animationCompleted()
}
}
}
Loader {
id: loaderCurrentItem
anchors.fill: parent
}
Loader {
id: loaderNextItem
anchors.fill: parent
}
ShaderEffectSource {
id: textureSource
hideSource: false
}
ShaderEffectSource {
id: textureDestination
hideSource: false
}
Loader {
id: loaderShaderEffect
anchors.fill: parent
onLoaded: {
if( (itemList.length % 2) == 0 ) {
textureSource.sourceItem = loaderCurrentItem.item
textureDestination.sourceItem = loaderNextItem.item
//console.log("(shader) l="+itemList.length + " from CURR to NEXT")
} else {
textureSource.sourceItem = loaderNextItem.item
textureDestination.sourceItem = loaderCurrentItem.item
//console.log("(shader) l="+itemList.length + " from NEXT to CURR")
}
item.srcSampler = textureSource
item.dstSampler = textureDestination
root.progress = 0.0
animProgress.restart()
}
}
Binding {
target: loaderShaderEffect.item
property: "progress"
value: root.progress
}
}