-
Notifications
You must be signed in to change notification settings - Fork 2
/
InfiniteScrollItem.qml
72 lines (63 loc) · 2.03 KB
/
InfiniteScrollItem.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
import QtQuick 2.3
/*!
\qmltype InfiniteScrollItem
\inqmlmodule Bacon2D
\inherits Item
\ingroup graphics
\brief Enable an Item to do a infinite scroll. Good for moving background
*/
Item {
id:root
/*!
\qmlproperty Item InfiniteScrollItem::target
\brief \l Item that will used as texture for scrolling effect.
*/
default property Item target
/*!
\qmlproperty Item InfiniteScrollItem::offsetX
\brief \l The amount of vertical pixels that will be shifted.
*/
property real offsetX: 0;
/*!
\qmlproperty Item InfiniteScrollItem::offsetY
\brief \l The amount of horizontal pixels that will be shifted
*/
property real offsetY: 0;
implicitWidth: target.width
implicitHeight: target.height
ShaderEffectSource{
id:shaderSource
width: target.width; height:target.height
sourceItem: target
hideSource:true
visible:false
}
ShaderEffect {
id:shader
width: target.width; height:target.height
property real shaderXStep: target ? offsetX / target.height : 0
property real shaderYStep: target ? offsetY / target.width : 0
property Item target: shaderSource
blending: false
vertexShader: "
uniform highp mat4 qt_Matrix;
attribute highp vec4 qt_Vertex;
attribute highp vec2 qt_MultiTexCoord0;
varying highp vec2 coord;
void main() {
coord = qt_MultiTexCoord0;
gl_Position = qt_Matrix * qt_Vertex;
}"
fragmentShader: "
uniform float width;
uniform lowp float qt_Opacity;
uniform sampler2D target;
uniform float shaderXStep;
uniform float shaderYStep;
varying highp vec2 coord;
void main(void) {
vec4 texel = texture2D(target, vec2(mod(coord.x + shaderXStep, 1.0), mod(coord.y + shaderYStep, 1.0)));
gl_FragColor = texel * qt_Opacity;
} "
}
}